/* Design tokens follow Forui's zinc theme (shadcn/ui style). Light by default; dark from the system
   preference unless the user picked a theme, which theme.js stores as <html data-theme>. */
:root {
  --bg: #ffffff; --fg: #09090b; --card: #ffffff;
  --primary: #18181b; --primary-fg: #fafafa;
  --secondary: #f4f4f5; --secondary-fg: #18181b;
  --muted: #f4f4f5; --muted-fg: #71717a;
  --destructive: #ef4444; --destructive-fg: #fafafa; --error: #dc2626; --ok: #16a34a;
  --border: #e4e4e7; --ring: #18181b; --barrier: rgba(0, 0, 0, .2);
  --c1: #2563eb; --c2: #16a34a; --c3: #d97706; --c4: #9333ea;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
  --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, .2), 0 2px 6px rgba(0, 0, 0, .06);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #09090b; --fg: #fafafa; --card: #09090b;
    --primary: #fafafa; --primary-fg: #18181b;
    --secondary: #27272a; --secondary-fg: #fafafa;
    --muted: #27272a; --muted-fg: #a1a1aa;
    --destructive: #dc2626; --destructive-fg: #fafafa; --error: #f87171; --ok: #4ade80;
    --border: #27272a; --ring: #d4d4d8; --barrier: rgba(0, 0, 0, .48);
    --c1: #3b82f6; --c2: #22c55e; --c3: #f59e0b; --c4: #a855f7;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #09090b; --fg: #fafafa; --card: #09090b;
  --primary: #fafafa; --primary-fg: #18181b;
  --secondary: #27272a; --secondary-fg: #fafafa;
  --muted: #27272a; --muted-fg: #a1a1aa;
  --destructive: #dc2626; --destructive-fg: #fafafa; --error: #f87171; --ok: #4ade80;
  --border: #27272a; --ring: #d4d4d8; --barrier: rgba(0, 0, 0, .48);
  --c1: #3b82f6; --c2: #22c55e; --c3: #f59e0b; --c4: #a855f7;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 10px 30px -10px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

/* ------------------------------------------------------------ base */

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
a { color: var(--fg); font-weight: 500; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 4px; transition: text-decoration-color .15s; }
a:hover { text-decoration-color: currentColor; }
p a, .muted a, .qr a { text-decoration-color: var(--muted-fg); }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
:not(pre) > code { background: var(--muted); padding: .15em .4em; border-radius: 4px; }
pre { background: color-mix(in srgb, var(--muted) 55%, var(--bg)); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 0; overflow: auto; white-space: pre; line-height: 1.6; }
h1 { font-size: 24px; line-height: 1.25; font-weight: 600; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 16px; line-height: 1.4; font-weight: 600; letter-spacing: -.01em; margin: 0 0 16px; }
h3 { font-size: 14px; font-weight: 600; margin: 20px 0 8px; }
h3:first-child { margin-top: 0; }
p { margin: 0 0 12px; }
.muted { color: var(--muted-fg); }
.small { font-size: 12.5px; }
.icon { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------ layout */

.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 85%, transparent); border-bottom: 1px solid var(--border); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.topbar-inner { max-width: 1140px; margin: 0 auto; height: 56px; padding: 0 16px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; text-decoration: none; }
.brand img { border-radius: 6px; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted-fg); text-decoration: none; transition: color .15s, background-color .15s; }
.nav a:hover { color: var(--fg); background: var(--secondary); }
.nav a[aria-current="page"] { color: var(--fg); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.container { max-width: 1140px; margin: 0 auto; padding: 32px 16px 80px; }

.page-head { margin-bottom: 24px; }
.page-head p { margin: 4px 0 0; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.row > h2 { margin: 0; }
.stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }

/* ------------------------------------------------------------ cards */

.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.panel > .row.spread:first-child { margin-bottom: 16px; }
.panel > :last-child { margin-bottom: 0; }
.panel > p.error:last-child:empty { display: none; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.stat .label { color: var(--muted-fg); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 40px 16px; }
.empty h3 { margin: 0 0 4px; font-size: 16px; }
.empty p { color: var(--muted-fg); margin: 0 0 16px; }
.secret { background: color-mix(in srgb, var(--muted) 55%, var(--bg)); border: 1px dashed var(--border); border-radius: var(--radius); padding: 12px 14px; word-break: break-all; }

/* ------------------------------------------------------------ forms */

label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 6px; }
label .muted { font-weight: 400; }
input, select, textarea { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--fg); font: inherit; transition: border-color .15s, box-shadow .15s; }
textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
input::placeholder, textarea::placeholder { color: var(--muted-fg); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 18%, transparent); }
input:disabled, select:disabled, textarea:disabled { opacity: .5; cursor: not-allowed; }
select { appearance: none; -webkit-appearance: none; padding-right: 36px; cursor: pointer; background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center / 16px; }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; margin: 0; accent-color: var(--primary); cursor: pointer; box-shadow: none; }
input.switch { appearance: none; -webkit-appearance: none; width: 36px; height: 20px; border-radius: 999px; border: 2px solid transparent; background: var(--border) radial-gradient(circle, var(--bg) 7px, transparent 7.5px) no-repeat 0 50% / 16px 16px; transition: background-color .15s, background-position .15s; }
input.switch:checked { background-color: var(--primary); background-image: radial-gradient(circle, var(--primary-fg) 7px, transparent 7.5px); background-position: 100% 50%; }
input.switch:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.field { margin-bottom: 16px; }
.fields { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.check { display: inline-flex; gap: 8px; align-items: center; font-weight: 500; margin: 0; cursor: pointer; }
.checks { display: flex; flex-wrap: wrap; gap: 10px 20px; margin-bottom: 16px; }
.error { color: var(--error); margin: 12px 0 0; font-weight: 500; }
.error:empty { display: none; }

/* ------------------------------------------------------------ buttons */

button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 16px; border-radius: var(--radius); border: 1px solid transparent; background: var(--primary); color: var(--primary-fg); font: inherit; font-size: 14px; font-weight: 500; white-space: nowrap; text-decoration: none; cursor: pointer; transition: background-color .15s, color .15s, border-color .15s; }
button:hover, .btn:hover { background: color-mix(in srgb, var(--primary) 88%, var(--bg)); text-decoration: none; }
button.secondary, .btn.secondary { background: var(--secondary); color: var(--secondary-fg); }
button.secondary:hover, .btn.secondary:hover { background: color-mix(in srgb, var(--secondary) 70%, var(--bg)); }
button.outline, .btn.outline { background: var(--bg); border-color: var(--border); color: var(--fg); }
button.outline:hover, .btn.outline:hover { background: var(--secondary); }
button.ghost, .btn.ghost { background: transparent; color: var(--fg); }
button.ghost:hover, .btn.ghost:hover { background: var(--secondary); }
button.danger, .btn.danger { background: var(--destructive); color: var(--destructive-fg); }
button.danger:hover, .btn.danger:hover { background: color-mix(in srgb, var(--destructive) 88%, var(--bg)); }
button.link { height: auto; padding: 0; border: 0; background: none; color: var(--fg); font-weight: 500; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 4px; transition: text-decoration-color .15s; }
button.link:hover { background: none; text-decoration-color: currentColor; }
button.sm, .btn.sm { height: 32px; padding: 0 12px; font-size: 13px; gap: 6px; }
button.block { width: 100%; }
button:disabled { opacity: .5; pointer-events: none; }
[data-copy] .when-copied, [data-copy].copied .when-idle { display: none; }
[data-copy].copied .when-copied { display: block; color: var(--ok); }

