/* Commitments Tracker
   Light and dark themes. The light theme is the default; dark follows the
   system unless the person picks one (data-theme on <html>, set by the theme
   switch and by an inline script in index.html before first paint). */

:root {
  color-scheme: light;
  --bg: #f7f4fb;
  --surface: #ffffff;
  --surface-2: #fbf9fd;
  --sidebar: #f1ecf8;
  --text: #2a2638;
  --muted: #6d6880;
  --faint: #a9a4b8;
  --line: #e9e3f1;
  --line-strong: #d9d1e6;
  --accent: #5468c4;
  /* Chart series (validated for colour-vision deficiency on --surface;
     committed is also dashed, so identity never rests on hue alone). */
  --series-committed: #d9622b;
  --series-invoiced: #0b8fc4;
  --series-paid: #1f9a4f;
  --accent-hover: #4457b0;
  --accent-text: #ffffff;
  --accent-soft: #e7ebfb;
  --danger: #d0021b;
  --danger-soft: #ffe1e5;
  --warn: #94570a;
  --warn-soft: #fff1dc;
  --ok: #2c7a4b;
  --ok-soft: #e2f5e8;
  --info: #3c6bb0;
  --info-soft: #e4eefb;
  --neutral-soft: #efebf4;
  --shadow: 0 1px 1px rgba(0, 0, 0, 0.03), 0 2px 5px rgba(60, 66, 87, 0.08);
  --shadow-pop: 0 7px 14px rgba(60, 66, 87, 0.12), 0 3px 6px rgba(0, 0, 0, 0.08);
  --focus: 0 0 0 3px rgba(84, 104, 196, 0.3);
  --bar-invoiced: #9fb2f2;
  --bar-paid: #8fd6a8;
  --radius: 8px;
  --radius-sm: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16141e;
    --surface: #1f1c2a;
    --surface-2: #252134;
    --sidebar: #1b1825;
    --text: #ece8f4;
    --muted: #a39db5;
    --faint: #6b6581;
    --line: #2f2b3e;
    --line-strong: #3c3751;
    --accent: #aab8ff;
    --series-committed: #d95926;
    --series-invoiced: #1b9ccf;
    --series-paid: #22a865;
    --accent-hover: #c3cdff;
    --accent-text: #16141e;
    --accent-soft: rgba(170, 184, 255, 0.16);
    --danger: #ff4f62;
    --danger-soft: rgba(255, 79, 98, 0.18);
    --warn: #f4c986;
    --warn-soft: rgba(244, 201, 134, 0.14);
    --ok: #a3e2b8;
    --ok-soft: rgba(163, 226, 184, 0.14);
    --info: #a2c6ff;
    --info-soft: rgba(162, 198, 255, 0.14);
    --neutral-soft: rgba(163, 157, 181, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-pop: 0 10px 24px rgba(0, 0, 0, 0.5);
    --focus: 0 0 0 3px rgba(170, 184, 255, 0.4);
    --bar-invoiced: #8a9ee6;
    --bar-paid: #86cfa0;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16141e;
  --surface: #1f1c2a;
  --surface-2: #252134;
  --sidebar: #1b1825;
  --text: #ece8f4;
  --muted: #a39db5;
  --faint: #6b6581;
  --line: #2f2b3e;
  --line-strong: #3c3751;
  --accent: #aab8ff;
  --series-committed: #d95926;
  --series-invoiced: #1b9ccf;
  --series-paid: #22a865;
  --accent-hover: #c3cdff;
  --accent-text: #16141e;
  --accent-soft: rgba(170, 184, 255, 0.16);
  --danger: #ff4f62;
  --danger-soft: rgba(255, 79, 98, 0.18);
  --warn: #f4c986;
  --warn-soft: rgba(244, 201, 134, 0.14);
  --ok: #a3e2b8;
  --ok-soft: rgba(163, 226, 184, 0.14);
  --info: #a2c6ff;
  --info-soft: rgba(162, 198, 255, 0.14);
  --neutral-soft: rgba(163, 157, 181, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-pop: 0 10px 24px rgba(0, 0, 0, 0.5);
  --focus: 0 0 0 3px rgba(170, 184, 255, 0.4);
  --bar-invoiced: #8a9ee6;
  --bar-paid: #86cfa0;
}

* { box-sizing: border-box; }

html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 14px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; margin: 0.15rem 0 0.35rem; }
h2 { font-size: 1.05rem; font-weight: 650; margin: 1.8rem 0 0.6rem; }
h3 { font-size: 0.95rem; font-weight: 650; margin: 0 0 0.8rem; }
small { font-size: 0.8rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }

.muted { color: var(--muted); }
.warn { color: var(--warn); }
.neg { color: var(--danger); font-weight: 650; }

/* ------------------------------------------------------------------ Shell */

.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--sidebar); border-right: 1px solid var(--line); padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; color: var(--text); font-weight: 700; }
.brand:hover { color: var(--text); }
.brand-mark { width: 30px; height: 30px; flex: none; display: block; }
.brand-mark .mark-a { fill: var(--bar-invoiced); }
.brand-mark .mark-b { fill: var(--bar-paid); }
.brand-mark .mark-c { fill: var(--accent); }
.brand-name { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name small { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm);
            color: var(--muted); font-weight: 550; }
