:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --card: #111827;
  --muted: #94a3b8;
  --text: #f8fafc;
  --accent: #38bdf8;
  --danger: #fb7185;
  --ok: #22c55e;
  --border: #1f2937;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(180deg, #020617 0%, #0f172a 100%);
  color: var(--text);
}

.container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 28px 32px 40px;
}

.hero p { color: var(--muted); margin-top: 0; }

section {
  margin-top: 0;
  padding: 28px 0 0;
  border-top: 1px solid var(--border);
}

section:first-of-type { border-top: none; padding-top: 20px; }

h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

#meta { color: var(--muted); font-size: 14px; }

.trend-banner {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #334155;
  background: rgba(15, 23, 42, 0.85);
  color: #e2e8f0;
}

.trend-banner h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.trend-badges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-bottom: 6px;
}

.trend-badges > div {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(2, 6, 23, 0.45);
}

.trend-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

@media (max-width: 960px) {
  .trend-grid {
    grid-template-columns: 1fr;
  }
}

.trend-block {
  padding: 10px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.35);
}

.trend-block-head {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 8px;
}

.trend-block-title {
  font-weight: 700;
}

.trend-block-horizon {
  opacity: 0.85;
  font-size: 12px;
}

.trend-block-value {
  text-align: right;
}

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(17, 24, 39, 0.8);
}

.controls label {
  font-weight: 600;
}

.metric {
  font-size: 28px;
  font-weight: 700;
  margin: 6px 0;
}

.note {
  color: #facc15;
  margin-bottom: 8px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 14px;
}

.card-list {
  margin: 0;
  padding-left: 20px;
}

.card {
  border: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.9);
  border-radius: 10px;
  padding: 14px;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.kv {
  color: var(--muted);
  font-size: 13px;
  margin-top: 8px;
}

.reason-kv {
  margin-top: 8px;
}

.reason-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
  align-items: start;
}

.reason-row + .reason-row {
  margin-top: 6px;
}

.reason-key {
  color: var(--text);
  opacity: 0.85;
  font-weight: 700;
  white-space: nowrap;
}

.reason-val {
  color: var(--muted);
  line-height: 1.5;
  word-break: break-word;
}

.kv > div + div {
  margin-top: 2px;
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 560px;
  overflow: auto;
}

table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: rgba(2, 6, 23, 0.95);
  z-index: 1;
}

td.analysis {
  min-width: 260px;
  color: #dbeafe;
  line-height: 1.5;
}

.impact-inline {
  margin-top: 6px;
  color: #fde68a;
  line-height: 1.45;
}

.change {
  color: #e2e8f0;
  line-height: 1.5;
  margin: 8px 0;
}

.impact {
  color: #fde68a;
  margin: 8px 0 4px;
  line-height: 1.5;
}

.analysis-note {
  color: #c7d2fe;
  margin: 6px 0;
  line-height: 1.5;
}

.bias-up {
  color: #4ade80;
  font-weight: 700;
}

.bias-down {
  color: #fb7185;
  font-weight: 700;
}

.bias-side {
  color: #facc15;
  font-weight: 700;
}

.bias-muted {
  color: #94a3b8;
  font-weight: 700;
}

.overview-link {
  color: inherit;
  text-decoration: none;
}

.overview-link:hover {
  text-decoration: underline;
}

.metric-link {
  display: block;
}

.whale-list {
  margin: 10px 0 0;
  padding-left: 18px;
  line-height: 1.6;
}

.whale-list li div + div {
  margin-top: 2px;
}

.muted {
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
}

