/* ---------------------------------------------------------------- tokens */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --surface-3: #e9e8e3;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --border: rgba(11, 11, 11, 0.1);
  --border-strong: rgba(11, 11, 11, 0.18);
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --accent: #2a78d6;
  --accent-btn: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.1);
  --series-1: #2a78d6;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(0, 0, 0, 0.07);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --surface-3: #2c2c2a;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.18);
    --grid: #2c2c2a;
    --baseline: #383835;
    --accent: #3987e5;
    --accent-btn: #256abf;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --series-1: #3987e5;
    --good-text: #0ca30c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --surface-3: #2c2c2a;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --grid: #2c2c2a;
  --baseline: #383835;
  --accent: #3987e5;
  --accent-btn: #256abf;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --series-1: #3987e5;
  --good-text: #0ca30c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 var(--font);
  background: var(--page);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 18px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent-btn); border-color: transparent; color: #fff; }
.btn-primary:hover { background: var(--accent-btn); filter: brightness(1.08); }
.btn-danger { color: var(--critical); }
.btn-danger:hover { background: color-mix(in srgb, var(--critical) 10%, transparent); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 34px; padding: 0; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ----------------------------------------------------------------- forms */
.field { display: grid; gap: 6px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.field small { color: var(--muted); font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; min-height: 34px; width: 100%;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); }
.check input { width: 16px; height: 16px; min-height: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.form-error { color: var(--critical); font-size: 13px; margin: 0; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { flex: 1 1 160px; }

/* ----------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); display: grid; gap: 16px; padding: 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.login-card p { margin: -8px 0 4px; }

/* ----------------------------------------------------------------- brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-lg { font-size: 20px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent-btn); position: relative; flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 8px 5px; background: #fff; border-radius: 2px;
  -webkit-mask: radial-gradient(circle at 0 50%, transparent 3px, #000 3.5px) left / 51% 100% no-repeat,
                radial-gradient(circle at 100% 50%, transparent 3px, #000 3.5px) right / 51% 100% no-repeat;
          mask: radial-gradient(circle at 0 50%, transparent 3px, #000 3.5px) left / 51% 100% no-repeat,
                radial-gradient(circle at 100% 50%, transparent 3px, #000 3.5px) right / 51% 100% no-repeat;
}

/* ----------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 22px;
  padding: 18px 14px; background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar .brand { padding: 4px 8px; }
.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--ink-2); font-weight: 500; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--ink); }
.nav a.active .nav-ico { color: var(--accent); }
.nav-ico { width: 18px; text-align: center; color: var(--muted); }
.sidebar-foot { margin-top: auto; display: grid; gap: 12px; }
.sidebar-actions { display: flex; justify-content: space-between; }
.sys-status { display: grid; gap: 6px; font-size: 12.5px; padding: 10px; background: var(--surface-2); border-radius: 8px; }
.sys-row { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot-good { background: var(--good); }
.dot-warning { background: var(--warning); }
.dot-critical { background: var(--critical); }
.scrim { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.menu-btn { display: none; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on .live-dot { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.live.off .live-dot { background: var(--critical); }
.view { padding: 24px 28px 48px; max-width: 1280px; width: 100%; display: grid; gap: 20px; align-content: start; }
.view:focus { outline: none; }

/* ----------------------------------------------------------------- cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; }
.grid-even { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 4px; }
.tile-label { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.tile-value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.25; }
.tile-sub { font-size: 12.5px; color: var(--muted); }
.tile-hero { background: var(--accent-soft); border-color: transparent; }

.alert { display: flex; gap: 10px; padding: 10px 14px; border-radius: 8px; font-size: 13px; background: color-mix(in srgb, var(--warning) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent); }
.alert-icon { font-weight: 700; }
.alert ul { margin: 0; padding-left: 18px; }

/* ------------------------------------------------------------------ list */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 12px; align-items: flex-start; padding: 11px 16px; border-top: 1px solid var(--border); }
.feed li:first-child { border-top: 0; }
.feed-main { flex: 1; min-width: 0; }
.feed-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; }
.feed-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-amt { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.feed-ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); font-size: 13px; flex: none; }
.feed-ico.good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good-text); }
.feed-ico.warn { background: color-mix(in srgb, var(--warning) 18%, transparent); }
.feed-ico.bad { background: color-mix(in srgb, var(--critical) 12%, transparent); color: var(--critical); }
.feed li.flash { animation: flash 2.4s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--good) 16%, transparent); } to { background: transparent; } }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* ----------------------------------------------------------------- table */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar input[type="search"] { width: 260px; max-width: 100%; }
.toolbar select, .toolbar input[type="date"] { width: auto; }
.toolbar .spacer { flex: 1; }
.summary { font-size: 13px; color: var(--ink-2); }
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; min-width: 760px; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; background: var(--surface); position: sticky; top: 0; }
.table td.r, .table th.r { text-align: right; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.flash { animation: flash 2.4s ease-out; }
.cell-main { font-weight: 550; }
.cell-sub { font-size: 12px; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 13px; color: var(--ink-2); }

.tabs { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: 9px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 13px; font-weight: 500; padding: 5px 12px; border-radius: 7px; cursor: pointer; }
.tabs button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

/* ---------------------------------------------------------------- badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px 2px 7px; border-radius: 999px; font-size: 12px; font-weight: 550; color: var(--ink); white-space: nowrap; background: var(--surface-3); }
.badge-icon { font-size: 11px; font-weight: 700; }
.badge-good { background: color-mix(in srgb, var(--good) 14%, transparent); }
.badge-good .badge-icon { color: var(--good-text); }
.badge-warning { background: color-mix(in srgb, var(--warning) 20%, transparent); }
.badge-serious { background: color-mix(in srgb, var(--serious) 22%, transparent); }
.badge-critical { background: color-mix(in srgb, var(--critical) 14%, transparent); }
.badge-critical .badge-icon { color: var(--critical); }
.badge-info { background: var(--accent-soft); }
.badge-info .badge-icon { color: var(--accent); }
.badge-neutral { color: var(--ink-2); }
.pill { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); font-size: 11.5px; font-weight: 600; color: var(--ink-2); letter-spacing: 0.02em; }

/* ----------------------------------------------------------------- chart */
.chart { position: relative; padding: 12px 16px 8px; }
.chart svg { display: block; width: 100%; height: 240px; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .base-line { stroke: var(--baseline); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series-1); }
.chart .bar.dim { opacity: 0.35; }
.chart .hit { fill: transparent; cursor: default; outline: none; }
.chart .hit:hover, .chart .hit:focus-visible { fill: var(--accent-soft); }
.chart .cap-label { fill: var(--ink-2); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-tip {
  position: fixed; z-index: 50; pointer-events: none; padding: 8px 10px; border-radius: 8px; font-size: 12.5px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border); box-shadow: var(--shadow); min-width: 140px;
}
.chart-tip strong { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.chart-table { padding: 0 16px 12px; }
.chart-table table { min-width: 0; }

/* ----------------------------------------------------------------- modal */
.modal {
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--border);
  border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(0, 0, 0, 0.45); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; font-size: 16px; }
.modal-body { padding: 18px; overflow: auto; display: grid; gap: 18px; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border); }
.modal-foot:empty { display: none; }
.modal-foot .left { margin-right: auto; }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 18px; margin: 0; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.detail { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 20px; align-items: start; }
.qr-box { display: grid; gap: 8px; justify-items: center; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: #fff; color: #0b0b0b; }
.qr-box img { width: 200px; height: 200px; image-rendering: pixelated; }
.qr-box .countdown { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.amount-lg { font-size: 22px; font-weight: 650; letter-spacing: -0.02em; }
.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 8px; }
.subcard { border: 1px solid var(--border); border-radius: 10px; padding: 14px; display: grid; gap: 12px; }
details > summary { cursor: pointer; color: var(--ink-2); font-weight: 500; }
pre.code, pre.transcript {
  margin: 8px 0 0; padding: 12px; background: var(--surface-2); border-radius: 8px; overflow: auto; max-height: 340px;
  font: 12px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}
.copy { display: inline-flex; gap: 6px; align-items: center; }
.webhook-url { display: flex; gap: 8px; }
.webhook-url input { font-family: var(--mono); font-size: 12.5px; }
ol.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; color: var(--ink-2); }

