:root {
  --paper: #f4f1ea;
  --paper-2: #ece7db;
  --paper-3: #e3dccf;
  --ink: #141414;
  --ink-2: #2c2a27;
  --muted: #6d6a63;
  --line: #1a1a1a14;
  --line-strong: #1a1a1a30;
  --accent: #b44a23;     /* sienna */
  --accent-deep: #7a2d14;
  --accent-soft: #e9c9b7;
  --ok: #1e6b3c;
  --warn: #a65a00;
  --surface: #fffdf9;
  --shadow-1: 0 1px 0 rgba(20,20,20,0.06), 0 12px 32px rgba(20,20,20,0.06);

  --f-sans: "Inter", "Noto Sans TC", ui-sans-serif, system-ui, sans-serif;
  --f-display: "Fraunces", "Noto Serif TC", Georgia, serif;
  --f-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; }
html { overflow-x: hidden; }
body {
  min-height: 100vh;
  font-family: var(--f-sans);
  color: var(--ink);
  overflow-x: hidden;
  background:
    radial-gradient(900px 600px at 90% -10%, rgba(180,74,35,0.12), transparent 60%),
    radial-gradient(700px 500px at -5% 110%, rgba(20,20,20,0.06), transparent 60%),
    linear-gradient(180deg, rgba(255,253,249,0.9) 0%, rgba(244,241,234,0.94) 24%, rgba(244,241,234,1) 100%),
    var(--paper);
  -webkit-font-smoothing: antialiased;
  letter-spacing: 0.002em;
}

::selection { background: var(--accent); color: #fff; }

/* TOP BAR */
.top {
  border-bottom: 1px solid var(--line);
  background: rgba(255,253,249,0.88);
  backdrop-filter: saturate(1.1) blur(8px);
  position: sticky; top: 0; z-index: 50;
}
.top-inner {
  width: min(1440px, calc(100vw - 40px));
  margin: 0 auto;
  min-height: 64px;
  padding: 14px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
}
.mark { display: flex; align-items: center; gap: 14px; }
.mark-text { display: grid; line-height: 1.1; }
.mark-text strong { font-family: var(--f-display); font-weight: 700; font-size: 1.05rem; letter-spacing: 0.01em; }
.mark-text span { font-size: 0.76rem; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }

.top-meta { display: flex; align-items: center; gap: 10px; font-family: var(--f-mono); font-size: 0.78rem; color: var(--muted); }
.top-meta .divider { opacity: 0.5; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px rgba(30,107,60,0.12); }
.dot.err { background: var(--accent); box-shadow: 0 0 0 4px rgba(180,74,35,0.15); }

/* SHELL */
.shell {
  width: min(1440px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 32px 0 72px;
  display: grid;
  gap: 28px;
  overflow-x: clip;
}

.card-shell {
  background: linear-gradient(180deg, rgba(255,253,249,0.98), rgba(255,253,249,0.9));
  border: 1px solid rgba(20,20,20,0.12);
  border-radius: 28px;
  box-shadow: var(--shadow-1);
}

/* HERO */
.hero {
  display: block;
}

.overview-label,
.section-kicker {
  display: inline-block;
  margin-bottom: 10px;
  font-family: var(--f-mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.overview-card p,
.section-heading p,
.foot p {
  margin: 0;
  color: var(--ink-2);
  line-height: 1.65;
}

.hero-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  overflow: hidden;
}
.stat {
  padding: 24px 22px 20px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: grid; gap: 4px;
}
.stat:nth-child(2n) { border-right: 0; }
.stat:nth-last-child(-n+2) { border-bottom: 0; }
.stat-k {
  font-family: var(--f-mono);
  font-size: 0.68rem; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--muted);
}
.stat strong {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: clamp(1.8rem, 2.6vw, 2.4rem);
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--ink);
}
.stat-sub { font-size: 0.8rem; color: var(--muted); }

.section-heading h2,
.foot strong {
  display: block;
  margin: 0 0 8px;
  font-family: var(--f-display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* FILTER BAR */
.filterbar {
  display: grid;
  grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.3fr) minmax(0, 1.8fr);
  gap: 24px;
  align-items: end;
  padding: 28px;
}
.section-heading {
  display: grid;
  align-content: start;
  gap: 12px;
  min-width: 0;
}
.section-heading h2 {
  margin: 0;
  font-size: clamp(1.6rem, 2vw, 2rem);
}
.filter-group {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.filter-group:nth-of-type(2) {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 16px;
}
.f { display: grid; gap: 6px; min-width: 0; }
.f.grow { min-width: 220px; }
.f > span {
  font-family: var(--f-mono);
  font-size: 0.66rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted);
}
.f select, .f input {
  width: 100%;
  min-width: 0;
  height: 46px;
  padding: 0 14px;
  font: 500 0.92rem/1 var(--f-sans);
  color: var(--ink);
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
  appearance: none;
}
.f input[type="date"] {
  min-inline-size: 0;
  width: 100%;
}
.f select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink) 50%),
    linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 18px) 17px, calc(100% - 13px) 17px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
