:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #1d4ed8;
  --primary-ink: #ffffff;
  --primary-soft: #dbeafe;
  --success: #047857;
  --success-soft: #d1fae5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", "Nirmala UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #0f172a;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #1f2a3d;
    --primary: #3b82f6;
    --primary-soft: #172554;
    --success: #34d399;
    --success-soft: #064e3b;
    --warn: #fbbf24;
    --warn-soft: #451a03;
    --danger: #f87171;
    --danger-soft: #450a0a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }

.container { max-width: 1280px; margin: 0 auto; padding: 20px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h2 { font-size: 16px; margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* ---------- buttons & inputs ---------- */
.btn { --b: var(--surface); --c: var(--text); appearance: none; border: 1px solid var(--border); background: var(--b); color: var(--c); padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; transition: filter .15s, transform .05s; }
.btn:hover { filter: brightness(.96); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { --b: var(--primary); --c: var(--primary-ink); border-color: transparent; }
.btn-success { --b: var(--success); --c: #fff; border-color: transparent; }
.btn-warn { --b: var(--warn-soft); --c: var(--warn); border-color: transparent; }
.btn-danger { --b: var(--danger-soft); --c: var(--danger); border-color: transparent; }
.btn-ghost { --b: transparent; border-color: transparent; }
.btn-lg { padding: 14px 22px; font-size: 17px; border-radius: 11px; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn kbd { font-family: var(--mono); font-size: 11px; opacity: .7; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; }

label.field { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
label.field > span { display: block; margin-bottom: 4px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 64px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

/* ---------- misc ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge-priority { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-open { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-break { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-closed { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-return { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { background: none; border: none; font: inherit; font-weight: 600; color: var(--muted); padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 30px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }

.empty { text-align: center; color: var(--muted); padding: 24px 12px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; width: min(92vw, 460px); }
.toast { background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-weight: 500; animation: pop .2s ease-out; }
.toast.error { background: #991b1b; }
.toast.success { background: #065f46; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

.conn { font-size: 12px; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.conn .dot { background: var(--success); }
.conn.off .dot { background: var(--danger); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(100%, 380px); }

/* ---------- launcher ---------- */
.launch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.launch { display: block; text-decoration: none; color: inherit; transition: border-color .15s; }
.launch:hover { border-color: var(--primary); }
.launch h3 { font-size: 16px; margin-bottom: 4px; }
.launch p { margin: 0; color: var(--muted); font-size: 14px; }
.launch .ico { font-size: 26px; margin-bottom: 8px; }

/* ---------- token chips ---------- */
.token-chip { font-family: var(--mono); font-weight: 800; font-size: 15px; padding: 4px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); display: inline-block; }
.token-chip.priority { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

@media (max-width: 640px) {
  .container { padding: 16px; }
  .topbar { padding: 10px 16px; }
}
