/* web-ui: the only stylesheet for server-rendered apps.
   Layers: tokens -> base -> components -> responsive -> utilities.
   Raw colors/sizes are allowed ONLY in the tokens layer.
   Visual language = locusfe / ui-next: same palette (libs/ui-next/src/theme.rs),
   DM Sans, filled inputs, borderless surface panels, pill nav, compact density.
   Phone: nav becomes a bottom tab bar, like locusfe. */

@font-face { font-family: "Google Sans Flex"; src: url("googlesans.woff2") format("woff2"); font-weight: 100 1000; font-display: swap; }
/* Metric-matched fallback: if the real font is late, the swap does not move layout. */
@font-face { font-family: "Google Sans Fallback"; src: local("Arial"), local("Helvetica"), local("Liberation Sans"); ascent-override: 96.6%; descent-override: 28.6%; line-gap-override: 0%; size-adjust: 100%; }

/* ---------- tokens (mirror ui-next Theme::light / Theme::dark) ---------- */
:root {
  --bg: #f7f7fa;        /* Bg */
  --surface: #ffffff;   /* Surface */
  --raised: #ebedf2;    /* Raised */
  --text: #1a1c21;      /* Text */
  --dim: #6b7380;       /* Dim */
  --accent: #3366e6;    /* Accent */
  --on-accent: #ffffff; /* OnAccent */
  --border: #d6dbe6;    /* Border */
  --danger: #cc3333;    /* Danger */
  --success: #338026;   /* Success (syntax string) */
  --warning: #bf610d;   /* syntax number */
  --input: #e8ebf0;     /* input_bg */
  --ring: rgba(51, 102, 230, 0.35);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 40px;
  --r: 6px; --r-lg: 10px;
  --font: "Google Sans Flex", "Google Sans Fallback", ui-sans-serif, system-ui, sans-serif;
  --mono: "GeistMono NF", "JetBrains Mono", ui-monospace, monospace;
  --t-xs: 12px; --t-sm: 13px; --t-md: 14px; --t-lg: 16px; --t-xl: 22px; --t-2xl: 34px;
  --page-width: 960px;
  --form-width: 380px;
  --ctl-h: 32px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121419; --surface: #1c1f26; --raised: #292b36;
    --text: #e6e8ed; --dim: #8c94a3; --accent: #5c8cfa; --on-accent: #ffffff;
    --border: #333845; --danger: #f06161; --success: #99d185; --warning: #f5a866;
    --input: #11121a; --ring: rgba(92, 140, 250, 0.4);
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font); font-size: var(--t-md); line-height: 1.5;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh; display: flex; flex-direction: column;
}
h1, h2, h3 { font-weight: 500; color: var(--text); }
h1 { font-size: var(--t-xl); line-height: 1.3; }
h2 { font-size: var(--t-md); }
h3 { font-size: var(--t-md); }
p { color: var(--dim); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; border-radius: var(--r); }
code, pre, kbd { font-family: var(--mono); font-size: 0.92em; }
code { background: var(--raised); padding: 1px 5px; border-radius: 4px; }
pre { background: var(--input); padding: var(--s3) var(--s4); border-radius: var(--r); overflow-x: auto; }
pre code { background: none; padding: 0; }
img { max-width: 100%; display: block; }
hr { border: 0; border-top: 1px solid var(--border); }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; height: var(--ctl-h); padding: 0 10px;
  background: var(--input); border: 1px solid var(--border); border-radius: var(--r);
  color: var(--text);
}
textarea { height: auto; min-height: 7rem; padding: var(--s2) 10px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--dim); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { font-size: var(--t-sm); color: var(--dim); }
::selection { background: var(--ring); }

/* ---------- components ---------- */
.page { width: 100%; max-width: var(--page-width); margin: 0 auto; padding: var(--s5) var(--s5) var(--s6); flex: 1; }
.page.stack { gap: var(--s4); }

/* top bar: brand left, links as a pill group (locusfe tab strip) */
.nav {
  position: sticky; top: 0; z-index: 10; height: 48px;
  display: flex; align-items: center; gap: 2px;
  padding: 0 max(var(--s5), calc((100% - var(--page-width)) / 2 + var(--s5)));
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.nav .brand { color: var(--text); font-weight: 500; font-size: var(--t-md); margin-right: auto; }
.nav .brand:hover { text-decoration: none; }
.nav a:not(.brand) {
  color: var(--dim); font-size: var(--t-md); padding: 4px 12px; border-radius: var(--r);
}
.nav a:not(.brand):hover { color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--accent); background: var(--raised); }
.nav > span { margin-left: var(--s3); color: var(--dim); font-size: var(--t-sm); }
.footer { color: var(--dim); font-size: var(--t-xs); padding: var(--s4) var(--s5); text-align: center; }

