/* Techridge Cashflow prototype — shared tokens plus per-variant layout.
   Variants share small pieces (rows, forms, chart) but each owns its page structure. */

:root {
  --paper: #EEF2F1;
  --surface: #FFFFFF;
  --ink: #17262E;
  --muted: #5A6B74;
  --line: #CBD5D2;
  --line-strong: #93A3A0;
  --blue: #245C87;
  --blue-soft: #DCE7EF;
  --blue-ink: #173F5D;
  --red: #B4231A;
  --red-soft: #F7E0DD;
  --amber: #8A5A00;
  --amber-soft: #F5EBD2;
  --green: #2A6E4A;
  --res: #6F8089;
  --sans: "Avenir Next", Seravek, "Segoe UI", system-ui, -apple-system, sans-serif;
  --serif: Charter, "Iowan Old Style", Georgia, "Times New Roman", serif;
  --radius: 6px;
  --shadow: 0 10px 30px rgba(23, 38, 46, 0.18);
}

* { box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--sans); line-height: 1.45; font-feature-settings: "tnum" 1;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: #fff; padding: 6px 10px; border-radius: 4px; z-index: 50; }
.skip:focus { left: 8px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.neg { color: var(--red); }
.pos { color: var(--green); }
.strong { font-weight: 600; }
.spacer { flex: 1; }
.empty { padding: 28px 8px; color: var(--muted); }

.brand { font-family: var(--serif); font-weight: 400; font-size: 1.35rem; letter-spacing: 0.005em; white-space: nowrap; }

/* ---------- buttons, segmented controls, inputs ---------- */
.btn {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius);
  padding: 6px 12px; line-height: 1.2; color: var(--ink);
}
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-ink); border-color: var(--blue-ink); }
.btn-small { padding: 3px 9px; font-size: 0.86rem; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--blue); padding: 4px 8px; }
.btn-quiet:hover { border-color: transparent; text-decoration: underline; }
.btn-danger-quiet { border-color: transparent; background: transparent; color: var(--red); }
.btn-icon { border: 0; background: transparent; font-size: 1.5rem; line-height: 1; padding: 2px 8px; color: var(--muted); }
.link-btn { border: 0; background: none; padding: 0; color: var(--blue); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.link-btn:hover { color: var(--blue-ink); }
.link-btn.neg { color: var(--red); }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg-btn { border: 0; background: transparent; padding: 6px 14px; color: var(--muted); border-right: 1px solid var(--line); }
.seg-btn:last-child { border-right: 0; }
.seg-btn[aria-pressed="true"] { background: var(--ink); color: #fff; }
.seg-small .seg-btn { padding: 4px 10px; font-size: 0.86rem; }
.seg-wrap { display: inline-flex; align-items: center; gap: 8px; }
.seg-label { color: var(--muted); font-size: 0.86rem; }
.select { border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); padding: 5px 8px; max-width: 100%; }
.input { border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); padding: 6px 8px; width: 100%; }
.check { display: inline-flex; align-items: center; gap: 8px; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--blue); }

/* ---------- status line ---------- */
.status { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; font-size: 0.86rem; }
.status .link-btn { display: inline-flex; align-items: center; gap: 6px; text-decoration-style: dotted; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); display: inline-block; }

/* ---------- what-if ---------- */
.whatif { display: flex; flex-direction: column; gap: 6px; }
.whatif .check { font-weight: 500; }
.whatif-result { font-size: 0.93rem; }
.whatif.on { border-left: 3px solid var(--red); padding-left: 10px; }

/* ---------- tags and rows ---------- */
.tag { display: inline-block; font-size: 0.78rem; padding: 1px 7px; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); background: var(--surface); }
.tag-overdue { border-color: var(--amber); color: var(--amber); background: var(--amber-soft); }
.tag-whatif { border-color: var(--red); color: var(--red); background: var(--red-soft); }
.tag-edit { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }
.tag-new { border-color: var(--green); color: var(--green); }
.tag-res { border-style: dashed; }
.note { font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 0.9rem; }
.src-btn { border: 0; background: none; padding: 0; color: var(--blue); font-size: 0.86rem; text-decoration: underline dotted; text-underline-offset: 3px; }
.src-btn:hover { color: var(--blue-ink); }
.amt { font-weight: 500; white-space: nowrap; }
.amt.res { color: var(--res); }

