/* Billhead. A business look: navy ink on cool paper, ledger rules, tabular numbers.
   Type: IBM Plex Sans for words, IBM Plex Mono for numbers and invoice numbers. Both ship with the app. */
@font-face { font-family: "Plex Sans"; src: url("fonts/plex-sans-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("fonts/plex-sans-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("fonts/plex-sans-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("fonts/plex-sans-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("fonts/plex-mono-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("fonts/plex-mono-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("fonts/plex-mono-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --sans: "Plex Sans", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "Plex Mono", "SF Mono", Menlo, Consolas, monospace;
  --bg: #F3F5F8; --surface: #FFFFFF; --surface-2: #EEF1F5; --ink: #15202B; --ink-2: #3D4A58; --muted: #65717F; --line: #D9DFE7; --line-2: #C5CDD8;
  --navy: #1C3F7A; --navy-deep: #122A52; --navy-soft: #E3EAF6; --navy-ink: #FFFFFF;
  --green: #1B7F4C; --green-soft: #DDF3E6; --amber: #A86A12; --amber-soft: #FBEFD6; --red: #B42318; --red-soft: #FBE3E0;
  --shadow: 0 1px 2px rgba(21, 32, 43, 0.06), 0 8px 24px rgba(21, 32, 43, 0.08);
  --shadow-lg: 0 24px 60px rgba(21, 32, 43, 0.22);
  --radius: 12px; --radius-sm: 8px; --tab-h: 62px; --header-h: 54px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}
:root[data-look="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root[data-look="auto"] { color-scheme: dark; } }
:root[data-look="dark"], :root[data-look="auto"].dark-auto {
  --bg: #0E1319; --surface: #161C25; --surface-2: #1F2733; --ink: #E7ECF2; --ink-2: #C3CBD6; --muted: #93A0AF; --line: #28323F; --line-2: #35414F;
  --navy: #7FA6EA; --navy-deep: #A9C3F2; --navy-soft: #1D2B45; --navy-ink: #0E1319;
  --green: #4CC38A; --green-soft: #15311F; --amber: #E6A93F; --amber-soft: #352A12; --red: #F2615A; --red-soft: #3A1A18;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--sans); font-size: 16px; line-height: 1.45; color: var(--ink); background: var(--bg); min-height: 100vh; min-height: 100dvh; overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
body.has-tabs { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
p { margin: 0 0 0.75rem; }
a { color: var(--navy); }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.right { text-align: right; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Header and tabs ---------- */
.hdr { position: sticky; top: 0; z-index: 20; height: calc(var(--header-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); display: flex; align-items: center; gap: 0.5rem; padding-left: 0.6rem; padding-right: 0.6rem; background: color-mix(in srgb, var(--surface) 86%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
.hdr .brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; text-decoration: none; color: var(--ink); min-width: 0; }
.hdr .brand .mark { width: 28px; height: 28px; border-radius: 7px; flex: none; }
.hdr .title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr .back { display: inline-flex; align-items: center; gap: 0.2rem; padding: 0.5rem 0.55rem; border: 0; background: transparent; border-radius: 8px; color: var(--navy); font-weight: 600; cursor: pointer; }
.hdr .back:hover { background: var(--navy-soft); }
.hdr .actions { display: flex; gap: 0.3rem; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(4, 1fr); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.02em; position: relative; transition: color 0.2s; }
.tabs a svg { width: 24px; height: 24px; transition: transform 0.25s var(--ease); }
.tabs a.on { color: var(--navy); }
.tabs a.on svg { transform: translateY(-1px); }
.tabs a.on::before { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--navy); }
.tabs a .dot { position: absolute; top: 8px; right: calc(50% - 18px); width: 8px; height: 8px; border-radius: 50%; background: var(--red); }

/* ---------- Layout ---------- */
.view { max-width: 720px; margin: 0 auto; padding: 1rem 1rem 2rem; animation: rise 0.32s var(--ease); min-width: 0; }
.view > *, .stack > * { min-width: 0; }
.view.wide { max-width: 980px; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(0.96); opacity: 0; } 100% { transform: none; opacity: 1; } }
.stack { display: grid; gap: 0.8rem; }
.row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; gap: 0.8rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.card.navy { background: var(--navy); color: var(--navy-ink); border-color: transparent; }
.card.navy .muted { color: color-mix(in srgb, var(--navy-ink) 70%, transparent); }
.ledger { position: relative; }
.ledger::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--navy); border-radius: var(--radius) var(--radius) 0 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; min-height: 44px; padding: 0.55rem 1rem; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 0.95rem; cursor: pointer; text-decoration: none; transition: transform 0.12s var(--ease), background-color 0.15s, box-shadow 0.15s; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: var(--navy-ink); }
.btn.primary:hover { background: var(--navy-deep); border-color: var(--navy-deep); }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--navy-soft); }
.btn.block { width: 100%; }
.btn.big { min-height: 52px; font-size: 1.02rem; border-radius: 12px; }
.btn.small { min-height: 36px; padding: 0.3rem 0.7rem; font-size: 0.86rem; border-radius: 8px; }
.btn[disabled] { opacity: 0.55; cursor: default; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-text { background: none; border: 0; padding: 0.4rem 0.2rem; color: var(--navy); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.btn-text.quiet { color: var(--muted); font-weight: 500; }
.btn-text.danger { color: var(--red); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* Fields */
.field { display: grid; gap: 0.3rem; }
.field > label, .field > .lbl { font-size: 0.82rem; font-weight: 600; color: var(--ink-2); }
.field .help { font-size: 0.8rem; color: var(--muted); }
.input, .field input[type="text"], .field input[type="email"], .field input[type="tel"], .field input[type="url"], .field input[type="number"], .field input[type="date"], .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 0.6rem 0.75rem; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface); color: var(--ink); outline: none; transition: border-color 0.15s, box-shadow 0.15s; -webkit-appearance: none; appearance: none; }
.field textarea { min-height: 88px; resize: vertical; line-height: 1.4; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { border-color: var(--navy); box-shadow: 0 0 0 3px color-mix(in srgb, var(--navy) 22%, transparent); }
.field input.mono, .field input[inputmode="decimal"] { font-family: var(--mono); }
.field select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2365717F' stroke-width='1.8'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.8rem center; padding-right: 2.2rem; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.money-in { position: relative; }
.money-in::before { content: attr(data-sym); position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-family: var(--mono); pointer-events: none; }
.money-in input, .field .money-in input[type="text"] { padding-left: 1.7rem; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 48px; padding: 0.5rem 0; cursor: pointer; }
.switch .sw { position: relative; width: 46px; height: 28px; border-radius: 14px; background: var(--line-2); flex: none; transition: background 0.2s; }
.switch .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.22s var(--ease); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch input:checked + .sw { background: var(--green); }
.switch input:checked + .sw::after { transform: translateX(18px); }
.switch .sw-l { display: grid; gap: 0.1rem; }
.switch .sw-l .help { font-size: 0.8rem; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { display: inline-flex; align-items: center; gap: 0.3rem; min-height: 38px; padding: 0.35rem 0.8rem; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: all 0.15s; }
.chip:hover { border-color: var(--navy); }
.chip.on { background: var(--navy); border-color: var(--navy); color: var(--navy-ink); }
.chip.add { border-style: dashed; color: var(--navy); }
.pill { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.draft { background: var(--surface-2); color: var(--muted); }
.pill.sent { background: var(--navy-soft); color: var(--navy); }
.pill.paid { background: var(--green-soft); color: var(--green); }
.pill.partial { background: var(--amber-soft); color: var(--amber); }
.pill.overdue { background: var(--red-soft); color: var(--red); }
.pill.void { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
.pill.adv { background: var(--navy); color: var(--navy-ink); }
.pill.simple { background: var(--surface-2); color: var(--ink-2); }

/* Lists */
.list { display: grid; gap: 0.5rem; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 0.8rem; align-items: center; width: 100%; text-align: left; font: inherit; padding: 0.8rem 0.9rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: inherit; cursor: pointer; transition: transform 0.15s var(--ease), box-shadow 0.15s; animation: rise 0.3s var(--ease) both; }
.item:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.item > div { min-width: 0; }
.item .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { font-size: 0.84rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .amt { font-family: var(--mono); font-weight: 600; text-align: right; font-size: 1.02rem; }
.item .amt.due { color: var(--red); }
.item .r { display: grid; justify-items: end; gap: 0.25rem; }
.list .item:nth-child(2) { animation-delay: 0.04s; } .list .item:nth-child(3) { animation-delay: 0.08s; } .list .item:nth-child(4) { animation-delay: 0.12s; } .list .item:nth-child(5) { animation-delay: 0.16s; } .list .item:nth-child(n+6) { animation-delay: 0.2s; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty svg { width: 48px; height: 48px; opacity: 0.5; margin-bottom: 0.5rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 0.5rem 0 0.6rem; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem; }
.stat { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem 0.8rem; }
.stat .v { font-family: var(--mono); font-weight: 600; font-size: clamp(0.88rem, 3.5vw, 1.15rem); letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 420px) { .stat .l { font-size: 0.64rem; letter-spacing: 0.02em; } }
@media (max-width: 380px) { .stats { gap: 0.4rem; } .stat { padding: 0.6rem 0.55rem; } }
.stat .l { font-size: 0.74rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat.red .v { color: var(--red); }
.stat.green .v { color: var(--green); }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--navy); border-radius: 4px; transition: width 0.6s var(--ease); }

/* Tier and tool choice */
.choice { display: grid; gap: 0.75rem; }
.choice .opt { display: grid; gap: 0.3rem; text-align: left; padding: 1rem 1.1rem; border: 2px solid var(--line); border-radius: var(--radius); background: var(--surface); cursor: pointer; transition: border-color 0.15s, transform 0.15s var(--ease), box-shadow 0.15s; }
.choice .opt:hover { border-color: var(--navy); box-shadow: var(--shadow); transform: translateY(-1px); }
.choice .opt .h { display: flex; justify-content: space-between; align-items: baseline; gap: 0.6rem; font-size: 1.1rem; font-weight: 600; }
.choice .opt .price { font-family: var(--mono); color: var(--navy); font-weight: 600; }
.choice .opt .price s { color: var(--muted); font-weight: 400; margin-right: 0.3rem; }
.choice .opt ul { margin: 0.3rem 0 0; padding-left: 1.1rem; color: var(--ink-2); font-size: 0.9rem; line-height: 1.5; }
.choice .opt.adv { border-color: var(--navy); }
.choice .opt.adv .h { color: var(--navy); }

/* Wizard */
.wiz { max-width: 640px; margin: 0 auto; padding: 0.6rem 1rem 7rem; }
.wiz .prog { display: flex; gap: 4px; margin: 0.4rem 0 1rem; }
.wiz .prog i { flex: 1; height: 4px; border-radius: 2px; background: var(--line); transition: background 0.3s; }
.wiz .prog i.done { background: var(--navy); }
.wiz .prog i.now { background: var(--navy); opacity: 0.55; }
.wiz .q { font-size: 1.45rem; font-weight: 600; letter-spacing: -0.015em; margin: 0.2rem 0 0.4rem; line-height: 1.2; }
.wiz .why { color: var(--muted); margin-bottom: 1rem; }
.wiz .step { animation: rise 0.3s var(--ease); display: grid; gap: 0.8rem; }
.wiz-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: flex; gap: 0.6rem; padding: 0.7rem 1rem calc(0.7rem + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.wiz-nav .btn.primary { flex: 1; }
.wiz .lines-ed { display: grid; gap: 0.6rem; }
.wiz .line { display: grid; gap: 0.5rem; padding: 0.8rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); animation: pop 0.25s var(--ease); }
.wiz .line .nums { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.5rem; }
.wiz .line .nums.adv { grid-template-columns: 1fr 1fr 1.2fr; }
.wiz .line .foot { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.wiz .line .lamt { font-family: var(--mono); font-weight: 600; }
.wiz .picked { display: grid; gap: 0.2rem; padding: 0.8rem 0.9rem; border-radius: var(--radius); background: var(--navy-soft); color: var(--ink); }
.sig-wrap { border: 1px dashed var(--line-2); border-radius: var(--radius); background: #fff; position: relative; overflow: hidden; }
.sig-wrap canvas { display: block; width: 100%; height: 180px; touch-action: none; }
.sig-wrap .base { position: absolute; left: 1rem; right: 1rem; bottom: 2.2rem; border-top: 1px solid #c9cfd8; pointer-events: none; }
.sig-wrap .x { position: absolute; left: 0.6rem; bottom: 2.3rem; color: #c9cfd8; font-size: 0.9rem; pointer-events: none; }
.sig-wrap .hint { position: absolute; left: 0; right: 0; bottom: 0.4rem; text-align: center; font-size: 0.75rem; color: #9aa3ae; pointer-events: none; }
.sig-saved img { max-height: 70px; max-width: 240px; display: block; }

/* ---------- The invoice (live editor and read-only preview) ---------- */
.inv-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.7rem; }
.inv-tools .spacer { flex: 1; }
.inv-note { font-size: 0.85rem; color: var(--muted); margin: 0 0 0.7rem; }
.inv-bar { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.55rem 0.8rem; border-radius: var(--radius); background: var(--navy-soft); color: var(--ink); font-size: 0.88rem; margin-bottom: 0.7rem; }
.inv-bar b { font-weight: 600; }
.inv-bar.warn { background: var(--amber-soft); }
.inv { --accent: #1C3F7A; position: relative; background: #fff; color: #1a2330; border: 1px solid var(--line); box-shadow: var(--shadow-lg); padding: 1.6rem 1.7rem 1.3rem; font-size: 0.9rem; line-height: 1.42; font-family: var(--sans); border-radius: 4px; animation: pop 0.3s var(--ease); }
.inv h2, .inv h3 { margin: 0; }
.inv h3 { font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700; color: #6b7684; margin-bottom: 0.3rem; }
.inv b { font-weight: 600; }
.inv .ed { display: block; min-width: 2ch; outline: none; border-radius: 3px; padding: 0 0.15em; margin: 0 -0.15em; white-space: pre-wrap; overflow-wrap: anywhere; transition: background-color 0.15s, box-shadow 0.15s; cursor: text; }
.inv .ed.inl, .inv .ed.b { display: inline; }
.inv .ed:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.inv .ed:focus { background: color-mix(in srgb, var(--accent) 9%, transparent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }
.inv .ed:empty::before { content: attr(data-ph); color: #9aa3ae; font-style: italic; font-weight: 400; pointer-events: none; }
.inv .ed.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.inv .ed.num.inl { display: inline; text-align: left; }
.inv .ed.b { font-weight: 600; }
.inv .add { font: inherit; font-size: 0.72rem; font-weight: 600; color: var(--accent); background: transparent; border: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 999px; padding: 0.15rem 0.6rem; cursor: pointer; line-height: 1.5; white-space: nowrap; }
.inv .add:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); border-style: solid; }
.inv .add.adv::after { content: "Advanced"; margin-left: 0.4rem; font-size: 0.6rem; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.75; }
.inv .adds { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }
.inv .adds.right { justify-content: flex-end; }
.inv .rm { font: inherit; font-size: 1rem; line-height: 1; color: #9aa3ae; background: transparent; border: 0; cursor: pointer; padding: 0 0.25rem; vertical-align: middle; }
.inv .rm:hover { color: var(--red); }
.inv .tax { font: inherit; font-size: 0.6rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; line-height: 1; padding: 0.25rem 0.4rem; border-radius: 999px; border: 1px solid #c9cfd8; background: #fff; color: #9aa3ae; cursor: pointer; }
.inv .tax[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.inv-top { display: grid; grid-template-columns: 1fr auto; gap: 1.2rem; align-items: start; border-bottom: 3px solid var(--accent); padding-bottom: 1rem; margin-bottom: 1.1rem; }
.inv-biz { display: grid; gap: 0.1rem; align-content: start; }
.inv-biz .bn { font-size: 1.35rem; font-weight: 600; color: var(--accent); line-height: 1.15; margin-bottom: 0.2rem; }
.inv-biz .bc { color: #5a6573; font-size: 0.84rem; }
.inv .logo-wrap { position: relative; display: inline-block; margin-bottom: 0.5rem; width: fit-content; }
.inv .logo-wrap img { max-height: 60px; max-width: 200px; width: auto; height: auto; display: block; }
.inv .logo-rm { position: absolute; top: -8px; right: -14px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); }
.inv .logo-add { width: fit-content; margin-bottom: 0.6rem; }
.inv-title { text-align: right; display: grid; justify-items: end; gap: 0.3rem; }
.inv-title h2 { font-size: 1.9rem; letter-spacing: 0.1em; text-transform: uppercase; line-height: 1; color: var(--accent); font-weight: 700; }
.inv .color-pick { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.72rem; color: #9aa3ae; cursor: pointer; position: relative; }
.inv .color-pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.inv .color-pick i { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15); }
.inv-meta { display: grid; grid-template-columns: auto auto; gap: 0.15rem 0.9rem; font-size: 0.86rem; justify-content: end; margin: 0.3rem 0 0; }
.inv-meta > div { display: contents; }
.inv-meta dt { color: #5a6573; text-align: right; }
.inv-meta dd { margin: 0; font-weight: 600; text-align: right; font-family: var(--mono); font-size: 0.84rem; }
.inv-meta dd .ed { display: inline-block; text-align: right; min-width: 6ch; }
.inv-meta .big dd { font-size: 1rem; }
.inv .dt { position: relative; display: inline-block; cursor: pointer; border-radius: 3px; padding: 0 0.15em; margin: 0 -0.15em; }
.inv .dt:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.inv .dt input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.inv .dt .ph { color: #9aa3ae; font-style: italic; font-weight: 400; }
.inv .sel { position: relative; display: inline-block; }
.inv .sel select { font: inherit; font-weight: 600; color: inherit; border: 0; background: transparent; padding: 0 1.1em 0 0.15em; margin: 0 -0.15em; cursor: pointer; appearance: none; -webkit-appearance: none; border-radius: 3px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239aa3ae' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.1em center; }
.inv .sel select:hover { background-color: color-mix(in srgb, var(--accent) 7%, transparent); }
.inv .sel-text { display: none; }
.inv-parties { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1.1rem; margin-bottom: 1.1rem; }
.inv-parties > div { min-width: 0; }
.inv-parties .bn { font-weight: 600; }
.inv .period { margin-top: 0.3rem; font-size: 0.84rem; color: #5a6573; }
.inv-lines { width: 100%; border-collapse: collapse; margin-bottom: 0.8rem; }
.inv-lines th, .inv-lines td { padding: 0.4rem 0.4rem; border-bottom: 1px solid #e4e8ee; vertical-align: top; }
.inv-lines th { font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: #fff; background: var(--accent); text-align: left; }
.inv-lines th.num, .inv-lines td.num { text-align: right; white-space: nowrap; font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 0.86rem; }
.inv-lines td.num .ed { display: inline-block; min-width: 4ch; }
.inv-lines td .t { color: #9aa3ae; font-size: 0.68rem; margin-left: 0.3rem; }
.inv-lines .ctl { width: 1%; white-space: nowrap; text-align: right; }
.inv-lines .ld { min-height: 1.3em; }
.inv-lines .addrow td { border-bottom: 0; padding-top: 0.5rem; }
.inv-sum { display: grid; grid-template-columns: minmax(0, 1fr) minmax(14rem, 17rem); gap: 1.2rem; align-items: start; margin-bottom: 1.1rem; }
.inv-totals { display: grid; gap: 0.15rem; }
.inv-totals > div { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: 0.1rem 0.4rem; }
.inv-totals > div > span:last-child, .inv-totals > div > .ed { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.inv-totals .quiet { color: #9aa3ae; }
.inv-totals .total { border-top: 1px solid #c9cfd8; margin-top: 0.3rem; padding-top: 0.4rem; font-weight: 600; }
.inv-totals .due { background: var(--accent); color: #fff; font-weight: 700; font-size: 1.02rem; padding: 0.5rem 0.6rem; margin-top: 0.4rem; border-radius: 4px; }
.inv-totals .adds { justify-content: flex-end; }
.inv-prog { border: 1px solid #e4e8ee; border-radius: 6px; padding: 0.7rem 0.8rem; font-size: 0.84rem; }
.inv-prog > div { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: 0.1rem 0; }
.inv-prog > div > span:first-child { white-space: nowrap; }
.inv-prog > div > span:last-child, .inv-prog > div > .ed { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; }
.inv-prog .bar { height: 6px; border-radius: 3px; background: #e4e8ee; margin: 0.4rem 0 0.2rem; overflow: hidden; display: block; padding: 0; }
.inv-prog .bar i { display: block; height: 100%; background: var(--accent); }
.inv-pay { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1.1rem; border-top: 1px solid #e4e8ee; padding-top: 1rem; font-size: 0.84rem; }
.inv-sig { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1.1rem; margin-top: 1.1rem; font-size: 0.84rem; }
.inv-sig .sig-img { height: 54px; display: block; }
.inv-sig .line { border-top: 1px solid #1a2330; margin-top: 1.9rem; padding-top: 0.25rem; color: #5a6573; font-size: 0.78rem; }
.inv-sig .line.signed { margin-top: 0.2rem; }
.inv-fine { margin-top: 1rem; font-size: 0.72rem; color: #5a6573; white-space: pre-wrap; }
.inv-foot { margin-top: 1.3rem; padding-top: 0.7rem; border-top: 1px solid #e4e8ee; display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; font-size: 0.72rem; color: #9aa3ae; }
.inv-foot b { color: #5a6573; font-weight: 600; }
.inv.readonly .ed { cursor: default; }
.inv.readonly .ed:hover { background: none; }
.inv .stamp { position: absolute; right: 8%; top: 22%; padding: 0.4rem 1rem; border: 4px solid; border-radius: 8px; font-size: 2rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; transform: rotate(-14deg); opacity: 0.85; pointer-events: none; mix-blend-mode: multiply; font-family: var(--mono); }
.inv .stamp.paid { color: #1B7F4C; border-color: #1B7F4C; }
.inv .stamp.void { color: #B42318; border-color: #B42318; }
.inv .stamp.slam { animation: slam 0.45s var(--ease); }
@keyframes slam { 0% { transform: rotate(-14deg) scale(2.2); opacity: 0; } 60% { transform: rotate(-14deg) scale(0.96); opacity: 0.9; } 100% { transform: rotate(-14deg) scale(1); opacity: 0.85; } }
@media (max-width: 600px) {
  .inv { padding: 1.1rem 0.9rem; font-size: 0.86rem; }
  .inv-top { grid-template-columns: 1fr; gap: 0.8rem; }
  .inv-title { text-align: left; justify-items: start; }
  .inv-meta { justify-content: start; }
  .inv-meta dt, .inv-meta dd { text-align: left; }
  .inv-meta dd .ed { text-align: left; }
  .inv-sum { grid-template-columns: 1fr; }
  /* Line items as stacked rows: the description, then qty, unit, rate and the amount on one line. */
  .inv-lines thead { display: none; }
  .inv-lines, .inv-lines tbody { display: block; }
  .inv-lines tr { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.15rem 0.7rem; padding: 0.45rem 0; border-bottom: 1px solid #e4e8ee; }
  .inv-lines tr.addrow { border-bottom: 0; }
  .inv-lines td { display: block; border: 0; padding: 0; }
  .inv-lines td:first-child { flex-basis: 100%; }
  .inv-lines td.num::before { content: attr(data-l); font-family: var(--sans); font-size: 0.62rem; font-weight: 600; color: #9aa3ae; margin-right: 0.3rem; text-transform: uppercase; letter-spacing: 0.06em; }
  .inv-lines td.amt { margin-left: auto; font-weight: 600; }
  .inv-lines td.ctl { flex-basis: auto; }
  .inv-lines td.num .ed { min-width: 3ch; }
}

/* Sheets, toasts */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; background: rgba(10, 16, 24, 0.5); animation: fade 0.2s; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet { width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; overflow: auto; background: var(--surface); border-radius: 18px 18px 0 0; padding: 0.7rem 1.1rem calc(1.2rem + env(safe-area-inset-bottom)); animation: up 0.3s var(--ease); box-shadow: var(--shadow-lg); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line-2); margin: 0 auto 0.8rem; }
.sheet h2 { margin-bottom: 0.3rem; }
.sheet .actions { display: grid; gap: 0.5rem; margin-top: 1rem; }
@media (min-width: 640px) { .sheet-wrap { align-items: center; padding: 1rem; } .sheet { border-radius: 18px; } }
.toast { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; background: var(--ink); color: var(--bg); padding: 0.6rem 1rem; border-radius: 999px; font-size: 0.9rem; font-weight: 500; box-shadow: var(--shadow-lg); animation: up 0.3s var(--ease); max-width: calc(100% - 2rem); text-align: center; }
.toast.out { animation: fade 0.25s reverse forwards; }
body.has-tabs .toast { bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); }

/* Desktop: the tab bar becomes a left rail */
@media (min-width: 900px) {
  body.has-tabs { padding-bottom: 0; padding-left: 200px; }
  .tabs { top: 0; bottom: 0; right: auto; width: 200px; height: auto; grid-template-columns: 1fr; align-content: start; padding: 1rem 0.6rem; gap: 0.2rem; border-top: 0; border-right: 1px solid var(--line); background: var(--surface); }
  .tabs a { flex-direction: row; justify-content: flex-start; gap: 0.7rem; padding: 0.6rem 0.8rem; border-radius: 10px; font-size: 0.95rem; }
  .tabs a.on { background: var(--navy-soft); }
  .tabs a.on::before { display: none; }
  .tabs a .dot { top: 10px; right: 10px; }
  .tabs .rail-brand { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.8rem 1rem; font-weight: 700; font-size: 1.05rem; }
  .tabs .rail-brand img { width: 30px; height: 30px; border-radius: 8px; }
  .hdr { padding-left: 1rem; }
  .hdr .brand { display: none; }
  .wiz-nav { left: 200px; }
  .toast { bottom: 24px; }
}
@media (max-width: 899px) { .tabs .rail-brand { display: none; } }

/* Print: the invoice alone. A preview that is not unlocked prints with a watermark. */
@media print {
  @page { size: letter; margin: 0.5in; }
  body { background: #fff !important; padding: 0 !important; }
  .hdr, .tabs, .inv-tools, .inv-note, .inv-bar, .wiz-nav, .toast, .sheet-wrap, .inv .add, .inv .adds, .inv .rm, .inv .tax, .inv .color-pick, .inv .dt input, .inv .sel select, .inv-lines .ctl, .no-print { display: none !important; }
  .inv .sel-text { display: inline; }
  .inv .ed:empty { display: none; }
  .inv .ed, .inv .dt { background: none !important; box-shadow: none !important; }
  .inv-lines thead { display: table-header-group; }
  .inv-lines, .inv-lines tbody { display: table; width: 100%; }
  .inv-lines tbody { display: table-row-group; }
  .inv-lines tr { display: table-row; }
  .inv-lines td { display: table-cell; border-bottom: 1px solid #e4e8ee; padding: 0.28rem 0.35rem; }
  .inv-lines td.num::before { content: none; }
  .view { max-width: none; padding: 0; animation: none; }
  .inv { box-shadow: none; border: 0; padding: 0; font-size: 10pt; line-height: 1.35; animation: none; }
  .inv-lines th, .inv-totals .due, .inv-prog .bar i, .inv .tax[aria-pressed="true"] { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .inv.locked::after { content: "PREVIEW"; position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) rotate(-30deg); font-size: 90pt; font-weight: 700; color: rgba(180, 35, 24, 0.18); letter-spacing: 0.2em; pointer-events: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
