:root {
  --bg: #15081b;
  --bg-deep: #0d0411;
  --surface: rgba(43, 16, 52, 0.92);
  --surface-2: rgba(62, 22, 74, 0.94);
  --surface-3: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.2);
  --text: #fbf7ff;
  --muted: #d8c6e8;
  --dim: #b990d1;
  --primary: #a855f7;
  --primary-2: #ec4899;
  --accent: #22d3ee;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #fb7185;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
}

body[data-theme="blue"] {
  --bg: #071827;
  --bg-deep: #030b14;
  --surface: rgba(14, 36, 58, 0.94);
  --surface-2: rgba(20, 54, 86, 0.94);
  --dim: #9ec7e8;
  --primary: #38bdf8;
  --primary-2: #2563eb;
  --accent: #34d399;
}

body[data-theme="green"] {
  --bg: #061a18;
  --bg-deep: #020d0c;
  --surface: rgba(12, 45, 40, 0.94);
  --surface-2: rgba(16, 71, 62, 0.94);
  --dim: #99f6e4;
  --primary: #10b981;
  --primary-2: #22d3ee;
  --accent: #fde047;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: "Microsoft YaHei", "Trebuchet MS", sans-serif;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,0.025) 1px, transparent 1px),
    radial-gradient(circle at 78% 18%, color-mix(in srgb, var(--primary) 28%, transparent), transparent 30%),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-deep) 100%);
  background-size: 36px 36px, 36px 36px, auto, auto;
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
select { font: inherit; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  overflow: auto;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 92%, #000), color-mix(in srgb, var(--bg-deep) 92%, #000));
  border-right: 1px solid var(--line);
}

.brand {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 68px;
  padding: 8px 8px 16px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  font-size: 24px;
  font-weight: 900;
  box-shadow: 0 0 28px color-mix(in srgb, var(--primary) 42%, transparent);
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.25;
}

.brand-subtitle {
  margin-top: 5px;
  color: var(--dim);
  font-size: 12px;
}

.side-section {
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface) 78%, #000));
  box-shadow: var(--shadow);
}

.section-heading {
  margin-bottom: 12px;
  color: var(--dim);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.upload-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.file-picker,
.primary-btn {
  min-height: 54px;
  border-radius: 8px;
}

.file-picker {
  position: relative;
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.055);
  cursor: pointer;
}

.file-picker input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-icon {
  grid-row: 1 / 3;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--primary) 26%, transparent);
  color: var(--accent);
  font-size: 22px;
  font-weight: 800;
}

.file-picker-static {
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.055);
  min-height: 54px;
  border-radius: 8px;
}

.picker-title {
  min-width: 0;
  font-size: 14px;
  font-weight: 800;
}

.picker-desc {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.retention-preview {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.retention-preview strong {
  color: var(--text);
}

.retention-subheading {
  margin-top: 14px;
}

.primary-btn,
.action-btn {
  display: inline-grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--primary) 55%, transparent);
  color: white;
  font-weight: 800;
  cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 0 24px color-mix(in srgb, var(--primary) 32%, transparent);
  transition: transform 0.15s ease, border-color 0.15s ease, filter 0.15s ease;
}

.action-btn {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
}

.primary-btn:hover,
.action-btn:hover,
.nav-item:hover,
.theme-dot:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.primary-btn:disabled,
.primary-btn.is-busy {
  cursor: wait;
  opacity: 0.78;
  filter: saturate(0.8);
  transform: none;
}

.retention-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.retention-controls label {
  display: grid;
  gap: 6px;
  color: var(--dim);
  font-size: 12px;
  font-weight: 800;
}

.retention-controls input,
.retention-controls select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
}

.retention-controls option {
  color: #111827;
}

.theme-switcher {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.theme-dot {
  display: grid;
  place-items: center;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  cursor: pointer;
}

.theme-dot span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  box-shadow: 0 0 18px currentColor;
}

.theme-dot.is-active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.nav-box {
  display: grid;
  gap: 7px;
}

.nav-item {
  width: 100%;
  min-height: 39px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.045);
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.nav-item.is-active {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 48%, transparent);
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--primary) 28%, transparent), rgba(255,255,255,0.04));
}