.f input[type="date"]::-webkit-calendar-picker-indicator { opacity: 0.55; cursor: pointer; }
.f select:focus, .f input:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(180,74,35,0.15);
}
.filter-actions { display: flex; gap: 10px; align-self: end; }
.btn-solid, .btn-ghost {
  height: 46px; padding: 0 20px;
  font: 600 0.85rem/1 var(--f-sans);
  letter-spacing: 0.06em; text-transform: uppercase;
  border-radius: 999px; cursor: pointer; border: 1px solid var(--ink);
  transition: transform 80ms ease, background 120ms ease, color 120ms ease;
}
.btn-solid { background: var(--ink); color: var(--paper); }
.btn-solid:hover { background: var(--accent); border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--ink); color: var(--paper); }
.btn-solid:active, .btn-ghost:active { transform: translate(1px, 1px); }

/* CHARTS */
.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.chart {
  background: rgba(255,253,249,0.92);
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  padding: 22px 22px 18px;
  box-shadow: 0 10px 24px rgba(20,20,20,0.04);
}
.chart > header {
  display: flex; align-items: baseline; justify-content: space-between;
  padding-bottom: 14px; margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.chart h3 { margin: 0; font-family: var(--f-display); font-weight: 600; font-size: 1.15rem; letter-spacing: -0.01em; }
.chart-note { font-family: var(--f-mono); font-size: 0.72rem; color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase; }

.bars { display: grid; gap: 10px; }
.bar-row {
  display: grid;
  grid-template-columns: 140px 1fr 80px;
  gap: 14px; align-items: center;
  font-size: 0.88rem;
}
.bar-row > span:first-child {
  color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar-track { height: 8px; background: var(--paper-2); position: relative; }
.bar-fill {
  position: absolute; inset: 0 auto 0 0;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent));
  transition: width 400ms cubic-bezier(0.16, 1, 0.3, 1);
}
.bar-row strong {
  font-family: var(--f-mono); font-size: 0.82rem; color: var(--ink); text-align: right;
  font-weight: 600;
}

/* RESULTS */
.results { display: grid; gap: 18px; padding: 28px; }
.results-head {
  display: flex; justify-content: space-between; align-items: end; gap: 24px;
  padding-bottom: 12px; border-bottom: 1px solid var(--line-strong);
}
.results-head h2 { margin: 0 0 4px; font-family: var(--f-display); font-weight: 600; font-size: 1.6rem; letter-spacing: -0.01em; }
.results-head p { margin: 0; color: var(--muted); font-family: var(--f-mono); font-size: 0.8rem; }

.page-ctrl { display: flex; align-items: end; gap: 14px; }
.mini { display: grid; gap: 6px; }
.mini > span {
  font-family: var(--f-mono); font-size: 0.66rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted);
}
.mini select {
  height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); background: #fff; font: 500 0.88rem var(--f-sans); border-radius: 12px;
}
.pager {
  display: flex; align-items: center; gap: 6px;
  height: 40px; border: 1px solid var(--line-strong); background: #fff; padding: 0 6px;
  border-radius: 999px;
  font-family: var(--f-mono); font-size: 0.85rem;
}
.pager button {
  width: 28px; height: 28px; border: 0; background: transparent; cursor: pointer;
  font-size: 1.2rem; line-height: 1; color: var(--ink);
}
.pager button:hover { background: var(--paper-2); }
.pager input {
  width: 52px; height: 28px; text-align: center;
  border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  font-family: var(--f-mono); font-size: 0.85rem; background: transparent;
}
.pager input::-webkit-outer-spin-button, .pager input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.pager span { color: var(--muted); padding-right: 4px; }

