/* =====================================================================
   Authority Engine — design system v3 ("Signal")
   Precise, calm, technical. Colour always carries meaning:
   violet→cyan = the system / the loop · amber = YOUR move ·
   emerald = established · rose = refused/broken · O0→O4 = evidence.
   Self-hosted fonts + icons; CSP 'self' only; no inline styles/scripts.
   ===================================================================== */

@font-face { font-family: "Inter"; src: url("/static/fonts/inter-latin.woff2") format("woff2");
  font-weight: 400 800; font-style: normal; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("/static/fonts/jetbrainsmono-latin.woff2") format("woff2");
  font-weight: 400 600; font-display: swap; }
@font-face { font-family: "Instrument Serif"; src: url("/static/fonts/instrumentserif-latin.woff2") format("woff2");
  font-weight: 400; font-display: swap; }

/* ---------- tokens (light) ---------- */
:root {
  --bg: #f5f6fb;
  --bg-glow-1: rgba(109, 94, 252, .10);
  --bg-glow-2: rgba(34, 195, 238, .08);
  --surface: #ffffff;
  --surface-2: #f2f4fa;
  --surface-3: #e9ecf6;
  --glass: rgba(255, 255, 255, .78);
  --ink: #0e1426;
  --ink-2: #33405a;
  --muted: #66718c;
  --rule: #e3e7f1;
  --rule-strong: #cbd2e3;
  --primary: #5b4cf0;
  --primary-soft: #eeecff;
  --grad: linear-gradient(135deg, #6d5efc 0%, #3b82f6 55%, #22c3ee 100%);
  --grad-soft: linear-gradient(135deg, rgba(109,94,252,.12), rgba(34,195,238,.10));
  --you: #a5530a; --you-bg: #fff3dc; --you-line: #f6c26b;
  --ok: #08795a; --ok-bg: #dcf6ec;
  --warn: #9a5b00; --warn-bg: #fff2d6;
  --bad: #be1846; --bad-bg: #ffe3ea;
  --info: #2e5bd8; --info-bg: #e5edff;
  --o0: #94a0b8; --o1: #d48a1e; --o2: #86a326; --o3: #12a172; --o4: #0ea5c6;
  --focus: #5b4cf0;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-1: 0 1px 2px rgba(14, 20, 38, .05), 0 1px 1px rgba(14, 20, 38, .03);
  --shadow-2: 0 10px 30px -12px rgba(14, 20, 38, .18), 0 2px 6px rgba(14, 20, 38, .05);
  --shadow-glow: 0 8px 28px -10px rgba(91, 76, 240, .45);
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --rail-w: 252px;
  color-scheme: light;
}

/* ---------- tokens (dark): explicit choice, or system preference ---------- */
:root[data-theme="dark"] {
  --bg: #070a16; --bg-glow-1: rgba(124, 108, 255, .20); --bg-glow-2: rgba(34, 195, 238, .12);
  --surface: #0f1427; --surface-2: #151b33; --surface-3: #1c2342; --glass: rgba(13, 18, 36, .72);
  --ink: #eceffb; --ink-2: #c3c9e2; --muted: #8b94b8; --rule: #222a4b; --rule-strong: #323c66;
  --primary: #8f83ff; --primary-soft: rgba(143, 131, 255, .16);
  --grad-soft: linear-gradient(135deg, rgba(143,131,255,.16), rgba(61,214,245,.10));
  --you: #ffbe6b; --you-bg: rgba(255, 176, 64, .14); --you-line: rgba(255, 176, 64, .55);
  --ok: #4fd6a5; --ok-bg: rgba(79, 214, 165, .13);
  --warn: #ffc76b; --warn-bg: rgba(255, 199, 107, .12);
  --bad: #ff7d99; --bad-bg: rgba(255, 125, 153, .13);
  --info: #8fb0ff; --info-bg: rgba(143, 176, 255, .13);
  --o0: #7c86a6; --o1: #f0a43a; --o2: #a8c94a; --o3: #34d399; --o4: #38d3f0;
  --focus: #a59bff;
  --shadow-1: 0 1px 0 rgba(255, 255, 255, .03) inset;
  --shadow-2: 0 16px 40px -18px rgba(0, 0, 0, .7);
  --shadow-glow: 0 10px 34px -12px rgba(143, 131, 255, .55);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #070a16; --bg-glow-1: rgba(124, 108, 255, .20); --bg-glow-2: rgba(34, 195, 238, .12);
    --surface: #0f1427; --surface-2: #151b33; --surface-3: #1c2342; --glass: rgba(13, 18, 36, .72);
    --ink: #eceffb; --ink-2: #c3c9e2; --muted: #8b94b8; --rule: #222a4b; --rule-strong: #323c66;
    --primary: #8f83ff; --primary-soft: rgba(143, 131, 255, .16);
    --grad-soft: linear-gradient(135deg, rgba(143,131,255,.16), rgba(61,214,245,.10));
    --you: #ffbe6b; --you-bg: rgba(255, 176, 64, .14); --you-line: rgba(255, 176, 64, .55);
    --ok: #4fd6a5; --ok-bg: rgba(79, 214, 165, .13);
    --warn: #ffc76b; --warn-bg: rgba(255, 199, 107, .12);
    --bad: #ff7d99; --bad-bg: rgba(255, 125, 153, .13);
    --info: #8fb0ff; --info-bg: rgba(143, 176, 255, .13);
    --o0: #7c86a6; --o1: #f0a43a; --o2: #a8c94a; --o3: #34d399; --o4: #38d3f0;
    --focus: #a59bff;
    --shadow-1: 0 1px 0 rgba(255, 255, 255, .03) inset;
    --shadow-2: 0 16px 40px -18px rgba(0, 0, 0, .7);
    --shadow-glow: 0 10px 34px -12px rgba(143, 131, 255, .55);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; min-height: 100vh; color: var(--ink); background: var(--bg);
  font: 400 15px/1.6 var(--sans); font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
body::before {  /* aurora — fixed, behind everything, purely atmospheric */
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(1000px 520px at 85% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(800px 420px at -5% 10%, var(--bg-glow-2), transparent 60%);
}
a { color: var(--primary); text-decoration: none; text-underline-offset: 3px; }
a:hover { text-decoration: underline; }
.panel a, .notice a, li a, td a { overflow-wrap: anywhere; }
:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { color: var(--ink); line-height: 1.2; letter-spacing: -.015em; margin: 0 0 .6rem; }
h1 { font-family: var(--display); font-weight: 400; font-size: clamp(1.9rem, 1.2rem + 2vw, 2.7rem); letter-spacing: -.01em; }
h2 { font-size: 1.06rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
p { margin: 0 0 .75rem; }
code, .mono { font-family: var(--mono); font-size: .84em; }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.skip { position: absolute; left: -999px; top: .5rem; z-index: 100; background: var(--surface); padding: .6rem 1rem; border-radius: 10px; box-shadow: var(--shadow-2); }
.skip:focus { left: 1rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 20px; height: 20px; flex: none; display: inline-block; vertical-align: -4px; }
.icon.sm { width: 16px; height: 16px; vertical-align: -3px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 1.1rem .85rem 1rem;
  background: var(--glass); backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border-right: 1px solid var(--rule); display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: .7rem; padding: .3rem .5rem 1.2rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px; flex: none; display: grid; place-items: center;
  background: var(--grad); color: #fff; box-shadow: var(--shadow-glow); font-weight: 800; font-size: 1rem;
}
.brand b { display: block; font-size: .98rem; font-weight: 700; letter-spacing: -.01em; }
.brand div span { display: block; color: var(--muted); font-size: .74rem; }
.nav { list-style: none; margin: 0; padding: 0; }
.nav li { margin: 2px 0; }
.nav .group { margin: 1.15rem .7rem .35rem; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.nav a {
  position: relative; display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem;
  border-radius: 11px; color: var(--ink-2); font-weight: 520; font-size: .92rem;
  transition: background-color .15s, color .15s;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a .icon { color: var(--muted); }
.nav a[aria-current="page"] { background: var(--grad-soft); color: var(--ink); font-weight: 650; }
.nav a[aria-current="page"] .icon { color: var(--primary); }
.nav a[aria-current="page"]::before {
  content: ""; position: absolute; left: -.85rem; top: 22%; bottom: 22%; width: 3px; border-radius: 0 3px 3px 0; background: var(--grad);
}
.nav .label { flex: 1; min-width: 0; }
.rail-foot { margin-top: auto; padding: .9rem .4rem .2rem; border-top: 1px solid var(--rule); display: grid; gap: .5rem; }
.rail-foot .me { display: flex; align-items: center; gap: .6rem; color: var(--ink-2); font-size: .84rem; min-width: 0; padding: .3rem; border-radius: 10px; }
.rail-foot .me:hover { background: var(--surface-2); text-decoration: none; }
.rail-foot .me span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--grad); color: #fff; font-weight: 700; font-size: .8rem; text-transform: uppercase; }
.rail-tools { display: flex; gap: .4rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; padding: 0; min-height: 0;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: inline-block; }

.main { padding: 2.2rem clamp(1rem, 3.2vw, 3rem) 5rem; max-width: 1280px; width: 100%; min-width: 0; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; gap: 1.2rem; align-items: flex-end; justify-content: space-between; margin-bottom: 1.6rem; }
.page-head .lede { color: var(--muted); max-width: 66ch; margin: .2rem 0 0; font-size: .95rem; }
.crumbs { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; font-size: .82rem; color: var(--muted); margin-bottom: .5rem; }
.crumbs a { color: var(--muted); }
.appbar, .tabbar { display: none; }  /* phone only */

/* ---------- surfaces ---------- */
.panel {
  position: relative; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 1.25rem 1.35rem; box-shadow: var(--shadow-1); margin-bottom: 1.15rem; min-width: 0;
  animation: rise .35s ease both; transition: box-shadow .2s;
}
.panel:hover { box-shadow: var(--shadow-2); }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.panel-head { display: flex; gap: .75rem; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-bottom: .8rem; }
.panel-head h2, .panel-head h3 { margin: 0; display: flex; align-items: center; gap: .5rem; }
.panel.accent::after { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; border-radius: var(--radius) var(--radius) 0 0; background: var(--grad); }
.grid { display: grid; gap: 1.15rem; grid-template-columns: repeat(12, minmax(0, 1fr)); align-items: start; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row.spread { justify-content: space-between; }
.divider { border: 0; border-top: 1px solid var(--rule); margin: 1.1rem 0; }
.mt-3 { margin-top: 1rem; } .mb-2 { margin-bottom: .5rem; } .mb-3 { margin-bottom: 1rem; } .mb-4 { margin-bottom: 1.5rem; } .mt-2 { margin-top: .5rem; } .p-3 { padding: 1rem; }

/* ---------- hero + loop (Aujourd'hui) ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: calc(var(--radius) + 4px); padding: 1.6rem 1.6rem 1.4rem;
  margin-bottom: 1.3rem; border: 1px solid var(--rule); background: var(--surface); box-shadow: var(--shadow-2);
  animation: rise .35s ease both;
}
.hero::before { content: ""; position: absolute; inset: 0; background: var(--grad-soft); pointer-events: none; }
.hero > * { position: relative; }
.hero .eyebrow { font-size: .72rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--primary); }
.hero h1 { margin: .25rem 0 .35rem; }
.hero .lede { color: var(--ink-2); max-width: 62ch; margin: 0; }
.tiles { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-top: 1.2rem; }
.tile {
  display: block; padding: .9rem 1rem; border-radius: 12px; background: var(--surface); border: 1px solid var(--rule);
  color: var(--ink); transition: transform .15s, box-shadow .15s, border-color .15s;
}
a.tile:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--rule-strong); }
.tile b { display: block; font-size: 1.9rem; font-weight: 750; line-height: 1.1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: .8rem; font-weight: 550; }
.tile.you { border-color: var(--you-line); background: linear-gradient(180deg, var(--you-bg), var(--surface)); }
.tile.you b { color: var(--you); }

.loop { display: flex; align-items: stretch; margin: 1.4rem 0 .1rem; overflow-x: auto; padding-bottom: .3rem; scrollbar-width: thin; }
.loop-step { flex: 1 0 100px; position: relative; text-align: center; padding: .2rem .3rem; color: var(--ink-2); }
.loop-step:hover { text-decoration: none; }
.loop-step .node {
  width: 46px; height: 46px; margin: 0 auto .45rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); border: 1.5px solid var(--rule-strong); font-weight: 750; font-variant-numeric: tabular-nums;
  color: var(--ink); position: relative; z-index: 1; transition: transform .15s;
}
.loop-step:hover .node { transform: scale(1.07); }
.loop-step.live .node { border: 0; background: var(--grad); color: #fff; box-shadow: var(--shadow-glow); }
.loop-step.you .node { border: 2px solid var(--you-line); background: var(--you-bg); color: var(--you); }
.loop-step::after { content: ""; position: absolute; top: calc(.2rem + 23px); left: 50%; width: 100%; height: 2px; background: var(--rule-strong); z-index: 0; }
.loop-step:last-child::after { display: none; }
.loop-step .lbl { display: block; font-size: .76rem; font-weight: 650; line-height: 1.25; }
.loop-step .sub { display: block; font-size: .68rem; color: var(--muted); }

/* ---------- queue (whose move) ---------- */
.queue { list-style: none; margin: 0; padding: 0; }
.queue li { display: grid; grid-template-columns: auto 1fr auto; gap: .9rem; align-items: start; padding: .85rem .4rem; border-top: 1px solid var(--rule); border-radius: 10px; transition: background-color .15s; }
.queue li:first-child { border-top: 0; }
.queue li:hover { background: var(--surface-2); }
.queue .what { min-width: 0; }
.queue .what a { font-weight: 620; color: var(--ink); }
.queue .why { color: var(--muted); font-size: .86rem; margin-top: .1rem; }

/* ---------- ledger ---------- */
.ledger { display: grid; grid-template-columns: minmax(130px, 32%) 1fr; margin: 0; }
.ledger dt, .ledger dd { padding: .55rem 0; border-top: 1px solid var(--rule); margin: 0; }
.ledger dt { color: var(--muted); font-size: .84rem; padding-right: 1rem; font-weight: 550; }
.ledger dd { min-width: 0; overflow-wrap: anywhere; }
.ledger > :nth-child(1), .ledger > :nth-child(2) { border-top: 0; }

/* ---------- chips, counts, evidence meter ---------- */
.chip {
  display: inline-flex; align-items: center; gap: .38rem; white-space: nowrap; line-height: 1.5;
  border-radius: 999px; padding: .08rem .62rem; font-size: .74rem; font-weight: 650; letter-spacing: .005em;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--rule);
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .55; flex: none; }
.chip.you { background: var(--you-bg); color: var(--you); border-color: transparent; }
.chip.sys { color: var(--muted); }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.chip.info { background: var(--info-bg); color: var(--info); border-color: transparent; }
a.chip:hover { text-decoration: none; border-color: var(--rule-strong); }
/* evidence level = 4-segment meter: O0 none lit … O4 all lit */
.chip.lvl { padding: .08rem .58rem .08rem .48rem; background: var(--surface); border-color: currentColor; font-weight: 750; letter-spacing: .03em; }
.chip.lvl::before {
  width: 25px; height: 8px; border-radius: 2px; opacity: 1;
  background: linear-gradient(90deg, currentColor 0 var(--fill, 0%), var(--rule-strong) var(--fill, 0%) 100%);
  -webkit-mask: repeating-linear-gradient(90deg, #000 0 5px, transparent 5px 6.67px);
          mask: repeating-linear-gradient(90deg, #000 0 5px, transparent 5px 6.67px);
}
.chip.O0 { color: var(--o0); --fill: 0%; } .chip.O1 { color: var(--o1); --fill: 25%; }
.chip.O2 { color: var(--o2); --fill: 50%; } .chip.O3 { color: var(--o3); --fill: 75%; }
.chip.O4 { color: var(--o4); --fill: 100%; }
.count { font-weight: 700; font-size: .72rem; min-width: 1.5rem; text-align: center; border-radius: 999px; padding: .05rem .45rem; background: var(--surface-3); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.count.hot { background: var(--you-bg); color: var(--you); }
.nav a[aria-current="page"] .count { background: var(--surface); }

/* ---------- notices / toasts ---------- */
.notice {
  display: block; position: relative; border: 1px solid var(--rule); border-left: 4px solid var(--rule-strong);
  background: var(--surface); padding: .85rem 1rem; border-radius: 12px; margin: 0 0 1.1rem; box-shadow: var(--shadow-1);
}
.notice strong { display: block; margin-bottom: .1rem; font-weight: 650; }
.notice.ok { border-left-color: var(--ok); background: linear-gradient(90deg, var(--ok-bg), var(--surface) 70%); }
.notice.warn { border-left-color: var(--warn); background: linear-gradient(90deg, var(--warn-bg), var(--surface) 70%); }
.notice.bad { border-left-color: var(--bad); background: linear-gradient(90deg, var(--bad-bg), var(--surface) 70%); }
.notice.you { border-left-color: var(--you-line); background: linear-gradient(90deg, var(--you-bg), var(--surface) 75%); }
.flash { animation: drop .3s ease both; padding-right: 3rem; }
.flash .dismiss { position: absolute; top: .55rem; right: .55rem; width: 32px; height: 32px; }
.flash.hide { opacity: 0; transform: translateY(-6px); transition: opacity .3s, transform .3s; }
.empty {
  padding: 1.6rem 1.2rem; text-align: center; color: var(--muted); border: 1.5px dashed var(--rule-strong);
  border-radius: 12px; background: var(--surface-2);
}
.empty strong { display: block; color: var(--ink); font-family: var(--display); font-weight: 400; font-size: 1.35rem; margin-bottom: .2rem; }

/* ---------- lifecycle stepper ---------- */
.lifecycle { display: flex; list-style: none; margin: 0 0 1.3rem; padding: 0; overflow-x: auto; }
.lifecycle li { flex: 1 0 110px; position: relative; padding: 0 .4rem 0 0; font-size: .8rem; font-weight: 650; color: var(--muted); }
.lifecycle li::before {
  content: ""; display: block; width: 14px; height: 14px; border-radius: 50%; margin: 0 0 .5rem; position: relative; z-index: 1;
  background: var(--surface); border: 2px solid var(--rule-strong);
}
.lifecycle li::after { content: ""; position: absolute; top: 6px; left: 16px; right: 2px; height: 2px; background: var(--rule-strong); }
.lifecycle li:last-child::after { display: none; }
.lifecycle li.done { color: var(--ink-2); }
.lifecycle li.done::before { background: var(--ok); border-color: var(--ok); }
.lifecycle li.done::after { background: var(--ok); }
.lifecycle li.current { color: var(--ink); }
.lifecycle li.current::before { background: var(--you); border-color: var(--you); box-shadow: 0 0 0 5px var(--you-bg); }
.lifecycle li .who { display: block; font-size: .7rem; font-weight: 450; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem; }
th { text-align: left; font-weight: 700; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); border-bottom: 1px solid var(--rule-strong); padding: .6rem .65rem; white-space: nowrap; }
td { border-bottom: 1px solid var(--rule); padding: .7rem .65rem; vertical-align: top; overflow-wrap: anywhere; }
tbody tr { transition: background-color .12s; }
tbody tr:hover td { background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- forms ---------- */
form { margin: 0; }
label { display: block; font-size: .82rem; font-weight: 650; color: var(--ink-2); margin: .75rem 0 .3rem; }
.hint { display: block; font-weight: 450; color: var(--muted); font-size: .77rem; margin-top: .05rem; }
input[type=text], input[type=url], input[type=password], input[type=date], input[type=datetime-local], input[type=email],
input[type=number], select, textarea, .form-control, .form-select {
  width: 100%; font: inherit; font-size: .93rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule-strong); border-radius: var(--radius-sm); padding: .62rem .75rem; min-height: 44px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 7rem; resize: vertical; line-height: 1.5; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 450; line-height: 1.45; }
.check input { margin-top: .2rem; width: 1.1rem; height: 1.1rem; accent-color: var(--primary); flex: none; }
fieldset { border: 1px solid var(--rule); border-radius: 12px; padding: .5rem 1rem 1rem; margin: .9rem 0; min-width: 0; background: var(--surface-2); }
legend { font-size: .8rem; font-weight: 700; color: var(--ink-2); padding: 0 .4rem; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: 1rem; align-items: center; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; cursor: pointer;
  font: 650 .88rem/1.2 var(--sans); padding: .62rem 1.05rem; min-height: 42px; border-radius: 11px;
  border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink); text-decoration: none;
  transition: transform .12s, box-shadow .15s, background-color .15s, border-color .15s, filter .15s;
}
button:hover, .btn:hover { background: var(--surface-2); border-color: var(--muted); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary, button.primary { background: var(--grad); color: #fff; border: 0; box-shadow: var(--shadow-glow); }
.btn-primary:hover, button.primary:hover { background: var(--grad); filter: brightness(1.07); }
button.approve { background: var(--ok); border-color: var(--ok); color: #fff; }
button.approve:hover { background: var(--ok); filter: brightness(1.08); }
button.danger, .btn-outline-danger { color: var(--bad); border-color: var(--bad); background: transparent; }
button.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--primary); font-weight: 550; box-shadow: none; }
button.link:hover { text-decoration: underline; background: none; }
.btn-sm, button.btn-sm { padding: .38rem .72rem; min-height: 34px; font-size: .8rem; border-radius: 9px; }

details { border: 1px solid var(--rule); border-radius: 12px; background: var(--surface); margin: .65rem 0; }
details > summary { cursor: pointer; padding: .75rem 1rem; font-weight: 620; list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 1rem; border-radius: 12px; }
details > summary:hover { background: var(--surface-2); }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: ""; flex: none; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .2s; margin-right: .25rem; }
details[open] > summary::after { transform: rotate(-135deg); }
details > .body { padding: .2rem 1rem 1rem; }
details.plain { border: 0; background: none; margin: .35rem 0; }
details.plain > summary { padding: .3rem 0; font-weight: 580; color: var(--primary); justify-content: flex-start; }
details.plain > summary:hover { background: none; text-decoration: underline; }
details.plain > summary::after { width: 7px; height: 7px; border-color: var(--primary); }

.hash { font-family: var(--mono); font-size: .76rem; background: var(--surface-2); border: 1px solid var(--rule); padding: .08rem .4rem; border-radius: 6px; overflow-wrap: anywhere; }
.quote { border-left: 3px solid var(--rule-strong); padding: .55rem .9rem; color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border-radius: 0 10px 10px 0; max-height: 22rem; overflow-y: auto; font-size: .9rem; }
pre.quote { font-size: .76rem; }
.untrusted { display: inline-flex; align-items: center; gap: .35rem; font-size: .66rem; font-weight: 750; color: var(--warn); text-transform: uppercase; letter-spacing: .1em; margin-bottom: .35rem; }
.untrusted::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: currentColor; }
ul.clean { list-style: none; margin: 0; padding: 0; }
ul.clean li { padding: .55rem 0; border-top: 1px solid var(--rule); }
ul.clean li:first-child { border-top: 0; }
ul.checks { margin: 0; padding: 0; list-style: none; }
ul.checks li { position: relative; padding: .3rem 0 .3rem 1.6rem; }
ul.checks li::before { content: ""; position: absolute; left: .2rem; top: .64rem; width: 9px; height: 9px; border-radius: 3px; border: 2px solid var(--primary); }
ol { padding-left: 1.3rem; } ol li { margin: .25rem 0; }
.kpi { display: flex; gap: 1.8rem; flex-wrap: wrap; }
.kpi div { min-width: 6.5rem; }
.kpi b { display: block; font-size: 1.85rem; font-weight: 750; line-height: 1.1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: .78rem; font-weight: 550; }
.copy-btn { margin-left: .35rem; width: 30px; height: 30px; vertical-align: middle; }
.copy-btn.done { color: var(--ok); border-color: var(--ok); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.login { width: min(420px, 100%); }
.login .brand { justify-content: center; padding-bottom: .6rem; }
.login h1 { text-align: center; font-size: 2.6rem; margin-bottom: .3rem; }
.login .lede { text-align: center; color: var(--muted); font-size: .9rem; margin-bottom: 1.4rem; }
.login .panel { padding: 1.5rem; box-shadow: var(--shadow-2); }
.login button.primary { width: 100%; min-height: 46px; }

/* legacy dashboard compatibility */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow-1); }
.badge { display: inline-block; padding: .06rem .5rem; border-radius: 999px; font-size: .74rem; font-weight: 650; background: var(--surface-2); border: 1px solid var(--rule); }
.text-secondary, .text-muted { color: var(--muted) !important; }
.text-success { color: var(--ok) !important; } .text-warning { color: var(--warn) !important; } .text-danger { color: var(--bad) !important; }
.d-flex { display: flex; } .gap-1 { gap: .25rem; } .gap-2 { gap: .5rem; } .gap-3 { gap: 1rem; }
.row.g-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.fs-3 { font-size: 1.6rem; font-weight: 700; }
.verdict-PASS { color: var(--ok); font-weight: 650; } .verdict-REVISE { color: var(--warn); font-weight: 650; } .verdict-REJECT { color: var(--bad); font-weight: 650; }
.legacy table { display: block; overflow-x: auto; max-width: 100%; }
.legacy form { max-width: 100%; }
.legacy input, .legacy select { max-width: 100%; }

/* ---------- motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- tablet: icon rail ---------- */
@media (max-width: 1180px) {
  .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; }
}
@media (max-width: 1080px) and (min-width: 861px) {
  :root { --rail-w: 78px; }
  .rail { padding: 1rem .6rem; align-items: center; }
  .brand { padding: .2rem 0 1rem; }
  .brand > div, .nav .label, .nav .group, .rail-foot .me span { display: none; }
  .nav a { justify-content: center; padding: .7rem; }
  .nav a .count { position: absolute; top: 1px; right: -2px; font-size: .6rem; min-width: 1.1rem; padding: 0 .25rem; }
  .nav a[aria-current="page"]::before { left: -.6rem; }
  .rail-foot { justify-items: center; }
  .rail-tools { flex-direction: column; }
}

/* ---------- phone: app layout ---------- */
@media (max-width: 860px) {
  .shell { display: block; }
  .rail { display: none; }
  .appbar {
    display: flex; position: sticky; top: 0; z-index: 30; align-items: center; justify-content: space-between; gap: .6rem;
    padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top));
    background: var(--glass); backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
    border-bottom: 1px solid var(--rule);
  }
  .appbar .brand { padding: 0; }
  .appbar .brand div span { display: none; }
  .appbar .rail-tools { gap: .35rem; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; z-index: 40; left: .6rem; right: .6rem;
    bottom: max(.6rem, env(safe-area-inset-bottom)); padding: .35rem; border-radius: 20px;
    background: var(--glass); backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
    border: 1px solid var(--rule); box-shadow: var(--shadow-2);
  }
  .tabbar a, .tabbar summary {
    position: relative; display: flex; flex-direction: column; align-items: center; gap: .15rem; padding: .45rem .1rem;
    border-radius: 14px; color: var(--muted); font-size: .66rem; font-weight: 650; min-height: 50px; justify-content: center;
    list-style: none; cursor: pointer;
  }
  .tabbar summary::-webkit-details-marker { display: none; }
  .tabbar a:hover { text-decoration: none; }
  .tabbar a[aria-current="page"] { color: var(--primary); background: var(--grad-soft); }
  .tabbar .dot { position: absolute; top: 3px; left: calc(50% + 4px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--you); color: #fff; font-size: .6rem; line-height: 17px; text-align: center; font-weight: 750; }
  .tabbar details { border: 0; background: none; margin: 0; }
  .tabbar details > summary:hover { background: none; }
  .tabbar details > summary::after { display: none; }
  .tabbar details[open] > summary { color: var(--primary); }
  .sheet {
    position: fixed; left: .6rem; right: .6rem; bottom: calc(max(.6rem, env(safe-area-inset-bottom)) + 76px);
    padding: .6rem; border-radius: 18px; background: var(--surface); border: 1px solid var(--rule); box-shadow: var(--shadow-2);
    display: grid; grid-template-columns: repeat(3, 1fr); gap: .3rem; animation: rise .2s ease both;
  }
  .sheet a, .sheet button { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: .75rem .2rem; border-radius: 12px; color: var(--ink-2); font-size: .74rem; font-weight: 600; border: 0; background: none; min-height: 0; }
  .sheet a:hover, .sheet button:hover { background: var(--surface-2); text-decoration: none; }
  .sheet a[aria-current="page"] { color: var(--primary); background: var(--grad-soft); }
  .sheet form { display: contents; }
  .main { padding: 1.1rem 1rem 7.5rem; }
  .page-head { margin-bottom: 1.1rem; }
  .panel { padding: 1.05rem 1rem; }
  .hero { padding: 1.25rem 1.05rem 1.1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .ledger { grid-template-columns: 1fr; }
  .ledger dt { border-top: 1px solid var(--rule); padding-bottom: 0; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
  .ledger dd { border-top: 0; padding-top: .15rem; }
  .queue li { grid-template-columns: 1fr; gap: .35rem; }
  .chip { white-space: normal; overflow-wrap: break-word; word-break: normal; max-width: 100%; }
  .row > span { min-width: 0; }
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border: 1px solid var(--rule); border-radius: 12px; padding: .65rem .85rem; margin-bottom: .7rem; background: var(--surface); }
  table.cards td { border: 0; padding: .3rem 0; display: grid; grid-template-columns: 7rem minmax(0, 1fr); gap: .6rem; }
  table.cards td::before { content: attr(data-label); color: var(--muted); font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding-top: .18rem; }
  table.cards td > .chip { justify-self: start; }
  table.cards td:first-child { grid-template-columns: 1fr; padding-bottom: .45rem; }
  table.cards td:first-child::before { display: none; }
  table.cards tbody tr:hover td { background: none; }
  .loop-step { flex-basis: 82px; }
  .loop-step .node { width: 40px; height: 40px; }
  .loop-step::after { top: calc(.2rem + 20px); }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .kpi { gap: 1.2rem; }
}
@media print {
  .rail, .appbar, .tabbar, .actions, form { display: none !important; }
  .shell { display: block; } body::before { display: none; }
}
