:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --est: #ea580c;
  --ok: #15803d;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft JhengHei", "Noto Sans TC", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.topbar { background: #0f172a; color: #fff; padding: 14px 0 12px; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 0 18px; }
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }
.topbar .muted { color: #94a3b8; margin: 4px 0 0; font-size: 12.5px; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; display: block; }

.fatal {
  max-width: 1200px; margin: 14px auto 0; padding: 12px 16px;
  background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; border-radius: var(--radius);
}

main { max-width: 1200px; margin: 0 auto; padding: 16px 18px 8px; display: flex; flex-direction: column; gap: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: 0 1px 2px rgba(15,23,42,.04); }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.kpi-est { border-color: #fdba74; background: #fff7ed; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-val { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); }

/* Controls */
.controls { display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-start; }
.ctrl-block { display: flex; flex-direction: column; gap: 4px; }
.ctrl-block.grow { flex: 1 1 320px; }
.ctrl-block label { font-weight: 600; font-size: 13px; }
.ctrl-block label b { color: var(--accent); }
input[type="range"] { width: 100%; max-width: 420px; accent-color: var(--accent); }
.btn-row { display: flex; gap: 6px; }
.btn-row button, .legend-head button {
  border: 1px solid var(--line); background: #f8fafc; color: var(--ink);
  padding: 5px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.btn-row button:hover, .legend-head button:hover { background: #eef2f7; }
.btn-row button.active { background: #0f172a; color: #fff; border-color: #0f172a; }
.est-note { flex: 1 1 260px; font-size: 12.5px; color: #9a3412; background: #fff7ed; border: 1px dashed #fdba74; border-radius: 8px; padding: 8px 10px; }

/* Chart */
.chart-wrap { position: relative; height: 460px; }

/* Legend */
.legend-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.legend-head input[type="search"] {
  flex: 1 1 200px; max-width: 300px; padding: 5px 10px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 13px;
}
.legend-head select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #fff; }
.legend-pin { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px dashed var(--line); }
.legend-pin:empty { display: none; }
.legend-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 300px; overflow-y: auto; padding-right: 4px; }
.lg-item {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  background: #f8fafc; border-radius: 999px; padding: 3px 10px 3px 7px; cursor: pointer; font-size: 12px;
  max-width: 300px;
}
.lg-item:hover { background: #eef2f7; }
.lg-item .swatch { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; border: 1px solid rgba(0,0,0,.15); }
.lg-item .lg-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lg-item .lg-share { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.lg-item.off { opacity: .4; }
.lg-item.off .lg-name { text-decoration: line-through; }
.lg-item.pinned { border-color: #c4b5fd; background: #f5f3ff; }

/* Table */
.table-head { display: flex; justify-content: space-between; align-items: center; }
.table-head button { border: 1px solid var(--line); background: #f8fafc; border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.table-scroll { max-height: 520px; overflow: auto; margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
thead th {
  position: sticky; top: 0; background: #f8fafc; border-bottom: 1px solid var(--line);
  padding: 7px 10px; font-size: 12px; color: var(--muted); white-space: nowrap; z-index: 1;
}
td { padding: 5px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.left, td.left { text-align: left; }
.m-name { font-weight: 600; }
.m-slug { color: var(--muted); font-size: 11px; }
tr.glm-hl td { background: #eef2ff; }
tr.total td { font-weight: 700; background: #f8fafc; border-top: 1px solid var(--line); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; white-space: nowrap; }
.src-direct { background: #dcfce7; color: #166534; }
.src-free { background: #e2e8f0; color: #475569; }
.src-fallback { background: #fef3c7; color: #92400e; }

footer { max-width: 1200px; margin: 0 auto; padding: 6px 18px 28px; }
footer p { font-size: 12px; color: var(--muted); line-height: 1.7; }
.social-links { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; }
.social-links a { color: var(--accent); font-weight: 600; text-decoration: none; }
.social-links a:hover { text-decoration: underline; }
.social-links span { color: var(--muted); }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .chart-wrap { height: 380px; }
}
