/* thrubill - one stylesheet, no framework. Tokens first, then the shell, then components. */
/* IBM Plex, served from this app (SIL Open Font License; see fonts/IBM-Plex-LICENSE.txt).
   latin-ext carries the rupee sign and loads only on pages that use it. */
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-sans-latin-ext-400-normal.1bc0d8e41d21.woff2") format("woff2"); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-sans-latin-400-normal.77bc02670657.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-latin-ext-500-normal.93a0df997e00.woff2") format("woff2"); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-sans-latin-500-normal.f7016cd446d2.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-latin-ext-600-normal.8fccbdf5bf67.woff2") format("woff2"); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/ibm-plex-sans-latin-600-normal.196e3cbc5fee.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/ibm-plex-mono-latin-400-normal.4cc7b4398540.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/ibm-plex-mono-latin-500-normal.bc5ccab82723.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --font: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --text: #121820;
  --text-2: #3a4450;
  --muted: #5d6773;        /* labels, captions: 5.6:1 on white */
  --border: #e2e5e9;
  --border-2: #eef0f2;
  --field-border: #cfd4da;
  --bg: #f4f5f3;           /* page */
  --surface: #ffffff;
  --sunk: #f8f9f7;

  --side: #121820;         /* sidebar and dark bars */
  --side-ink: #c3cad3;
  --side-mute: #8a94a0;
  --side-accent: #8fa2ff;

  --accent: #2340c8;       /* cobalt: actions, links, "your move" */
  --accent-ink: #1a2f96;
  --accent-soft: #ebeefb;
  --accent-text: #ffffff;

  /* Status always means the same thing about money */
  --ok-text: #0d6e4c;   --ok-bg: #e3f2ea;      /* settled */
  --warn-text: #8a5200; --warn-bg: #fbefd9;    /* waiting on someone */
  --danger: #b23118;    --danger-bg: #fbe7e1;  /* overdue, act now */
  --lock: #4b5562;      --lock-bg: #eceef1;    /* locked until the client pays */

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(18, 24, 32, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); text-decoration: underline; }
h1 { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0 0 6px; font-size: 26px; line-height: 1.2; font-weight: 600; letter-spacing: -0.02em; }
h2 { margin: 28px 0 12px; font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
h2 .muted { font-weight: 400; }
strong, b { font-weight: 600; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
[hidden] { display: none !important; }
[id] { scroll-margin-top: 1rem; }

/* ---------- Shell ---------- */
.app { display: flex; min-height: 100vh; }
/* The dark column runs the full page height even when the sticky sidebar is shorter */
.app:not(.app-top) { background: linear-gradient(90deg, var(--side) 240px, transparent 240px); }
.app-top { flex-direction: column; }
.main { flex: 1 1 0; min-width: 0; }
.page { width: 100%; max-width: 1200px; padding: 28px 32px 72px; }
.app-top .page { max-width: 1104px; margin: 0 auto; }

/* Sidebar (operators) */
.side { flex: 0 0 240px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; padding: 20px 14px; background: var(--side); color: var(--side-ink); }
.side-bar { display: flex; align-items: center; justify-content: space-between; }
.side-body { flex: 1; display: flex; flex-direction: column; gap: 20px; min-height: 0; }
.brand { display: inline-flex; align-items: center; gap: 10px; padding: 2px 8px; color: #fff; font-weight: 600; font-size: 19px; letter-spacing: -0.02em; text-decoration: none; }
.brand:hover { color: #fff; text-decoration: none; }
.brand svg { flex: none; }
.org { display: flex; flex-direction: column; padding: 10px; border-radius: var(--radius-sm); background: rgba(255, 255, 255, 0.05); min-width: 0; }
.org b { color: #fff; font-weight: 500; overflow-wrap: anywhere; }
.org span { color: var(--side-mute); font-size: 12.5px; overflow-wrap: anywhere; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-g { padding: 14px 10px 6px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--side-mute); }
.nav-i { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: 7px; color: var(--side-ink); }
.nav-i:hover { background: rgba(255, 255, 255, 0.06); color: #fff; text-decoration: none; }
.nav-i svg { flex: none; opacity: 0.8; }
.nav-i[aria-current="page"] { background: rgba(255, 255, 255, 0.1); color: #fff; font-weight: 500; }
.nav-i[aria-current="page"] svg { opacity: 1; color: var(--side-accent); }
.nav-i .count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: rgba(255, 255, 255, 0.12); color: #fff; font-size: 11.5px; font-weight: 500; display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.nav-i .count.hot { background: #e0603f; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 12px 10px 0; border-top: 1px solid rgba(255, 255, 255, 0.08); font-size: 12.5px; color: var(--side-mute); }
.side-foot .nav-i { padding: 0; height: 30px; font-size: 14px; }
.side-foot .nav-i:hover, .side-foot .nav-i[aria-current="page"] { background: none; }
.side-foot .link { color: var(--side-ink); font-size: 12.5px; }
.side a:focus-visible, .side button:focus-visible, .ptop a:focus-visible, .ptop button:focus-visible { outline: 2px solid var(--side-accent); outline-offset: 2px; }
.menu-button { display: none; }

/* Dark top bar (contractors, approvers, signed-out pages) */
.ptop { display: flex; flex-wrap: wrap; align-items: center; gap: 0 28px; min-height: 60px; padding: 0 32px; background: var(--side); color: #fff; }
.ptop .brand { padding: 0; font-size: 17px; }
.ptabs { display: flex; gap: 24px; }
.ptabs a { display: flex; align-items: center; height: 60px; color: var(--side-ink); border-bottom: 2px solid transparent; }
.ptabs a:hover { color: #fff; text-decoration: none; }
.ptabs a[aria-current="page"] { color: #fff; border-bottom-color: var(--side-accent); font-weight: 500; }
.ptop-user { margin-left: auto; display: flex; align-items: center; gap: 16px; font-size: 13px; color: var(--side-ink); }
.ptop-user .link { color: #fff; font-size: 13px; }

/* Public read-only pages */
.pubbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.pubbar-in { max-width: 1104px; margin: 0 auto; padding: 14px 32px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.pubbar-t { flex: 1 1 260px; min-width: 0; display: flex; flex-direction: column; }
.pubbar + .page { max-width: 1104px; margin: 0 auto; }
.pubbar + .page-doc { max-width: 944px; }

/* ---------- Page header ---------- */
.crumb { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.crumb a { color: var(--muted); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 4px; }
.page-head > div:first-child { min-width: 0; }
.page-head p { margin: 0; }
.page-head + p.muted, h1 + p.muted { margin: 0 0 4px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-head .button { margin-top: 20px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0 24px; }
.below { margin-top: 12px; font-size: 13px; }
.jump { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 14px 0 0; font-size: 13px; }
.plan { display: flex; align-items: center; gap: 8px; }

/* ---------- Buttons ---------- */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 6px 14px; border: 1px solid var(--accent); border-radius: var(--radius-sm); background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 500; text-align: center; text-decoration: none; white-space: nowrap; cursor: pointer; box-shadow: var(--shadow); }
.button:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: var(--accent-text); text-decoration: none; }
.button-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.button-secondary:hover { background: var(--sunk); border-color: var(--border); color: var(--text); }
.button-ink { background: var(--text); border-color: var(--text); color: #fff; }
.button-ink:hover { background: #000; border-color: #000; color: #fff; }
.button:disabled { opacity: 0.45; cursor: default; }
.link { padding: 0; font: inherit; color: var(--accent); background: none; border: 0; cursor: pointer; }
.link:hover { color: var(--accent-ink); text-decoration: underline; }
.button:focus-visible, .link:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Status pills ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 11px; font-size: 12px; font-weight: 500; white-space: nowrap; vertical-align: middle; background: var(--lock-bg); color: var(--lock); letter-spacing: 0; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-paid { background: var(--ok-bg); color: var(--ok-text); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge-sent, .badge-ready { background: var(--accent-soft); color: var(--accent-ink); }
.badge-due { background: var(--danger-bg); color: var(--danger); }
.badge-void { text-decoration: line-through; }

/* ---------- Cards, panels, facts ---------- */
.panel, .facts, .kv, .table-wrap, .paper, .entry-grid { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 20px; }
.panel p { margin: 0 0 12px; }
.panel p:last-child { margin-bottom: 0; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px 24px; margin: 20px 0 0; padding: 20px; }
.facts dt { margin: 0 0 3px; font-size: 12.5px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; }
.facts dd .muted { font-weight: 400; }
.kv { list-style: none; margin: 0; padding: 0; overflow: hidden; }
.kv li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 20px; }
.kv li + li { border-top: 1px solid var(--border-2); }
.empty { padding: 20px; color: var(--muted); background: transparent; border: 1px dashed var(--field-border); border-radius: var(--radius); }
.paper { padding: 32px; overflow-x: auto; }
.meter { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 16px 0; padding: 12px 14px; background: var(--accent-soft); border: 1px solid #d5dcfa; border-radius: var(--radius-sm); font-size: 13px; }

/* ---------- Composed screens: columns, cards with a header, rows ---------- */
.cols { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 24px; align-items: start; margin-top: 24px; }
.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; margin-top: 24px; }
.pile { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.stack-s { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-key { border-color: #c9d2f7; }
.card-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 16px 20px; border-bottom: 1px solid var(--border-2); }
.card-h h2, .card-h h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-b { padding: 20px; }
.card-b > p { margin: 0 0 12px; }
.card-b > p:last-child { margin-bottom: 0; }
.card-f { padding: 12px 20px; border-top: 1px solid var(--border-2); color: var(--muted); font-size: 13px; }
.card > .table-wrap { border: 0; border-radius: 0; box-shadow: none; }
.card + .card, .card + h2 { margin-top: 24px; }
.pile > .card + .card, .cols > .card + .card { margin-top: 0; }
.cols + .card, .cols + section, .stats + .table-wrap, .stats + .card, .table-wrap + .table-wrap { margin-top: 24px; }
.note { display: flex; gap: 10px; align-items: flex-start; margin: 16px 0; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--sunk); border: 1px solid var(--border-2); color: var(--text-2); font-size: 13px; }
.who { display: flex; flex-direction: column; min-width: 0; }
.who span { font-size: 12.5px; color: var(--muted); }
.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); font-size: 12px; font-weight: 400; letter-spacing: 0; color: var(--text-2); }
.figure { font-weight: 600; font-variant-numeric: tabular-nums; }
.quiet { color: var(--text-2); }
.late { color: var(--danger); font-weight: 500; }
.good { color: var(--ok-text); }
.sr { position: absolute; left: -9999px; }
.button-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.button-lg { min-height: 44px; padding: 8px 18px; font-size: 15px; }
.button-wide { width: 100%; }
.button-danger { color: var(--danger); }
.button-danger:hover { color: var(--danger); }

/* Rows that ask for action */
.todo { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 14px 20px; border-bottom: 1px solid var(--border-2); }
.todo:last-child { border-bottom: 0; }
.todo-n { flex: none; width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-weight: 600; font-variant-numeric: tabular-nums; background: var(--sunk); color: var(--text-2); }
.todo-ready { background: var(--accent-soft); color: var(--accent-ink); }
.todo-due { background: var(--danger-bg); color: var(--danger); }
.todo-wait { background: var(--warn-bg); color: var(--warn-text); }
.todo-t { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.todo-t b { font-weight: 500; }

/* "You owe / you are owed" lines */
.ledger-h { margin: 0; padding: 14px 20px 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.ledger-h-next { padding-top: 18px; border-top: 1px solid var(--border); }
.ledger-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border-2); }
.ledger-row:last-child { border-bottom: 0; }
.ledger-row-sunk { background: var(--sunk); }
.ledger-l { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-width: 0; }
.ledger-r { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.card-b .ledger-row { padding: 8px 0; }

/* The money flow strip: where one period is, from hours to money */
.flow { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
.flow-s { display: flex; flex-direction: column; gap: 4px; min-width: 0; padding-right: 12px; }
.flow-bar { height: 4px; border-radius: 2px; background: var(--border); margin-bottom: 10px; }
.flow-l { font-size: 12px; color: var(--muted); }
.flow-v { font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.flow-m { font-size: 12.5px; color: var(--muted); }
.flow-s.is-done .flow-bar { background: var(--ok-text); }
.flow-s.is-now .flow-bar { background: var(--accent); }
.flow-s.is-now .flow-l { color: var(--accent-ink); font-weight: 500; }
.flow-s.is-next .flow-v { color: var(--muted); font-weight: 500; }

/* Days of a period */
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.days-head { margin-bottom: 6px; font-size: 11.5px; color: var(--muted); }
.day { min-height: 56px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border-2); background: var(--surface); display: flex; flex-direction: column; justify-content: space-between; font-size: 12px; color: var(--muted); min-width: 0; }
.day b { font-size: 14px; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.day.has { background: var(--accent-soft); border-color: #d5dcfa; }
.day.off { background: transparent; border-style: dashed; }
.day.today { outline: 2px solid var(--accent); outline-offset: -1px; }
.day.blank { visibility: hidden; }
.pile-top { margin-top: 24px; }
.card > .entry-form .entry-grid { border: 0; border-radius: 0; box-shadow: none; }
.card > .entry-form .alert { margin: 16px 20px 0; }

/* Timeline (invoice status) */
.tl { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.tl li { display: flex; gap: 12px; padding: 0 0 16px; position: relative; }
.tl li:last-child { padding-bottom: 0; }
.tl .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border); background: #fff; margin-top: 4px; flex: none; position: relative; z-index: 1; }
.tl li::after { content: ""; position: absolute; left: 5px; top: 16px; bottom: -2px; width: 2px; background: var(--border-2); }
.tl li:last-child::after { display: none; }
.tl b { font-weight: 500; }
.tl .done .dot { background: var(--ok-text); border-color: var(--ok-text); }
.tl .now .dot { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tl .now.late .dot { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }
.tl .now.late b { color: var(--danger); }
.doc-col { min-width: 0; }
.h-num { font-size: 24px; font-weight: 500; }
.h3 { margin: 0; font-size: 13px; font-weight: 600; }
.ink { color: var(--text); }
.card-top { margin-top: 24px; }
.card-b .inline-form:first-child { margin-top: 0; }

/* Tabs that carry a figure; share-link row */
.tabs-2 a { display: flex; flex-direction: column; gap: 2px; }
.tabs-2 a b { font-weight: inherit; }
.tabs-2 a > span { font-size: 12.5px; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.share { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.share-t { flex: 1 1 240px; }
.share .copy { flex: 2 1 320px; width: auto; }
.share-card { margin-bottom: 20px; }
.card-h .who h2 { font-size: 15px; }

.problems { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.problems b { font-weight: 600; }

/* Rate card */
.rate-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.rate-v { font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rate-bar { display: flex; gap: 2px; height: 8px; border-radius: 4px; overflow: hidden; }
.rate-bar i { background: var(--border); }
.rate-bar i.keep { background: var(--ok-text); }
.rate-total { padding-top: 10px; border-top: 1px solid var(--border-2); }
.h-at { font-weight: 400; }
.facts-plain { margin: 0; border: 0; border-radius: 0; box-shadow: none; }

/* Progress and aging bars */
.bar { height: 6px; border-radius: 3px; background: var(--border-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok-text); border-radius: 3px; }
.stat-bar .bar { order: -1; margin-top: 2px; }
.aging-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--border-2); }
.aging-bar i { display: block; height: 100%; }
.aging-0 { background: var(--accent); }
.aging-1 { background: #e0a23a; }
.aging-2 { background: #d9683f; }
.aging-3 { background: var(--danger); }
.aging-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; margin-top: 14px; }

/* ---------- Figures ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-top: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.stat { display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: 4px; padding: 18px 20px; box-shadow: 1px 0 0 var(--border-2), 0 1px 0 var(--border-2); }
.stat-value { font-size: 24px; line-height: 1.25; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-label { color: var(--muted); font-size: 12.5px; }
a.stat { color: inherit; text-decoration: none; }
a.stat:hover { background: var(--sunk); }
.stat-key { background: var(--accent-soft); }
.stat-key .stat-label { color: var(--accent-ink); font-weight: 500; }
.stat-warn { background: var(--danger-bg); }
.stat-warn .stat-label { color: var(--danger); font-weight: 500; }
.stats.aging { margin-top: 8px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; text-align: left; white-space: nowrap; vertical-align: middle; }
th { padding: 10px 16px; font-size: 12px; font-weight: 500; color: var(--muted); background: var(--sunk); border-bottom: 1px solid var(--border); }
th.num, td.num { text-align: right; }
tbody tr + tr td { border-top: 1px solid var(--border-2); }
td.wrap { white-space: normal; min-width: 14rem; }
tr.current td { background: var(--accent-soft); }
tr.sum td { border-top: 1px solid var(--border); background: var(--sunk); color: var(--muted); }
tr.sum strong { color: var(--text); }
tr.detail-row td { padding-top: 0; border-top: 0 !important; }
tr.detail-row summary, .row-menu summary { cursor: pointer; color: var(--accent); font-size: 12.5px; }
tr.detail-row table.lines { margin-top: 8px; }
.row-menu[open] { padding: 6px 0; }
.row-menu .inline-form { margin-top: 6px; }
.row-actions { display: flex; gap: 12px; align-items: baseline; }

table.lines td { vertical-align: top; }
table.lines td.wrap { min-width: 10rem; max-width: 34rem; }
table.lines tbody tr td { border-top: 0; }
table.lines tbody tr.day-start td { border-top: 1px solid var(--border-2); }
table.lines tbody tr:first-child td { border-top: 0; }
table.lines tr.day-total td { color: var(--muted); font-size: 12.5px; padding-top: 0; }

table.edit-lines { width: 100%; margin-bottom: 12px; }
table.edit-lines td { padding: 6px 8px 6px 0; white-space: normal; vertical-align: middle; border: 0; }
table.edit-lines .inline-form { margin-top: 0; flex-wrap: nowrap; }
table.edit-lines input[type="text"] { min-width: 16rem; }

/* ---------- Tabs, year switch, two-way switch ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 24px 0 16px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 10px 14px 12px; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--text-2); font-weight: 500; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.tabs a .muted { font-weight: 400; }
.years { display: inline-flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--border-2); }
.years a { padding: 4px 12px; border-radius: 7px; color: var(--text-2); font-size: 13px; }
.years a:hover { text-decoration: none; color: var(--text); }
.years a[aria-current="page"] { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: var(--shadow); }
.switch { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin: 24px 0 16px; }
.switch a { display: flex; flex-direction: column; gap: 6px; padding: 20px 22px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); min-width: 0; }
.switch a:hover { border-color: #c9cfd6; text-decoration: none; }
.switch a[aria-current="page"] { border: 2px solid var(--accent); padding: 19px 21px; }
.switch-label { font-size: 12.5px; color: var(--muted); }
.switch a[aria-current="page"] .switch-label { color: var(--accent-ink); font-weight: 500; }
.switch-value { font-size: 28px; line-height: 1.2; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.switch-value .muted { font-size: 12.5px; font-weight: 400; letter-spacing: 0; }

/* ---------- Forms ---------- */
.form { max-width: 560px; }
.form .actions { margin-top: 24px; }
.form fieldset { margin: 24px 0 0; padding: 0; border: 0; }
.form legend { padding: 0; font-weight: 600; font-size: 15px; }
.field { margin: 16px 0; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; }
.field input, .field select, .field textarea, .inline-form input, .inline-form select, .page-head select {
  min-height: 40px; padding: 8px 12px; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--field-border); border-radius: var(--radius-sm);
}
.field input, .field select, .field textarea { width: 100%; }
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .inline-form input:focus, .inline-form select:focus, .page-head select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.field input[type="checkbox"], .field input[type="radio"] { width: auto; min-height: 0; margin-right: 6px; accent-color: var(--accent); }
.field input[type="color"] { width: 64px; height: 40px; padding: 3px; cursor: pointer; }
.field input[type="file"] { padding: 7px 12px; }
.field-check label { font-weight: 400; font-size: 14px; }
.field input:disabled, .field select:disabled { background: var(--sunk); color: var(--muted); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field ul, .field li { list-style: none; margin: 0; padding-left: 0; }
.field li label { font-weight: 400; font-size: 14px; display: block; margin: 4px 0; }
.optional { font-weight: 400; font-size: 12.5px; color: var(--muted); }
.hint { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }
.error { margin: 6px 0 0; font-size: 12.5px; color: var(--danger); }
.alert { padding: 10px 14px; border: 1px solid var(--danger); border-radius: var(--radius-sm); background: var(--danger-bg); color: var(--danger); }
.alert p { margin: 0; }
.inline-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.inline-form label { font-size: 13px; font-weight: 500; }
.inline-form select { max-width: 14rem; }
.copy { width: 100%; min-height: 38px; padding: 8px 12px; font: 12.5px var(--mono); color: var(--text-2); background: var(--sunk); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.flash { margin: 0 0 16px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--ok-bg); color: var(--ok-text); }
.flash-error { background: var(--danger-bg); color: var(--danger); }

/* ---------- Timesheet entry ---------- */
.entry-grid { display: grid; grid-template-columns: 9.5rem 7rem 1fr 1fr; gap: 0 14px; padding: 6px 20px 20px; }
.entry-grid .field { margin: 14px 0 0; }
.entry-grid .field-description { grid-column: 1 / 4; }
.entry-grid .field-hours { grid-column: 4; }
.entry-grid .field-submit { grid-column: 1 / -1; }

/* ---------- Dashboard, settings, pricing ---------- */
.queue li a { color: var(--text); }
.queue li a:hover { color: var(--accent-ink); }
.settings-menu li a { font-weight: 500; }
.steps { counter-reset: step; }
.steps li.done { color: var(--muted); }
.on-phone { display: none; }

/* ---------- Sign-in and other signed-out pages ---------- */
.auth-split { min-height: 100vh; display: flex; flex-wrap: wrap; background: var(--surface); }
.auth-side { flex: 1 1 480px; display: flex; flex-direction: column; justify-content: space-between; gap: 40px; padding: 48px 56px; background: var(--side); color: #fff; }
.auth-side .brand { padding: 0; font-size: 21px; align-self: flex-start; }
.auth-pitch { display: flex; flex-direction: column; gap: 28px; max-width: 460px; }
.auth-headline { margin: 0; font-size: 36px; line-height: 1.15; font-weight: 600; letter-spacing: -0.025em; }
.chain { list-style: none; margin: 0; padding: 0; }
.chain li { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.08); color: #dfe4ea; }
.chain .n { font-family: var(--mono); font-size: 12px; color: var(--side-accent); width: 20px; }
.chain b { font-weight: 500; color: #fff; }
.chain em { margin-left: auto; font-style: normal; font-size: 12.5px; color: var(--side-mute); }
.auth-note { margin: 0; font-size: 12.5px; color: var(--side-mute); }
.auth-main { flex: 1 1 420px; display: flex; align-items: center; justify-content: center; padding: 48px 32px; }
.auth-card { width: 100%; max-width: 380px; }
.auth.wide .auth-card { max-width: 640px; }
.auth-card h1 { font-size: 24px; }
.auth-card .button { width: 100%; min-height: 44px; margin-top: 8px; font-size: 15px; }
.auth-links { margin: 20px 0 0; font-size: 12.5px; color: var(--muted); text-align: center; }

@media (max-width: 1100px) { .cols { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Narrow screens: the sidebar becomes a bar with a Menu button ---------- */
@media (max-width: 760px) {
  .app, .app:not(.app-top) { flex-direction: column; background: none; }
  .side { position: static; flex: none; height: auto; overflow: visible; padding: 10px 16px; gap: 0; }
  .side .brand { padding: 0; font-size: 17px; }
  .menu-button {
    display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px;
    font: inherit; font-weight: 500; color: #fff; background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14); border-radius: var(--radius-sm); cursor: pointer;
  }
  .menu-button::before { content: ""; width: 16px; height: 11px; border-top: 2px solid currentColor; border-bottom: 2px solid currentColor; background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat; }
  .menu-button[aria-expanded="true"]::before { display: none; }
  /* Closed by default once the script has run; without JS everything stays visible */
  .js .app:not(.open) [data-menu] { display: none; }
  .side-body { gap: 8px; padding: 12px 0 8px; }
  .nav-i { height: 48px; padding: 0 12px; font-size: 16px; border-radius: var(--radius-sm); }
  .nav-g { padding: 16px 12px 6px; }
  .side-foot { padding: 12px 12px 0; font-size: 14px; }
  .side-foot .nav-i { height: 44px; font-size: 16px; }
  .side-foot .link { min-height: 44px; font-size: 14px; }

  .ptop { padding: 0 16px; min-height: 0; gap: 0 20px; }
  .ptop .brand { height: 52px; }
  .ptop-user .via { display: none; }
  .ptop-user .link { min-height: 44px; }
  .ptabs { order: 3; flex: 1 1 100%; gap: 22px; }
  .ptabs a { height: 44px; }

  .page { padding: 20px 16px 56px; }
  .cols, .cols-2 { grid-template-columns: minmax(0, 1fr); gap: 20px; margin-top: 20px; }
  .day { padding: 4px 5px; min-height: 50px; font-size: 10.5px; }
  .day b { font-size: 12.5px; }
  .flow { grid-auto-flow: row; grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .flow-bar { margin-bottom: 6px; }
  .pile { gap: 20px; }
  .card-h, .todo, .ledger-row { padding-left: 16px; padding-right: 16px; }
  .card-b { padding: 16px; }
  .ledger-h { padding-left: 16px; padding-right: 16px; }
  .button-sm { min-height: 40px; }
  .pubbar-in { padding: 12px 16px; }
  .switch { grid-template-columns: 1fr; gap: 12px; }
  .switch-value { font-size: 22px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat { padding: 14px; }
  .stat-value { font-size: 19px; }
  .page-head .actions { width: 100%; }
  .entry-grid { grid-template-columns: 1fr 1fr; padding: 4px 14px 14px; }
  .entry-grid .field-description { grid-column: 1 / -1; }
  .entry-grid .field-hours { grid-column: auto; }

  .auth-side { flex: 1 1 100%; padding: 14px 16px; }
  .auth-side .brand { font-size: 17px; }
  .auth-pitch, .auth-note { display: none; }
  .auth-main { flex: 1 1 100%; align-items: flex-start; padding: 28px 16px 40px; }
}

/* ---------- Phones ---------- */
@media (max-width: 640px) {
  body { font-size: 16px; }
  h1 { font-size: 24px; overflow-wrap: anywhere; }
  h2 { margin-top: 24px; }

  /* Tap targets, and 16px inputs so iOS doesn't zoom the page on focus */
  .button, .field input, .field select, .field textarea, .inline-form input, .inline-form select, .copy, .page-head select { min-height: 44px; font-size: 16px; }
  .link, .row-menu summary, .tabs a { padding-top: 8px; padding-bottom: 8px; }
  .years a { padding: 8px 12px; }
  .field input[type="checkbox"], .field input[type="radio"] { min-height: 0; width: 20px; height: 20px; flex: none; margin: 2px 0 0; }
  .field li label, .field-check label { display: flex; align-items: flex-start; gap: 10px; padding: 6px 0; }

  /* Headers and action rows stack */
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head > .button, .page-head .actions .button, .page-head .actions form { width: 100%; }
  .page-head .actions form .button { width: 100%; }
  .section-head { align-items: center; }
  .actions { align-items: stretch; }
  .panel .actions > *, .panel .actions form .button, .form .actions .button { flex: 1 1 100%; width: 100%; }
  .form { max-width: none; }
  .columns { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr 1fr; gap: 14px 16px; padding: 16px; }
  .panel { padding: 16px; }
  .kv li { flex-wrap: wrap; gap: 2px 16px; padding: 12px 16px; }
  .paper { padding: 16px; }

  /* Rows of small controls wrap, each control taking the full width */
  .inline-form { align-items: stretch; flex-direction: column; flex-wrap: nowrap; gap: 6px; }
  table.edit-lines .inline-form { flex-wrap: nowrap; }
  .inline-form input, .inline-form select, .inline-form .button { width: 100%; max-width: none; }
  table.edit-lines input[type="text"] { min-width: 0; }

  /* Tabs and year switches scroll sideways instead of wrapping into a block */
  .tabs, .years { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; max-width: 100%; }
  .tabs::-webkit-scrollbar, .years::-webkit-scrollbar { display: none; }
  .tabs a, .years a { white-space: nowrap; flex: none; }

  /* Tables become cards: one row per card, "Label   value" per line (see tables.js) */
  table.stack, table.stack > tbody, table.stack > tbody > tr, table.stack > tbody > tr > td { display: block; width: 100%; }
  table.stack > thead { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }
  table.stack > tbody > tr { padding: 12px 16px; border-top: 1px solid var(--border-2); }
  table.stack > tbody > tr:first-child { border-top: 0; }
  table.stack > tbody > tr > td { padding: 3px 0; white-space: normal; border: 0 !important; text-align: left; overflow-wrap: anywhere; background: none; }
  table.stack > tbody > tr > td[data-label] { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; text-align: right; }
  table.stack > tbody > tr > td[data-label]::before { content: attr(data-label); flex: none; max-width: 45%; color: var(--muted); font-size: 12.5px; text-align: left; }
  table.stack > tbody > tr > td:empty { display: none; }
  /* The first cell names the row, so it reads as the card's title */
  table.stack > tbody > tr > td:first-child[data-label] { display: block; text-align: left; font-weight: 600; }
  table.stack > tbody > tr > td:first-child[data-label]::before { display: none; }
  /* Long text gets its own lines under its label */
  table.stack > tbody > tr > td.wrap[data-label] { display: block; text-align: left; max-width: none; min-width: 0; }
  table.stack > tbody > tr > td.wrap[data-label]::before { display: block; }
  /* Total rows keep "what   amount" on one line */
  table.stack > tbody > tr.sum { display: flex; justify-content: space-between; gap: 16px; background: var(--sunk); }
  table.stack > tbody > tr.sum > td { width: auto; display: block; }
  table.stack > tbody > tr.sum > td:empty, table.stack > tbody > tr.day-total > td:empty { display: none; }
  .on-phone { display: inline; }
  table.stack > tbody > tr.sum > td::before, table.stack > tbody > tr.day-total > td::before { display: none !important; }
  table.stack > tbody > tr.day-total { display: flex; justify-content: space-between; padding-top: 0; border-top: 0; }
  table.stack > tbody > tr.day-total > td { width: auto; display: block; }
  table.stack > tbody > tr.detail-row { border-top: 0; padding-top: 0; }
  table.lines.stack > tbody > tr { border-top: 0; }
  table.lines.stack > tbody > tr.day-start { border-top: 1px solid var(--border-2); }
  .row-actions { justify-content: flex-end; }

  /* Small edit tables inside panels (no headings): each row becomes a block */
  table.edit-lines, table.edit-lines tbody, table.edit-lines tr, table.edit-lines td { display: block; width: 100%; }
  table.edit-lines tr { padding: 8px 0; border-top: 1px solid var(--border-2); }
  table.edit-lines tr:first-child { border-top: 0; }
  table.edit-lines td { padding: 2px 0; text-align: left !important; }
  .table-wrap { overflow-x: visible; }
}

/* ---------- Print ---------- */
@media print {
  .side, .ptop, .pubbar, .no-print { display: none !important; }
  body { background: #fff; }
  .page { max-width: none; padding: 0; }
  .paper { border: 0; box-shadow: none; padding: 0; }
}