/* ---------------------------------------------------------------- gopay */
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy-row { display: flex; align-items: center; gap: 10px; color: var(--ink-2); }
.portal-shot { width: 100%; border: 1px solid var(--border); border-radius: 8px; }
.qris-preview { width: 160px; height: 160px; background: #fff; border-radius: 10px; padding: 6px; border: 1px solid var(--border); }
.choice-list { display: grid; gap: 8px; }
.provider-opts { display: grid; gap: 10px; }
.provider-opt { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.provider-opt input { width: 16px; height: 16px; min-height: 0; margin-top: 3px; }
.provider-opt.active { border-color: var(--accent); background: var(--accent-soft); }
.provider-opt.disabled { opacity: 0.55; cursor: not-allowed; }
.code-input { font-size: 22px; letter-spacing: 0.3em; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 10px; width: min(360px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); animation: toast-in 0.2s ease-out; font-size: 13.5px;
}
.toast-ico { font-weight: 700; }
.toast.good { border-left: 4px solid var(--good); }
.toast.bad { border-left: 4px solid var(--critical); }
.toast.info { border-left: 4px solid var(--accent); }
.toast strong { display: block; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1080px) {
  .grid-2, .grid-even { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow); }
  .shell.menu-open .sidebar { transform: none; }
  .shell.menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.4); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .view { padding: 16px 16px 40px; }
}
@media (max-width: 600px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .detail { grid-template-columns: minmax(0, 1fr); }
  .qr-box { justify-self: center; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
  .tile { padding: 12px; }
  .tile-value { font-size: 18px; overflow-wrap: anywhere; }
  .toolbar input[type="search"] { width: 100%; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .live-text { display: none; }
}
@media (forced-colors: active) {
  .chart .bar { fill: CanvasText; }
}