.nav-item svg { flex: none; }
.nav-item:hover { background: var(--neutral-soft); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.who { padding: 0 10px; font-size: 0.85rem; }
.who strong { display: block; color: var(--text); font-weight: 600; }

.main-col { min-width: 0; }
main { max-width: 1240px; margin: 0 auto; padding: 24px 32px 48px; }

/* Theme switch: a segmented control */
.theme-switch { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--neutral-soft);
                border-radius: var(--radius-sm); padding: 2px; margin: 0 4px; }
.theme-switch button { all: unset; cursor: pointer; text-align: center; padding: 4px 0; font-size: 0.8rem;
                       color: var(--muted); border-radius: 5px; }
.theme-switch button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.theme-switch button:focus-visible { box-shadow: var(--focus); }

/* ----------------------------------------------------------- Page header */

.crumbs { margin: 0; font-size: 0.85rem; color: var(--muted); }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 1.8rem 0 0.6rem; }
.section-head h2 { margin: 0; }
.report-form { position: absolute; right: 0; top: 100%; z-index: 5; width: 420px; max-width: calc(100vw - 32px); margin-top: 6px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-pop); }
a.button { display: inline-block; text-decoration: none; }
.logo-preview { max-height: 64px; max-width: 240px; background: #fff; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 8px 10px; }
.org-switcher { display: flex; flex-direction: column; gap: 4px; padding: 0 10px 12px; font-size: 0.8rem; color: var(--muted); }
.org-switcher select { width: 100%; }
.quote-editor .quote-section { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 10px; }
table.quote-lines input { width: 100%; min-width: 0; }
table.quote-lines td { padding: 4px 4px; vertical-align: middle; }
table.quote-lines td.qty { width: 4.5rem; }
table.quote-lines td.unit, table.quote-lines td.code { width: 5.5rem; }
table.quote-lines td.price { width: 7rem; }
table.quote-lines td:first-child { min-width: 12rem; }
table.quote-lines td.qty input, table.quote-lines td.price input { text-align: right; }
.quote-add { gap: 8px; align-items: center; margin: 6px 0 4px; }
table.quote-totals { width: auto; min-width: 22rem; margin: 12px 0 12px auto; }
table.quote-totals th { text-align: left; font-weight: 500; }
table.quote-totals tr.total th, table.quote-totals tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
p.pre { white-space: pre-wrap; }
@media (max-width: 640px) {
  table.quote-lines thead { display: none; }
  table.quote-lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 6px 0; border-bottom: 1px solid var(--line); }
  table.quote-lines td:first-child { grid-column: 1 / -1; }
  table.quote-lines td.qty, table.quote-lines td.unit, table.quote-lines td.price, table.quote-lines td.code { width: auto; }
  table.quote-totals { min-width: 0; width: 100%; }
}
.activity { margin-top: 28px; }
.activity .filters { gap: 8px; }
ol.events { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
ol.events li.event { display: grid; grid-template-columns: 9.5rem minmax(0, 1fr) auto; gap: 4px 14px; align-items: baseline;
  padding: 9px 2px; border-bottom: 1px solid var(--line); }
.event-what small { display: block; }
@media (max-width: 640px) { ol.events li.event { grid-template-columns: 1fr; } }
.jump-bar { position: sticky; top: 0; z-index: 4; display: flex; gap: 4px 14px; flex-wrap: wrap; align-items: center;
  margin: 4px 0 12px; padding: 8px 0; background: var(--bg); border-bottom: 1px solid var(--line); }
.jump-bar button.link { font-weight: 600; padding: 2px 0; }
.anchor { scroll-margin-top: 56px; }
.show-all { margin: 6px 0 4px; }
details.closed-quotes { margin: 12px 0; }
details.closed-quotes > summary { cursor: pointer; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.ages { display: flex; flex-wrap: wrap; gap: 2px 12px; }
.checks { display: flex; flex-direction: column; gap: 4px; }
.aging h3 { margin: 0.4rem 0 0.4rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.actions, .row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ----------------------------------------------------------------- Cards */

.card-panel, .tile, form.card, table, .summary-strip, .modal {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ---------------------------------------------------------------- Tables */

table { width: 100%; border-collapse: separate; border-spacing: 0; overflow: hidden; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { background: var(--surface-2); font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
           letter-spacing: 0.04em; color: var(--muted); white-space: nowrap; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tfoot th, tfoot td { font-weight: 650; border-top: 1px solid var(--line-strong); border-bottom: 0; background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.voided td { color: var(--faint); text-decoration: line-through; text-decoration-color: var(--line-strong); }
tr.chosen td { background: var(--ok-soft); }
ul.plain { list-style: none; margin: 0; padding: 0; }
/* Narrower than a wide desktop: tables keep each cell on one line and
   scroll sideways inside themselves rather than squash dates and numbers. */
@media (max-width: 1100px) {
  table { display: block; overflow-x: auto; }
  th, td { white-space: nowrap; }
}

/* ---------------------------------------------------------------- Badges */

.badge { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: 0.75rem;
         font-weight: 600; line-height: 1.5; background: var(--neutral-soft); color: var(--muted); white-space: nowrap; vertical-align: middle; }
.badge-accepted, .badge-approved, .badge-recorded, .badge-valid, .badge-active { background: var(--ok-soft); color: var(--ok); }
.badge-submitted, .badge-quoted, .badge-expiring { background: var(--warn-soft); color: var(--warn); }
.badge-draft, .badge-closed { background: var(--info-soft); color: var(--info); }
.badge-signed, .badge-agreed { background: var(--ok-soft); color: var(--ok); }
.badge-proposed { background: var(--warn-soft); color: var(--warn); }
.badge-lost { background: var(--neutral-soft); color: var(--muted); }
.badge-void, .badge-rejected, .badge-expired, .badge-declined, .badge-missing, .badge-inactive { background: var(--danger-soft); color: var(--danger); }
.badge-admin { background: var(--accent-soft); color: var(--accent); }
.badge-demo { background: transparent; color: var(--accent); border: 1px dashed var(--accent); }
.currency-tag { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 0.75rem; letter-spacing: 0.02em; vertical-align: 1px; }
.cad-line { margin-top: -4px; }
.chip { display: inline-block; margin: 0 6px 6px 0; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 550; }

.demo-banner { border: 1px dashed var(--accent); background: var(--accent-soft); color: var(--accent);
               padding: 7px 12px; border-radius: var(--radius-sm); margin: 8px 0; font-size: 0.9rem; }

/* -------------------------------------------- Summary strip (Procore-style) */

/* Hairlines between every cell, however the grid wraps: the strip's own
   colour shows through a 1px gap between the items. */
.summary-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin: 16px 0 6px;
                 gap: 1px; background: var(--line); overflow: hidden; }
.summary-item { padding: 14px 16px; min-width: 0; background: var(--surface); }
.summary-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.summary-value { font-size: 1.25rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; }
.summary-value.neg { color: var(--danger); font-weight: 750; }
.summary-note { font-size: 0.78rem; color: var(--muted); }
.summary-item.lead .summary-value { color: var(--accent); }

/* Progress: invoiced and paid as shares of committed */
.progress { margin: 12px 0 4px; }
.progress-track { position: relative; height: 10px; border-radius: 999px; background: var(--neutral-soft); overflow: hidden; }
.progress-invoiced, .progress-paid { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 999px; }
/* Pastel blue = invoiced, pastel green = paid (paid sits on top of invoiced). */
.progress-invoiced { background: var(--bar-invoiced); }
.progress-paid { background: var(--bar-paid); }
.progress-track.over { outline: 2px solid var(--danger); outline-offset: 1px; }
.progress-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--bar-paid); margin-right: 6px; vertical-align: -1px; }
.swatch.invoiced { background: var(--bar-invoiced); }
.mini-progress { width: 90px; height: 6px; border-radius: 999px; background: var(--neutral-soft); overflow: hidden; display: inline-block; vertical-align: middle; }
.mini-progress span { display: block; height: 100%; background: var(--bar-invoiced); border-radius: 999px; }

/* ------------------------------------------------------------------ Tabs */

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 24px 0 16px;
        overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tab { all: unset; cursor: pointer; padding: 9px 14px; color: var(--muted); font-weight: 550; white-space: nowrap;
       border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab:focus-visible { box-shadow: var(--focus); border-radius: var(--radius-sm); }
.tab .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 999px;
              background: var(--neutral-soft); color: var(--muted); font-size: 0.75rem; text-align: center; }

/* ------------------------------------------------------- Details and figures */

dl.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 12px 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; }

.figures { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 16px 0; }
.figure { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
          display: flex; flex-direction: column; box-shadow: var(--shadow); }
.figure-label { font-size: 0.78rem; color: var(--muted); }
.figure-value { font-size: 1.15rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.figure.neg .figure-value { color: var(--danger); }

/* ---------------------------------------------------------------- Buttons */

button, .button {
  font: inherit; font-weight: 600; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  padding: 6px 14px; border-radius: var(--radius-sm); cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; line-height: 1.4; min-height: 34px; box-shadow: var(--shadow);
  text-decoration: none; transition: background 0.12s, border-color 0.12s;
}
button:hover, .button:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-text); }
button:focus-visible, .button:focus-visible, a:focus-visible { outline: none; box-shadow: var(--focus); }
button:disabled { opacity: 0.55; cursor: default; }
button.secondary, .button.secondary { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
button.secondary:hover, .button.secondary:hover { background: var(--surface-2); color: var(--text); border-color: var(--line-strong); }
button.danger { background: var(--surface); color: var(--danger); border-color: var(--line-strong); }
button.danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
button.link { background: none; border: 0; box-shadow: none; color: var(--accent); padding: 0 4px; min-height: 0; font-weight: 550; }
button.link:hover { background: none; color: var(--accent-hover); }
button.small, .button.small { padding: 3px 10px; font-size: 0.82rem; min-height: 0; }
a.small { padding-left: 8px; font-size: 0.85rem; }

/* ------------------------------------------------------------------ Forms */

form.card { padding: 18px; margin: 12px 0; max-width: 720px; width: 100%; box-shadow: var(--shadow-pop); }
form.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
form.inline input { min-width: 200px; width: auto; min-height: 34px; }
form.inline button { width: auto; }
.inline-card { min-width: 280px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; flex: 1; min-width: 160px; }
.field > span { font-size: 0.82rem; font-weight: 600; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 0.9rem; color: var(--muted); }
input, select {
  font: inherit; padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); width: 100%; min-height: 34px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
input[type=checkbox] { width: auto; min-height: 0; accent-color: var(--accent); }

/* --------------------------------------------------------------- Messages */

.error-box { background: var(--danger-soft); color: var(--danger); font-weight: 550; border-left: 3px solid var(--danger); padding: 10px 14px; border-radius: var(--radius-sm); margin: 10px 0; }
.error-box ul { margin: 4px 0 0; padding-left: 18px; }
.error { color: var(--danger); }
ul.warnings { background: var(--warn-soft); color: var(--warn); padding: 10px 14px 10px 32px; border-radius: var(--radius-sm); margin: 10px 0; }
.flash { margin-bottom: 14px; }

/* --------------------------------------------------------------- Sign in */

.sign-in { max-width: 400px; margin: 12vh auto; padding: 32px; background: var(--surface); border: 1px solid var(--line);
           border-radius: 12px; box-shadow: var(--shadow-pop); }
.sign-in h1 { display: flex; align-items: center; gap: 10px; font-size: 1.3rem; margin-bottom: 18px; }
.sign-in button[type=submit] { width: 100%; }

/* ----------------------------------------------------------------- Modal */

.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 24, 0.55); display: flex;
                  align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal { padding: 24px; max-width: 420px; width: 100%; max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: var(--shadow-pop); }
.code-form { display: flex; flex-direction: column; gap: 10px; }
.code-form label { color: var(--muted); }
/* Six digits, evenly spaced and truly centred: the trailing letter-spacing
   is balanced by the same padding on the left. */
.code-input { width: 11ch; max-width: 100%; align-self: flex-start;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.6rem;
  font-variant-numeric: tabular-nums; letter-spacing: 0.4em; padding: 8px 0 8px 0.4em; text-align: center; }
.code-input::placeholder { color: var(--faint); }
.code-form .actions { display: flex; align-items: center; gap: 14px; margin-top: 4px; }
.qr { display: block; margin: 8px auto; background: #fff; padding: 6px; border-radius: var(--radius-sm); }
.compliance { display: flex; gap: 20px; flex-wrap: wrap; }

/* ------------------------------------------------------- Dashboard tiles */

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 14px; margin-top: 14px; }
.tile { padding: 16px 18px; min-width: 0; }
.tile h2 { font-size: 0.8rem; margin: 0; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.tile-figure { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 4px 0 4px; letter-spacing: -0.01em; }
.tile p { margin: 4px 0; font-size: 0.88rem; }
ul.tile-list { list-style: none; margin: 8px 0; padding: 0; }
ul.tile-list li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0;
                  border-top: 1px solid var(--line); font-size: 0.88rem; }
ul.tile-list li a { overflow-wrap: anywhere; }

/* ---------------------------------------------------------- Small screens */

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto;
             border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; gap: 4px; }
  .brand { padding: 4px 8px 4px 0; }
  .brand-name { display: none; }
  .nav-item { white-space: nowrap; padding: 6px 8px; }
  .nav-item.active { box-shadow: inset 0 -2px 0 var(--accent); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
  .nav-item svg { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: 0; flex-direction: row; align-items: center; }
  .theme-switch { width: 156px; flex: none; }
  .who { display: none; }
  main { padding: 16px; }
  /* The nav wraps instead of scrolling once the as-of picker needs the room. */
  .sidebar { flex-wrap: wrap; overflow-x: visible; }
  .sidebar-foot { flex-wrap: wrap; gap: 8px 12px; }
  .as-of-picker { display: flex; align-items: center; gap: 8px; }
  .as-of-picker label { margin: 0; }
}

/* ---------------------------------------------------------------------------
   S-curve */

.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
              box-shadow: var(--shadow); padding: 16px 18px 12px; margin: 20px 0; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.chart-head h2 { margin: 0; }
.chart-head p { margin: 2px 0 0; font-size: 0.85rem; }
.chart-legend { list-style: none; display: flex; gap: 16px; margin: 4px 0 0; padding: 0; font-size: 0.85rem; color: var(--muted); }
.chart-legend li { display: flex; align-items: center; gap: 6px; }
.chart-wrap { position: relative; margin-top: 8px; min-height: 40px; }
.chart { display: block; overflow: visible; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .end-label { fill: var(--text); font-size: 12px; font-weight: 550; font-variant-numeric: tabular-nums; }
.chart .crosshair line { stroke: var(--line-strong); stroke-width: 1; }
.chart-tip { position: absolute; top: 4px; pointer-events: none; background: var(--surface); color: var(--text);
             border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: var(--shadow);
             padding: 8px 10px; font-size: 0.82rem; min-width: 190px; z-index: 2; }
.chart-tip strong { display: block; margin-bottom: 4px; }
.chart-tip div { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; }
.chart-tip .num { font-variant-numeric: tabular-nums; }
.chart-foot { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.chart-slider { width: 100%; accent-color: var(--accent); margin: 0 0 8px; }
.chart-readout { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; font-size: 0.88rem;
                 font-variant-numeric: tabular-nums; }
.chart-readout button.secondary { margin-left: auto; }
.chart-card table { box-shadow: none; }

/* ---------------------------------------------------------------------------
   As-of view: read the past, change nothing */

.as-of-picker label { display: block; font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
                      letter-spacing: 0.04em; color: var(--muted); margin-bottom: 4px; }
.as-of-row { display: flex; align-items: center; gap: 8px; }
.as-of-row input { flex: 1; min-width: 0; }
.as-of-mode .as-of-picker input { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn); }
.as-of-banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 16px;
                padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--warn);
                border-left-width: 4px; background: var(--warn-soft); color: var(--text); }
