/* PBMS — instrument ledger theme */
:root {
  --paper: #edf0f3;
  --surface: #ffffff;
  --ink: #141d27;
  --muted: #5c6a79;
  --line: #d4dbe2;
  --accent: #0f5e63;
  --accent-soft: #e3eeef;
  --red: #b3402f;
  --amber: #b17400;
  --green: #2e7d4f;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Consolas", monospace;
  --sans: system-ui, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
html { font-size: var(--fs, 15px); }
body { font: 1rem/1.55 var(--sans); color: var(--ink); background: var(--paper); }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* Shell */
#app { display: grid; grid-template-columns: 196px 1fr; min-height: 100vh; }
nav.rail { background: var(--ink); color: #c8d2dc; padding: 14px 0; position: sticky; top: 0; height: 100vh; }
nav.rail .brand { font-family: var(--mono); font-size: 1rem; letter-spacing: .18em; color: #fff; padding: 4px 18px 16px; border-bottom: 1px solid #2a3542; }
nav.rail .brand small { display: block; font-size: .6rem; letter-spacing: .3em; color: #7d8b99; margin-top: 2px; }
nav.rail a { display: block; padding: 9px 18px; color: #aab6c2; font-size: .87rem; border-left: 3px solid transparent; }
nav.rail a:hover { color: #fff; background: #1c2733; }
nav.rail a.active { color: #fff; border-left-color: var(--accent); background: #1c2733; }
nav.rail .who { position: absolute; bottom: 12px; left: 18px; right: 18px; font-size: .74rem; color: #7d8b99; font-family: var(--mono); }
nav.rail .who button { background: none; border: 1px solid #3a4753; color: #aab6c2; font-size: .67rem; padding: 2px 8px; margin-top: 6px; }

main { padding: 22px 28px 60px; max-width: 1360px; }
header.page { display: flex; align-items: baseline; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
header.page h1 { font-size: 1.27rem; font-weight: 650; letter-spacing: .01em; }
header.page .crumb { color: var(--muted); font-family: var(--mono); font-size: .8rem; }
header.page .grow { flex: 1; }

/* Signature: control strip */
.strip { display: flex; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-bottom: 18px; flex-wrap: wrap; }
.strip .cell { padding: 12px 18px; border-right: 1px solid var(--line); min-width: 128px; }
.strip .cell:last-child { border-right: 0; }
.strip .k { font-size: .67rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.strip .v { font-family: var(--mono); font-size: 1.27rem; font-variant-numeric: tabular-nums; margin-top: 2px; }
.strip .v.good { color: var(--green); } .strip .v.bad { color: var(--red); } .strip .v.warn { color: var(--amber); }

/* Cards, tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 16px 18px; margin-bottom: 16px; }
.card h2 { font-size: .74rem; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; font-weight: 600; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 980px) { #app { grid-template-columns: 1fr } nav.rail { position: static; height: auto } .cols,.cols3 { grid-template-columns: 1fr } }

table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th { text-align: left; font-size: .67rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--line); font-weight: 600; }
td { padding: 7px 10px; border-bottom: 1px solid #e8edf1; vertical-align: top; }
tr:hover td { background: #f6f8fa; }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
td.mono { font-family: var(--mono); font-size: .8rem; }
.neg { color: var(--red); } .pos { color: var(--green); }

/* Chips, RAG, buttons */
.rag { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.rag.R { background: var(--red); } .rag.A { background: var(--amber); } .rag.G { background: var(--green); }
.chip { display: inline-block; font-family: var(--mono); font-size: .74rem; padding: 1px 8px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: #f4f6f8; white-space: nowrap; }
.chip.ok { color: var(--green); border-color: #bcd8c8; background: #eef6f1; }
.chip.warn { color: var(--amber); border-color: #e3cf9d; background: #faf4e4; }
.chip.err { color: var(--red); border-color: #e0b3aa; background: #f9ecea; }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 4px; padding: 7px 14px; font-size: .87rem; }
.btn:hover { background: #0b4a4e; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.small { padding: 3px 10px; font-size: .8rem; }
.btn.danger { background: var(--red); }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--ink); }
label.f { display: block; font-size: .74rem; color: var(--muted); margin: 8px 0 2px; letter-spacing: .06em; text-transform: uppercase; }
form.inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; font-size: .87rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* Heat map */
.heat { border-collapse: collapse; }
.heat td.cell { width: 46px; text-align: center; font-family: var(--mono); font-size: .74rem; padding: 5px 2px; border: 1px solid #fff; }
.heat .h0 { background: #eef1f4; color: #9aa7b3; }
.heat .h1 { background: #dcebe7; }
.heat .h2 { background: #b7d9d0; }
.heat .h3 { background: #7dbcae; color: #fff; }
.heat .h4 { background: #3d8f80; color: #fff; }
.heat .hover { background: #b17400; color: #fff; }
.heat .hred { background: var(--red); color: #fff; }

/* Charts */
.chart svg { display: block; width: 100%; }
.chart .axis { stroke: var(--line); }
.chart text { font-family: var(--mono); font-size: .67rem; fill: var(--muted); }
.legend { display: flex; gap: 14px; font-size: .74rem; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* Dashboard widgets */
.widgets { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.widget { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; }
.widget.wide { grid-column: 1 / -1; }
.widget h3 { font-size: .74rem; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; display: flex; }
.widget h3 .grow { flex: 1; }
.widget h3 button { border: 0; background: none; color: var(--muted); font-size: .8rem; padding: 0 3px; }
@media (max-width: 980px) { .widgets { grid-template-columns: 1fr } }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--ink); }
.login { width: 340px; background: var(--surface); border-radius: 8px; padding: 30px; }
.login .brand { font-family: var(--mono); letter-spacing: .18em; font-size: 1.2rem; }
.login .brand small { display: block; font-size: .6rem; letter-spacing: .3em; color: var(--muted); margin: 3px 0 20px; }

.muted { color: var(--muted); font-size: .8rem; }
.error { color: var(--red); font-size: .87rem; margin-top: 8px; }
.toast { position: fixed; bottom: 18px; right: 18px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 6px; font-size: .87rem; z-index: 50; }
.searchbox { position: relative; }
.searchbox .results { position: absolute; top: 38px; right: 0; width: 320px; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(20,29,39,.12); z-index: 40; max-height: 320px; overflow: auto; }
.searchbox .results a { display: block; padding: 8px 12px; border-bottom: 1px solid #eef1f4; font-size: .87rem; }
.searchbox .results a:hover { background: var(--accent-soft); }
.bignum { font-family: var(--mono); font-size: 1.47rem; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: no-preference) { .card, .widget { transition: box-shadow .15s } .card:hover, .widget:hover { box-shadow: 0 2px 10px rgba(20,29,39,.06) } }


/* ===== Dark theme (toggle persisted; respects prefers-color-scheme on first visit) ===== */
[data-theme="dark"] {
  --paper: #10161d;
  --surface: #182029;
  --ink: #dbe3ea;
  --muted: #8b99a7;
  --line: #2a3542;
  --accent: #4db6ac;
  --accent-soft: #1c2e2d;
  --red: #e07a6a;
  --amber: #d9a441;
  --green: #6fbf8f;
}
[data-theme="dark"] nav.rail { background: #0b1016; }
[data-theme="dark"] .chip { background: #1f2933; }
[data-theme="dark"] tr:hover td { background: #1c2630; }
[data-theme="dark"] .heat .h0 { background: #1c2630; color: #55636f; }
[data-theme="dark"] .searchbox .results { background: var(--surface); }
[data-theme="dark"] .login-wrap { background: #0b1016; }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea { background: #10161d; color: var(--ink); border-color: var(--line); }
[data-theme="dark"] .gantt-container { background: var(--surface); }

/* ===== Editable month-granularity timeline (Required roles / Assigned staff Gantt) ===== */
.tl-wrap { background: var(--surface); }
.tl-header > div { user-select: none; }
.tl-bar { box-sizing: border-box; box-shadow: 0 1px 2px rgba(20,29,39,.25); }
.tl-bar:not(.locked):hover { filter: brightness(1.08); }
.tl-bar:active:not(.locked) { cursor: grabbing !important; }
.tl-bar .tl-handle:hover { background: rgba(255,255,255,.4); }
.tl-palette { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; padding: 10px; border: 1px dashed var(--line); border-radius: 6px; }
.tl-palette .chip[draggable="true"] { cursor: grab; }
.tl-palette .chip[draggable="true"]:active { cursor: grabbing; }
.tl-pct-pop { position: fixed; z-index: 45; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(20,29,39,.18); padding: 10px 12px; width: 220px; }
[data-theme="dark"] .tl-pct-pop { background: var(--surface); }
.tl-pct-pop input[type="range"] { width: 100%; }

/* ===== Work-package grouping (Schedule tab, Resources tab) ===== */
.wp-section { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; }
.wp-section summary { cursor: pointer; list-style: revert; }
.wp-section summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wp-meter { display: inline-block; width: 140px; height: 8px; border-radius: 4px; background: var(--paper); vertical-align: middle; margin: 0 8px; overflow: hidden; }
.wp-meter > span { display: block; height: 100%; border-radius: 4px 0 0 4px; }
.wp-meter.m-low > span { background: var(--red); }
.wp-meter.m-mid > span { background: var(--amber); }
.wp-meter.m-full > span { background: var(--green); }
.wp-meter.m-over > span { background: var(--accent); }

/* ===== Header controls (theme, font scale) ===== */
.hctl { display: flex; gap: 4px; align-items: center; }
.hctl button { background: var(--surface); border: 1px solid var(--line); color: var(--ink); border-radius: 4px; padding: 4px 9px; font-size: .8rem; }
.hctl button:hover { border-color: var(--accent); }

/* ===== Entity drawer (click-through details) ===== */
.drawer-back { position: fixed; inset: 0; background: rgba(10,15,20,.45); z-index: 60; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 92vw); background: var(--surface); border-left: 1px solid var(--line); z-index: 61; padding: 20px 22px; overflow-y: auto; box-shadow: -8px 0 30px rgba(0,0,0,.18); }
.drawer h2 { font-size: 1.05rem; margin-bottom: 2px; }
.drawer .sub { color: var(--muted); font-family: var(--mono); font-size: .78rem; margin-bottom: 14px; }
.drawer h3 { font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 16px 0 6px; }
.drawer .x { position: absolute; top: 12px; right: 14px; background: none; border: 0; font-size: 1.1rem; color: var(--muted); }
a.ent { color: var(--accent); cursor: pointer; text-decoration: none; border-bottom: 1px dotted var(--accent); }
a.ent:hover { border-bottom-style: solid; }

/* ===== Chart.js canvases ===== */
.chartbox { position: relative; height: 240px; }
.chartbox.tall { height: 300px; }

/* Cash strip under the Gantt */
.cashstrip svg { display: block; width: 100%; }

/* Scrollable heat maps at fine granularity */
.heatwrap { max-height: 520px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.heatwrap table { border-collapse: separate; border-spacing: 0; }
.heatwrap thead th, .heatwrap tr:first-child th { position: sticky; top: 0; background: var(--surface); z-index: 3; }
.heatwrap td:first-child, .heatwrap th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 2; }
.heatwrap tr:first-child th:first-child { z-index: 4; }

.rowhl td { background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* Gantt SVGs keep their intrinsic size; the wrapper scrolls, the card contains */

/* Change log view (Issue 1.2.3): CHANGELOG.md rendered by the mdLite() formatter — the global
   `* { margin: 0 }` reset leaves headings/paragraphs/lists flush against each other, so this
   restores normal document spacing scoped to just this one card. */
.changelog h1 { font-size: 1.1rem; margin: 0 0 12px; }
.changelog h2 { font-size: .95rem; color: var(--accent); margin: 28px 0 8px; padding-top: 16px; border-top: 1px solid var(--line); }
.changelog h2:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.changelog h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 6px; }
.changelog p { margin: 0 0 10px; line-height: 1.5; }
.changelog ul, .changelog ol { margin: 0 0 10px; padding-left: 22px; }
.changelog li { margin-bottom: 6px; line-height: 1.5; }
.changelog code { font-family: var(--mono); font-size: .85em; background: color-mix(in srgb, var(--accent) 10%, transparent); padding: 1px 4px; border-radius: 3px; }


/* Planning tab: Excel-style planned purchases grid (Issue 1.4.0) */
table.xgrid { border: 1px solid var(--line); }
table.xgrid th, table.xgrid td { border: 1px solid var(--line); }
table.xgrid td { padding: 0; vertical-align: middle; }
table.xgrid td.ro, table.xgrid td.num.ro { padding: 5px 8px; }
table.xgrid td.ctl { padding: 3px 6px; text-align: center; white-space: nowrap; }
table.xgrid input, table.xgrid select { width: 100%; border: 0; border-radius: 0; background: transparent; padding: 6px 8px; font: inherit; color: inherit; outline: none; }
table.xgrid input[type="number"] { text-align: right; font-family: var(--mono); }
table.xgrid input:focus, table.xgrid select:focus { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
table.xgrid tr.converted td { background: #f6f8fa; color: var(--muted); }
table.xgrid tr.total td { font-weight: 600; padding: 6px 8px; background: #f6f8fa; }
table.xgrid input[type="checkbox"] { width: auto; }
/* Finance: expenditure by category */
table.ebc tr.ebc_top td { background: #f6f8fa; }
table.ebc tr.total td { border-top: 2px solid var(--line); }
table.ebc .ebc_tg { padding: 0 6px; min-width: 24px; }
table.ebc .ebc_sp { display: inline-block; width: 28px; }

/* Budget figures and work-package sections (Issue 1.4.2) */
.use-meter { display: inline-block; width: 70px; height: 7px; border-radius: 4px; background: var(--paper); vertical-align: middle; margin-right: 6px; overflow: hidden; }
.use-meter > span { display: block; height: 100%; }
.use-meter.u-ok > span { background: var(--green); }
.use-meter.u-warn > span { background: var(--amber); }
.use-meter.u-over > span { background: var(--red); }
.wp-section .wp-sum { display: inline-flex; flex-wrap: wrap; gap: 4px 16px; justify-content: space-between; width: calc(100% - 20px); vertical-align: middle; }
.wp-section .wp-sum-fig { font-size: .8rem; }
.wp-section .wp-body { margin-top: 10px; }
.wp-section h3, #cmpout h3, .card h3.sub { font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 12px 0 6px; font-weight: 600; }
.strip.compact { margin-bottom: 8px; }
.strip.compact .cell { padding: 6px 12px; min-width: 104px; }
.strip.compact .v { font-size: .95rem; }
table.xgrid input.chg { background: color-mix(in srgb, var(--amber) 16%, transparent); }
table.xgrid input:disabled { color: var(--ink); }
table.xgrid tr.rv_grp td { background: #f6f8fa; }
[data-theme="dark"] table.xgrid tr.rv_grp td { background: #1c2630; }
