/* Design tokens, layout primitives and components shared by every app. styles/app.css sets --accent. */
:root {
  --bg: #f7f6f2;
  --panel: #fffefb;
  --panel-2: #f0eee8;
  --line: #e1ddd3;
  --text: #1d1c19;
  --muted: #6a665d;
  --accent: #3f5873;
  --accent-ink: #ffffff;
  --good: #2f7d4f;
  --warn: #a8690b;
  --bad: #b8392f;
  --radius: 6px;
  --shadow: none;
  --shadow-lg: 0 8px 24px -10px rgba(40, 34, 20, .22);
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513; --panel: #1d1c1a; --panel-2: #252421; --line: #34322d;
    --text: #ebe9e3; --muted: #9d998f; --accent-ink: #ffffff;
    --good: #5fae7d; --warn: #d39a3a; --bad: #e0675b;
    --shadow: none; --shadow-lg: 0 8px 24px -10px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161513; --panel: #1d1c1a; --panel-2: #252421; --line: #34322d;
    --text: #ebe9e3; --muted: #9d998f; --accent-ink: #ffffff;
    --good: #5fae7d; --warn: #d39a3a; --bad: #e0675b;
    --shadow: none; --shadow-lg: 0 8px 24px -10px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font-body, system-ui, -apple-system, 'Segoe UI', sans-serif);
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--accent); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.01em; }
p { margin: 0 0 .75em; }
code, pre { font-family: var(--mono); font-size: .9em; }
pre { background: var(--panel-2); padding: 12px; border-radius: 8px; overflow: auto; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { font-size: 18px; margin: 0; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; align-items: center; flex: none; }
main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.side { grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grow { flex: 1; min-width: 0; }
@media (max-width: 820px) {
  .cols-2, .cols-3, .side { grid-template-columns: minmax(0, 1fr); }
  main { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .brand p { display: none; }
}

/* surfaces */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); min-width: 0;
}
.card h2 { font-size: 16px; }
.card h3 { font-size: 13.5px; color: var(--muted); font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 32px 12px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* controls */
.input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; outline: none;
}
textarea { resize: vertical; min-height: 110px; line-height: 1.45; }
.input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
label > .input, label > textarea, label > select { margin-top: 5px; font-weight: 400; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }

.btn {
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; border-radius: 8px;
  padding: 8px 14px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; position: relative;
  transition: transform .05s, background .15s, border-color .15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn.loading { color: transparent !important; }
.btn.loading::after {
  content: ''; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--muted) transparent var(--muted) transparent; animation: spin .8s linear infinite;
}
.btn.primary.loading::after { border-color: var(--accent-ink) transparent var(--accent-ink) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; }

.tag {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
  padding: 1px 7px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.tag.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--line)); }
.tag.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.tag.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.tag.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button {
  font: inherit; font-weight: 600; font-size: 14px; background: none; border: 0; color: var(--muted);
  padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

.stat { background: var(--panel-2); border-radius: 10px; padding: 12px 14px; }
.stat .v { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.stat .k { font-size: 12.5px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.table-wrap { overflow: auto; max-width: 100%; }

.prose p:last-child { margin-bottom: 0; }
.prose ul, .prose ol { padding-left: 20px; margin: 0 0 .75em; }
.prose h3, .prose h4, .prose h5 { margin-top: 1em; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 15px; }

.bar { height: 8px; background: var(--panel-2); border-radius: 2px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); transition: width .4s; }

/* AI badge, banner, modal (rendered by ai.js) */
.ai-badge {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 10px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.ai-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.ai-badge.live .dot { background: var(--good); }
.ai-demo-banner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 24px; font-size: 13px; background: color-mix(in srgb, var(--warn) 12%, var(--panel)); border-bottom: 1px solid var(--line);
}
.ai-modal { position: fixed; inset: 0; background: rgba(10, 12, 20, .55); display: grid; place-items: center; z-index: 100; padding: 16px; }
.ai-modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 22px; width: min(460px, 100%); box-shadow: var(--shadow); }
.ai-modal-card label { margin-bottom: 12px; }
.ai-modal-card label a { font-weight: 500; float: right; }
.ai-modal-status { min-height: 20px; font-size: 13px; margin-bottom: 10px; word-break: break-word; }

.toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 200; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 6px; font-size: 14px; box-shadow: var(--shadow); transition: opacity .4s, transform .4s; max-width: 420px; }
.toast.err { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }

footer.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 24px; }

