/* QMS website (CAPA / NC, Quality Issue Tracker, …) — stylesheet
   One family (Archivo, variable width + weight). Condensed widths carry headings and figures;
   normal width carries body text. Colour tokens per theme; due-band colours match the Power App. */

@font-face {
  font-family: 'Archivo';
  src: url('/static/fonts/archivo-latin-wdth-normal.woff2') format('woff2-variations');
  font-weight: 100 900; font-stretch: 62% 125%; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Archivo';
  src: url('/static/fonts/archivo-latin-ext-wdth-normal.woff2') format('woff2-variations');
  font-weight: 100 900; font-stretch: 62% 125%; font-style: normal; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ------------------------------------------------------------------ tokens */
:root {
  --font: 'Archivo', 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  --navy: #10284a;
  --brand: #2f6fb3;
  --bg: #edf0f4;
  --surface: #ffffff;
  --raised: #f6f8fb;
  --ink: #14233a;
  --muted: #56647a;
  --line: #d3dae4;
  --line-strong: #b5c0cf;
  --accent: #2563a8;
  --accent-ink: #ffffff;
  --accent-soft: #e3edf9;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --ok: #1f7a3f;
  --ok-soft: #e0f3e6;
  --warn: #8a5a00;
  --warn-soft: #fff1d6;
  --bar: #10284a;
  --bar-ink: #e9eff8;
  --focus: #2f80ed;
  --shadow: 0 1px 2px rgba(16, 40, 74, .06), 0 2px 8px rgba(16, 40, 74, .05);
  /* due bands (Power App colours) */
  --b-overdue: #6b3fa0; --b-overdue-bg: #ebe0f7;
  --b-due7: #b3261e;    --b-due7-bg: #ffdcdc;
  --b-due15: #b35c00;   --b-due15-bg: #ffe6cc;
  --b-due21: #8a7300;   --b-due21-bg: #fff7c2;
  --b-later: #2e7d32;   --b-later-bg: #dcf5dc;
  --b-closed: #6b7280;  --b-closed-bg: #eef0f3;
  --radius-s: 4px; --radius: 6px; --radius-l: 10px;
  --pad: 1rem; --row: .7rem;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #0d1522; --surface: #142033; --raised: #1b2a42; --ink: #e6ecf5; --muted: #9aa9be;
  --line: #26364f; --line-strong: #3a4e6e; --accent: #6aa8ec; --accent-ink: #08121f; --accent-soft: #1d3452;
  --danger: #ff8a7f; --danger-soft: #3a1c1c; --danger-ink: #2a0d0b; --ok: #6fd292; --ok-soft: #173426; --warn: #f2c25b; --warn-soft: #3a2f12;
  --bar: #08101c; --bar-ink: #dbe5f3; --shadow: 0 1px 2px rgba(0,0,0,.4);
  --b-overdue: #c6a3f2; --b-overdue-bg: #33224d; --b-due7: #ff9a92; --b-due7-bg: #4a1f1f;
  --b-due15: #ffb870; --b-due15-bg: #4a2f14; --b-due21: #ecd66a; --b-due21-bg: #3f3812;
  --b-later: #85d98a; --b-later-bg: #1b3a1f; --b-closed: #9aa3b2; --b-closed-bg: #222c3b;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme='system'] {
    --bg: #0d1522; --surface: #142033; --raised: #1b2a42; --ink: #e6ecf5; --muted: #9aa9be;
    --line: #26364f; --line-strong: #3a4e6e; --accent: #6aa8ec; --accent-ink: #08121f; --accent-soft: #1d3452;
    --danger: #ff8a7f; --danger-soft: #3a1c1c; --danger-ink: #2a0d0b; --ok: #6fd292; --ok-soft: #173426; --warn: #f2c25b; --warn-soft: #3a2f12;
    --bar: #08101c; --bar-ink: #dbe5f3; --shadow: 0 1px 2px rgba(0,0,0,.4);
    --b-overdue: #c6a3f2; --b-overdue-bg: #33224d; --b-due7: #ff9a92; --b-due7-bg: #4a1f1f;
    --b-due15: #ffb870; --b-due15-bg: #4a2f14; --b-due21: #ecd66a; --b-due21-bg: #3f3812;
    --b-later: #85d98a; --b-later-bg: #1b3a1f; --b-closed: #9aa3b2; --b-closed-bg: #222c3b;
    color-scheme: dark;
  }
}
/* Dusk: low-glare mid-dark for tablets on the shop floor */
:root[data-theme='dusk'] {
  --bg: #23282f; --surface: #2c323a; --raised: #343b44; --ink: #eceae4; --muted: #b3b0a8;
  --line: #3f4650; --line-strong: #555d69; --accent: #8fbfe8; --accent-ink: #14202c; --accent-soft: #33414f;
  --danger: #f29b8f; --danger-soft: #4a2e2b; --danger-ink: #2a0d0b; --ok: #9ad3a6; --ok-soft: #2b3d31; --warn: #e9c46a; --warn-soft: #463d24;
  --bar: #1b1f25; --bar-ink: #e6e3dc; --shadow: none;
  --b-overdue: #c9b0ec; --b-overdue-bg: #3d3350; --b-due7: #f2a198; --b-due7-bg: #4d302e;
  --b-due15: #f0b97c; --b-due15-bg: #4b3a28; --b-due21: #e2d27e; --b-due21-bg: #46412a;
  --b-later: #a3d9a5; --b-later-bg: #2f4331; --b-closed: #b0b3b8; --b-closed-bg: #383e46;
  color-scheme: dark;
}
/* High contrast */
:root[data-theme='contrast'] {
  --bg: #ffffff; --surface: #ffffff; --raised: #ffffff; --ink: #000000; --muted: #1f1f1f;
  --line: #000000; --line-strong: #000000; --accent: #0038a8; --accent-ink: #ffffff; --accent-soft: #dce6ff;
  --danger: #a10000; --danger-soft: #ffe5e5; --ok: #005c1a; --ok-soft: #e1f5e6; --warn: #6b4200; --warn-soft: #fff0cc;
  --bar: #000000; --bar-ink: #ffffff; --shadow: none; --focus: #ff6a00;
  --b-overdue: #4b0f8f; --b-due7: #8f0000; --b-due15: #7a3c00; --b-due21: #5c4c00; --b-later: #0b5b16; --b-closed: #333333;
}
:root[data-theme='contrast'] * { border-color: #000 !important; }

:root[data-density='compact'] { --pad: .7rem; --row: .4rem; }

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 0.95rem; line-height: 1.5; font-stretch: 100%;
  font-feature-settings: 'tnum' 1; min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); text-underline-offset: .15em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