.high { background: rgba(251, 113, 133, 0.2); color: #fecdd3; }
.medium { background: rgba(56, 189, 248, 0.2); color: #bae6fd; }
.low { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }

.upcoming { color: var(--ok); }
.recent { color: #fbbf24; }

a { color: var(--accent); }

/* ── Gate Score 水平條形圖 ─────────────────────────────────────── */
.gate-hero {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  align-items: start;
}

@media (max-width: 860px) {
  .gate-hero { grid-template-columns: 1fr; }
}

.gate-status-panel {
  min-width: 0;
}

.gate-bar-wrap {
  height: 315px;
}

.gate-status {
  font-size: 1.5em;
  font-weight: 700;
  margin-bottom: 4px;
}

.gate-avg {
  font-size: 1em;
  margin-bottom: 16px;
  color: var(--muted);
}

.gate-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
}

.gate-table th {
  color: var(--muted);
  font-weight: 600;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.gate-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #1e293b;
}

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

/* ── Gate Legend ─────────────────────────────────────────────────── */
.gate-legend {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #1e293b;
}

.gate-legend-title {
  font-size: 0.78em;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.gate-legend-rows {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.gate-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  border-left-width: 3px;
  border-left-style: solid;
  background: rgba(255,255,255,0.02);
  opacity: 0.55;
  transition: opacity 0.2s;
}

.gate-legend-row.gate-legend-active {
  opacity: 1;
  background: rgba(255,255,255,0.06);
}

.gate-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.gate-legend-name {
  font-weight: 700;
  font-size: 0.88em;
  width: 36px;
  flex-shrink: 0;
}

.gate-legend-range {
  font-size: 0.78em;
  color: var(--muted);
  width: 90px;
  flex-shrink: 0;
}

.gate-legend-desc {
  font-size: 0.8em;
  color: var(--muted);
}

/* ── Gate Composite Score + Factor Delta ─────────────────────────── */
.gate-composite-wrap {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.composite-card {
  background: #0d1b2e;
  border: 1px solid #1e3a5f;
  border-radius: 10px;
  padding: 14px 20px;
  min-width: 200px;
  flex: 1;
}
.composite-title {
  font-size: 0.78em;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.composite-score {
  font-size: 2em;
  font-weight: 700;
  line-height: 1.1;
}
.composite-label {
  font-size: 0.95em;
  font-weight: 600;
  margin-top: 2px;
}
.composite-coverage {
  font-size: 0.78em;
  color: var(--muted);
  margin-top: 6px;
}

.fd-card {
  background: #0d1b2e;
  border: 1px solid #1e3a5f;
  border-radius: 10px;
  padding: 14px 20px;
  flex: 1;
  min-width: 240px;
}
.fd-title {
  font-size: 0.78em;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.fd-count {
  font-size: 1em;
  color: #38bdf8;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
}
.fd-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 0.82em;
  border-bottom: 1px solid #1e293b;
}
.fd-row:last-child { border-bottom: none; }
.fd-key {
  flex: 1;
  color: #cbd5e1;
  font-family: monospace;
  font-size: 0.95em;
}
.fd-diff {
  font-weight: 700;
  min-width: 52px;
  text-align: right;
}
.fd-tag {
  font-size: 0.75em;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
}
.fd-tag-dir { background: #1e3a5f; color: #38bdf8; }
.fd-tag-move { background: #2d1f00; color: #fbbf24; }
.fd-empty {
  font-size: 0.85em;
  color: var(--muted);
  padding: 4px 0;
}

/* ── Composite history chart ─────────────────────────────────────── */
.gate-composite-history-wrap {
  margin-top: 16px;
  background: #0d1b2e;
  border: 1px solid #1e3a5f;
  border-radius: 10px;
  padding: 14px 20px 10px;
}
.composite-history-title {
  font-size: 0.78em;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}


/* ── Synthesis Panel ─────────────────────────────────────────────── */
.gate-synthesis-panel {
  background: #0a1628;
  border: 1px solid #1e3a5f;
  border-radius: 12px;
  padding: 18px 22px;
  margin-bottom: 16px;
  display: none;
}
.gate-synthesis-panel.syn-ready { display: block; }
.syn-header {
  font-size: 0.75em;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 14px;
}
.syn-rows {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.syn-row {
  flex: 1;
  min-width: 140px;
  background: #0f1f38;
  border: 1px solid #1e3a5f;
  border-radius: 8px;
  padding: 10px 14px;
}
.syn-dim {
  font-size: 0.72em;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.syn-source {
  font-size: 0.7em;
  color: #334155;
  margin-bottom: 6px;
}
.syn-value {
  font-size: 1.05em;
  font-weight: 700;
}
.syn-verdict {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-top: 14px;
  border-top: 1px solid #1e3a5f;
}
.syn-badge {
  font-size: 1em;
  font-weight: 700;
  padding: 6px 18px;
  border-radius: 6px;
  white-space: nowrap;
}
.syn-note {
  font-size: 0.82em;
  color: var(--muted);
}

/* ── Stale data warning banner ───────────────────────────────────── */
.stale-banner {
  background: #7a3d00;
  color: #ffd580;
  text-align: center;
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
  border-radius: 4px;
}

/* ── Hero header ─────────────────────────────────────────────────── */
.hero {
  padding-bottom: 20px;
}
.hero h1 { margin: 0 0 4px; font-size: 1.5rem; }
.hero-inner {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.top-nav {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  padding-top: 4px;
  flex-wrap: wrap;
}


/* ── Overview card grid ───────────────────────────────────────────── */
.overview-card-grid {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

/* ── Tab bar ─────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-size: 0.9em;
  font-family: inherit;
  padding: 8px 14px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.tab-icon { margin-right: 4px; }

/* ── Tab panels ──────────────────────────────────────────────────── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── 金十數據快訊 ────────────────────────────────────────────────── */
.jin10-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  .jin10-wrap { grid-template-columns: 1fr; }
}
.jin10-col {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.jin10-col-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 10px 14px 6px;
  border-bottom: 1px solid var(--border);
}
.jin10-col-live { border-top: 2px solid #38bdf8; }
.jin10-col-hist  { border-top: 2px solid #818cf8; }

/* 即時 header */
.jin10-live-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.82rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.jin10-live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #22c55e;
  animation: jin10-blink 1.4s infinite;
}
@keyframes jin10-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}
.jin10-fetch-time { margin-left: auto; font-size: 0.75rem; }

/* 列表捲動 */
.jin10-live-list, .jin10-hist-list {
  max-height: 520px;
  overflow-y: auto;
}

/* 歷史 tab 篩選 */
.jin10-hist-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.jin10-tab {
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.jin10-tab.active, .jin10-tab:hover {
  background: #1e3a5f;
  color: var(--text);
}

/* 單筆快訊 */
.jin10-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.jin10-item:last-child { border-bottom: none; }
.jin10-item:hover { background: rgba(255,255,255,0.03); }

.jin10-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.jin10-time {
  font-size: 0.74rem;
  color: var(--muted);
  min-width: 70px;
}

/* 方向 badge */
.jin10-dir {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 4px;
}
.jin10-dir.bull    { background: rgba(34,197,94,0.15);  color: #22c55e; }
.jin10-dir.bear    { background: rgba(251,113,133,0.15); color: #fb7185; }
.jin10-dir.ambig   { background: rgba(251,191,36,0.15);  color: #fbbf24; }
.jin10-dir.neutral { background: rgba(148,163,184,0.12); color: var(--muted); }

/* 信心指數 dots */
.jin10-confidence { display: flex; gap: 3px; margin-left: auto; }
.jin10-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border);
}
.jin10-dot.on { background: #38bdf8; }

.jin10-content {
  margin: 0 0 4px;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
}
.jin10-content a {
  color: inherit;
  text-decoration: none;
}
.jin10-content a:hover { color: var(--accent); }

.jin10-commentary {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
}

.jin10-empty {
  padding: 20px 14px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

/* ── 宏觀日程篩選 tab ────────────────────────────────────────────── */
.macro-filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.macro-tab {
  padding: 4px 14px;
  border: 1px solid #334155;
  border-radius: 6px;
  background: #1f2937;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.macro-tab.active {
  background: var(--accent);
  color: #0f172a;
  border-color: var(--accent);
}