.rows { list-style: none; margin: 0; padding: 0; }
.row { display: grid; grid-template-columns: 76px 1fr auto auto; gap: 4px 16px; align-items: start; padding: 10px 8px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row.cancels { opacity: 0.6; }
.row.overdue .row-date { color: var(--amber); font-weight: 500; }
.row-date { padding-top: 2px; }
.row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-name { font-weight: 500; }
.row-who { font-size: 0.86rem; }
.row-meta { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 3px; }
.row-act { padding-top: 1px; }

/* ---------- period detail ---------- */
.pd { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.pd-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 18px; }
.pd-title { font-family: var(--serif); font-weight: 400; font-size: 1.25rem; }
.pd-range { color: var(--muted); font-family: var(--sans); font-size: 0.93rem; }
.pd-sum { font-size: 0.93rem; color: var(--muted); }
.pd-sum strong { color: var(--ink); }
.pd-sum strong.neg { color: var(--red); }

/* ---------- edit form ---------- */
.edit-form { display: flex; flex-direction: column; gap: 14px; }
.edit-form.inline { padding: 14px 12px 16px 84px; background: var(--blue-soft); border-left: 3px solid var(--blue); }
.edit-title { font-weight: 600; font-size: 1.05rem; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 0.86rem; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.edit-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.edit-actions .btn { white-space: nowrap; }
.err { color: var(--red); font-size: 0.9rem; min-height: 1.2em; }
.err:empty { display: none; }

/* ---------- overlay: drawer or modal ---------- */
.ov { position: fixed; inset: 0; background: rgba(23, 38, 46, 0.35); z-index: 40; display: flex; }
.ov-drawer { justify-content: flex-end; }
.ov-modal { align-items: center; justify-content: center; padding: 16px; }
.ov-panel { background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column; max-height: 100%; }
.ov-drawer .ov-panel { width: min(460px, 100%); height: 100%; }
.ov-modal .ov-panel { width: min(560px, 100%); max-height: calc(100vh - 32px); border-radius: var(--radius); }
.ov-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.ov-head h2 { font-family: var(--serif); font-weight: 400; font-size: 1.25rem; }
.ov-body { padding: 18px; overflow: auto; }
.ov-body p + p, .ov-body p + table, .ov-body table + p, .ov-body ol + p { margin-top: 12px; }
.dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 0 0 12px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.src-table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
.src-table th, .src-table td { text-align: left; padding: 5px 0; border-bottom: 1px solid var(--line); }
.src-table th { font-weight: 500; color: var(--muted); }
.change-list { padding-left: 20px; margin: 8px 0; }
.change-list li + li { margin-top: 6px; }
.ov-body h3 { font-size: 1rem; margin: 16px 0 4px; }

/* ---------- chart ---------- */
.chart { width: 100%; height: auto; display: block; font-family: var(--sans); }
.chart .col { fill: transparent; cursor: pointer; }
.chart .col:hover { fill: rgba(36, 92, 135, 0.06); }
.chart .col.selected { fill: rgba(36, 92, 135, 0.1); }
.chart .divider { stroke: var(--line-strong); stroke-dasharray: 3 4; }
.chart .grid { stroke: var(--line); }
.chart .zero { stroke: var(--ink); stroke-width: 1.2; }
.chart .axis-label { font-size: 11px; fill: var(--muted); }
.chart .area-pos { fill: rgba(36, 92, 135, 0.14); }
.chart .area-neg { fill: rgba(180, 35, 26, 0.18); }
.chart .line-main { fill: none; stroke: var(--blue-ink); stroke-width: 2.2; stroke-linejoin: round; }
.chart .line-base { fill: none; stroke: var(--blue-ink); stroke-width: 1.4; stroke-dasharray: 5 4; opacity: 0.55; }
.chart .pt { fill: var(--surface); stroke: var(--blue-ink); stroke-width: 2; }
.chart .pt-label { font-size: 11px; fill: var(--ink); }
.chart .flag-pole { stroke: var(--amber); stroke-width: 1.5; }
.chart .flag-pt { fill: var(--amber); }
.chart .flag { fill: var(--amber); }
.chart .flag-pole.neg { stroke: var(--red); }
.chart .flag-pt.neg, .chart .flag.neg { fill: var(--red); }
.chart .flag-text { font-size: 12px; font-weight: 600; fill: #fff; }
.chart .receipt-mark { fill: var(--green); }
.chart .hatch-line { stroke: var(--res); stroke-width: 1.2; }
.chart .res-bar { stroke: var(--res); stroke-width: 0.6; }

/* period tabs under the chart (A) */
.ptabs { display: grid; grid-template-columns: repeat(12, 1fr); padding: 0 calc(16 / 1100 * 100%) 0 calc(64 / 1100 * 100%); }
.ptab { border: 0; border-top: 3px solid transparent; background: transparent; padding: 8px 4px 10px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; min-width: 0; }
.ptab.first-month { border-left: 1px dashed var(--line-strong); }
.ptab:hover { background: rgba(36, 92, 135, 0.06); }
.ptab.selected { border-top-color: var(--blue); background: rgba(36, 92, 135, 0.1); }
.ptab-label { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.ptab-val { font-size: 0.86rem; font-weight: 500; }
.ptab.negative .ptab-val { color: var(--red); }
.ptab-flag, .rail-flag { font-size: 0.72rem; color: #fff; background: var(--amber); padding: 0 6px; border-radius: 3px; }
.ptab.negative .ptab-flag, .rail-btn.negative .rail-flag, .l-period.low.negative .ptab-flag { background: var(--red); }

/* ---------- proto switcher: deliberately alien to the page ---------- */
.proto-bar {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 60;
  display: flex; align-items: center; gap: 6px; background: #101820; color: #fff;
  border-radius: 999px; padding: 6px 8px 6px 6px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px;
}
.proto-btn { background: #2A3640; color: #fff; border: 0; border-radius: 999px; width: 30px; height: 30px; }
.proto-btn:hover { background: #3C4A56; }
.proto-label { padding: 0 6px; white-space: nowrap; }
.proto-label b { color: #FFD166; margin-right: 6px; }
.proto-hint { color: #8CA0B3; padding-right: 6px; }
.proto-btn:focus-visible { outline-color: #FFD166; }
body { padding-bottom: 72px; }

.foot { margin-top: 24px; display: flex; flex-direction: column; gap: 8px; max-width: 78ch; }

/* =================== VARIANT A: timeline first =================== */
.variant-A { max-width: 1240px; margin: 0 auto; padding: 18px 28px 40px; }
.a-top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 22px; margin-bottom: 18px; }
.a-top .status { margin-left: auto; }
.headline { display: grid; grid-template-columns: 1fr 1fr 1.2fr 1.6fr; gap: 0; margin-bottom: 16px; border-top: 1px solid var(--line-strong); }
.hl-item { padding: 12px 16px 12px 0; margin-right: 16px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hl-item:last-child { border-right: 0; margin-right: 0; }
.hl-label { font-size: 0.86rem; color: var(--muted); }
.hl-val { font-size: 1.7rem; font-weight: 500; letter-spacing: -0.01em; line-height: 1.15; text-align: left; }
.hl-low .hl-val { color: var(--amber); }
.hl-low.neg .hl-val { color: var(--red); }
.hl-sub { font-size: 0.86rem; color: var(--muted); }
.hl-whatif { justify-content: center; }
.a-chart-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 8px 0; margin-bottom: 16px; overflow-x: auto; }
.a-chart-scroll { min-width: 760px; }

/* =================== VARIANT B: one ledger =================== */
.variant-B { max-width: 1280px; margin: 0 auto; padding: 18px 24px 40px; }
.b-top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 24px; margin-bottom: 10px; }
.b-brand { display: flex; align-items: baseline; gap: 12px; }
.b-controls { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.b-top .status { margin-left: auto; }
.b-summary { display: flex; flex-wrap: wrap; gap: 6px 26px; padding: 10px 0; border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line); font-size: 0.95rem; }
.b-summary strong { font-weight: 600; }
.b-whatif { padding: 10px 0 14px; max-width: 640px; }
.b-whatif .whatif { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.b-whatif .whatif-result { flex-basis: 100%; }
.b-ledger-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 250px); }
.ledger { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 0.93rem; }
.ledger th { position: sticky; top: 0; background: var(--surface); text-align: left; font-weight: 500; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line-strong); z-index: 2; }
.ledger th.num { text-align: right; }
.ledger td { padding: 7px 10px; vertical-align: top; border-bottom: 1px solid var(--line); }
.ledger td.num { text-align: right; white-space: nowrap; }
.ledger .c-date { white-space: nowrap; color: var(--muted); width: 84px; }
.ledger .c-src { width: 130px; }
.ledger .c-bar { width: 120px; }
.ledger .c-act { width: 68px; text-align: right; }
.ledger .c-item { min-width: 0; }
.ledger .row-name { display: block; }
.ledger .row-who { display: block; }
.l-open td { background: var(--paper); }
.l-period td { padding: 0; background: var(--paper); border-bottom: 1px solid var(--line-strong); }
.l-period-btn { width: 100%; border: 0; background: transparent; padding: 8px 10px; display: flex; align-items: center; gap: 12px; text-align: left; font-family: var(--serif); font-size: 1.05rem; border-left: 3px solid transparent; }
.l-period-btn:hover { background: rgba(36, 92, 135, 0.06); }
.l-period.selected .l-period-btn { border-left-color: var(--blue); background: rgba(36, 92, 135, 0.1); }
.l-period.low .l-period-btn { border-left-color: var(--amber); }
.l-period-name .muted { font-family: var(--sans); font-size: 0.86rem; }
.l-period-count { margin-left: auto; font-family: var(--sans); font-size: 0.86rem; }
.l-period.first-month td { border-top: 2px dashed var(--line-strong); }
.l-row.cancels td { opacity: 0.6; }
.l-row.res td { color: var(--muted); }
.l-row.overdue .c-date { color: var(--amber); font-weight: 500; }
.l-row.editing td { border-bottom-color: transparent; background: var(--blue-soft); }
.l-edit td { padding: 0; }
.l-total td { font-weight: 500; border-bottom: 2px solid var(--line-strong); background: #F7F9F8; }
.l-total.low td { background: var(--amber-soft); }
.l-total.low.negative td { background: var(--red-soft); }
.l-total .muted { font-weight: 400; }
.l-total .c-bal .neg { color: var(--red); }
.bar { display: block; height: 10px; background: var(--paper); border-radius: 2px; overflow: hidden; margin-top: 5px; }
.bar-fill { display: block; height: 100%; background: var(--blue); opacity: 0.55; }
.bar.neg .bar-fill { background: var(--red); opacity: 0.8; }

/* =================== VARIANT C: written brief =================== */
.variant-C { max-width: 1180px; margin: 0 auto; padding: 22px 28px 40px; }
.c-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; margin-bottom: 26px; }
.c-top-right { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.brief { font-family: var(--serif); font-size: 1.22rem; line-height: 1.55; max-width: 62ch; display: flex; flex-direction: column; gap: 14px; margin-bottom: 30px; }
.brief .c-key { font-size: 1.5rem; line-height: 1.35; }
.brief strong { font-family: var(--sans); font-weight: 600; font-size: 0.92em; white-space: nowrap; }
.brief .muted { font-size: 1rem; font-family: var(--sans); color: var(--muted); }
.brief .status { font-family: var(--sans); margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--line-strong); }
.inline-btn { border: 0; background: none; padding: 0; font: inherit; color: var(--blue); text-decoration: underline; text-decoration-style: dotted; text-decoration-thickness: 1.5px; text-underline-offset: 4px; }
.inline-btn:hover { color: var(--blue-ink); text-decoration-style: solid; }
.c-body > * { min-width: 0; }
.c-body { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 22px; align-items: start; }
.rail-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.rail-list li.first-month { border-top: 2px dashed var(--line-strong); }
.rail-btn { width: 100%; border: 0; background: transparent; text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 0 10px; padding: 9px 12px; border-left: 3px solid transparent; border-bottom: 1px solid var(--line); }
.rail-list li:last-child .rail-btn { border-bottom: 0; }
.rail-btn:hover { background: rgba(36, 92, 135, 0.06); }
.rail-btn.selected { border-left-color: var(--blue); background: rgba(36, 92, 135, 0.1); }
.rail-btn.low { border-left-color: var(--amber); }
.rail-name { font-weight: 500; }
.rail-net { grid-row: 2; font-size: 0.82rem; }
.rail-end { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-weight: 500; }
.rail-btn.negative .rail-end { color: var(--red); }
.rail-flag { grid-column: 1; grid-row: 3; justify-self: start; margin-top: 3px; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .headline { grid-template-columns: 1fr 1fr; border-top: 0; }
  .hl-item { border-right: 0; border-top: 1px solid var(--line); margin-right: 0; padding-right: 8px; }
  .hl-whatif { grid-column: 1 / -1; }
  .c-body { grid-template-columns: minmax(0, 1fr); }
  .rail-list { display: flex; overflow-x: auto; border-radius: var(--radius); }
  .rail-list li { flex: 0 0 auto; }
  .rail-list li.first-month { border-top: 0; border-left: 2px dashed var(--line-strong); }
  .rail-btn { border-left: 0; border-top: 3px solid transparent; border-bottom: 0; border-right: 1px solid var(--line); min-width: 140px; }
  .rail-btn.selected { border-top-color: var(--blue); }
  .rail-btn.low { border-top-color: var(--amber); }
  .brief { font-size: 1.1rem; }
  .brief .c-key { font-size: 1.3rem; }
}
@media (max-width: 640px) {
  html { font-size: 14.5px; }
  .variant-A, .variant-B, .variant-C { padding: 14px 14px 40px; }
  .a-top .status, .b-top .status { margin-left: 0; }
  .headline { grid-template-columns: 1fr; }
  .hl-val { font-size: 1.45rem; }
  .row { grid-template-columns: 64px 1fr; }
  .row .amt { grid-column: 2; }
  .row-act { grid-column: 2; }
  .field-row { grid-template-columns: 1fr; }
  .edit-form.inline { padding-left: 12px; }
  .pd-head { flex-direction: column; gap: 2px; }
  /* ledger becomes a stacked list */
  .b-ledger-wrap { max-height: none; overflow: visible; }
  .ledger thead { display: none; }
  .ledger, .ledger tbody, .ledger tr, .ledger td { display: block; width: auto; }
  .ledger tr { border-bottom: 1px solid var(--line); padding: 8px 10px; }
  .ledger td { border: 0; padding: 1px 0; }
  .ledger .c-date { width: auto; font-size: 0.86rem; }
  .ledger td.num { text-align: left; }
  .ledger .c-bal::before { content: "balance "; color: var(--muted); font-weight: 400; }
  .ledger .c-bal:empty { display: none; }
  .ledger .c-bar { display: none; }
  .ledger .c-act { text-align: left; padding-top: 6px; }
  .l-period-btn { flex-wrap: wrap; }
  .l-total td.c-bal::before { content: "end "; }
  .l-edit td { padding: 0; }
  .proto-bar { bottom: 8px; }
}
@media (prefers-reduced-motion: no-preference) {
  .seg-btn, .btn, .rail-btn, .ptab, .l-period-btn { transition: background-color 120ms ease, border-color 120ms ease; }
}
@media print { .proto-bar, .status .btn { display: none; } body { background: #fff; } }
