/* Layout: top bar with tabs, stage strip, filter row, dense table; editing in a right-side drawer. */
:root {
  --bg: #f3f5f7; --surface: #ffffff; --surface-2: #eef1f4; --line: #d9dfe5;
  --fg: #16212c; --muted: #5e6b78; --accent: #14507a; --accent-fg: #ffffff; --sun: #e09a14;
  --ok: #1f7a4d; --ok-bg: #e3f3ea; --warn: #9a5b00; --warn-bg: #fdf1dc; --bad: #b3261e; --bad-bg: #fbe5e3;
  --s0: #6b7785; --s1: #2f6fa3; --s2: #6c4fb0; --s3: #b8741a; --s4: #2c8a5a; --s5: #17663f;
  --f-ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --r: 8px; --shadow: 0 8px 30px rgba(15, 35, 55, .18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419; --surface: #161d24; --surface-2: #1d262f; --line: #2b3742;
    --fg: #e4eaf0; --muted: #94a3b2; --accent: #5aa7de; --accent-fg: #07131d; --sun: #f0b443;
    --ok: #6fd3a0; --ok-bg: #12321f; --warn: #f0b443; --warn-bg: #352812; --bad: #ff8a80; --bad-bg: #3a1714;
    --s0: #8d9aa8; --s1: #6fb0e3; --s2: #a891ea; --s3: #f0b443; --s4: #6fd3a0; --s5: #3fbf7f;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--f-ui); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; font-size: 12.5px; }
[hidden] { display: none !important; }

/* Auth pages */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; display: grid; gap: 14px; }
.auth-card h1 { margin: 6px 0 0; font-size: 22px; }
.auth-card fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px 14px; display: grid; gap: 10px; margin: 0; }
.auth-card legend { padding: 0 6px; font-weight: 600; font-size: 13px; color: var(--muted); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand b { display: block; letter-spacing: .12em; font-size: 15px; }
.brand small { display: block; color: var(--muted); font-size: 12px; margin-top: -2px; }
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: conic-gradient(from 210deg, var(--sun) 0 25%, var(--accent) 25% 100%); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: var(--surface); box-shadow: inset 0 0 0 3px var(--sun); }
label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
input, select, textarea { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 14px; color: var(--fg); min-width: 0; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible, tr:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); padding: 0; }
.alert { background: var(--bad-bg); color: var(--bad); border-radius: 6px; padding: 9px 12px; font-size: 13.5px; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 7px 13px; cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; color: var(--fg); }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; padding: 10px; }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* App shell */
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-in { display: flex; align-items: center; gap: 18px; padding: 10px 16px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tabs a { padding: 7px 12px; border-radius: 6px; text-decoration: none; color: var(--muted); font-weight: 500; }
.tabs a.on { background: var(--surface-2); color: var(--fg); }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
main { padding: 16px; max-width: 1500px; margin: 0 auto; display: grid; gap: 14px; }
.view-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.view-head h1 { margin: 0; font-size: 20px; margin-right: auto; text-wrap: balance; }

/* Stage strip */
.stages { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.stage { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 9px 11px; cursor: pointer; text-align: left; display: grid; gap: 2px; border-top: 3px solid var(--c, var(--line)); }
.stage b { font-size: 21px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stage span { font-size: 12px; color: var(--muted); }
.stage.on { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--c); }
@media (max-width: 900px) { .stages { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 520px) { .stages { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { flex: 1 1 220px; }
.filters select { flex: 0 1 190px; width: auto; }

/* Tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.tbl-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.nm { font-weight: 600; min-width: 170px; }
table.data td.nm small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.nowrap { white-space: nowrap; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.chip { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 9px; height: 9px; border-radius: 2px; background: var(--line); }
.dots i.on { background: var(--c); }

/* Drawer */
.scrim { position: fixed; inset: 0; background: rgba(10, 20, 30, .35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100%); background: var(--surface); z-index: 41; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.drawer-h { display: flex; align-items: center; gap: 10px; padding: calc(14px + env(safe-area-inset-top, 0px)) 18px 12px; border-bottom: 1px solid var(--line); }
.drawer-h h2 { margin: 0; font-size: 18px; margin-right: auto; min-width: 0; overflow-wrap: anywhere; }
.drawer-b { overflow-y: auto; padding: 16px 18px; display: grid; gap: 18px; flex: 1; }
.drawer-f { display: flex; gap: 8px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); flex-wrap: wrap; }
.drawer-f .sp { margin-right: auto; }
.sec h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid .full { grid-column: 1 / -1; }
@media (max-width: 520px) { .grid { grid-template-columns: minmax(0, 1fr); } }

/* Pipeline steps in drawer */
.steps { display: grid; gap: 6px; }
.step { display: grid; grid-template-columns: 26px minmax(0, 1fr) 150px; gap: 10px; align-items: center; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; }
.step .k { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--muted); }
.step.done .k { background: var(--c); border-color: var(--c); color: var(--surface); }
.step .t { font-weight: 500; }
.step .t small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.step input[type=date] { padding: 5px 8px; font-size: 13px; }
@media (max-width: 520px) { .step { grid-template-columns: 26px minmax(0, 1fr); } .step input[type=date], .step .rt { grid-column: 2; } }
.checks { display: flex; gap: 18px; flex-wrap: wrap; }
.checks label { display: flex; align-items: center; gap: 7px; color: var(--fg); font-size: 14px; }
.links { display: grid; gap: 6px; }
.links .row { display: flex; gap: 6px; }
.links .row input { flex: 1; }
.hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13px; }
.hist li { border-left: 2px solid var(--line); padding-left: 10px; }
.hist pre { margin: 2px 0 0; white-space: pre-wrap; font: 12px/1.4 var(--f-mono); color: var(--muted); }

/* Annex builder */
.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: minmax(0, 1fr); } }
.pane { padding: 14px; display: grid; gap: 12px; }
.pane h2 { margin: 0; font-size: 15px; }
.sel-all { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
table.data td.cb, table.data th.cb { width: 34px; }

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 6px; z-index: 60; font-size: 14px; max-width: calc(100% - 32px); }
.toast.err { background: var(--bad); color: #fff; }
.confirm { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--warn-bg); color: var(--warn); padding: 8px 10px; border-radius: 6px; font-size: 13px; }
@media (prefers-reduced-motion: no-preference) { .drawer { animation: slide .18s ease-out; } @keyframes slide { from { transform: translateX(30px); opacity: .6; } } }
@media (max-width: 640px) { .who span { display: none; } .top-in { gap: 10px; } }