h1, h2, h3 { font-stretch: 78%; line-height: 1.15; margin: 0 0 .5rem; letter-spacing: -.005em; }
h1 { font-size: 1.85rem; font-weight: 750; }
h2 { font-size: 1.3rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: .4rem 0 .8rem; max-width: 72ch; }
small, .muted { color: var(--muted); }
code, .mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: .88em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: .5rem 1rem; z-index: 100; }
.skip:focus { left: .5rem; }

/* ------------------------------------------------------------------ top bar */
.topbar { background: var(--bar); color: var(--bar-ink); position: sticky; top: 0; z-index: 30; }
.topbar .inner { max-width: 1320px; margin: 0 auto; display: flex; align-items: center; gap: 1.25rem; padding: 0 1.25rem; min-height: 3.4rem; }
.mark { display: flex; align-items: center; gap: .6rem; color: inherit; text-decoration: none; font-stretch: 72%; font-weight: 750; font-size: 1.12rem; letter-spacing: .01em; white-space: nowrap; }
.mark svg, .mark img { flex: none; display: block; }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a { color: inherit; text-decoration: none; padding: .45rem .7rem; border-radius: var(--radius-s); opacity: .82; font-weight: 550; }
.nav a:hover { opacity: 1; background: rgba(255,255,255,.08); }
.nav a[aria-current='page'] { opacity: 1; box-shadow: inset 0 -3px 0 #6aa8ec; border-radius: 0; }
.usermenu { position: relative; }
.usermenu > button { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.22); border-radius: 999px; padding: .3rem .8rem .3rem .35rem; display: flex; gap: .5rem; align-items: center; font: inherit; cursor: pointer; }
.avatar { width: 1.75rem; height: 1.75rem; border-radius: 50%; background: #2f6fb3; color: #fff; display: grid; place-items: center; font-size: .75rem; font-weight: 700; font-stretch: 85%; }
.menu { position: absolute; right: 0; top: calc(100% + .4rem); min-width: 14rem; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: .35rem; display: none; }
.menu.open { display: block; }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: .5rem .7rem; color: var(--ink); text-decoration: none; background: none; border: 0; font: inherit; border-radius: var(--radius-s); cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--raised); }
.menu .who { padding: .5rem .7rem .6rem; border-bottom: 1px solid var(--line); margin-bottom: .3rem; }
.menu .who strong { display: block; }
.topbar .nav { overflow-x: auto; scrollbar-width: none; min-width: 0; }
.topbar .nav a { white-space: nowrap; }
.nav .short { display: none; }
@media (max-width: 1000px) { .nav .long { display: none; } .nav .short { display: inline; } }
@media (max-width: 760px) {
  .nav a { padding: .45rem .45rem; }
  .topbar .inner { gap: .6rem; padding: 0 .75rem; }
  .mark span { display: none; }
  .usermenu .name { display: none; }
}