/* panel: Surface fill, no border, no shadow */
.card { background: var(--surface); border-radius: var(--r-lg); padding: var(--s4); }
.card.stack { gap: var(--s3); }
.card > h2:first-child + p { margin-top: calc(var(--s2) * -1); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: var(--ctl-h); padding: 0 14px; border: 0; border-radius: var(--r);
  cursor: pointer; white-space: nowrap;
  background: var(--raised); color: var(--text); font-size: var(--t-md);
}
.btn:hover { filter: brightness(1.08); text-decoration: none; color: var(--text); }
.btn-primary, .btn-primary:hover { background: var(--accent); color: var(--on-accent); }
.btn-danger, .btn-danger:hover { color: var(--danger); }

form.card { max-width: var(--form-width); }
form.card.wide { max-width: none; }
.card .from { color: var(--text); font-weight: 500; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field .hint { color: var(--dim); font-size: var(--t-xs); }
.field .error { color: var(--danger); font-size: var(--t-xs); }
.field:has(.error) input, .field:has(.error) textarea { border-color: var(--danger); }

.alert {
  display: flex; align-items: center; gap: 10px;
  padding: 10px var(--s4); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text); font-size: var(--t-md);
}
.alert::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--dim); }
.alert-info::before { background: var(--accent); }
.alert-success::before { background: var(--success); }
.alert-error { color: var(--danger); }
.alert-error::before { background: var(--danger); }

/* status: coloured dot + text, no pill fill */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-sm); color: var(--dim); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { color: var(--success); }
.badge-warning { color: var(--warning); }
.badge-danger { color: var(--danger); }

/* table: lives on a panel, hairline rows */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--r-lg); padding: var(--s1) var(--s4); }
.table { width: 100%; border-collapse: collapse; font-size: var(--t-md); font-variant-numeric: tabular-nums; }
.table th, .table td { text-align: left; padding: 9px var(--s3); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th:first-child, .table td:first-child { padding-left: 0; }
.table th:last-child, .table td:last-child { padding-right: 0; text-align: right; }
.table th { font-size: var(--t-xs); font-weight: 400; color: var(--dim); }
.table td { color: var(--dim); }
.table td:first-child { color: var(--text); }
.table tbody tr:last-child td { border-bottom: 0; }

/* empty: centred in a panel, like locusfe "Your library is empty" */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--s2);
  text-align: center; color: var(--dim); font-size: var(--t-md);
  padding: var(--s6) var(--s4); background: var(--surface); border-radius: var(--r-lg);
}

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: var(--s2); }
.stat { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border-radius: var(--r-lg); padding: var(--s3) var(--s4); }
.stat .label { color: var(--dim); font-size: var(--t-sm); }
.stat .value { font-size: var(--t-xl); font-weight: 500; font-variant-numeric: tabular-nums; }

.hero { padding: var(--s6) 0 var(--s5); display: flex; flex-direction: column; gap: var(--s3); align-items: flex-start; }
.hero h1 { font-size: var(--t-2xl); line-height: 1.15; letter-spacing: -0.01em; max-width: 22ch; }
.hero p { font-size: var(--t-lg); max-width: 36rem; }
.hero .btn { margin-top: var(--s2); height: 36px; }

.price { display: flex; flex-direction: column; gap: var(--s3); }
.price h3 { color: var(--dim); font-weight: 400; }
.price .amount { font-size: 28px; font-weight: 500; line-height: 1; font-variant-numeric: tabular-nums; }
.price ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; flex: 1; color: var(--dim); }
.price li::before { content: "✓"; color: var(--accent); margin-right: var(--s2); }
.price .btn { width: 100%; margin-top: var(--s2); }

.prose { max-width: 40rem; display: flex; flex-direction: column; gap: 1em; font-size: var(--t-lg); line-height: 1.7; }
article:has(> .prose), article:has(> .prose) + section { width: 100%; max-width: 40rem; }
.prose p, .prose li { color: var(--text); }
.prose h1 { font-size: 30px; line-height: 1.2; }
.prose h2 { margin-top: 0.6em; font-size: 20px; }
.prose ul, .prose ol { padding-left: 1.25em; }
.prose blockquote { border-left: 2px solid var(--border); padding-left: var(--s4); color: var(--dim); }
.prose img { border-radius: var(--r-lg); }
.prose .math svg { display: inline-block; vertical-align: -0.25em; }
.prose .math-block { display: flex; justify-content: center; overflow-x: auto; padding: var(--s2) 0; }
.prose .diagram { margin: 0; padding: var(--s4); background: var(--surface); border-radius: var(--r-lg); overflow-x: auto; display: flex; justify-content: center; }
.prose .diagram svg { max-width: 100%; height: auto; }

/* license: the key is the hero of the panel */
.license { background: var(--surface); border-radius: var(--r-lg); padding: var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.license-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3); }
.license-head h3 { font-size: var(--t-lg); }
.key { display: flex; align-items: center; gap: var(--s2); background: var(--input); border-radius: var(--r); padding: 6px 6px 6px var(--s4); }
.key-text { flex: 1; font-size: 18px; font-weight: 500; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; color: var(--text); overflow-wrap: anywhere; user-select: all; }
.copy { background: var(--surface); }
.copy[data-done] { color: var(--success); }
.license-foot { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.slots { display: inline-flex; gap: 4px; }
.slot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--border); }
.slot.on { background: var(--accent); border-color: var(--accent); }
.license:has(.badge-danger) .key-text { color: var(--dim); text-decoration: line-through; }