/* pages + navigation (lib/router.js) */
.page { display: none; }
.page.active { display: contents; }
.topnav { display: flex; gap: 2px; align-items: center; flex: 1; justify-content: center; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.topnav a { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; white-space: nowrap; }
.topnav a:hover { background: var(--panel-2); color: var(--text); }
.topnav a.on { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.topnav .ico { font-size: 15px; }
main.settings { max-width: 760px; }
.settings h3 { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 16px; margin: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.page-head h2 { font-size: 22px; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.list-item { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.topbar { flex-wrap: wrap; row-gap: 8px; padding-bottom: 0 !important; }
.topbar .brand, .topbar .top-actions { padding-bottom: 2px; }
.topnav { order: 3; flex-basis: 100%; justify-content: flex-start; margin: 0 -10px; }
.topnav a { padding: 8px 10px 10px !important; }


/* ---------- type and details ---------- */
body { font-size: 14.5px; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -.01em; }
.topbar { padding: 10px 24px; min-height: 58px; background: var(--bg); }
.brand h1 { font-family: var(--font-head, inherit); font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.brand h1 a { color: var(--text); text-decoration: none; }
.brand p { font-size: 12.5px; }
.page-head h2 { font-family: var(--font-head, inherit); font-weight: 600; }
.card { padding: 20px; }
.card h2 { font-size: 15px; font-weight: 600; }
.btn { font-weight: 500; font-size: 13.5px; padding: 7px 13px; background: var(--panel); border-radius: var(--radius); }
.btn:hover { background: var(--panel-2); border-color: color-mix(in srgb, var(--text) 22%, var(--line)); }
.btn.ghost { background: transparent; }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); filter: none; }
.btn:focus-visible, .topnav a:focus-visible, .ai-badge:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.input, textarea, select { background: var(--panel); border-radius: var(--radius); padding: 8px 10px; }
.input:focus, textarea:focus, select:focus { box-shadow: none; outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 0; }
label { font-weight: 500; color: var(--text); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 15px; }
.stat .v { font-size: 22px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tag { font-weight: 500; font-size: 12px; }
td { font-variant-numeric: tabular-nums; }
.topnav a { font-weight: 500; font-size: 14px; padding: 6px 10px; border-radius: var(--radius); }
.topnav a.on { background: transparent; color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }
.ai-badge { font-weight: 500; font-size: 12.5px; background: var(--panel); }
.ai-demo-banner { background: var(--panel-2); color: var(--muted); padding: 7px 24px; font-size: 13px; }
.ai-demo-banner b { color: var(--text); font-weight: 600; }
.ai-modal-card { box-shadow: var(--shadow-lg); }
.toast { box-shadow: var(--shadow-lg); font-size: 13.5px; }
.empty { background: transparent; }
footer.foot { font-size: 12px; }
::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }

/* ---------- account chip ---------- */
.account { position: relative; }
.account-menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 10px; display: grid; gap: 6px; min-width: 200px; z-index: 60; }

/* ---------- AI command box ---------- */
.copilot-trigger kbd { font: 500 11px var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; margin-left: 4px; }
.copilot-fab { position: fixed; right: 16px; bottom: 16px; z-index: 70; box-shadow: var(--shadow-lg); }
.copilot { position: fixed; right: 16px; top: 112px; z-index: 71; width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 132px); display: flex; flex-direction: column; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow-lg); padding: 16px; }
.copilot .tabs { margin: 0; }
.copilot [data-pane] { min-height: 0; }
.copilot textarea { resize: vertical; font-size: 14px; flex: 1; min-height: 64px; }
.copilot-log { overflow-y: auto; max-height: 340px; display: flex; flex-direction: column; gap: 12px; }
.copilot-me { font-size: 14px; font-weight: 600; white-space: pre-wrap; }
.copilot-ai { font-size: 14px; white-space: pre-wrap; color: var(--text); padding-left: 10px; border-left: 2px solid var(--line); margin-top: -6px; }
.copilot-ai.err { color: var(--bad); border-left-color: var(--bad); }
.copilot-step { font-size: 12.5px; margin-top: 4px; color: var(--muted); }
.copilot-step::before { content: 'Done: '; color: var(--good); font-weight: 600; }
.copilot-step.bad::before { content: 'Failed: '; color: var(--bad); }
.copilot-ex { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.copilot-ex .btn { font-weight: 400; text-align: left; white-space: normal; color: var(--muted); padding: 3px 0; border: 0; background: none; }
.copilot-ex .btn:hover { color: var(--text); background: none; text-decoration: underline; }
@media print { .copilot, .copilot-fab, .copilot-trigger { display: none !important; } }
