:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --line: #e5e7eb;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);

  --brand: #d7262e;
  --deposit: #059669;
  --txs: #0891b2;
  --withdraw: #e11d48;
  --revenue: #4f46e5;
  --register: #d97706;

  --good: #047857;
  --good-bg: #d1fae5;
  --bad: #be123c;
  --bad-bg: #ffe4e6;
  --flat: #64748b;
  --flat-bg: #eef2f6;

  --oracle-1: #1e1b4b;
  --oracle-2: #312e81;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17;
    --surface: #131a26;
    --surface-2: #182131;
    --text: #e8edf5;
    --text-2: #a3b0c2;
    --text-3: #64748b;
    --line: #243042;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
    --deposit: #34d399;
    --txs: #22d3ee;
    --withdraw: #fb7185;
    --revenue: #818cf8;
    --register: #fbbf24;
    --good: #6ee7b7;
    --good-bg: rgba(16, 185, 129, .16);
    --bad: #fda4af;
    --bad-bg: rgba(244, 63, 94, .16);
    --flat: #94a3b8;
    --flat-bg: rgba(148, 163, 184, .14);
    --oracle-1: #1b1745;
    --oracle-2: #2a2672;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  padding: 0 16px 48px;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "IBM Plex Sans Thai", system-ui, sans-serif;
  font-feature-settings: "tnum" 1, "cv11" 1;
}
.topbar, .status, main { max-width: 1360px; margin-left: auto; margin-right: auto; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 24px 0 8px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(135deg, #ef4444, #b91c1c); color: #fff; font-weight: 800; font-size: 22px;
  box-shadow: 0 6px 16px -6px rgba(215, 38, 46, .6);
}
.brand h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.brand p { margin: 0; color: var(--text-2); font-size: 14px; }

.controls { display: flex; gap: 8px; align-items: center; }
.date-pill, .icon-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--text-2);
  font: 500 14px "IBM Plex Sans Thai", "Inter", sans-serif; box-shadow: var(--shadow);
}
.date-pill input {
  border: 0; background: transparent; color: var(--text); font: 600 14px "Inter", sans-serif; outline: none;
  color-scheme: light dark;
}
.icon-btn { width: 40px; padding: 0; justify-content: center; cursor: pointer; }
.icon-btn:hover { color: var(--text); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.controls svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.status { color: var(--text-3); font: 400 12px "IBM Plex Sans Thai", sans-serif; margin-top: 0; margin-bottom: 20px; text-align: right; }
.status.error { color: var(--bad); }

/* ---------- section heads ---------- */
.section-head, .panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-head { margin: 0 0 12px; }
h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.muted { color: var(--text-3); font-weight: 500; }
.chip {
  font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface);
  border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}

/* ---------- hero (this month) ---------- */
.hero-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.kpi {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); padding: 18px 18px 14px; overflow: hidden;
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
}
.kpi::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--accent);
}
.kpi-label { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; font-weight: 600; }
.kpi-icon {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-size: 13px; font-weight: 700;
}
.kpi-value {
  font-size: clamp(24px, 2.3vw, 34px); font-weight: 700; letter-spacing: -.03em; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-value .cur { font-size: .6em; color: var(--text-3); font-weight: 600; margin-right: 2px; }
.kpi-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.vs { color: var(--text-3); font-size: 12px; }
.spark { width: 100%; height: 56px; display: block; margin: 6px 0 2px; overflow: visible; }
.kpi-foot {
  display: flex; justify-content: space-between; gap: 8px; border-top: 1px dashed var(--line);
  padding-top: 10px; margin-top: 2px; font-size: 13px; color: var(--text-2);
}
.kpi-foot b { color: var(--text); font-weight: 600; }
.kpi-foot div { display: flex; flex-direction: column; gap: 2px; }
.kpi-foot div:last-child { text-align: right; }
.kpi-foot small { color: var(--text-3); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }

.delta {
  display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 700;
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
}
.delta.good { color: var(--good); background: var(--good-bg); }
.delta.bad { color: var(--bad); background: var(--bad-bg); }
.delta.flat { color: var(--flat); background: var(--flat-bg); }

/* ---------- lower panels ---------- */
.lower-grid { display: grid; grid-template-columns: 1fr 1fr 1.1fr; gap: 16px; margin-top: 28px; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  padding: 18px; display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.foot-note { margin: auto 0 0; color: var(--text-3); font: 400 12px "IBM Plex Sans Thai", sans-serif; }

.list { display: flex; flex-direction: column; }
.li {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.li:last-child { border-bottom: 0; }
.li .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.li .name { font-size: 13px; color: var(--text-2); font-weight: 500; }
.li .name small { display: block; color: var(--text-3); font-size: 11px; font-weight: 400; margin-top: 1px; }
.li .num { text-align: right; display: flex; align-items: center; gap: 10px; }
.li .num b { font-size: 17px; font-weight: 700; letter-spacing: -.02em; }

/* ---------- oracle ---------- */
.oracle {
  background: radial-gradient(120% 120% at 100% 0%, var(--oracle-2), var(--oracle-1));
  border-color: transparent; color: #eef2ff;
}
.oracle .chip { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.16); color: #e0e7ff; }
.oracle .foot-note { color: #a5b4fc; }
.fc { padding: 10px 0 14px; border-bottom: 1px solid rgba(255,255,255,.1); }
.fc:last-child { border-bottom: 0; }
.fc-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.fc-label { font-size: 13px; color: #c7d2fe; font-weight: 600; }
.fc-pct { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.fc-pct.hit { background: rgba(52, 211, 153, .18); color: #6ee7b7; }
.fc-pct.miss { background: rgba(251, 191, 36, .18); color: #fcd34d; }
.fc-value { font-size: 28px; font-weight: 700; letter-spacing: -.03em; margin: 4px 0 10px; }
.bar { position: relative; height: 10px; border-radius: 999px; background: rgba(255,255,255,.1); }
.bar .pred, .bar .actual { position: absolute; inset: 0 auto 0 0; border-radius: 999px; }
.bar .pred {
  background: repeating-linear-gradient(-45deg, rgba(165,180,252,.55) 0 6px, rgba(165,180,252,.3) 6px 12px);
}
.bar .actual { background: linear-gradient(90deg, #818cf8, #c4b5fd); }
.bar .target { position: absolute; top: -5px; bottom: -5px; width: 2px; background: #fde68a; border-radius: 2px; }
.fc-legend { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; font-size: 12px; color: #a5b4fc; flex-wrap: wrap; }
.fc-legend b { color: #eef2ff; font-weight: 600; }
.fc-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }

/* ---------- responsive ---------- */
@media (max-width: 1240px) {
  .hero-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lower-grid { grid-template-columns: 1fr 1fr; }
  .oracle { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .hero-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .lower-grid { grid-template-columns: 1fr; }
  .kpi { padding: 14px; }
  .status { text-align: left; }
}
@media (max-width: 480px) {
  .hero-grid { grid-template-columns: 1fr; }
  .date-pill span { display: none; }
}
