:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #f9f9f7;
  --surface-3: #f0efec;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #76746e;
  --accent: #2a78d6;
  --accent-hover: #256abf;
  --accent-soft: #e6f0fc;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --good-ink: #006300;
  --good-soft: #e3f4e3;
  --warn: #fab219;
  --warn-ink: #7a5000;
  --warn-soft: #fff4dc;
  --bad: #d03b3b;
  --bad-ink: #b02a2a;
  --bad-soft: #fbe7e7;
  --neutral-soft: #ecebe7;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --shadow-lg: 0 12px 48px rgba(11, 11, 11, 0.18);
  --radius: 10px;
  --radius-sm: 6px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #20201f;
    --surface-3: #2a2a28;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #98968f;
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-soft: #15283f;
    --good-ink: #3fc43f;
    --good-soft: #142a14;
    --warn-ink: #fab219;
    --warn-soft: #2e2510;
    --bad-ink: #f07a7a;
    --bad-soft: #341818;
    --neutral-soft: #2a2a28;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2c2c2a;
    --axis: #383835;
    --shadow: none;
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #20201f;
  --surface-3: #2a2a28;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #98968f;
  --accent: #3987e5;
  --accent-hover: #5598e7;
  --accent-soft: #15283f;
  --good-ink: #3fc43f;
  --good-soft: #142a14;
  --warn-ink: #fab219;
  --warn-soft: #2e2510;
  --bad-ink: #f07a7a;
  --bad-soft: #341818;
  --neutral-soft: #2a2a28;
  --series-1: #3987e5;
  --series-2: #d95926;
  --grid: #2c2c2a;
  --axis: #383835;
  --shadow: none;
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--text-2); }
.hint { color: var(--muted); font-size: 12.5px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Brand & top bar ---- */
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 650; font-size: 15px; color: var(--text); white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-lg { font-size: 20px; }
.brand-mark {
  width: 24px; height: 24px; border-radius: 7px; background: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9 17h5l2-6 3 12 2-6h2' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: cover;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 24px; height: 56px;
}
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: var(--text-2); padding: 6px 12px; border-radius: var(--radius-sm);
  font-weight: 500; white-space: nowrap;
}
.nav a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav-badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px;
  border-radius: 9px; background: var(--warn); color: #3a2600; font-size: 11px; font-weight: 700; vertical-align: 1px;
}