.as-of-banner button { margin-left: auto; }
.as-of-mode main button:not(.tab):not(.keep),
.as-of-mode main form,
.as-of-mode main .actions > *:not(.keep),
.as-of-mode main input:not(.chart-slider):not([type="date"]) { display: none; }

/* ---------------------------------------------------------------------------
   Import */

.import-panel { padding: 16px 18px; margin: 16px 0; }
.import-panel p { margin: 0 0 12px; }
.file-pick { display: flex; flex-direction: column; gap: 6px; font-weight: 550; }
.file-pick input[type="file"] { font: inherit; }
.import-actions { margin: 20px 0; }
.done-box { margin: 16px 0; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--ok);
            border-left-width: 4px; background: var(--ok-soft); color: var(--text); }

.accept-form { position: absolute; right: 0; top: 100%; z-index: 5; width: min(420px, calc(100vw - 32px)); margin-top: 8px; text-align: left; }
.page-head .actions { position: relative; }

/* ---------------------------------------------------------------------------
   Help (the manual) */

.help-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 32px; align-items: start; }
.help-toc { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; font-size: 0.88rem; }
.help-toc-title { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 6px; }
.help-toc ul { list-style: none; margin: 0; padding: 0; }
.help-toc li { margin: 0; }
.help-toc li.level-3 { padding-left: 12px; }
.help-toc button.link { text-align: left; padding: 3px 0; color: var(--muted); font-weight: 500; }
.help-toc button.link:hover { color: var(--accent); }
.manual { max-width: 760px; line-height: 1.6; }
.manual h1 { display: none; }                 /* the page has its own title */
.manual h2 { margin: 32px 0 8px; padding-top: 8px; border-top: 1px solid var(--line); scroll-margin-top: 16px; }
.manual h2:first-of-type { border-top: 0; margin-top: 0; }
.manual h3 { margin: 24px 0 6px; scroll-margin-top: 16px; }
.manual table { margin: 12px 0 16px; font-size: 0.9rem; }
.manual code { background: var(--neutral-soft); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
.manual ul, .manual ol { padding-left: 22px; }
@media (max-width: 860px) {
  .help-layout { grid-template-columns: 1fr; }
  .help-toc { position: static; max-height: none; }
}

/* ---------------------------------------------------------------------------
   Tour */

.tour { position: fixed; inset: 0; z-index: 50; }
.tour-dim { position: fixed; inset: 0; background: rgba(10, 16, 24, 0.55); }
.tour-spot { position: fixed; border-radius: 10px; box-shadow: 0 0 0 9999px rgba(10, 16, 24, 0.55), 0 0 0 2px var(--accent);
             pointer-events: none; transition: all 0.2s ease; }
.tour-card { position: fixed; background: var(--surface); color: var(--text); border: 1px solid var(--line-strong);
             border-radius: var(--radius); box-shadow: var(--shadow-pop); padding: 16px 18px; outline: none; }
.tour-card h2 { margin: 2px 0 6px; font-size: 1.05rem; }
.tour-card p { margin: 0 0 12px; line-height: 1.5; }
.tour-count { font-size: 0.75rem; color: var(--muted); margin: 0 !important; }
.tour-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tour-nav { display: flex; gap: 8px; }
@media (prefers-reduced-motion: reduce) { .tour-spot { transition: none; } }

/* ---------------------------------------------------------------------------
   "?" explanations (native details/summary) and two-line tile rows */

.help-tip { display: inline-block; position: relative; vertical-align: middle; }
.help-tip > summary { list-style: none; cursor: pointer; display: inline-grid; place-items: center;
                      width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--line-strong);
                      color: var(--muted); font-size: 0.75rem; font-weight: 700; background: var(--surface); }
.help-tip > summary::-webkit-details-marker { display: none; }
.help-tip > summary:hover, .help-tip[open] > summary { color: var(--accent); border-color: var(--accent); }
.help-tip > summary:focus-visible { outline: none; box-shadow: var(--focus); }
.help-tip-body { position: absolute; right: 0; top: 26px; z-index: 20; width: min(360px, calc(100vw - 48px));
                 background: var(--surface); color: var(--text); border: 1px solid var(--line-strong);
                 border-radius: var(--radius); box-shadow: var(--shadow-pop); padding: 12px 14px;
                 font-size: 0.86rem; font-weight: 400; line-height: 1.5; text-align: left; white-space: normal; }
.help-tip-body p { margin: 0 0 8px; }
.help-tip-body ul { margin: 0; padding-left: 18px; }
.help-tip-body li { margin: 0 0 6px; }
.tile-list .row-label { display: flex; flex-direction: column; min-width: 0; }
.tile-list .row-note { color: var(--muted); font-size: 0.8rem; }
.tile-list .row-value { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
/* In a warning the explanation opens beneath the message, full width. */
.warnings .help-tip[open] { display: block; margin-top: 8px; }
.warnings .help-tip-body { position: static; width: auto; box-shadow: none; }
