/* Palette roles. Light is the base; dark is a selected set of steps, not a flip. */
:root {
  color-scheme: light;
  --bg:             #f4f3f0;
  --surface-1:      #fcfcfb;
  --surface-2:      #f0efec;
  --border:         #e3e2dd;
  --grid:           #eae9e5;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #83817b;
  --series-1:       #2a78d6;
  --series-2:       #eb6834;
  --good:           #0ca30c;
  --warning:        #fab219;
  --shadow:         0 1px 2px rgba(11,11,11,.05), 0 8px 24px -12px rgba(11,11,11,.12);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg:             #121211;
    --surface-1:      #1a1a19;
    --surface-2:      #232322;
    --border:         #302f2c;
    --grid:           #2a2a28;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #8f8e85;
    --series-1:       #3987e5;
    --series-2:       #d95926;
    --good:           #0ca30c;
    --warning:        #fab219;
    --shadow:         0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:             #121211;
  --surface-1:      #1a1a19;
  --surface-2:      #232322;
  --border:         #302f2c;
  --grid:           #2a2a28;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #8f8e85;
  --series-1:       #3987e5;
  --series-2:       #d95926;
  --shadow:         0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--series-1); }

/* ---------------------------------------------------------------- login */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 14px; padding: 28px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p  { margin: 0 0 20px; color: var(--text-secondary); font-size: 13px; }

input[type="password"], input[type="search"], select {
  width: 100%; padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-1);
  color: var(--text-primary); font: inherit; font-size: 13px;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 2px;
}
button {
  font: inherit; font-size: 13px; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-1);
  color: var(--text-primary); padding: 8px 13px;
}
button:hover { background: var(--surface-2); }
button.primary {
  width: 100%; margin-top: 14px; background: var(--series-1);
  border-color: var(--series-1); color: #fff; padding: 10px; font-weight: 600;
}
button.primary:hover { filter: brightness(1.06); background: var(--series-1); }
.err { color: #d03b3b; font-size: 13px; margin-top: 12px; min-height: 18px; }

/* --------------------------------------------------------------- layout */
.page { max-width: 1320px; margin: 0 auto; padding: 22px 20px 64px; }

header.top {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 6px;
}
header.top h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; }
.meta { color: var(--text-muted); font-size: 12px; }
.spacer { flex: 1 1 auto; }
.tools { display: flex; gap: 8px; align-items: center; }

.filters {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin: 16px 0 18px; padding: 12px 14px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
}
.filters label { font-size: 12px; color: var(--text-secondary); margin-right: 4px; }
.filters select { width: auto; min-width: 130px; max-width: 260px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 7px 12px; background: var(--surface-1); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--series-1); color: #fff; }

/* ------------------------------------------------------------ stat tiles */
.tiles {
  display: grid; gap: 12px; margin-bottom: 14px;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
}
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 15px 16px; box-shadow: var(--shadow);
}
.tile .k { font-size: 12px; color: var(--text-secondary); margin-bottom: 7px; }
.tile .v { font-size: 27px; font-weight: 650; letter-spacing: -.02em; line-height: 1.1; }
.tile .s { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.tile .s.warn { color: var(--text-secondary); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

/* ---------------------------------------------------------------- cards */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(12, 1fr); }
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; box-shadow: var(--shadow);
  min-width: 0;
}
.card h2 { font-size: 13px; font-weight: 620; margin: 0 0 2px; }
.card .sub { font-size: 12px; color: var(--text-muted); margin: 0 0 12px; }
.span-12 { grid-column: span 12; }
.span-7  { grid-column: span 7; }
.span-5  { grid-column: span 5; }
.span-6  { grid-column: span 6; }
.span-3  { grid-column: span 3; }
@media (max-width: 1000px) {
  .span-7, .span-5, .span-6, .span-3 { grid-column: span 12; }
}

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 0 0 10px; }
.legend span { font-size: 12px; color: var(--text-secondary); display: inline-flex; align-items: center; }

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font-family: inherit; }
.empty { color: var(--text-muted); font-size: 13px; padding: 28px 0; text-align: center; }

.tooltip {
  position: fixed; z-index: 40; pointer-events: none; opacity: 0;
  transition: opacity .09s ease; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px;
  box-shadow: var(--shadow); font-size: 12px; max-width: 300px;
  color: var(--text-primary);
}
.tooltip .t-title { font-weight: 620; margin-bottom: 5px; }
.tooltip .t-row { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.tooltip .t-row .t-val { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------------------------------------------------------------- table */
.table-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.table-tools input[type="search"] { max-width: 260px; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th {
  position: sticky; top: 0; background: var(--surface-1); z-index: 1;
  font-weight: 600; color: var(--text-secondary); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em;
}
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
td.wrap { white-space: normal; min-width: 190px; max-width: 320px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--text-secondary);
}
.badge.paid { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.mono { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- bar list */
.barlist { display: flex; flex-direction: column; gap: 13px; }
.barrow { cursor: default; }
.barhead {
  display: flex; align-items: baseline; gap: 10px;
  font-size: 12.5px; margin-bottom: 5px;
}
.barlabel {
  color: var(--text-primary); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1 1 auto;
}
.barval {
  flex: 0 0 auto; color: var(--text-primary);
  font-variant-numeric: tabular-nums; font-weight: 620;
}
.barval .sub2 { color: var(--text-muted); font-weight: 400; margin-left: 5px; }
.bartrack { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.barfill { height: 100%; border-radius: 4px; background: var(--series-1); min-width: 3px; }
.barrow:hover .bartrack { background: var(--grid); }

/* ------------------------------------------------- 看板专用（投放漏斗） */
.chip {
  display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-secondary); margin-left: 2px;
  font-variant-numeric: tabular-nums;
}
.chip.up   { color: var(--good);    border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.chip.down { color: var(--series-2); border-color: color-mix(in srgb, var(--series-2) 40%, transparent); }

.barfoot { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }
.note {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--grid);
  font-size: 12px; color: var(--text-muted); line-height: 1.6;
}

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text-primary); }
tbody tr.on { background: color-mix(in srgb, var(--series-1) 9%, transparent); }
tbody tr.total td { font-weight: 620; border-top: 1px solid var(--border); border-bottom: 0; }
tbody tr.total:hover { background: transparent; }
#chTable tbody tr:not(.total) { cursor: pointer; }

#segMetric button { padding: 6px 10px; font-size: 12.5px; }
#footnote { line-height: 1.7; max-width: 90ch; }
#yearTable td.sel, #yearTable th.sel { background: color-mix(in srgb, var(--series-1) 9%, transparent); }
#yearTable th.sel { color: var(--text-primary); }
#yearTable td:first-child { color: var(--text-secondary); }
#segPeriod button { white-space: nowrap; }
@media (max-width: 560px) {
  .page { padding: 18px 14px 48px; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .tile .v { font-size: 23px; }
}
