/* Cogs app chrome. A tool, not a graphic: it borrows the house palette and type from
   newsgfxproj design/tokens.css (read-only) but keeps its own denser layout. Self-hosted font only. */

@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-style: normal; font-display: swap; src: url("/engine/vendor/fonts/ibm-plex-sans/IBMPlexSans-Regular.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-style: italic; font-display: swap; src: url("/engine/vendor/fonts/ibm-plex-sans/IBMPlexSans-Italic.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 600; font-style: normal; font-display: swap; src: url("/engine/vendor/fonts/ibm-plex-sans/IBMPlexSans-SemiBold.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 700; font-style: normal; font-display: swap; src: url("/engine/vendor/fonts/ibm-plex-sans/IBMPlexSans-Bold.woff2") format("woff2"); }

:root {
  --font: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ink: #0c0c0c;            /* house ink */
  --ink-2: #3d3d3d;          /* 10.9:1 */
  --muted: #5f5f5f;          /* 6.4:1 on white, 5.9:1 on --bg-alt */
  --focus: #1f5fd6;          /* house focus, 5.7:1 */
  --bg: #ffffff;
  --bg-alt: #f5f5f5;
  --bg-app: #efefed;
  --frame: #52514e;          /* house frame grey; white text 7.9:1 */
  --rule: #dcdcdc;
  --rule-strong: #b5b5b2;
  --blue: #2d5bb3;           /* darker step of house cat-1 for text: 6.4:1 */
  --blue-tint: #e0ecfe;
  --teal: #00675f;           /* darker step of house cat-2 for text: 6.9:1 */
  --teal-tint: #dcf2ef;
  --red: #a3401f;            /* darker step of house terracotta: 6.3:1 */
  --red-tint: #fbe7e0;
  --amber-ink: #6b4f00;      /* on amber tint: 7.4:1 */
  --amber-tint: #fdf1cc;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --radius: 4px;
  --header-h: 52px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 15px; line-height: 1.45; color: var(--ink); background: var(--bg-app); }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 var(--space-3); }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0 0 var(--space-3); }