/* TABLE with visible drag scrollbar below */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  max-width: 100%;
}
.table-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--paper-2);
  max-height: 560px;
  overflow-y: auto;
}
.table-scroll::-webkit-scrollbar { height: 12px; width: 10px; }
.table-scroll::-webkit-scrollbar-track { background: var(--paper-2); }
.table-scroll::-webkit-scrollbar-thumb {
  background: linear-gradient(90deg, var(--accent-deep), var(--accent));
  border-radius: 999px;
  border: 2px solid var(--paper-2);
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;                /* let headers decide width — single flat row */
  min-width: 100%;
  font-size: 0.88rem;
}
thead th {
  position: sticky; top: 0; z-index: 2;
  background: linear-gradient(180deg, #1d1b18, #141414); color: var(--paper);
  font-family: var(--f-mono);
  font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  font-weight: 600;
  text-align: left;
  padding: 12px 14px;
  white-space: nowrap;               /* flat single-line headers (平平的) */
  border-right: 1px solid rgba(255,253,249,0.12);
}
thead th:last-child { border-right: 0; }
tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  vertical-align: top;
  color: var(--ink-2);
  white-space: nowrap;               /* flat rows, drag to see more */
  max-width: 420px;
  overflow: hidden; text-overflow: ellipsis;
}
tbody td:last-child { border-right: 0; }
tbody tr:nth-child(even) td { background: rgba(236,231,219,0.35); }
tbody tr:hover td { background: var(--accent-soft); color: var(--ink); }
tbody td.empty { color: var(--muted); font-style: italic; }
tbody td.num {
  font-family: var(--f-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
tbody td.accent { color: var(--accent-deep); font-weight: 600; }
tbody tr.no-data td {
  text-align: center; color: var(--muted); padding: 48px 0; white-space: normal;
}

/* FOOTER */
.foot {
  display: flex; justify-content: space-between; gap: 20px; align-items: end;
  color: var(--muted); font-family: var(--f-mono); font-size: 0.78rem;
  padding: 12px 4px 0;
}

/* RESPONSIVE */
@media (max-width: 1240px) {
  .hero {
    grid-template-columns: 1fr;
  }
  .filterbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1080px) {
  .top-inner {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }
  .results,
  .filterbar {
    padding: 24px;
  }
  .filter-group, .filter-group:nth-of-type(2) { grid-template-columns: 1fr 1fr; }
  .filter-group:nth-of-type(2) .f.grow {
    grid-column: 1 / -1;
    min-width: 0;
  }
  .charts { grid-template-columns: 1fr; }
  .results-head {
    flex-direction: column;
    align-items: flex-start;
  }
  .page-ctrl {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
}

@media (max-width: 720px) {
  .shell,
  .top-inner {
    width: min(1440px, calc(100vw - 24px));
  }
  .results,
  .filterbar,
  .chart,
  .overview-card {
    padding: 20px;
  }
  .hero-stats {
    grid-template-columns: 1fr;
  }
  .stat { border-right: 0; }
  .stat:nth-last-child(-n+2) {
    border-bottom: 1px solid var(--line);
  }
  .filter-group, .filter-group:nth-of-type(2) {
    grid-template-columns: 1fr;
  }
  .filter-actions {
    width: 100%;
    justify-content: stretch;
    flex-direction: column;
  }
  .filter-actions > * {
    width: 100%;
  }
  .page-ctrl,
  .foot {
    align-items: flex-start;
    justify-content: flex-start;
    flex-direction: column;
  }
  .bar-row {
    grid-template-columns: minmax(0, 90px) 1fr 56px;
    gap: 10px;
  }
  tbody td {
    max-width: 280px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