/* ------------------------------------------------------------------ module bar (under the top bar) */
.modbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.modbar .inner { max-width: 1320px; margin: 0 auto; display: flex; align-items: center; gap: 1.25rem; padding: 0 1.25rem; min-height: 3rem; }
.modname { display: flex; align-items: center; gap: .55rem; color: var(--ink); text-decoration: none; font-stretch: 75%; font-weight: 750; font-size: 1.02rem; white-space: nowrap; }
.modname img { flex: none; display: block; }
.subnav { display: flex; gap: .15rem; overflow-x: auto; scrollbar-width: none; flex: 1; }
.subnav a { color: var(--muted); text-decoration: none; padding: .8rem .75rem .7rem; font-weight: 600; font-stretch: 92%; white-space: nowrap; border-bottom: 3px solid transparent; display: inline-flex; gap: .35rem; align-items: center; }
.subnav a:hover { color: var(--ink); }
.subnav a[aria-current='page'] { color: var(--ink); border-bottom-color: var(--accent); }
.subnav .count { font-size: .72rem; font-weight: 700; min-width: 1.3rem; text-align: center; padding: 0 .4rem; border-radius: 999px; background: var(--danger); color: var(--danger-ink, #fff); line-height: 1.5; }
@media (max-width: 760px) { .modname span { display: none; } .modbar .inner { gap: .5rem; padding: 0 .75rem; } .subnav a { padding: .75rem .5rem .65rem; } }

/* ------------------------------------------------------------------ QMS home */
.home-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.home-head img { flex: none; border-radius: 12px; }
.home-head h1 { margin: 0; }
.home-head p { margin: .2rem 0 0; color: var(--muted); }
.modules { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 25rem), 1fr)); gap: 1rem; }
.module-card { display: grid; grid-template-rows: auto 1fr auto; gap: .9rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 1.25rem; box-shadow: var(--shadow); color: var(--ink); text-decoration: none; position: relative; }
.module-card:hover { border-color: var(--accent); }
.module-card .mc-head { display: flex; gap: .85rem; align-items: center; }
.module-card .mc-head img { flex: none; border-radius: 10px; }
.module-card h2 { margin: 0; }
.module-card .mc-head small { display: block; }
.module-card p { margin: 0; color: var(--muted); }
.mini-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(5.4rem, 1fr)); gap: .5rem; }
.mini-kpis a, .mini-kpis div { display: block; text-decoration: none; color: var(--ink); background: var(--raised); border-radius: var(--radius); padding: .55rem .7rem; border-left: 4px solid var(--k, var(--accent)); }
.mini-kpis a:hover { background: var(--accent-soft); }
.mini-kpis b { display: block; font-size: 1.75rem; font-weight: 800; font-stretch: 70%; line-height: 1.05; }
.mini-kpis span { font-size: .8rem; color: var(--muted); font-weight: 550; }
.mini-kpis .bad { --k: var(--danger); } .mini-kpis .bad b { color: var(--danger); }
.mini-kpis .over { --k: var(--b-overdue); } .mini-kpis .over b { color: var(--b-overdue); }
.mini-kpis .soon { --k: var(--b-due7); }
.module-card .mc-foot { display: flex; gap: .5rem; flex-wrap: wrap; }
.module-card .private { position: absolute; top: 1rem; right: 1rem; }
.linked-issue { border-left-color: var(--b-due15); }