a { color: var(--blue); }
a:hover { color: var(--ink); }
code, pre, .mono { font-family: var(--mono); font-size: 13px; }
pre { white-space: pre-wrap; word-break: break-word; background: var(--bg-alt); padding: var(--space-3); border-radius: var(--radius); margin: 0 0 var(--space-3); max-height: 420px; overflow: auto; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1[tabindex="-1"]:focus, main:focus { outline: none; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: absolute; left: var(--space-2); top: -60px; background: var(--ink); color: #fff; padding: var(--space-2) var(--space-3); z-index: 100; border-radius: var(--radius); }
.skip-link:focus { top: var(--space-2); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pre-text { white-space: pre-wrap; word-break: break-word; }
.unsafe-url { font-family: var(--mono); font-size: 13px; color: var(--red); }

/* ---------- Header ---------- */
.app-header { height: var(--header-h); background: var(--frame); color: #fff; display: flex; align-items: center; gap: var(--space-4); padding: 0 var(--space-4); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; font-size: 18px; color: #fff; text-decoration: none; letter-spacing: 0.02em; display: flex; align-items: center; gap: var(--space-2); }
.brand-mark { width: 22px; height: 22px; border: 3px dotted #fff; border-radius: 50%; display: inline-block; }
.app-nav { display: flex; gap: var(--space-1); flex: 1; min-width: 0; overflow-x: auto; }
.app-nav a { color: #fff; text-decoration: none; padding: 6px 10px; border-radius: var(--radius); white-space: nowrap; }
.app-nav a:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.app-nav a[aria-current="page"] { background: #fff; color: var(--ink); font-weight: 600; }
.app-nav .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; background: var(--amber-tint); color: var(--amber-ink); border-radius: 10px; font-size: 12px; font-weight: 600; text-align: center; }
.user-menu { display: flex; align-items: center; gap: var(--space-2); white-space: nowrap; }
.user-menu .role { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; background: rgba(255, 255, 255, 0.16); padding: 2px 6px; border-radius: 3px; }
.user-menu a, .user-menu button { color: #fff; }
.app-header .btn-ghost { color: #fff; border-color: transparent; }
.app-header .btn-ghost:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }

main { display: block; }
.page { max-width: 1200px; margin: 0 auto; padding: var(--space-5) var(--space-4); }
.page-head { display: flex; align-items: flex-end; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-4); }
.page-head h1 { margin: 0; flex: 1; }
.panel-box { background: var(--bg); border: 1px solid var(--rule); border-radius: var(--radius); padding: var(--space-4); margin-bottom: var(--space-4); }
.banner { padding: var(--space-3) var(--space-4); border-radius: var(--radius); margin-bottom: var(--space-4); border-left: 4px solid; }
.banner-warn { background: var(--amber-tint); color: var(--amber-ink); border-color: #b08500; }
.banner-info { background: var(--blue-tint); color: #1c2f62; border-color: var(--blue); }
.banner-error { background: var(--red-tint); color: #5d1416; border-color: var(--red); }
.banner-ok { background: var(--teal-tint); color: #003d38; border-color: var(--teal); }

/* ---------- Controls ---------- */
.btn { font: inherit; font-size: 14px; font-weight: 600; line-height: 1.2; padding: 8px 14px; min-height: 36px; border-radius: var(--radius); border: 1px solid var(--rule-strong); background: var(--bg); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn:hover { background: var(--bg-alt); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: var(--ink-2); }
a.btn-primary, a.btn-primary:hover { color: #fff; }
.btn-approve { background: var(--teal); color: #fff; border-color: var(--teal); }
.btn-approve:hover { background: #004f49; }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: #7f2f15; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn[aria-busy="true"]::after { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
.actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; margin-top: var(--space-3); }
.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { font: inherit; font-size: 13px; padding: 5px 10px; border: 0; background: var(--bg); color: var(--ink); cursor: pointer; min-height: 30px; }
.seg button + button { border-left: 1px solid var(--rule-strong); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; font-weight: 600; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="url"], input[type="number"], input[type="date"], select, textarea {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--bg); border: 1px solid #8c8c8c; border-radius: var(--radius); padding: 7px 10px; width: 100%; min-height: 36px;
}
textarea { resize: vertical; line-height: 1.4; }
textarea.code { font-family: var(--mono); font-size: 13px; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.field { margin-bottom: var(--space-3); }
.field label, .label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.field .hint { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.check { display: flex; gap: var(--space-2); align-items: flex-start; font-size: 14px; margin: var(--space-2) 0; }
.check input { margin-top: 3px; width: 18px; height: 18px; flex: none; }
.form-error { color: var(--red); font-weight: 600; font-size: 14px; }
.row { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1; min-width: 160px; }

/* ---------- Chips ---------- */
.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; background: var(--bg-alt); color: var(--ink-2); border: 1px solid var(--rule); vertical-align: middle; }
.chip-draft { background: #ececea; color: var(--ink-2); }
.chip-brief_approved { background: var(--blue-tint); color: #1c3f86; border-color: #b9cff5; }
.chip-draft_approved { background: var(--teal-tint); color: #003d38; border-color: #a8dcd5; }
.chip-published, .chip-live { background: var(--frame); color: #fff; border-color: var(--frame); }
.chip-proposed, .chip-pending { background: var(--amber-tint); color: var(--amber-ink); border-color: #ecd486; }
.chip-approved { background: var(--teal-tint); color: #003d38; border-color: #a8dcd5; }
.chip-rejected, .chip-revoked, .chip-error { background: var(--red-tint); color: #5d1416; border-color: #f0bfae; }
.chip-superseded, .chip-withdrawn, .chip-stale, .chip-dropped { background: #ececea; color: var(--muted); }
.chip-answered { background: var(--teal-tint); color: #003d38; }
.chip-open { background: var(--amber-tint); color: var(--amber-ink); }
.chip-locked { background: #ececea; color: var(--ink-2); }
.chip-enabled { background: var(--teal-tint); color: #003d38; }
.chip-disabled { background: #ececea; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 14px; background: var(--bg); }
table.data th, table.data td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.data th { font-weight: 600; background: var(--bg-alt); color: var(--ink-2); position: sticky; top: 0; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.blank { background: repeating-linear-gradient(135deg, #f1f0ee 0 4px, #e3e1dd 4px 5px); color: var(--muted); font-style: italic; }
table.data td.symbol { background: var(--amber-tint); color: var(--amber-ink); }
table.compact th, table.compact td { padding: 4px 8px; font-size: 13px; }

/* ---------- Library ---------- */
.lib-tools { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: flex-end; margin-bottom: var(--space-4); }
.lib-tools .field { margin: 0; }
.lib-tools .grow { flex: 1; min-width: 220px; }
.project-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--space-3); }
.project-card { background: var(--bg); border: 1px solid var(--rule); border-radius: var(--radius); padding: var(--space-3) var(--space-4); display: grid; grid-template-columns: 1fr 96px; gap: var(--space-3); position: relative; }
.project-card:hover { border-color: var(--rule-strong); }
.project-card:focus-within { outline: 3px solid var(--focus); outline-offset: 1px; }
.project-card h2 { font-size: 16px; margin: 0 0 4px; }
.project-card h2 a { color: var(--ink); text-decoration: none; }
.project-card h2 a::after { content: ""; position: absolute; inset: 0; }
/* Buttons sit above the stretched title link, or clicks open the project instead (10 Nov 2026 bug: Delete did nothing). */
.project-card .actions, .project-card button { position: relative; z-index: 1; }
.project-card h2 a:focus-visible { outline: none; }
.project-card .headline { font-size: 14px; color: var(--ink-2); margin: 0 0 var(--space-2); }
.project-card p.meta { margin: 6px 0 0; }
.grow { flex: 1; }
.project-card .meta { font-size: 13px; color: var(--muted); display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.thumb { width: 96px; height: 72px; border: 1px solid var(--rule); background: var(--bg-alt); object-fit: cover; object-position: top; }
.thumb-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; text-align: center; }
.empty { text-align: center; padding: var(--space-6); color: var(--muted); background: var(--bg); border: 1px dashed var(--rule-strong); border-radius: var(--radius); }

/* ---------- Workspace ---------- */
.ws { position: relative; display: grid; grid-template-columns: minmax(340px, 0.8fr) minmax(420px, 1.4fr); grid-template-rows: auto 1fr; height: calc(100vh - var(--header-h)); min-height: 560px; }
.ws-head { grid-column: 1 / -1; display: flex; gap: var(--space-3); align-items: center; padding: var(--space-2) var(--space-4); background: var(--bg); border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.ws-head h1 { font-size: 18px; margin: 0; }
.ws-head .slug { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.ws-head .spacer { flex: 1; }
.ws-col { min-height: 0; display: flex; flex-direction: column; background: var(--bg); border-right: 1px solid var(--rule); }
.ws-col:last-child { border-right: 0; }
.ws-col > h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--rule); }

/* Chat */
.chat { position: relative; }
.chat-log { flex: 1; overflow-y: auto; padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.msg { max-width: 92%; }
.msg-user { align-self: flex-end; }
.msg-assistant, .msg-system { align-self: flex-start; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg-user .who { text-align: right; }
.bubble { padding: var(--space-2) var(--space-3); border-radius: 10px; white-space: pre-wrap; word-break: break-word; }
.msg-user .bubble { background: var(--ink); color: #fff; border-bottom-right-radius: 2px; }
.msg-assistant .bubble { background: var(--bg-alt); border: 1px solid var(--rule); border-bottom-left-radius: 2px; }
.bubble + .bubble, .bubble + .tool, .tool + .bubble { margin-top: var(--space-1); }
.thinking { font-size: 13px; color: var(--muted); margin: 2px 0; }
.thinking summary { cursor: pointer; }
.thinking div { white-space: pre-wrap; padding: 4px 0 4px var(--space-3); border-left: 2px solid var(--rule); }
.tool { display: flex; gap: 6px; align-items: baseline; font-size: 13px; padding: 4px 8px; border-radius: var(--radius); background: #fafafa; border: 1px solid var(--rule); margin: 2px 0; }
.tool .tname { font-weight: 600; white-space: nowrap; }
.tool .tsum { color: var(--ink-2); }
.tool-running .tname::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border: 2px solid var(--blue); border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px; }
.tool-ok .tname::before { content: "✓ "; color: var(--teal); }
.tool-err { background: var(--red-tint); border-color: #f0bfae; }
.tool-err .tname::before { content: "✕ "; color: var(--red); }
.event-card { border: 1px solid var(--rule-strong); border-left: 4px solid var(--blue); background: var(--bg); border-radius: var(--radius); padding: var(--space-2) var(--space-3); margin: var(--space-1) 0; font-size: 14px; }
.event-card.card-approval { border-left-color: #b08500; }
.event-card.card-version { border-left-color: var(--teal); }
.event-card h3 { font-size: 14px; margin: 0 0 4px; }
.chat-error { background: var(--red-tint); color: #5d1416; border-radius: var(--radius); padding: var(--space-2) var(--space-3); font-size: 14px; }
.attach-chip { font-size: 13px; display: inline-flex; gap: 4px; align-items: center; background: var(--blue-tint); color: #1c2f62; border-radius: 12px; padding: 2px 4px 2px 10px; }
.attach-chip button { border: 0; background: transparent; cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 6px; color: inherit; border-radius: 50%; }
.composer { border-top: 1px solid var(--rule); padding: var(--space-2) var(--space-3) var(--space-3); background: var(--bg); }
.composer textarea { min-height: 64px; max-height: 200px; }
.composer .attachments { display: flex; gap: var(--space-1); flex-wrap: wrap; margin-bottom: var(--space-2); }
.composer .actions { margin-top: var(--space-2); justify-content: space-between; }
.dropzone-active::after { content: "Drop files to upload"; position: absolute; inset: 8px; display: flex; align-items: center; justify-content: center; border: 3px dashed var(--blue); background: rgba(224, 236, 254, 0.92); font-weight: 600; font-size: 18px; color: #1c2f62; border-radius: 8px; z-index: 5; pointer-events: none; }

/* Preview */
.preview-bar { display: flex; gap: var(--space-2); align-items: center; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.preview-bar select { width: auto; min-height: 30px; padding: 3px 8px; font-size: 14px; }
.preview-stage { flex: 1; overflow: auto; background: repeating-conic-gradient(#f3f3f1 0 25%, #fafaf9 0 50%) 0 0 / 16px 16px; padding: var(--space-4); display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.preview-banner { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--amber-ink); background: var(--amber-tint); padding: 3px 10px; border-radius: 3px; }
.preview-frame { border: 1px solid var(--rule-strong); background: #fff; display: block; height: 640px; max-width: 100%; }
.preview-blocked { max-width: 600px; width: 100%; background: var(--bg); border: 1px solid var(--rule); padding: var(--space-4); }
.preview-issues { border-top: 1px solid var(--rule); max-height: 32%; overflow-y: auto; padding: var(--space-2) var(--space-3); }
.preview-issues h3 { font-size: 13px; margin-bottom: var(--space-2); }
.issues { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.issue { display: grid; grid-template-columns: auto 1fr; column-gap: var(--space-2); font-size: 13px; padding: 4px 6px; border-radius: 3px; background: #fafafa; }
.issue .issue-meta { grid-column: 2; color: var(--muted); font-size: 12px; font-family: var(--mono); word-break: break-all; }
.lvl { font-weight: 700; font-size: 11px; text-transform: uppercase; padding: 1px 6px; border-radius: 3px; align-self: start; margin-top: 1px; }
.lvl-error { background: var(--red); color: #fff; }
.lvl-warning { background: var(--amber-tint); color: var(--amber-ink); border: 1px solid #ecd486; }
.lvl-info { background: var(--blue-tint); color: #1c2f62; }

/* Right panel tabs */
.tabs { display: flex; border-bottom: 1px solid var(--rule); overflow-x: auto; flex: none; }
.tabs [role="tab"] { font: inherit; font-size: 13px; font-weight: 600; padding: 10px 7px; border: 0; border-bottom: 3px solid transparent; background: none; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs [role="tab"]:hover { color: var(--ink); }
.tabs .badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 3px; background: var(--amber-tint); color: var(--amber-ink); border-radius: 9px; font-size: 11px; }
.tabpanel { flex: 1; overflow-y: auto; padding: var(--space-3); }
.tabpanel h3 { margin-top: var(--space-4); }
.tabpanel h3:first-child { margin-top: 0; }
.card { border: 1px solid var(--rule); border-radius: var(--radius); padding: var(--space-3); margin-bottom: var(--space-3); background: var(--bg); }
.card-head { display: flex; gap: var(--space-2); align-items: baseline; flex-wrap: wrap; margin-bottom: var(--space-2); }
.card-head h4 { margin: 0; font-size: 14px; flex: 1; min-width: 0; word-break: break-word; }
.reading { background: var(--bg-alt); border-left: 3px solid var(--blue); padding: var(--space-2) var(--space-3); margin: var(--space-2) 0; white-space: pre-wrap; }
.reading-label { font-weight: 600; font-size: 13px; color: var(--blue); }
.flags { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0; }
.flag { font-size: 12px; padding: 1px 6px; border-radius: 3px; background: var(--amber-tint); color: var(--amber-ink); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px var(--space-3); font-size: 14px; margin: 0; }
.kv dt { font-weight: 600; color: var(--ink-2); }
.kv dd { margin: 0; word-break: break-word; }
.vlist { list-style: none; margin: 0; padding: 0; }
.vlist li { border-bottom: 1px solid var(--rule); padding: var(--space-2) 0; }
.vlist .vrow { display: flex; gap: var(--space-2); align-items: baseline; flex-wrap: wrap; }
.vlist .vnum { font-weight: 700; font-variant-numeric: tabular-nums; }
.vlist .current { background: #f8fbff; }
.diff-sum { list-style: none; margin: 0 0 var(--space-3); padding: 0; font-size: 14px; }
.diff-sum li { padding: 3px 0 3px var(--space-3); border-left: 3px solid var(--blue); margin-bottom: 3px; }
.op-add { color: var(--teal); } .op-remove { color: var(--red); } .op-replace { color: var(--blue); }

/* ---------- Dialog ---------- */
dialog.dialog { border: 0; border-radius: 6px; padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3); color: var(--ink); }
dialog.dialog-wide { width: min(820px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(12, 12, 12, 0.5); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--rule); position: sticky; top: 0; background: var(--bg); z-index: 1; }
.dialog-head h2 { margin: 0; }
.dialog-close { font-size: 22px; padding: 2px 10px; }
.dialog-body { padding: var(--space-4); }
.confirm-headline { font-weight: 700; font-size: 17px; background: var(--bg-alt); padding: var(--space-2) var(--space-3); border-radius: var(--radius); }
.pub-result { border: 2px solid var(--frame); border-radius: var(--radius); padding: var(--space-3); }
.pub-result .big { font-size: 22px; font-weight: 700; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: var(--space-4); bottom: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); z-index: 1000; max-width: 380px; }
.toast { background: var(--ink); color: #fff; padding: var(--space-3) var(--space-4); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); font-size: 14px; }
.toast-error { background: #7f2f15; }
.toast-ok { background: #004f49; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-4); }
.login-card { background: var(--bg); border-top: 6px solid var(--frame); width: min(400px, 100%); padding: var(--space-6) var(--space-5); border-radius: var(--radius); box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08); }
.login-card .brand { color: var(--ink); margin-bottom: var(--space-5); font-size: 22px; }
.login-card .brand-mark { border-color: var(--ink); }
#login-help { margin-top: var(--space-5); }

/* ---------- Admin ---------- */
.split { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: var(--space-4); align-items: start; }
.rule-list { list-style: none; margin: 0; padding: 0; background: var(--bg); border: 1px solid var(--rule); border-radius: var(--radius); }
.rule-list li + li { border-top: 1px solid var(--rule); }
.rule-list a { display: block; padding: var(--space-2) var(--space-3); text-decoration: none; color: var(--ink); }
.rule-list a[aria-current="true"] { background: var(--blue-tint); }
.rule-list .rk { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.char-count { font-size: 12px; color: var(--muted); text-align: right; }
.char-count.over { color: var(--red); font-weight: 700; }
.test-result { border-top: 1px solid var(--rule); margin-top: var(--space-3); padding-top: var(--space-3); }

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- Tablet ---------- */
@media (max-width: 1180px) {
  .ws { grid-template-columns: minmax(300px, 1fr) minmax(380px, 1.2fr); grid-template-rows: auto minmax(520px, 1fr); height: auto; }
  .ws-col.chat { height: calc(100vh - var(--header-h) - 56px); min-height: 520px; position: sticky; top: var(--header-h); }
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .ws { grid-template-columns: 1fr; }
  .ws-col.chat { position: static; height: 70vh; }
  .app-header { gap: var(--space-2); }
  .user-menu .name { display: none; }
}

/* ---------- Approved sources, fetched datasets, calculations (DECISIONS #2, #10) ---------- */
.chip-tier { font-weight: 600; }
.chip-tier-government { background: var(--teal-tint); color: #003d38; }
.chip-tier-semi_state { background: var(--blue-tint); color: #1c2f62; }
.chip-tier-international_official { background: var(--bg-alt); color: var(--ink-2); border: 1px solid var(--rule-strong); }
.chip-tier-other_approved { background: var(--amber-tint); color: var(--amber-ink); }
.provenance { border-left: 4px solid var(--teal); background: var(--bg-alt); padding: var(--space-2) var(--space-3); margin: var(--space-2) 0 var(--space-3); border-radius: var(--radius); }
.provenance p { margin: 0 0 var(--space-1); }
.provenance .prov-url { word-break: break-all; }
.calc-card .method { font-weight: 600; background: var(--blue-tint); color: #1c2f62; padding: var(--space-2) var(--space-3); border-radius: var(--radius); }
.calc-card td.calc-out, .calc-card th.calc-out { background: var(--blue-tint); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px var(--space-3); margin: var(--space-2) 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; }
ol.history li { margin-bottom: var(--space-3); }

/* ---------- Markdown in chat bubbles (markdown.js: safe subset, DOM nodes only) ---------- */
.bubble.md, .thinking div.md { white-space: normal; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 var(--space-1); }
.md ul, .md ol { margin: 0 0 var(--space-1); padding-left: 1.4em; }
.md li + li { margin-top: 2px; }
.md code { font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace); font-size: 0.92em; background: rgba(0, 0, 0, 0.06); padding: 0 3px; border-radius: 3px; }
.md pre { white-space: pre-wrap; background: rgba(0, 0, 0, 0.05); padding: var(--space-1) var(--space-2); border-radius: var(--radius); margin: 0 0 var(--space-1); }
.md pre code { background: none; padding: 0; }
.md .md-heading { margin-top: var(--space-1); }

/* ---------- Data plan card, rearranged tables (DECISIONS #2 addendum) ---------- */
.event-card.card-transform { border-left-color: var(--teal); }
.card-plan .plan-head h3 { margin-bottom: 2px; }
.card-plan .plan-head .btn { margin: 4px 0 var(--space-1); }
.card-plan .plan-item + .plan-item { border-top: 1px solid var(--rule); margin-top: var(--space-1); padding-top: var(--space-1); }
.plan-done { margin: 2px 0; }
.lineage { color: var(--muted); }
.before-after { display: grid; grid-template-columns: 1fr; gap: var(--space-1); }
.before-after .table-wrap { max-width: 100%; overflow-x: auto; }

/* Review panel (DECISIONS #12): everything outstanding for the current draft, beside the preview */
.chip-not-checked { background: var(--amber-tint); color: var(--amber-ink); border-color: #ecd486; }
.chip-not-checked[hidden] { display: none; }
.review-head { margin-bottom: var(--space-3); }
.review-count { font-weight: 600; margin: 0 0 2px; }
.review-head .btn { margin-top: var(--space-1); }
.review-section { margin: var(--space-3) 0; }
.review-section > h3 { font-size: 14px; margin: 0 0 var(--space-2); }
.review-item { border: 1px solid var(--rule); border-left: 4px solid #b08500; border-radius: var(--radius); padding: var(--space-2) var(--space-3); margin: 0 0 var(--space-2); background: var(--bg); }
.review-item h4 { font-size: 14px; margin: 0 0 4px; }
.review-item.review-rearranged { border-left-color: var(--teal); }
.review-item.review-check { border-left-color: var(--red); }
.review-item .method { margin: 0 0 4px; }
.review-q { margin: 0 0 4px; font-weight: 600; }
.review-answer { margin: 0 0 var(--space-2); }
.review-answer .row input { flex: 1; }
.review-send-form textarea { width: 100%; }
.event-card.card-review { border-left-color: #b08500; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* ---------- Details drawer (the summary column was removed in DECISIONS #19) ---------- */
.ws-col.side { position: relative; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; background: var(--amber-tint); color: var(--amber-ink); border-radius: 9px; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; }
.side-detail { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.detail-head { display: flex; align-items: center; gap: var(--space-2); justify-content: flex-start; padding: 4px var(--space-2); border-bottom: 1px solid var(--rule); background: var(--bg-alt); }
.detail-head h2 { font-size: 15px; margin: 0; flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-head h2:focus { outline: none; }
.detail-head h2:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.side-detail .tabpanel { padding-top: var(--space-3); }
.evidence { margin: 4px 0 0; }
.evidence > summary { cursor: pointer; color: var(--blue); }
.evidence[open] > summary { margin-bottom: var(--space-2); }
.card-line { margin: 0 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-item .actions { margin-top: 4px; }
.review-item .calc-card .card-head { margin-bottom: 2px; }
.review-item .calc-card > .card-head { display: none; }   /* the item line already names it; status is "waiting" by definition */
.review-correct { margin-top: 4px; }
.notes-compare { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.notes-compare p { margin: 0 0 4px; }

/* Data tables: a page of rows, titles that don't wrap, long cells cut with an ellipsis (full text in the title) */
.dt { margin: var(--space-2) 0; }
.dt-head { display: flex; gap: var(--space-2); align-items: baseline; }
.dt-caption { color: var(--muted); }
.dt-constant { margin: 2px 0 4px; color: var(--ink-2); }
.dt-const { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dt-wide .dt-const { white-space: normal; }
.dt-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); }
table.dt-table { width: auto; min-width: 100%; table-layout: auto; }
table.dt-table th, table.dt-table td { white-space: nowrap; vertical-align: top; }
.dt-cell { display: block; max-width: 14em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.num .dt-cell { margin-left: auto; }
.dt-wide .dt-cell { max-width: 28em; }
.dt-wide .dt-wrap { max-height: 70vh; overflow: auto; }
.dt-pager { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-top: 4px; }
.dt-pager .dt-range { margin-right: auto; }
.dt-pager .btn { min-height: 26px; padding: 2px 8px; }

/* Chat: one activity row per turn, one approach disclosure, compact one-line notes */
.activity { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); margin: 2px 0 var(--space-1); }
.activity-spin { width: 10px; height: 10px; border: 2px solid var(--blue); border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; flex: none; }
.activity-now { font-weight: 600; }
.activity-step { color: var(--muted); }
.activity-done { font-size: 13px; color: var(--muted); }
.activity-done summary { cursor: pointer; }
.activity-list { margin: 4px 0 0; padding-left: 1.6em; color: var(--ink-2); }
.activity-list .step-note { color: var(--muted); }
.event-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--space-2); font-size: 13px; padding: 2px 0 2px var(--space-2); border-left: 3px solid var(--rule-strong); margin: var(--space-1) 0; }
.event-line.line-draft { border-left-color: var(--teal); }
.event-line.card-review { border-left-color: #b08500; }
.event-line .btn { min-height: 26px; padding: 2px 8px; }

/* Preview: checks folded into one line */
.preview-issues { max-height: 40%; }
.preview-checks > summary { cursor: pointer; font-size: 13px; font-weight: 600; padding: 2px 0; }
.preview-checks[open] > summary { margin-bottom: var(--space-2); }

/* "Cogs was updated — reload" */
.update-banner { position: fixed; left: var(--space-4); bottom: var(--space-4); z-index: 900; display: flex; align-items: center; gap: var(--space-2); background: var(--bg); border: 1px solid var(--rule-strong); border-left: 4px solid var(--blue); border-radius: var(--radius); padding: 4px 4px 4px var(--space-3); font-size: 13px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); }

/* New chart forms (DECISIONS #14): code shown as text, collapsed; the Forms library screen */
.form-code summary { cursor: pointer; font-size: .875rem; }
.form-code pre.code { max-height: 24rem; overflow: auto; background: var(--surface-alt, #f5f5f5); padding: var(--space-3); border-radius: var(--radius); font-size: .8125rem; line-height: 1.45; white-space: pre; }
.form-checks ul { margin: var(--space-2) 0 0; padding-left: 1.2em; }
.forms-layout { display: grid; grid-template-columns: minmax(14rem, 1fr) 2fr; gap: var(--space-4); align-items: start; }
.forms-list { display: grid; gap: var(--space-3); }
.forms-item ul.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.preview-new-form { margin: var(--space-2) 0; }
@media (max-width: 760px) { .forms-layout { grid-template-columns: 1fr; } }


/* ---------- DECISIONS #19: no right-hand column; the action bar and the detail drawer ---------- */
.ws-nav { display: flex; gap: 2px; flex-wrap: wrap; }
.ws-nav .btn.active { background: var(--bg-alt); font-weight: 600; }
.ws-nav .badge { margin-left: 4px; }
.action-bar { border-top: 1px solid var(--rule); background: var(--bg-alt); padding: var(--space-2) var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.action-bar[hidden] { display: none; }
.ab-status { margin: 0; font-weight: 600; font-size: 14px; }
.ab-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }
.ab-actions .btn-primary { min-height: 34px; }
.ws-col.side-drawer { position: absolute; top: 0; right: 0; bottom: 0; width: min(520px, 100%); z-index: 20; border-left: 1px solid var(--rule); box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12); }
.ws-col.side-drawer[hidden] { display: none; }
.detail-head .spacer { flex: 1; }

/* ---------- Chart library (DECISIONS #24) ---------- */
.chart-cats { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.chart-cats .btn[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.chart-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: var(--space-4); }
.chart-card { background: var(--bg); border: 1px solid var(--rule); border-radius: var(--radius); padding: var(--space-3) var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.chart-card-head { display: flex; gap: var(--space-2); align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.chart-card h2 { margin: 0; font-size: 17px; }
.chart-card p { margin: 0; }
.chart-media { border: 1px solid var(--rule); background: #fff; border-radius: var(--radius); overflow: hidden; min-height: 120px; }
.chart-sample { display: block; width: 100%; height: auto; }
.chart-sample-empty { padding: var(--space-4); text-align: center; }
.chart-needs ul { margin: var(--space-1) 0 0; padding-left: 1.2em; }
.chart-use { margin-top: auto; border-top: 1px solid var(--rule); padding-top: var(--space-2); display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-1); }
.chart-hint q { font-weight: 600; }
.house-status ul { margin: var(--space-1) 0 0; padding-left: 1.2em; }

/* Ways to show it (DECISIONS #27): suggested displays drawn from the project's own rows */
.advice { display: flex; flex-direction: column; gap: var(--space-3); }
.advice-grid { grid-template-columns: 1fr; }
.advice-card h3 { margin: 0; font-size: 16px; }
.advice-media { min-height: 160px; }
.advice-notes { margin: 0; padding-left: var(--space-4); }
.advice-own { display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-start; }
.advice-own textarea { width: 100%; }

/* Final check (DECISIONS #30) */
.final { display: flex; flex-direction: column; gap: var(--space-3); }
.final h3 { margin: var(--space-2) 0 0; }
.final-list { margin: 0; padding-left: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); }
.final-ask { font-weight: 600; margin: 0; }
.final-gap { color: var(--ink); }
.final-problems { border: 1px solid var(--rule); border-radius: var(--radius); padding: var(--space-3); }
.final-done { font-weight: 600; margin: 0; }
.final h4 { margin: var(--space-2) 0 0; font-size: 14px; }
.final-level { margin: 0; padding: var(--space-3); border: 1px solid var(--rule); border-radius: var(--radius); border-left-width: 6px; }
.final-level-high { border-left-color: #1b6e3a; }
.final-level-moderate { border-left-color: #a66a00; }
.final-level-low { border-left-color: #b3261e; }
.final-checks .chip-ok { background: #e3f1e8; }
.chip-limit { background: #fbeed3; }
.final-checks .chip-problem, .chip-problem { background: #f7dcd9; }
.chip-ok { background: #e3f1e8; }
.ab-others { display: flex; flex-direction: column; gap: 4px; padding-top: var(--space-2); border-top: 1px solid var(--rule); }
.ab-others-label { margin: 0; font-size: 12px; color: var(--muted); }
.ab-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ab-chip { min-height: 32px; font-weight: 500; background: var(--bg); }
.action-bar .ab-link { min-height: 32px; text-decoration: underline; text-underline-offset: 2px; padding-left: 6px; padding-right: 6px; }
.action-bar .btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.advice-draft { display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-start; }
.advice-draft p { margin: 0; }
.final-concerns { border: 1px solid var(--rule); border-left: 4px solid #a66a00; border-radius: var(--radius); padding: var(--space-3); }
.final-concerns p { margin: 0 0 var(--space-2); }
.final-all > summary { font-weight: 600; }


/* The final check is a card in the conversation, not a side panel */
.chat-card { align-self: stretch; background: var(--bg); border: 1px solid var(--rule-strong); border-radius: var(--radius); padding: var(--space-3); }
.chat-card-head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.chat-card-head h3 { margin: 0; font-size: 1rem; }
.chat-card-head .spacer { flex: 1; }

/* ---------- Cogs theme (15 Nov 2026): brighter, sharper, rounder; the person is using Cogs ---------- */
:root {
  --bg-app: #f3f6fc;
  --bg-alt: #f0f3fa;
  --frame: #0f1b3d;           /* deep navy header; white text 16:1 */
  --ink: #0b1220;
  --ink-2: #2b3550;
  --muted: #55607a;           /* 6.1:1 on white */
  --rule: #e1e6f0;
  --rule-strong: #b9c2d6;
  --blue: #1d4fd8;            /* 6.6:1 on white */
  --blue-tint: #e6eeff;
  --accent: #2f6bff;          /* bright accent for fills and highlights (white text 4.6:1 on --accent-ink) */
  --accent-ink: #1d4fd8;
  --teal: #00705f;
  --teal-tint: #ddf6ef;
  --radius: 8px;
  --shadow-1: 0 1px 2px rgba(15, 27, 61, .06), 0 1px 3px rgba(15, 27, 61, .08);
  --shadow-2: 0 4px 16px rgba(15, 27, 61, .10);
  --focus: #2f6bff;
}
body { background: var(--bg-app); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { letter-spacing: -0.01em; }
.app-header { background: linear-gradient(90deg, #0f1b3d 0%, #172a5c 100%); box-shadow: 0 2px 10px rgba(15, 27, 61, .25); }
.brand { font-size: 20px; letter-spacing: -0.01em; }
.brand-mark { border-color: #6ea0ff; box-shadow: 0 0 0 2px rgba(110, 160, 255, .25); }
.app-nav a { border-radius: 999px; padding: 6px 12px; font-weight: 500; opacity: .92; }
.app-nav a:hover { opacity: 1; }
.app-nav a[aria-current="page"] { background: #fff; color: var(--frame); font-weight: 600; opacity: 1; }
.user-menu .role { border-radius: 999px; background: rgba(110, 160, 255, .22); }

.btn { border-radius: 999px; padding: 8px 16px; box-shadow: var(--shadow-1); transition: background .15s, box-shadow .15s, transform .05s; }
.btn:hover { box-shadow: var(--shadow-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-primary:hover { background: #163fb0; }
.btn-ghost { box-shadow: none; }
.btn-small { padding: 4px 12px; }
.seg { border-radius: 999px; }
.seg button[aria-pressed="true"] { background: var(--accent-ink); }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="url"], input[type="number"], input[type="date"], select, textarea { border-color: var(--rule-strong); border-radius: var(--radius); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 107, 255, .2); outline: none; }

.panel-box, .project-card, .event-card, .chat-card { box-shadow: var(--shadow-1); border-color: var(--rule); }
.project-card:hover { box-shadow: var(--shadow-2); border-color: var(--rule-strong); }
.chip { border-radius: 999px; }
.chip-published, .chip-live { background: var(--accent-ink); border-color: var(--accent-ink); }

.ws-head { background: #fff; box-shadow: 0 1px 0 var(--rule); }
.ws-col { background: #fff; }
.ws-col > h2 { color: var(--accent-ink); font-weight: 700; background: linear-gradient(#fff, #f7f9ff); }
.chat-log { background: #fafbff; gap: var(--space-3); }
.bubble { border-radius: 16px; line-height: 1.5; }
.msg-user .bubble { background: var(--accent-ink); border-bottom-right-radius: 4px; box-shadow: var(--shadow-1); }
.msg-assistant .bubble { background: #fff; border: 1px solid var(--rule); border-bottom-left-radius: 4px; box-shadow: var(--shadow-1); }
.msg .who { font-weight: 600; letter-spacing: .02em; }
.msg-assistant .who { color: var(--accent-ink); }
.chat-card { border-left: 4px solid var(--accent); border-radius: var(--radius); }
.composer { background: #fff; border-top: 1px solid var(--rule); box-shadow: 0 -4px 12px rgba(15, 27, 61, .05); }
.action-bar { background: linear-gradient(#f6f8ff, #eef3ff); border-color: var(--rule); }
.table-wrap, table.data { border-radius: var(--radius); }
table.data th { background: #eef2fb; }
.banner { border-radius: var(--radius); }
@media (prefers-reduced-motion: reduce) { .btn { transition: none; } }

.chat.final-open .action-bar { display: none; }