.main { max-width: 1200px; margin: 0 auto; padding: 28px 16px 64px; outline: none; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .muted { margin-top: 4px; }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-body { padding: 20px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---- Stat tiles ---- */
.tile { padding: 16px 18px; display: block; color: inherit; }
a.tile:hover { text-decoration: none; border-color: var(--border-strong); }
.tile-label { color: var(--text-2); font-size: 13px; }
.tile-value { font-size: 28px; font-weight: 600; margin-top: 6px; letter-spacing: -0.01em; }
.tile-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.tile-alert .tile-value { color: var(--bad-ink); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--bad-ink); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn .spin {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Forms ---- */
.field { display: block; }
.field > span { display: block; font-weight: 500; margin-bottom: 6px; }
.field .hint { margin-top: 6px; }
input[type="text"], input[type="password"], input[type="search"], input[type="number"], input[type="url"], select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input.mono { font-family: var(--mono); font-size: 13px; }
select { padding-right: 28px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.form-error { color: var(--bad-ink); min-height: 1em; font-size: 13px; }
.form-error:empty { display: none; }

.switch { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  flex: none; width: 34px; height: 20px; border-radius: 10px; background: var(--axis);
  position: relative; transition: background 0.15s; margin-top: 1px;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch b { font-weight: 500; display: block; }

/* ---- Chips ---- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  border-radius: 11px; font-size: 12px; font-weight: 550; white-space: nowrap;
  background: var(--neutral-soft); color: var(--text-2);
}
.chip svg { width: 12px; height: 12px; flex: none; }
.chip-good { background: var(--good-soft); color: var(--good-ink); }
.chip-warn { background: var(--warn-soft); color: var(--warn-ink); }
.chip-bad { background: var(--bad-soft); color: var(--bad-ink); }
.chip-accent { background: var(--accent-soft); color: var(--accent); }

/* ---- Pixels ---- */
.pixel-card .card-head h2 { font-size: 15px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px 24px; }
.kv dt { color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.card-foot { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }

.kv .wide { grid-column: 1 / -1; }
.grow { flex: 1; }
.domains { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.domain {
  font-family: var(--mono); font-size: 12px; padding: 1px 7px; border-radius: 4px;
  background: var(--surface-3); color: var(--text); white-space: nowrap;
}
.card-warn { border-color: color-mix(in srgb, var(--warn) 55%, transparent); }
.card-warn .card-head { background: var(--warn-soft); border-radius: var(--radius) var(--radius) 0 0; }
td.actions { text-align: right; }
td.actions .btn + .btn { margin-left: 4px; }
.badge-rec { font-size: 11px; color: var(--good-ink); font-weight: 600; margin-left: 6px; }

.empty { text-align: center; padding: 48px 20px; }
.empty h2 { margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }

/* ---- Setup steps ---- */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.steps li { display: flex; gap: 14px; align-items: flex-start; }
.step-num {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: 13px;
}
.steps li.done .step-num { background: var(--good-soft); color: var(--good-ink); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 550; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.cell-trunc { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.mono.cell-trunc { max-width: 140px; }
.cell-msg { min-width: 240px; max-width: 360px; color: var(--text-2); font-size: 13px; }
.nowrap { white-space: nowrap; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input { width: auto; min-width: 130px; height: 32px; }
.filters input[type="search"] { min-width: 220px; flex: 1; }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); }

/* ---- Postback builder ---- */
.url-box {
  display: flex; gap: 8px; align-items: stretch;
}
.url-box code {
  flex: 1; min-width: 0; display: block; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); overflow-wrap: anywhere; line-height: 1.6;
}
.url-box code .macro { color: var(--accent); }
.url-box .btn { height: auto; }
.param-table td { vertical-align: middle; }
.param-table input[type="text"] { height: 32px; font-family: var(--mono); font-size: 12.5px; }
.param-table .pname { font-family: var(--mono); font-weight: 600; }
.badge-req { font-size: 11px; color: var(--accent); font-weight: 600; margin-left: 6px; }

.callout {
  border-radius: var(--radius-sm); padding: 12px 14px; background: var(--accent-soft); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.callout-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.callout-bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.callout-good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.callout ul { margin: 6px 0 0; padding-left: 18px; }

/* ---- Chart ---- */
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart { position: relative; margin-top: 12px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar-1 { fill: var(--series-1); }
.chart .bar-2 { fill: var(--series-2); }
.chart .hit { fill: transparent; }
.chart .hit:hover, .chart .hit.on { fill: var(--surface-3); opacity: 0.6; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 140px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: 8px 10px; font-size: 12.5px;
}
.tooltip .t-date { color: var(--muted); margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; }
.tooltip .t-row b { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(11, 11, 11, 0.45);
  display: grid; place-items: center; padding: 16px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 640px; background: var(--surface); border-radius: 12px;
  box-shadow: var(--shadow-lg); border: 1px solid var(--border); max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
}
.modal-wide { max-width: 900px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; flex-wrap: wrap; }

pre.json {
  margin: 0; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2);
  border: 1px solid var(--border); overflow: auto; max-height: 320px; line-height: 1.5;
}
.section-title { display: flex; align-items: center; gap: 8px; margin: 20px 0 8px; }
.section-title h3 { flex: 1; }

/* ---- Toasts ---- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  background: var(--text); color: var(--page); padding: 10px 14px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 13.5px; animation: toast-in 0.18s ease-out;
}
.toast-bad { background: var(--bad); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---- Login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 16px;
}

.card-head > .spacer { flex: 1 1 200px; }

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; height: auto; gap: 4px 12px; padding-top: 10px; }
  .topbar-inner .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; margin: 0 -8px; padding-bottom: 8px; }
  .nav a { padding: 6px 10px; }
  .main { padding-top: 20px; }
  .tile-value { font-size: 24px; }
  .card-head, .card-body, .card-pad { padding-left: 16px; padding-right: 16px; }
  /* Pending pixels: stack each row so the "Add token" button stays visible. */
  .pending-table thead { display: none; }
  .pending-table tr { display: grid; gap: 6px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
  .pending-table tr:last-child { border-bottom: 0; }
  .pending-table td { border: 0; padding: 0; text-align: left; }
  .pending-table td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 12.5px; }
  .pending-table td.actions { text-align: left; margin-top: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