main { flex: 1; width: 100%; max-width: 1320px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; justify-content: space-between; margin-bottom: 1.25rem; }
.page-head p { margin: .2rem 0 0; color: var(--muted); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
footer.foot { color: var(--muted); font-size: .8rem; text-align: center; padding: 1rem; }

/* ------------------------------------------------------------------ controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; font: inherit; font-weight: 600; font-size: .92rem; line-height: 1.2;
  padding: .58rem 1rem; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; min-height: 2.5rem; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); }
.btn.danger.solid { background: var(--danger); color: var(--danger-ink, #fff); border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: .3rem .6rem; min-height: 2rem; font-size: .84rem; }
.btn[disabled], .btn[aria-busy='true'] { opacity: .55; cursor: not-allowed; }
.btn svg { width: 1.05em; height: 1.05em; }

label, .label { display: block; font-weight: 600; font-size: .84rem; margin-bottom: .3rem; color: var(--ink); }
.req::after { content: ' *'; color: var(--danger); }
.hint { font-size: .82rem; color: var(--muted); margin: -.1rem 0 .45rem; max-width: 80ch; }
input[type='text'], input[type='email'], input[type='search'], input[type='password'], input[type='date'], input[type='number'], input:not([type]), select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  padding: .55rem .65rem; min-height: 2.5rem; }
textarea { min-height: 7rem; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent); outline-offset: 0; }
.upper { text-transform: uppercase; }
.upper::placeholder { text-transform: none; }
.invalid input, .invalid select, .invalid textarea, input.invalid { border-color: var(--danger); background: var(--danger-soft); }
.err { color: var(--danger); font-size: .84rem; margin-top: .3rem; font-weight: 550; }
input[type='checkbox'], input[type='radio'] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); vertical-align: -.15rem; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 500; }

.grid { display: grid; gap: 1rem 1.25rem; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c5 { grid-column: span 5; } .c6 { grid-column: span 6; } .c8 { grid-column: span 8; } .c12 { grid-column: span 12; }
@media (max-width: 900px) { .c3, .c4, .c5 { grid-column: span 6; } .c6, .c8 { grid-column: span 12; } }
@media (max-width: 560px) { .c3, .c4, .c5, .c6 { grid-column: span 12; } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: calc(var(--pad) * 1.25); box-shadow: var(--shadow); }
.panel + .panel { margin-top: 1rem; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .75rem; }

.notice { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: .75rem 1rem; border-radius: var(--radius-s); margin: 0 0 1rem; }
.notice.error { border-color: var(--danger); background: var(--danger-soft); }
.notice.ok { border-color: var(--ok); background: var(--ok-soft); }
.notice.warn { border-color: var(--warn); background: var(--warn-soft); }
.notice p { margin: .2rem 0; }

/* ------------------------------------------------------------------ status & due chips */
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .12rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 650; font-stretch: 88%; white-space: nowrap; border: 1px solid transparent; }
.chip::before { content: ''; width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
.chip.overdue { color: var(--b-overdue); background: var(--b-overdue-bg); }
.chip.due7 { color: var(--b-due7); background: var(--b-due7-bg); }
.chip.due15 { color: var(--b-due15); background: var(--b-due15-bg); }
.chip.due21 { color: var(--b-due21); background: var(--b-due21-bg); }
.chip.later { color: var(--b-later); background: var(--b-later-bg); }
.chip.closed, .chip.nodate { color: var(--b-closed); background: var(--b-closed-bg); }
.status { font-weight: 600; font-size: .85rem; }
.status.s-closed, .status.s-void { color: var(--muted); }
.days { font-variant-numeric: tabular-nums; font-weight: 700; font-stretch: 85%; }

/* ------------------------------------------------------------------ dashboard */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { display: block; text-decoration: none; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: .9rem 1rem 1rem; position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--k, var(--accent)); }
.kpi:hover { border-color: var(--k, var(--accent)); }
.kpi .n { font-size: 2.6rem; font-weight: 800; font-stretch: 70%; line-height: 1; display: block; margin-top: .35rem; }
.kpi .l { font-size: .88rem; color: var(--muted); font-weight: 550; }
.kpi.open { --k: var(--accent); } .kpi.overdue { --k: var(--b-overdue); } .kpi.due7 { --k: var(--b-due7); } .kpi.due15 { --k: var(--b-due15); } .kpi.due21 { --k: var(--b-due21); }
.kpi.overdue .n { color: var(--b-overdue); }

