:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --muted: #526070;
  --line: #d8dee5;
  --line-strong: #bcc7d3;
  --accent: #1d4ed8;
  --accent-soft: #dbeafe;
  --good: #047857;
  --warn: #b45309;
  --bad: #b42318;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.topbar,
.toolbar-band,
.section-band {
  width: min(1480px, 100%);
  margin: 0 auto 18px;
}

.topbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 28px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.topbar h1,
.section-head h2,
.chart-head h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 30px;
  line-height: 1.1;
}

.topbar-subtitle,
.section-head p,
#querySummary {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-session {
  display: flex;
  align-items: center;
  gap: 12px;
}

.session-label {
  height: 40px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.primary-button,
.ghost-button,
.seg {
  height: 40px;
  border-radius: 8px;
  padding: 0 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.primary-button {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 132px;
}

.primary-button:hover,
.ghost-button:hover,
.seg:hover {
  border-color: var(--line-strong);
}

.toolbar-band,
.section-band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
}

.toolbar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 14px;
}

.field-group {
  min-width: 0;
}

.field-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.field-group select,
.field-group input {
  width: 100%;
  height: 42px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 0 12px;
  color: var(--ink);
}

.coverage-strip {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.coverage-chip,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--line-strong);
}

.is-good .status-dot {
  background: var(--good);
}

.is-warn .status-dot {
  background: var(--warn);
}

.is-bad .status-dot {
  background: var(--bad);
}

.main-stack {
  width: min(1480px, 100%);
  margin: 0 auto;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-card h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
}

.auth-subtitle {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.auth-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.auth-error {
  min-height: 20px;
  margin: 0;
  color: var(--bad);
  font-size: 13px;
}

.auth-submit {
  width: 100%;
}

.section-head,
.chart-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-head h2 {
  font-size: 22px;
}

.chart-head h3 {
  font-size: 17px;
}

.chart-head span,
.section-head .status-pill {
  color: var(--muted);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  min-height: 126px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.kpi-label {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kpi-value {
  display: block;
  font-size: 28px;
  line-height: 1.1;
  font-weight: 800;
}

.kpi-sub {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.chart-grid,
.table-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.table-grid.dual,
.chart-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.table-grid:not(.dual) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.table-panel,
.chart-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 18px;
  min-width: 0;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

td {
  font-size: 13px;
}

tr:last-child td {
  border-bottom: none;
}

.line-chart,
.bar-chart {
  min-height: 240px;
}

.chart-svg {
  width: 100%;
  height: 260px;
  display: block;
}

.chart-axis-label {
  fill: var(--muted);
  font-size: 11px;
}

.chart-line-geo {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
}

.chart-line-storehub {
  fill: none;
  stroke: #ef6c00;
  stroke-width: 3;
}

.chart-gridline {
  stroke: var(--line);
  stroke-width: 1;
}

.bar-row {
  display: grid;
  grid-template-columns: 80px 1fr 84px;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #e8edf3;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #1d4ed8, #60a5fa);
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.seg.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.muted-empty {
  color: var(--muted);
  padding: 18px 0;
  text-align: center;
}

@media (max-width: 1200px) {
  .toolbar-grid,
  .kpi-grid,
  .chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-grid.dual,
  .table-grid:not(.dual) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .toolbar-band,
  .section-band {
    padding: 18px;
  }

  .topbar,
  .section-head,
  .chart-head {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .topbar-session {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    width: 100%;
  }

  .session-label,
  .primary-button,
  .ghost-button {
    width: 100%;
    min-width: 0;
    justify-content: center;
  }

  .toolbar-grid,
  .kpi-grid,
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .table-grid.dual,
  .table-grid:not(.dual) {
    grid-template-columns: 1fr;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .topbar-subtitle,
  .section-head p,
  #querySummary {
    font-size: 14px;
  }

  .section-head h2 {
    font-size: 20px;
  }

  .kpi-value {
    font-size: 24px;
  }

  .bar-row {
    grid-template-columns: 64px 1fr 72px;
  }
}

@media (max-width: 480px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .toolbar-band,
  .section-band,
  .auth-card {
    padding: 16px;
  }

  .topbar-actions,
  .topbar-session {
    grid-template-columns: 1fr;
  }

  .eyebrow {
    font-size: 11px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .kpi-card {
    min-height: 0;
  }

  th,
  td {
    padding: 10px 8px;
  }

  td {
    font-size: 12px;
  }
}

@media (max-width: 640px) {
  .data-table thead {
    display: none;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }

  .data-table tr:last-child {
    border-bottom: none;
  }

  .data-table td {
    border-bottom: none;
    padding: 6px 0;
  }

  .data-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
  }
}