/* Segmented control (Forui FTabs look), used for the theme picker. */
.seg { display: flex; gap: 2px; padding: 3px; border-radius: var(--radius); background: var(--muted); }
.seg button { width: 28px; height: 26px; padding: 0; border-radius: 6px; background: transparent; color: var(--muted-fg); }
.seg button:hover { background: transparent; color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--fg); box-shadow: var(--shadow-sm); }

/* ------------------------------------------------------------ tabs, tables, badges */

.tabs { display: flex; width: fit-content; max-width: 100%; gap: 2px; padding: 4px; margin: 20px 0 24px; border-radius: var(--radius); background: var(--muted); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 6px 12px; border-radius: 6px; color: var(--muted-fg); white-space: nowrap; text-decoration: none; transition: color .15s, background-color .15s; }
.tabs a:hover { color: var(--fg); }
.tabs a.active { background: var(--bg); color: var(--fg); box-shadow: var(--shadow-sm); }

.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: middle; }
th { height: 40px; padding-top: 0; padding-bottom: 0; color: var(--muted-fg); font-weight: 500; white-space: nowrap; }
tbody tr { transition: background-color .15s; }
tbody tr:hover { background: color-mix(in srgb, var(--muted) 50%, transparent); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; border: 1px solid transparent; background: var(--primary); color: var(--primary-fg); font-size: 12px; line-height: 16px; font-weight: 600; white-space: nowrap; }
.badge.gray { background: var(--secondary); color: var(--secondary-fg); }
.badge.outline { background: transparent; border-color: var(--border); color: var(--fg); font-weight: 500; }

/* ------------------------------------------------------------ pages */

.auth { max-width: 400px; margin: 48px auto; }
.auth-brand { display: flex; justify-content: center; margin-bottom: 20px; }
.auth-brand img { border-radius: 10px; }
.auth .panel { padding: 24px; }
.auth h1 { margin-bottom: 4px; }
.auth form { margin-top: 20px; }

.qr img { display: block; width: 160px; height: 160px; background: #fff; border-radius: var(--radius); padding: 8px; border: 1px solid var(--border); margin-bottom: 8px; }

.chart-box { position: relative; padding-left: 40px; }
.chart { width: 100%; height: 220px; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-dasharray: 4 4; }
.chart-y { position: absolute; left: 0; width: 32px; transform: translateY(-50%); text-align: right; color: var(--muted-fg); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-x { display: flex; justify-content: space-between; padding-left: 40px; margin-top: 6px; color: var(--muted-fg); font-size: 11px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: 12.5px; color: var(--muted-fg); text-transform: capitalize; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ------------------------------------------------------------ overlays */

#toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: flex; align-items: center; gap: 10px; min-width: 260px; max-width: min(420px, calc(100% - 32px)); padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--fg); box-shadow: var(--shadow-lg); font-weight: 500; animation: toast-in .2s ease-out; }
#toast .toast-ok { color: var(--ok); }
#toast .toast-error { display: none; color: var(--error); }
#toast.error .toast-error { display: block; }
#toast.error .toast-ok { display: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

dialog { width: min(440px, calc(100% - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); color: var(--fg); box-shadow: var(--shadow-lg); }
dialog[open] { animation: dialog-in .15s ease-out; }
dialog::backdrop { background: var(--barrier, rgba(0, 0, 0, .4)); }
dialog form { padding: 24px; }
dialog h2 { margin-bottom: 8px; }
dialog p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
@keyframes dialog-in { from { opacity: 0; transform: scale(.96); } }

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

@media (max-width: 640px) {
  .topbar-inner { gap: 12px; }
  .hide-sm { display: none; }
  #logout { width: 32px; padding: 0; }
  .container { padding-top: 24px; }
  .panel { padding: 16px; }
  #toast { left: 16px; right: 16px; bottom: 16px; max-width: none; min-width: 0; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions button { width: 100%; }
}