/* Due horizon — the dashboard's signature view */
.horizon { position: relative; }
.horizon svg { width: 100%; height: auto; display: block; overflow: visible; }
.horizon .zone { opacity: .55; }
.horizon .z-overdue { fill: var(--b-overdue-bg); } .horizon .z-due7 { fill: var(--b-due7-bg); } .horizon .z-due15 { fill: var(--b-due15-bg); } .horizon .z-due21 { fill: var(--b-due21-bg); } .horizon .z-later { fill: var(--b-later-bg); }
.horizon .axis { stroke: var(--line-strong); stroke-width: 1; }
.horizon .today { stroke: var(--ink); stroke-width: 2; }
.horizon .tick text, .horizon text { fill: var(--muted); font-family: var(--font); font-size: 11px; font-stretch: 85%; }
.horizon .today-label { fill: var(--ink); font-weight: 700; }
.horizon a .pin { stroke: var(--surface); stroke-width: 1.5; }
.horizon a:hover .pin, .horizon a:focus .pin { stroke: var(--ink); stroke-width: 2.5; }
.horizon a:focus { outline: none; }
.pin.overdue { fill: var(--b-overdue); } .pin.due7 { fill: var(--b-due7); } .pin.due15 { fill: var(--b-due15); } .pin.due21 { fill: var(--b-due21); } .pin.later { fill: var(--b-later); }
.legend { display: flex; flex-wrap: wrap; gap: .4rem .9rem; margin-top: .6rem; font-size: .82rem; color: var(--muted); }
.two { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; margin-top: 1rem; }
@media (max-width: 900px) { .two { grid-template-columns: 1fr; } }
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { display: grid; grid-template-columns: 4.5rem 1fr 2.5rem; gap: .6rem; align-items: center; padding: .25rem 0; }
.bars .track { display: block; height: .65rem; background: var(--raised); border-radius: 999px; overflow: hidden; }
.bars .fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bars .v { text-align: right; font-weight: 700; font-stretch: 85%; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: .55rem 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 1rem; }
.feed li:last-child { border-bottom: 0; }

