:root {
  --bg: #f6f5f1;
  --paper: #ffffff;
  --ink: #1d2327;
  --muted: #5f6a70;
  --line: #dcd9d0;
  --line-strong: #b9b5a8;
  /* Tofamba brand: navy and teal from the footprints logo */
  --navy: #132e54;
  --teal: #3a9e9a;
  --accent: #1d5f6f;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0ef;
  --ok: #2f6b3a;
  --ok-soft: #e4f0e4;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --bad: #a3312b;
  --bad-soft: #f8e3e1;
  --radius: 6px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 1.75rem 0 .6rem; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .87rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.mono { font-family: var(--mono); }

/* Layout */
.topbar { background: var(--navy); color: #fff; border-bottom: 3px solid var(--teal); }
.topbar .inner { max-width: 1200px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; gap: 24px; height: 52px; }
.brand { font-weight: 700; letter-spacing: .02em; color: #fff; text-decoration: none; display: flex; align-items: center; gap: 10px; }
.seal { width: 32px; height: 32px; border-radius: 50%; background: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.seal img { width: 20px; height: 26px; object-fit: contain; }
.brand span { color: #8fd3cd; font-weight: 500; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: #d6dde0; text-decoration: none; padding: 6px 10px; border-radius: var(--radius); }
.nav a:hover, .nav a.on { background: rgba(255,255,255,.1); color: #fff; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: #d9534f; color: #fff; font-size: .78rem; text-align: center; margin-left: 4px; }
.who { font-size: .87rem; color: #d6dde0; display: flex; gap: 10px; align-items: center; }
.who form { margin: 0; }
.who button { background: none; border: 1px solid rgba(255,255,255,.3); color: #fff; padding: 3px 10px; border-radius: var(--radius); cursor: pointer; }
main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 64px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* Surfaces */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.35rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .85rem; color: var(--muted); }
.stat.bad { border-color: #e6b9b5; background: var(--bad-soft); }
.stat.warn { border-color: #ecd59f; background: var(--warn-soft); }
.stat.good { border-color: #b8d6bb; background: var(--ok-soft); }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--paper); }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #faf9f6; }
tr:last-child td { border-bottom: none; }
table.fixed { table-layout: fixed; }
table.fixed td { overflow-wrap: anywhere; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
tr.clickable:hover td { background: #fbfaf7; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* Status chips */
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .8rem; font-weight: 600; white-space: nowrap; background: #eceae4; color: var(--muted); }
.chip.on_hold, .chip.open, .chip.rejected, .chip.fail { background: var(--bad-soft); color: var(--bad); }
.chip.ready_to_close, .chip.draft, .chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.in_progress, .chip.released { background: var(--accent-soft); color: var(--accent); }
.chip.closed, .chip.approved, .chip.pass, .chip.entered { background: var(--ok-soft); color: var(--ok); }
.chip.superseded, .chip.cancelled, .chip.retired { text-decoration: line-through; }

/* Flash and errors */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; }
.flash.ok { background: var(--ok-soft); border-color: #b8d6bb; color: var(--ok); }
.flash.warn { background: var(--warn-soft); border-color: #ecd59f; color: var(--warn); }
.flash.error { background: var(--bad-soft); border-color: #e6b9b5; color: var(--bad); }
.errors { background: var(--bad-soft); border: 1px solid #e6b9b5; color: var(--bad); padding: 10px 14px 10px 30px; border-radius: var(--radius); margin: 0 0 16px; }

/* Forms */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 3px; }
input[type=text], input[type=tel], input[type=email], input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: #fff; font: inherit; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input.num-input { text-align: right; font-variant-numeric: tabular-nums; }
textarea { min-height: 70px; }
.field { margin-bottom: 12px; }
.fields { display: grid; gap: 12px 14px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.fields .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 6px; color: var(--ink); font-size: .95rem; margin: 0; }
.check input { width: auto; }
.hint { font-size: .82rem; color: var(--muted); margin-top: 3px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 4px; margin: 0 0 16px; background: var(--paper); }
legend { font-weight: 650; padding: 0 6px; }
.btn, button.btn { display: inline-block; padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.secondary { background: #fff; color: var(--accent); }
.btn.danger { background: #fff; color: var(--bad); border-color: #d9a29d; }
.btn.small { padding: 4px 10px; font-size: .87rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; margin: 0; }
.qc-row { display: grid; grid-template-columns: 1fr auto auto 130px; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.qc-row:last-child { border-bottom: none; }
.req { color: var(--bad); }

/* Stage strip */
.stages { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stage { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stage.entered { border-left: 4px solid var(--ok); }
.stage.held { border-left: 4px solid var(--bad); }
.stage.next { border-left: 4px solid var(--accent); }
.stage h3 { margin: 0 0 6px; color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 1rem; display: flex; justify-content: space-between; }

/* Login */
.login { max-width: 380px; margin: 10vh auto; }
.login .card { padding: 26px; }
.login h1 { margin-bottom: 4px; }
.login .logo { display: block; width: 72px; height: 96px; object-fit: contain; margin: 0 0 14px; }
.login .product { color: var(--teal); font-weight: 600; }

/* Variances */
.variance > div:first-child { align-items: flex-start; }
.variance { border: 1px solid #e6b9b5; background: #fffaf9; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.variance .decide { display: grid; grid-template-columns: 200px 1fr auto auto; gap: 8px; margin-top: 10px; align-items: start; }
.trail td { font-size: .85rem; }

@media (max-width: 760px) {
  /* Phone: brand and sign-out on the first line, every menu item visible below (wrapping, no hidden scroll). */
  .topbar .inner { flex-wrap: wrap; height: auto; padding: 10px 16px 12px; gap: 8px 10px; }
  .brand { flex: 1 1 0; min-width: 0; }
  .brand span { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .who { order: 2; }
  .who > span { display: none; }
  .nav { order: 3; flex: 1 1 100%; flex-wrap: wrap; gap: 6px; }
  .nav a { background: rgba(255,255,255,.08); padding: 6px 12px; }
  main { padding: 16px; }
  .variance .decide, .qc-row { grid-template-columns: 1fr; }
  .page-head { align-items: flex-start; }
}

/* Phone: tables become one card per row, each value labelled with its column heading.
   The labels are copied from the header row by a small script in base.html. */
@media (max-width: 640px) {
  .table-wrap { border: none; overflow: visible; background: none; }
  table.stackable, table.stackable tbody, table.stackable tr, table.stackable td { display: block; width: 100%; }
  table.stackable { background: none; table-layout: auto; }
  table.stackable colgroup, table.stackable tr.head { display: none; }
  table.stackable tr { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 0; }
  table.stackable td { border: none; padding: 4px 12px 4px 40%; position: relative; text-align: left; white-space: normal; min-height: 1.6em; }
  table.stackable td::before { content: attr(data-label); position: absolute; left: 12px; width: calc(40% - 24px); color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; padding-top: 2px; }
  table.stackable td[data-label=""] { padding-left: 12px; }
  table.stackable td[data-label=""]::before { display: none; }
  table.stackable td.num { text-align: left; }
  table.stackable tr.total { background: var(--accent-soft); }
}

/* Reports */
.report-tile { display: block; text-decoration: none; color: var(--ink); }
.report-tile:hover { border-color: var(--accent); }
.report-tile h2 { margin-top: 0; color: var(--accent); }
.report-filter { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; padding: 12px 14px; }
.report-filter .field { margin: 0; min-width: 160px; }
.report-stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
table.report tr.total td { border-top: 2px solid var(--line-strong); background: #faf9f6; }
.print-only { display: none; }

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; font-size: 11px; }
  .topbar, .noprint, .flash { display: none !important; }
  .print-only { display: block; }
  main { max-width: none; padding: 0; }
  .card, .stat, .table-wrap { border-color: #999; }
  .stat { padding: 6px 8px; }
  .stat .value { font-size: 1.1rem; }
  th, td { padding: 4px 6px; }
  a { color: inherit; text-decoration: none; }
  .chip { background: none !important; padding: 0; }
}
.digest { white-space: pre-wrap; font-family: var(--mono); font-size: .85rem; margin: 0; background: #faf9f6; padding: 12px; border-radius: var(--radius); }
table.report td.mono { white-space: nowrap; overflow-wrap: normal; }

/* Charts (inline SVG). One series, recessive grid, reference lines dashed, values in text ink. */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axisline { stroke: var(--line-strong); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .val { fill: var(--ink); font-size: 11px; font-weight: 600; }
.chart .bar { fill: var(--accent); }
.chart .hit { fill: transparent; }
.chart .bar-g:hover .bar, .chart .bar-g:focus .bar { fill: var(--navy); }
.chart .bar-g:focus { outline: none; }
.chart .ref { stroke-width: 2; stroke-dasharray: 6 4; }
.chart .ref.limit { stroke: var(--bad); }
.chart .ref.base { stroke: var(--warn); }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; margin: 6px 0 4px; color: var(--muted); }
.chart-legend .sw { display: inline-block; width: 18px; height: 0; vertical-align: middle; margin-right: 4px; }
.chart-legend .sw.bar { height: 10px; width: 10px; background: var(--accent); border-radius: 2px; }
.chart-legend .sw.limit { border-top: 2px dashed var(--bad); }
.chart-legend .sw.base { border-top: 2px dashed var(--warn); }
tr.baseline-row td { background: var(--warn-soft); }

.chart-scroll { overflow-x: auto; }
@media (max-width: 640px) {
  .chart { min-width: 560px; }
  table.stackable tr.empty { display: none; }
}
table.costing tr.total td { border-top: 1px solid var(--line-strong); }
dl.kv { align-content: start; }
table.analysis th, table.analysis td { padding: 6px 7px; font-size: .85rem; }
table.analysis td.mono { white-space: nowrap; }