/* mail: folder rail + message list (mailserver) */
.mail { display: grid; grid-template-columns: 180px 1fr; gap: var(--s5); align-items: start; }
.folders { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 64px; }
.folders a { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-radius: var(--r); color: var(--dim); }
.folders a:hover { color: var(--text); text-decoration: none; background: var(--raised); }
.folders a[aria-current="page"] { color: var(--text); background: var(--raised); font-weight: 500; }
.count { font-size: var(--t-xs); color: var(--accent); font-variant-numeric: tabular-nums; }
.msgs { background: var(--surface); border-radius: var(--r-lg); overflow: hidden; }
.msgs h2 { font-size: var(--t-xs); color: var(--dim); font-weight: 500; padding: var(--s3) var(--s4) var(--s1); text-transform: uppercase; letter-spacing: 0.06em; }
.msg { display: grid; grid-template-columns: 8px minmax(0, 11rem) minmax(0, 1fr) auto; gap: var(--s3); align-items: baseline; padding: 10px var(--s4); color: var(--dim); border-top: 1px solid var(--border); }
.msgs h2 + .msg { border-top: 0; }
.msg:hover { background: var(--bg); text-decoration: none; }
.msg .from, .msg .line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg .from, .msg .subj { color: var(--text); }
.msg .date { font-size: var(--t-sm); font-variant-numeric: tabular-nums; }
.msg .dot { width: 7px; height: 7px; border-radius: 50%; align-self: center; }
.msg.unread .dot { background: var(--accent); }
.msg.unread .from, .msg.unread .subj { font-weight: 600; }
.msg .flag { color: var(--warning); margin-right: 4px; }

/* ---------- responsive: phone ---------- */
@media (max-width: 640px) {
  :root { --ctl-h: 40px; }
  .page { padding: var(--s4) var(--s3) calc(64px + var(--s5)); }
  /* nav: brand stays on top, links become a bottom tab bar */
  .nav { padding: 0 var(--s4); }
  .nav > span { display: none; }
  .nav a:not(.brand) { display: none; }
  .nav:has(a:not(.brand)) + .page + .footer, .nav:has(a:not(.brand)) ~ .footer { padding-bottom: 72px; }
  body > .tabs { display: flex; }
  input, select, textarea { font-size: 16px; } /* no iOS zoom-on-focus */
  form.card { max-width: none; }
  .hero { padding: var(--s5) 0 var(--s3); }
  .hero h1 { font-size: 28px; }
  .hero .btn { width: 100%; }
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 18px; }
  /* tables: one block per row, td[data-label] names the column */
  .table thead { display: none; }
  .table tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .table tbody tr:last-child { border-bottom: 0; }
  .table td, .table td:first-child, .table td:last-child {
    display: flex; justify-content: space-between; align-items: center; gap: var(--s3);
    padding: 2px 0; border: 0; text-align: right; white-space: normal;
  }
  .table td:not(:first-child)::before { content: attr(data-label); color: var(--dim); font-size: var(--t-sm); }
  .prose { font-size: 15px; }
  .key-text { font-size: 15px; letter-spacing: 0.04em; }
  .license-foot .btn { flex: 1; }
  .license-foot .grow { flex-basis: 60%; }
  .mail { grid-template-columns: 1fr; gap: var(--s3); }
  .folders { position: static; flex-direction: row; overflow-x: auto; }
  .folders a { flex: none; gap: var(--s2); }
  .msgs { margin: 0 calc(var(--s3) * -1); border-radius: 0; }
  .msg { grid-template-columns: 8px minmax(0, 1fr) auto; row-gap: 2px; }
  .msg .date { grid-row: 1; grid-column: 3; }
  .msg .line { grid-row: 2; grid-column: 2 / 4; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
}

/* bottom tab bar (phone only); rendered by `page` from the same links */
.tabs {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: 56px; padding: 6px var(--s2) calc(6px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--border);
  justify-content: space-around; align-items: stretch;
}
.tabs a { flex: 1; display: grid; place-items: center; border-radius: var(--r); color: var(--dim); font-size: var(--t-sm); }
.tabs a:hover { text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--accent); background: var(--raised); }

/* ---------- utilities (closed list) ---------- */
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: var(--s3); }
.gap-2 { gap: var(--s2); }
.gap-5 { gap: var(--s5); }
.grow { flex: 1; }
.muted { color: var(--dim); }
.small { font-size: var(--t-sm); }
.center { text-align: center; }
.narrow { max-width: var(--form-width); width: 100%; margin: var(--s5) auto 0; }
.narrow form.card { max-width: none; }
.narrow form.card .btn-primary { width: 100%; }
.mono { font-family: var(--mono); font-size: 0.92em; color: var(--text); }