/* ------------------------------------------------------------------ tables */
.filters { display: grid; grid-template-columns: minmax(14rem, 2fr) repeat(2, minmax(9rem, 1fr)) auto; gap: .75rem; align-items: end; margin-bottom: 1rem; }
@media (max-width: 760px) { .filters { grid-template-columns: 1fr 1fr; } .filters .wide { grid-column: span 2; } }
.views { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.views a { text-decoration: none; color: var(--ink); padding: .32rem .75rem; border-radius: 999px; border: 1px solid var(--line-strong); font-size: .86rem; font-weight: 550; background: var(--surface); }
.views a[aria-current='true'] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: var(--row) .8rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data thead th { position: sticky; top: 0; background: var(--raised); font-size: .78rem; font-weight: 700; color: var(--muted); letter-spacing: .02em; white-space: nowrap; z-index: 1; }
table.data thead th a { color: inherit; text-decoration: none; }
table.data thead th a[aria-sort]::after { content: ' ▲'; font-size: .7em; }
table.data thead th a[aria-sort='descending']::after { content: ' ▼'; }
table.data tbody tr:hover { background: var(--raised); }
table.data tbody tr.rowlink { cursor: pointer; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td .car-no { font-weight: 700; font-stretch: 85%; }
table.data tbody tr:last-child td { border-bottom: 0; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: .75rem; color: var(--muted); font-size: .88rem; }

/* ------------------------------------------------------------------ CAR editor */
.car-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem; margin-bottom: 1rem; }
.car-head h1 { margin: 0; font-size: 2.1rem; }
.car-head .meta { color: var(--muted); font-size: .88rem; }
/* The divider is an inset shadow (not a border the tabs overlap with a negative margin), so the bar never
   overflows vertically; it only scrolls sideways on narrow screens. */
.tabs { display: flex; gap: .15rem; box-shadow: inset 0 -2px 0 var(--line); margin-bottom: 1.25rem; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.tabs button { font: inherit; font-weight: 650; font-stretch: 88%; background: none; border: 0; padding: .7rem 1rem; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; flex: none; }
.tabs button[aria-selected='true'] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs button .count { font-size: .75rem; background: var(--raised); border-radius: 999px; padding: 0 .45rem; margin-left: .3rem; }
.tabs button.has-error { color: var(--danger); }
.tabpanel[hidden] { display: none; }
.savebar { position: sticky; bottom: 0; z-index: 20; margin-top: 1.5rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: .7rem 1rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; box-shadow: 0 -4px 18px rgba(0,0,0,.08); }
.savebar .state { font-size: .88rem; color: var(--muted); }
.savebar .state.dirty { color: var(--warn); font-weight: 600; }
.savebar .state.error { color: var(--danger); font-weight: 600; }
.savebar .state.ok { color: var(--ok); }
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 25; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-s); box-shadow: 0 8px 24px rgba(0,0,0,.15); max-height: 18rem; overflow-y: auto; margin-top: 2px; padding: .25rem; display: none; }
.picker-list.open { display: block; }
.picker-list button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: .45rem .55rem; font: inherit; color: var(--ink); border-radius: var(--radius-s); cursor: pointer; }
.picker-list button:hover, .picker-list button.active { background: var(--accent-soft); }
.picker-list .src { font-size: .72rem; color: var(--muted); float: right; }
.picker-list .sub { display: block; font-size: .8rem; color: var(--muted); }
.suggest { margin-top: .4rem; font-size: .85rem; }
.daysbox { display: flex; align-items: center; min-height: 2.5rem; }
.moc-table input, .moc-table select { min-height: 2.2rem; padding: .35rem .5rem; }
.moc-table td { padding: .35rem .4rem; }
.moc-table .tools { white-space: nowrap; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; margin-top: 1rem; }
.photo { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--raised); display: flex; flex-direction: column; }
.photo img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; background: #000; }
.photo .body { padding: .6rem .7rem .7rem; display: grid; gap: .5rem; }
.photo .ord { font-weight: 700; font-stretch: 85%; }
.drop { border: 2px dashed var(--line-strong); border-radius: var(--radius-l); padding: 1.25rem; display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .preview { max-height: 8rem; border-radius: var(--radius-s); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .7rem 0 .7rem 1.1rem; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 1.05rem; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline .when { color: var(--muted); font-size: .82rem; }
.timeline dl { display: grid; grid-template-columns: minmax(10rem, max-content) 1fr; gap: .15rem .9rem; margin: .4rem 0 0; font-size: .86rem; }
.timeline dt { color: var(--muted); }
.timeline dd { margin: 0; overflow-wrap: anywhere; }
.timeline del { color: var(--muted); }

dialog { border: 1px solid var(--line); border-radius: var(--radius-l); padding: 0; background: var(--surface); color: var(--ink); width: min(34rem, calc(100vw - 2rem)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(9, 18, 32, .55); }
dialog .dlg-head { padding: 1rem 1.25rem .25rem; }
dialog .dlg-body { padding: .5rem 1.25rem 1rem; display: grid; gap: .85rem; }
dialog .dlg-foot { padding: .85rem 1.25rem; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: .5rem; background: var(--raised); }

.toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 100; max-width: min(26rem, calc(100vw - 2rem)); }
.toast { background: var(--ink); color: var(--surface); padding: .75rem 1rem; border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: .9rem; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@media (prefers-reduced-motion: no-preference) { .toast { animation: toast-in .18s ease-out; } @keyframes toast-in { from { transform: translateY(6px); opacity: 0; } } }

/* ------------------------------------------------------------------ account / themes */
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: .75rem; }
.theme-card { position: relative; border: 2px solid var(--line); border-radius: var(--radius-l); padding: .6rem; cursor: pointer; display: block; font-weight: 600; background: var(--surface); }
.theme-card:has(input:checked) { border-color: var(--accent); }
.theme-card input { position: absolute; opacity: 0; }
.theme-card:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.swatch { height: 4.5rem; border-radius: var(--radius-s); margin-bottom: .5rem; display: grid; grid-template-rows: 1rem 1fr; overflow: hidden; border: 1px solid rgba(0,0,0,.1); }
.swatch i { display: block; }
.swatch .sw-body { display: flex; gap: 4px; padding: 6px; align-items: flex-end; }
.swatch .sw-body b { flex: 1; border-radius: 2px; }
.sw-light { background: #edf0f4; } .sw-light i { background: #10284a; } .sw-light b { background: #fff; height: 70%; } .sw-light b:nth-child(2) { background: #2563a8; height: 40%; }
.sw-dark { background: #0d1522; } .sw-dark i { background: #08101c; } .sw-dark b { background: #1b2a42; height: 70%; } .sw-dark b:nth-child(2) { background: #6aa8ec; height: 40%; }
.sw-dusk { background: #23282f; } .sw-dusk i { background: #1b1f25; } .sw-dusk b { background: #343b44; height: 70%; } .sw-dusk b:nth-child(2) { background: #8fbfe8; height: 40%; }
.sw-contrast { background: #fff; } .sw-contrast i { background: #000; } .sw-contrast b { background: #fff; border: 2px solid #000; height: 70%; } .sw-contrast b:nth-child(2) { background: #0038a8; height: 40%; }
.sw-system { background: linear-gradient(105deg, #edf0f4 50%, #0d1522 50%); } .sw-system i { background: linear-gradient(105deg, #10284a 50%, #08101c 50%); } .sw-system b { background: transparent; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg label { margin: 0; padding: .5rem .9rem; cursor: pointer; font-weight: 550; border-right: 1px solid var(--line-strong); }
.seg label:last-child { border-right: 0; }
.seg input { position: absolute; opacity: 0; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }

/* ------------------------------------------------------------------ auth pages */
.auth { min-height: calc(100vh - 3.4rem); display: grid; place-items: center; padding: 2rem 1rem; }
.auth-card { width: min(27rem, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 2rem; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 1.6rem; }
.auth-card form { display: grid; gap: .9rem; margin-top: 1rem; }
.btn.ms { width: 100%; background: var(--surface); border-color: var(--line-strong); padding: .75rem 1rem; }
.btn.ms svg { width: 1.2rem; height: 1.2rem; }
.qr { display: block; margin: .5rem auto; border-radius: var(--radius); background: #fff; padding: .4rem; }
.secret { font-family: ui-monospace, Consolas, monospace; letter-spacing: .08em; background: var(--raised); padding: .5rem .7rem; border-radius: var(--radius-s); text-align: center; overflow-wrap: anywhere; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; font-family: ui-monospace, Consolas, monospace; font-size: 1.05rem; background: var(--raised); padding: 1rem; border-radius: var(--radius); }
.otp { font-size: 1.5rem; letter-spacing: .35em; text-align: center; font-family: ui-monospace, Consolas, monospace; }

/* ------------------------------------------------------------------ admin */
.admin-shell { display: grid; grid-template-columns: 14rem 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .admin-shell { grid-template-columns: 1fr; } }
.admin-nav { position: sticky; top: 4.4rem; display: grid; gap: .1rem; }
.admin-nav .tag { font-size: .78rem; color: var(--muted); padding: 0 .7rem .5rem; font-weight: 600; }
.admin-nav a { color: var(--ink); text-decoration: none; padding: .48rem .7rem; border-radius: var(--radius-s); font-weight: 550; display: flex; justify-content: space-between; }
.admin-nav a:hover { background: var(--surface); }
.admin-nav a[aria-current='page'] { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent); }
@media (max-width: 900px) { .admin-nav { position: static; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); } }
.admin-ribbon { background: repeating-linear-gradient(-45deg, #8a5a00 0 10px, #6b4600 10px 20px); height: 4px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: .75rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: .85rem 1rem; }
.stat .k { font-size: .82rem; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 1.55rem; font-weight: 800; font-stretch: 72%; line-height: 1.15; margin-top: .2rem; }
.stat .s { font-size: .8rem; color: var(--muted); }
.meter { height: .5rem; background: var(--raised); border-radius: 999px; overflow: hidden; margin-top: .45rem; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.meter i.hot { background: var(--b-due15); } .meter i.crit { background: var(--danger); }
.spark { width: 100%; height: 3rem; display: block; margin-top: .4rem; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 1.6; }
.spark path.area { fill: var(--accent-soft); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; font-size: .9rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.console { background: #0b1220; color: #d7e1ee; font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: .82rem; line-height: 1.5; border-radius: var(--radius); padding: .9rem 1rem; height: 32rem; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid #1d2a40; }
.console .l-step { color: #8cc8ff; font-weight: 700; }
.console .l-error { color: #ff8f8f; font-weight: 700; }
.console .l-warn { color: #ffd479; }
.console .l-out { color: #9fb0c6; }
.console-bar { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .6rem; flex-wrap: wrap; }
.state-pill { font-weight: 700; font-stretch: 85%; padding: .15rem .65rem; border-radius: 999px; font-size: .85rem; }
.state-pill.running, .state-pill.applying { background: var(--accent-soft); color: var(--accent); }
.state-pill.succeeded, .state-pill.sent { background: var(--ok-soft); color: var(--ok); }
.state-pill.failed, .state-pill.invalid { background: var(--danger-soft); color: var(--danger); }
.state-pill.rolled_back, .state-pill.queued, .state-pill.processing, .state-pill.skipped { background: var(--warn-soft); color: var(--warn); }
.state-pill.uploaded, .state-pill.deleted, .state-pill.cancelled { background: var(--raised); color: var(--muted); }
.steps { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.steps li { font-size: .78rem; padding: .2rem .55rem; border-radius: var(--radius-s); background: var(--raised); color: var(--muted); font-weight: 600; }
.steps li.done { background: var(--ok-soft); color: var(--ok); }
.steps li.now { background: var(--accent); color: var(--accent-ink); }
.steps li.bad { background: var(--danger-soft); color: var(--danger); }
.inline-form { display: inline; }
.progress { height: .5rem; background: var(--raised); border-radius: 999px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
details.more summary { cursor: pointer; color: var(--accent); font-weight: 600; }
pre.block { background: var(--raised); padding: .75rem; border-radius: var(--radius-s); overflow: auto; font-size: .8rem; max-height: 22rem; }

/* connection checks */
.checks { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: .5rem; }
.checks li { display: grid; grid-template-columns: 1.8rem 1fr; gap: .6rem; padding: .6rem .75rem; border-radius: var(--radius); background: var(--raised); border-left: 4px solid var(--line-strong); }
.checks li p { margin: .15rem 0 0; }
.checks .mark { width: 1.6rem; height: 1.6rem; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .85rem; background: var(--line); color: var(--ink); }
.checks .pass { border-left-color: var(--ok); } .checks .pass .mark { background: var(--ok); color: #fff; }
.checks .fail { border-left-color: var(--danger); } .checks .fail .mark { background: var(--danger); color: #fff; }
.checks .warn { border-left-color: var(--warn); } .checks .warn .mark { background: var(--warn); color: #fff; }
.checks .info { border-left-color: var(--accent); } .checks .info .mark { background: var(--accent); color: var(--accent-ink); }
.copyrow { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.copyrow code { background: var(--raised); padding: .45rem .6rem; border-radius: var(--radius-s); overflow-wrap: anywhere; flex: 1; min-width: 16rem; }
.admin-main ol { padding-left: 1.25rem; } .admin-main ol li { margin: .25rem 0; }

/* report types */
.type-badge { display: inline-block; font-size: .72rem; font-weight: 800; font-stretch: 80%; letter-spacing: .04em; padding: .1rem .45rem; border-radius: var(--radius-s); border: 1.5px solid currentColor; vertical-align: middle; }
.type-badge.t-car { color: var(--accent); }
.type-badge.t-ncr { color: var(--b-due15); }
.type-badge.t-sample { color: var(--muted); border-style: dashed; }
.car-head .type-badge { font-size: .95rem; padding: .2rem .6rem; }
.horizon .pin.ncr { stroke: var(--ink); stroke-width: 2.5; }
.filters.four { grid-template-columns: minmax(14rem, 2fr) repeat(3, minmax(8rem, 1fr)) auto; }
@media (max-width: 900px) { .filters.four { grid-template-columns: 1fr 1fr; } .filters.four .wide { grid-column: span 2; } }
.cost-table input { min-height: 2.2rem; padding: .35rem .5rem; }
.cost-table td { padding: .35rem .4rem; }
.cost-table tfoot th { background: var(--raised); font-size: .9rem; color: var(--ink); }
.money { display: flex; align-items: center; gap: .3rem; }
.money input { text-align: right; font-variant-numeric: tabular-nums; }

.locs { display: flex; gap: .3rem .8rem; align-items: center; flex-wrap: wrap; }
.locs .check { margin: 0; font-weight: 600; }

.add-user > summary { list-style: none; cursor: pointer; display: inline-block; }
.add-user > summary::-webkit-details-marker { display: none; }
.add-user[open] > summary .btn { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.add-user[open] > summary .btn::after { content: ' — close'; font-weight: 500; }
.access-panel { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; margin: 1rem 0; font-size: .9rem; }
.access-panel .check { margin: 0; }
.access-panel .sep { width: 1px; height: 1.4rem; background: var(--line-strong); }

.dest { margin-top: .75rem; }
.dest-result { margin: .6rem 0 0; }

.auth-mark { display: block; margin: 0 0 1rem; border-radius: 12px; }

@media print {
  .topbar, .savebar, .tabs, .actions, footer { display: none !important; }
  .tabpanel[hidden] { display: block !important; }
  body { background: #fff; }
}