.workspace {
  min-width: 0;
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  min-height: 76px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--surface-2), color-mix(in srgb, var(--surface) 72%, #000));
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.status-pill,
.status-chip {
  display: inline-grid;
  place-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 8px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  font-size: 13px;
  font-weight: 800;
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.flash {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.flash-error { border-color: color-mix(in srgb, var(--danger) 55%, transparent); }
.flash-warning { border-color: color-mix(in srgb, var(--warning) 55%, transparent); }

.view-stack {
  min-width: 0;
}

.view-panel {
  display: none;
  min-height: calc(100vh - 130px);
  margin-top: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.055), rgba(255,255,255,0.02)),
    var(--surface);
  box-shadow: var(--shadow);
}

.view-panel.is-active {
  display: block;
  animation: viewIn 0.22s ease;
}

.analysis-stack .view-panel,
.history-root .view-panel,
.retention-root .view-panel {
  display: block;
  min-height: auto;
  margin-top: 14px;
}

.analysis-stack .view-panel:first-child,
.history-root .view-panel:first-child,
.retention-root .view-panel:first-child {
  margin-top: 0;
}

.root-panel {
  padding-bottom: 22px;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.section-kicker {
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.view-header h2 {
  margin: 4px 0 0;
  font-size: 24px;
  line-height: 1.25;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card,
.info-tile,
.chart-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.metric-card {
  min-height: 116px;
  padding: 16px;
}

.metric-label,
.info-tile span {
  color: var(--dim);
  font-size: 12px;
}

.metric-value,
.info-tile strong {
  display: block;
  min-width: 0;
  margin-top: 10px;
  font-size: 27px;
  line-height: 1.1;
  word-break: break-word;
}

.metric-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.info-tile {
  min-height: 108px;
  padding: 16px;
}

.info-tile.danger { border-color: color-mix(in srgb, var(--danger) 46%, transparent); }
.info-tile.warning { border-color: color-mix(in srgb, var(--warning) 46%, transparent); }

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 230px);
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  background: rgba(0, 0, 0, 0.14);
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  white-space: nowrap;
}

th:last-child,
td:last-child {
  border-right: none;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--accent);
  text-align: left;
  background: color-mix(in srgb, var(--surface-2) 88%, #000);
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.045);
}

.empty-note {
  min-height: 160px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
}

.package-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

.package-strip span {
  min-height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 0 12px;
  border: 1px solid color-mix(in srgb, var(--success) 44%, transparent);
  border-radius: 8px;
  color: var(--success);
  background: color-mix(in srgb, var(--success) 10%, transparent);
  font-size: 13px;
  font-weight: 800;
}

.split-tables {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.split-tables h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.history-section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  margin-bottom: 14px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
}

.history-group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin: 16px 0 8px 0;
  padding-bottom: 4px;
  border-bottom: 1.5px solid var(--line-strong);
  letter-spacing: 0.05em;
}

.history-compare-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

.history-compare-table td,
.history-compare-table th {
  border-right: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-compare-table td:last-child,
.history-compare-table th:last-child {
  border-right: none;
}

.history-compare-table td:first-child,
.history-compare-table th:first-child {
  color: var(--dim);
  font-weight: 600;
  text-align: left;
  width: 22%;
}

.history-compare-table td:nth-child(2),
.history-compare-table th:nth-child(2) {
  width: 26%;
}

.history-compare-table td:nth-child(3),
.history-compare-table th:nth-child(3) {
  width: 26%;
}

.history-compare-table td:nth-child(4),
.history-compare-table th:nth-child(4) {
  width: 26%;
}

.history-compare-table td:not(:first-child),
.history-compare-table th:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.history-compare-table thead tr {
  background: color-mix(in srgb, var(--surface-2) 88%, #000);
}

.history-compare-table tbody tr:hover {
  background: rgba(255,255,255,0.04);
}

/* 变化率颜色 */
.change-cell.up { color: var(--danger); font-weight: 600; }
.change-cell.down { color: #34d399; font-weight: 600; }


.history-conclusion {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.chart-grid.single {
  grid-template-columns: 1fr;
}

.chart-card {
  padding: 12px;
}

.chart-title {
  margin-bottom: 10px;
  color: var(--accent);
  font-weight: 800;
}

.chart-card img {
  width: 100%;
  display: block;
  border-radius: 6px;
  background: #fff;
}

.empty-panel {
  min-height: calc(100vh - 126px);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .brand {
    grid-column: 1 / -1;
  }

  .side-section {
    margin-bottom: 0;
  }

  .nav-box {
    grid-column: 1 / -1;
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .nav-box .section-heading {
    grid-column: 1 / -1;
  }

  .stats-row,
  .info-grid,
  .chart-grid,
  .split-tables,
  .history-compare-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 12px;
  }

  .sidebar,
  .nav-box {
    grid-template-columns: 1fr;
  }

  .topbar,
  .view-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .action-btn {
    flex: 1;
  }

  .stats-row,
  .info-grid,
  .chart-grid,
  .split-tables,
  .history-compare-grid {
    grid-template-columns: 1fr;
  }

  .view-panel {
    min-height: auto;
    padding: 14px;
  }
}
