/* MGMT Bird
   A dark theme in raven blue-black with a seafoam green accent.
   One typeface (Archivo). Pages use the full width of the screen: lists grow
   extra columns, and forms and detail pages put a side panel on the right. */

@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}

:root {
  color-scheme: dark;

  /* Surfaces, darkest to lightest */
  --bg: #0d0f17;
  --side: #090b11;
  --surface: #151925;
  --raised: #1c2130;
  --hover: #232a3c;

  /* Lines */
  --line: #272d40;
  --line-strong: #3a4260;

  /* Text */
  --text: #e9ebf3;
  --muted: #9ca3ba;
  --faint: #626a85;

  /* Accent: seafoam green. Marks the main action on a page and where you are. */
  --accent: #8ee4c4;
  --accent-bright: #b6f2de;
  --accent-ink: #06261d;
  --accent-wash: rgba(142, 228, 196, 0.11);
  --accent-line: rgba(142, 228, 196, 0.42);
  --link: #aab4ff;
  --link-bright: #c9cfff;

  /* Waiting and "check this": a soft periwinkle, so it never reads as approved. */
  --wait: #b3bcff;
  --wait-wash: rgba(170, 180, 255, 0.12);
  --wait-line: rgba(170, 180, 255, 0.42);

  /* Money in, money out, and their washes */
  --gain: #6fdcb0;
  --gain-wash: rgba(111, 220, 176, 0.12);
  --gain-line: rgba(111, 220, 176, 0.4);
  --loss: #ff8377;
  --loss-wash: rgba(255, 131, 119, 0.13);
  --loss-line: rgba(255, 131, 119, 0.45);

  --radius: 8px;
  --radius-lg: 12px;
  --tabs-height: 60px;
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; background: var(--bg); }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 0.97rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3 {
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0;
  text-wrap: balance;
}
h1 { font-size: clamp(1.5rem, 1.25rem + 1vw, 1.9rem); margin-bottom: 1.1rem; }
.page-head h1, .detail-head h1 { margin-bottom: 0; }
h2 { font-size: 1.15rem; margin: 2rem 0 0.75rem; }
h3 { font-size: 1.02rem; }

p { margin: 0 0 0.9rem; }
a { color: var(--link); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--link-bright); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

.num { font-variant-numeric: tabular-nums; }
.neg { color: var(--loss); }
.muted { color: var(--muted); }
.zero { color: var(--faint); }
.pre { white-space: pre-wrap; }
.sr, .skip:not(:focus) {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.skip:focus {
  position: fixed; top: 8px; left: 8px; z-index: 50;
  background: var(--raised); color: var(--text); padding: 0.5rem 0.75rem; border-radius: var(--radius);
}

/* ---------- Shell: top bar + bottom tabs on phones, sidebar on wide screens ---------- */

.side {
  background: var(--side);
  border-bottom: 1px solid var(--line);
  padding: 0.7rem 1rem;
  padding-top: calc(0.7rem + env(safe-area-inset-top));
}
.side a { color: var(--text); text-decoration: none; }
.brand { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.brand-text { display: flex; align-items: baseline; gap: 0.5rem; min-width: 0; }
.brand-name {
  font-weight: 700; font-size: 1.02rem; line-height: 1.2; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.brand-sub { color: var(--accent); font-size: 0.78rem; font-weight: 650; letter-spacing: 0.02em; flex: none; }
/* The MGMT Bird mark: a gull in flight over a ruled line, on a dark tile. */
.brand-mark { width: 30px; height: 30px; flex: none; display: block; }
.brand-mark-tile { fill: var(--raised); stroke: var(--line-strong); stroke-width: 1; }
.brand-mark-bird { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.brand-mark-line { fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; }
.side-nav, .side-foot { display: none; }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: flex;
  background: rgba(9, 11, 17, 0.94);
  backdrop-filter: blur(10px);
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; min-height: var(--tabs-height);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 600;
  position: relative;
}
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current] { color: var(--accent); }
.tabs .count { position: absolute; top: 6px; left: calc(50% + 8px); }

.count {
  display: inline-block; min-width: 1.3rem; padding: 0 0.35rem;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 999px; font-size: 0.72rem; font-weight: 700; text-align: center; line-height: 1.3rem;
  font-variant-numeric: tabular-nums;
}

.main {
  padding: 1.25rem 1rem calc(var(--tabs-height) + 2rem + env(safe-area-inset-bottom));
  min-width: 0;
  container: main / inline-size;
}

@media (min-width: 900px) {
  body.shell { display: grid; grid-template-columns: 15.5rem minmax(0, 1fr); min-height: 100vh; }
  .side {
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    display: flex; flex-direction: column; gap: 1.25rem;
    padding: 1.4rem 0.85rem 1.1rem;
    border-bottom: 0; border-right: 1px solid var(--line);
  }
  .brand { padding: 0 0.45rem 1.1rem; border-bottom: 1px solid var(--line); }
  .brand-mark { width: 34px; height: 34px; }
  .brand-text { flex-direction: column; gap: 0.1rem; }
  .brand-name { white-space: normal; font-size: 1.04rem; }
  .side-nav { display: flex; flex-direction: column; gap: 0.15rem; }
  .side-nav a {
    padding: 0.42rem 0.65rem; border-radius: var(--radius);
    display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
    color: var(--muted); font-weight: 550; font-size: 0.93rem;
  }
  .side-nav a:hover { background: var(--raised); color: var(--text); }
  .side-nav a[aria-current] { color: var(--accent-bright); background: var(--accent-wash); font-weight: 650; }
  .side-nav-flat a { font-weight: 600; font-size: 0.95rem; padding-block: 0.5rem; }

  /* Groups that open and close. A closed group shows the total of its counts. */
  .nav-group > summary {
    list-style: none; cursor: pointer; user-select: none;
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.45rem 0.65rem; border-radius: var(--radius);
    color: var(--text); font-weight: 650; font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase;
  }
  .nav-group > summary::-webkit-details-marker { display: none; }
  .nav-group > summary:hover { background: var(--raised); }
  .nav-group-label { flex: 1; }
  .nav-chevron { width: 14px; height: 14px; flex: none; fill: none; stroke: var(--faint); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.15s; }
  .nav-group[open] > summary .nav-chevron { transform: rotate(90deg); }
  .nav-group[open] > summary .nav-group-count { display: none; }
  .nav-group:not([open]) > summary { color: var(--muted); }
  .nav-group-items { display: flex; flex-direction: column; gap: 1px; padding: 0.1rem 0 0.45rem 0.55rem; margin-left: 0.65rem; border-left: 1px solid var(--line); }
  .nav-group-items a { padding-block: 0.36rem; }
  .nav-group-setup { margin-top: 0.6rem; padding-top: 0.6rem; border-top: 1px solid var(--line); }
  .side-foot {
    display: flex; flex-direction: column; align-items: flex-start; gap: 0.3rem;
    margin-top: auto; padding: 1rem 0.65rem 0; border-top: 1px solid var(--line); font-size: 0.9rem;
  }
  .side-foot a { font-weight: 600; }
  .side-foot a[aria-current] { color: var(--accent-bright); }
  .side-foot .linklike { color: var(--muted); text-decoration: none; }
  .side-foot .linklike:hover { color: var(--text); }
  .tabs { display: none; }
  /* The whole width is used; very large screens stop growing at a readable limit. */
  .main { padding: 1.9rem clamp(1.5rem, 2.6vw, 2.75rem) 4rem; max-width: 118rem; }
}

/* ---------- Signed-out pages ---------- */

body.bare {
  min-height: 100vh;
  background: radial-gradient(60rem 40rem at 50% -10%, #1a2036 0%, var(--bg) 60%) fixed;
}
.bare-main { padding: 8vh 1rem 3rem; }
.auth {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  border-top: 2px solid var(--accent);
  padding: 1.9rem 1.6rem 2rem; max-width: 27rem; margin: 0 auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.auth h1 { margin-bottom: 0.75rem; }
.auth-brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; color: var(--text); margin-bottom: 1rem; font-size: 0.98rem; }
.auth-brand .brand-mark { width: 32px; height: 32px; }
.auth-out { margin-top: 1.25rem; }
.auth-wide { max-width: 34rem; }
.restore { margin-top: 1.5rem; padding-top: 1.1rem; border-top: 1px solid var(--line); }
.restore > summary { cursor: pointer; color: var(--link); font-weight: 600; }
.restore[open] > summary { margin-bottom: 0.7rem; }
.restore .form { margin-top: 0.9rem; }
.narrow > .panel + .panel { margin-top: 1.25rem; }
.input-code { font-size: 1.4rem !important; font-weight: 650; letter-spacing: 0.18em; font-variant-numeric: tabular-nums; max-width: 14rem; }
.qr { margin: 0.7rem 0; }
.setup-key { display: block; width: fit-content; max-width: 100%; margin-top: 0.4rem; overflow-wrap: anywhere; }
.narrow > .hint + .form, .panel > .hint + p { margin-top: 0.85rem; }
.auth-out + .hint { margin-top: 0.9rem; }
.qr svg { display: block; width: 13rem; height: 13rem; border-radius: var(--radius); }
.recovery-codes { list-style: none; margin: 0.8rem 0 1rem; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: 0.45rem 1rem; }
.recovery-codes code { font-size: 1.02rem; font-weight: 650; letter-spacing: 0.04em; user-select: all; }
.bare-main > .flash { max-width: 27rem; margin-inline: auto; }
.bare-main > .narrow { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.75rem 1.5rem; margin: 0 auto; }

/* ---------- Page furniture ---------- */

/* Every page starts the same way: the title and a line about the page on the
   left, its buttons on the right (the main one last), stacked on narrow screens. */
.page-head { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.85rem 2rem; align-items: start; margin-bottom: 1.5rem; }
.page-sub { color: var(--muted); margin: 0.35rem 0 0; max-width: 70ch; }
.page-head > .btn { justify-self: start; }
/* A title with its line underneath, outside a page header, spaces the same way. */
h1:has(+ .page-sub) { margin-bottom: 0; }
h1 + .page-sub { margin-bottom: 1.5rem; }
.page-head h1 + .page-sub { margin-bottom: 0; }
@container main (min-width: 40rem) {
  .page-head:has(> :nth-child(2)) { grid-template-columns: minmax(0, 1fr) auto; }
  .page-head > :nth-child(2) { justify-self: end; }
  .page-head > .head-actions { justify-content: flex-end; padding-top: 0.2rem; }
}
.page-head > .head-actions > .btn-primary, .page-head > .head-actions > form:has(.btn-primary) { order: 1; }

/* The pages within one part of the app (Invoices, Clients, Invoice details). */
.section-tabs {
  display: flex; gap: 0.25rem; margin: -0.35rem 0 1.5rem; border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.section-tabs::-webkit-scrollbar { display: none; }
.section-tabs a {
  padding: 0.55rem 0.8rem 0.65rem; margin-bottom: -1px; white-space: nowrap;
  color: var(--muted); font-weight: 600; font-size: 0.93rem; text-decoration: none;
  border-bottom: 2px solid transparent;
}
.section-tabs a:hover { color: var(--text); border-bottom-color: var(--line-strong); }
.section-tabs a[aria-current] { color: var(--accent-bright); border-bottom-color: var(--accent); }
.lede { color: var(--muted); max-width: 65ch; }
.narrow { max-width: 44rem; }
.back { margin-bottom: 0.6rem; font-size: 0.9rem; }
.back a { text-decoration: none; color: var(--muted); font-weight: 600; }
.back a:hover { color: var(--text); }
.back a::before { content: "‹ "; }
.h-total { font-weight: 500; color: var(--muted); font-size: 0.95rem; margin-left: 0.4rem; letter-spacing: 0; }
.head-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* A panel: the basic container for a block of content. */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.15rem 1.25rem; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }

/* Main content with a side panel on wide screens; stacked on narrow ones. */
.split { display: grid; gap: 1.25rem; align-items: start; }
@media (min-width: 1100px) {
  .split { grid-template-columns: minmax(0, 1fr) minmax(20rem, 26rem); gap: 1.5rem; }
  .split-even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .split > .sticky { position: sticky; top: 1.5rem; }
}
.split > * { min-width: 0; }
.split h2:first-child { margin-top: 0; }

.flash, .notice {
  border-radius: var(--radius); padding: 0.7rem 0.95rem; margin: 0 0 1.25rem;
  border: 1px solid; max-width: 70rem;
}
.notice > :last-child { margin-bottom: 0; }
.flash-ok { background: var(--gain-wash); border-color: var(--gain-line); color: #c9f2de; }
.flash-error, .notice-no { background: var(--loss-wash); border-color: var(--loss-line); color: #ffd5d0; }
.notice-wait { background: var(--wait-wash); border-color: var(--wait-line); color: #dfe3ff; }
.notice-key { background: var(--surface); border-color: var(--accent-line); }
.flash a, .notice a { color: inherit; font-weight: 600; }
.notice a.btn { color: var(--text); }
.notice a.btn-primary { color: var(--accent-ink); }
.secret { font-size: 1.1rem; font-weight: 700; background: var(--accent-wash); color: var(--accent-bright); padding: 0.15rem 0.5rem; border-radius: 5px; user-select: all; }

.empty {
  border: 1px dashed var(--line-strong); border-radius: var(--radius-lg);
  padding: 2rem 1.5rem; color: var(--muted); background: var(--surface);
}
.empty > :last-child { margin-bottom: 0; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  min-height: 2.6rem; padding: 0.45rem 1rem;
  font: inherit; font-weight: 600; line-height: 1.2; text-decoration: none; cursor: pointer; white-space: nowrap;
  color: var(--text); background: var(--raised);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.btn:hover { background: var(--hover); border-color: #4a5478; color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-bright); border-color: var(--accent-bright); color: var(--accent-ink); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--link); padding-inline: 0.65rem; }
.btn-quiet:hover { background: var(--raised); border-color: var(--line); color: var(--link-bright); }
.btn-danger { background: #c9453a; border-color: #c9453a; color: #fff; }
.btn-danger:hover { background: #dc5a4e; border-color: #dc5a4e; color: #fff; }
.btn-danger-quiet { background: transparent; border-color: transparent; color: var(--loss); padding-inline: 0.65rem; }
.btn-danger-quiet:hover { background: var(--loss-wash); border-color: var(--loss-line); color: var(--loss); }
.btn-wide { width: 100%; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.linklike { font: inherit; background: none; border: 0; padding: 0; color: var(--link); text-decoration: underline; cursor: pointer; }
summary.btn { list-style: none; }
summary.btn::-webkit-details-marker { display: none; }

/* ---------- Forms ---------- */

.form { display: grid; gap: 1.05rem; }
.field { display: grid; gap: 0.35rem; min-width: 0; border: 0; padding: 0; margin: 0; align-content: start; }
.field-pair { display: grid; gap: 1.05rem; }
@media (min-width: 520px) { .field-pair { grid-template-columns: 1fr 1fr; } }

label, legend { font-weight: 600; font-size: 0.9rem; padding: 0; color: var(--text); }
.optional { font-weight: 400; color: var(--faint); font-size: 0.82rem; }
.hint { color: var(--muted); font-size: 0.88rem; margin: 0; max-width: 70ch; }
.error { color: var(--loss); font-size: 0.9rem; font-weight: 500; margin: 0; }
.error::before { content: "! "; font-weight: 700; }

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea {
  width: 100%; min-height: 2.6rem; padding: 0.5rem 0.75rem;
  font: inherit; color: var(--text); background: var(--raised);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:hover:not(:focus):not([type="checkbox"]):not([type="radio"]):not([type="file"]), select:hover:not(:focus), textarea:hover:not(:focus) { border-color: #4a5478; }
input[type="file"] { font: inherit; max-width: 100%; color: var(--muted); }
input[type="file"]::file-selector-button {
  font: inherit; font-weight: 600; color: var(--text); background: var(--raised);
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 0.45rem 0.85rem; margin-right: 0.75rem; cursor: pointer;
}
input[type="file"]::file-selector-button:hover { background: var(--hover); }
textarea { resize: vertical; min-height: 4.5rem; }
select:disabled { color: var(--faint); background: var(--surface); border-color: var(--line); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
[aria-invalid="true"] { border-color: var(--loss) !important; box-shadow: 0 0 0 1px var(--loss); }
.input-amount { font-size: 1.3rem !important; font-weight: 650; font-variant-numeric: tabular-nums; }

.check, .choice { display: flex; gap: 0.55rem; align-items: flex-start; font-weight: 400; cursor: pointer; }
.check input, .choice input { width: 1.1rem; height: 1.1rem; margin: 0.2rem 0 0; flex: none; accent-color: var(--accent); }
.choice { padding: 0.3rem 0; }
.choice strong { color: var(--text); }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-top: 0.3rem; }
.form-danger { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
/* A form shown to someone whose role can look but not change it. */
.form-lock { border: 0; margin: 0; padding: 0; min-width: 0; }
.form-lock :disabled { cursor: default; opacity: 1; }
.view-only { margin-bottom: 1rem; }
.lists-lock .item-add, .lists-lock .item-form .btn { display: none; }

/* The expense form: fields on the left, the receipt on the right. */
.expense-form { display: grid; gap: 1.25rem; align-items: start; }
.expense-fields { display: grid; gap: 1.05rem; }
.receipt-side { display: grid; gap: 1rem; }
@media (min-width: 1100px) {
  .expense-form {
    grid-template-columns: minmax(0, 1fr) minmax(20rem, 28rem); gap: 1.5rem;
    grid-template-areas: "fields scan" "fields receipt" "actions receipt";
    grid-template-rows: auto auto 1fr;
  }
  .expense-form > .scan { grid-area: scan; }
  .expense-form > .expense-fields { grid-area: fields; }
  .expense-form > .receipt-side { grid-area: receipt; }
  .expense-form > .form-actions { grid-area: actions; align-self: start; }
  /* Without the scan box (editing), the receipt panel starts at the top. */
  .expense-form.no-scan { grid-template-areas: "fields receipt" "actions receipt"; grid-template-rows: auto 1fr; }
}

/* Scan a receipt */
.scan { display: grid; gap: 0.55rem; justify-items: start; padding: 1.05rem 1.15rem; background: var(--accent-wash); border: 1px dashed var(--accent-line); border-radius: var(--radius-lg); }
.scan[hidden] { display: none; }
.scan .hint { color: var(--muted); }
.scan-status { margin: 0; font-weight: 500; }
.scan-status:empty { display: none; }
.scan-busy { color: var(--muted); }
.scan-ok { color: var(--gain); }
.scan-warn { color: var(--wait); }
.from-receipt { background: var(--accent-wash) !important; border-color: var(--accent-line) !important; }

/* Line items on the expense form */
.lines { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); padding: 0.9rem 1.05rem 1.05rem; margin: 0; min-width: 0; display: grid; gap: 0.7rem; }
.lines legend { padding: 0 0.4rem; margin-left: -0.4rem; }
.line-rows { display: grid; gap: 0.45rem; }
.line-row { display: grid; grid-template-columns: minmax(0, 1fr) 6.5rem 2.6rem; gap: 0.45rem; align-items: center; }
.line-row input.num, .line-tax input { text-align: right; font-variant-numeric: tabular-nums; }
.line-remove { padding: 0; min-width: 2.6rem; color: var(--muted); }
.line-remove:hover { color: var(--loss); background: var(--loss-wash); border-color: var(--loss-line); }
.line-remove[hidden] { display: block; visibility: hidden; }
.line-foot { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: end; justify-content: space-between; }
.line-tax { grid-template-columns: auto 6.5rem; align-items: center; gap: 0.6rem; margin-right: 3.05rem; margin-left: auto; }
.line-tax label { font-weight: 500; color: var(--muted); }
@media (max-width: 519px) {
  .lines { padding-inline: 0.8rem; }
  .line-row { grid-template-columns: minmax(0, 1fr) 5.4rem 2.2rem; gap: 0.35rem; }
  .line-row input { padding-inline: 0.55rem; }
  .line-remove { min-width: 2.2rem; }
  .line-tax { grid-template-columns: auto 5.4rem; margin-right: 2.55rem; }
}
.line-sum { margin: 0; font-size: 0.9rem; color: var(--muted); }
.line-sum:empty { display: none; }
.line-sum.is-ok { color: var(--gain); }
.line-sum.is-off { color: var(--wait); }

/* Line items on the expense page */
.lines-shown { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.lines-shown tfoot th, .lines-shown tfoot td { border-bottom: 0; padding-block: 0.3rem; color: var(--muted); font-weight: 500; font-size: 0.92rem; }
.lines-shown tfoot tr:first-child > * { border-top: 1px solid var(--line-strong); padding-top: 0.6rem; }
.lines-shown tfoot tr:last-child > * { padding-bottom: 0.7rem; }
.lines-shown .lines-total > * { color: var(--text); font-weight: 700; }
.lines-gap { margin-top: 0.5rem; color: var(--wait); }

.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.label-row .hint { text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.vendor-new[hidden] { display: none; }

/* A small question on top of the page, such as "Add this vendor?" */
.dialog {
  width: min(28rem, calc(100vw - 2rem)); padding: 1.3rem 1.35rem 1.4rem;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.dialog:not([open]) { display: none; } /* for browsers too old to know what a dialog is */
.dialog::backdrop { background: rgba(5, 6, 10, 0.66); }
.dialog h2 { margin: 0; font-size: 1.2rem; }
.dialog p { margin: 0; }
.dialog [hidden] { display: none; }

.receipt-preview { display: grid; gap: 0.5rem; }
.receipt-preview[hidden] { display: none; }
.receipt-preview img, .receipt-preview canvas { display: block; width: 100%; height: auto; max-height: 34rem; object-fit: contain; border-radius: var(--radius); background: #0a0c12; border: 1px solid var(--line); }
.receipt-preview figcaption, .receipt-name { color: var(--muted); font-size: 0.88rem; overflow-wrap: anywhere; }
figure { margin: 0; }

/* ---------- Filters ---------- */

.filters { margin-bottom: 1rem; }
.filters > summary { cursor: pointer; font-weight: 600; color: var(--link); padding: 0.35rem 0; width: fit-content; }
.filters > summary:hover { color: var(--link-bright); }
.filter-form {
  display: grid; gap: 0.8rem 1rem; padding: 1rem 1.1rem; margin-top: 0.4rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); align-items: end;
}
.field-grow { grid-column: span 2; }
.filter-actions { display: flex; gap: 0.5rem; }
@media (max-width: 519px) { .field-grow { grid-column: 1 / -1; } .filter-actions { grid-column: 1 / -1; } }

/* ---------- Tiles: the key figures at the top of a page ---------- */

.tiles { display: grid; gap: 0.85rem; margin: 0 0 1.5rem; padding: 0; list-style: none; grid-template-columns: repeat(auto-fit, minmax(9.75rem, 1fr)); }
.tile {
  display: grid; gap: 0.3rem; align-content: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1rem 1.15rem;
  color: var(--text); text-decoration: none;
}
a.tile:hover { border-color: var(--line-strong); background: var(--raised); color: var(--text); }
.tile dt, .tile-label { color: var(--muted); font-size: 0.86rem; font-weight: 500; }
.tile dd, .tile-value { margin: 0; font-weight: 700; font-size: clamp(1.25rem, 1.05rem + 0.9vw, 1.8rem); line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile-note, .tile dd.tile-note { color: var(--muted); font-size: 0.84rem; font-weight: 400; letter-spacing: 0; line-height: 1.4; }
.tile-key { border-color: var(--accent-line); background: linear-gradient(180deg, var(--accent-wash), transparent 70%), var(--surface); }
.tile-key dt, .tile-key .tile-label { color: var(--accent-bright); }
.tile-alert { border-color: var(--loss-line); }
.fig-sub { font-weight: 500; font-size: 0.95rem; color: var(--muted); margin-left: 0.4rem; letter-spacing: 0; }

/* ---------- Lists of expenses and income ---------- */

.list-total { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem 1rem; color: var(--muted); margin-bottom: 0.6rem; font-size: 0.92rem; }
.list-total strong { color: var(--text); }

.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; container-type: inline-size; }
.rows > li + li { border-top: 1px solid var(--line); }
.row {
  display: grid; gap: 0.15rem 1rem; align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "main amount" "date status";
  padding: 0.75rem 1rem; color: var(--text); text-decoration: none;
}
.row:hover { background: var(--raised); color: var(--text); }
.row-date { grid-area: date; color: var(--muted); font-size: 0.86rem; font-variant-numeric: tabular-nums; }
.row-main { grid-area: main; min-width: 0; display: grid; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-status { grid-area: status; justify-self: end; }
.row-amount { grid-area: amount; font-weight: 650; text-align: right; }
.row-cell, .rows-head { display: none; }
/* A list switches to one line per row once the list itself is wide enough. */
@container (min-width: 38rem) {
  .row { grid-template-columns: 6rem minmax(0, 1fr) auto 7.5rem; grid-template-areas: "date main status amount"; }
}
/* When the page is wide enough, the expense list spreads its details into
   columns. This follows the width of the content area, not the whole screen. */
@container main (min-width: 66rem) {
  .rows-wide .row, .rows-head {
    display: grid; gap: 0 1rem; align-items: center;
    grid-template-columns: 6rem minmax(9rem, 1.3fr) minmax(10rem, 1.3fr) minmax(7.5rem, 0.9fr) minmax(6.5rem, 0.7fr) 10.5rem 7rem;
    grid-template-areas: none;
  }
  .rows-wide .row > * { grid-area: auto; }
  .rows-wide .row-sub { display: none; }
  .rows-wide .row-cell { display: block; color: var(--muted); font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rows-wide .row-status { justify-self: start; }
  .rows-wide.no-who .row, .rows-head.no-who {
    grid-template-columns: 6rem minmax(9rem, 1.3fr) minmax(10rem, 1.4fr) minmax(6.5rem, 0.8fr) 10.5rem 7rem;
  }
  .rows-head { padding: 0 1rem 0.45rem; color: var(--faint); font-size: 0.8rem; font-weight: 600; }
  .rows-head > :last-child { text-align: right; }
}

.chip {
  display: inline-block; padding: 0.12rem 0.6rem; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.chip-wait { background: var(--wait-wash); color: var(--wait); border-color: var(--wait-line); }
.chip-ok { background: var(--gain-wash); color: var(--gain); border-color: var(--gain-line); }
.chip-owed { background: transparent; color: var(--gain); border-color: var(--gain); }
.chip-done { background: var(--raised); color: var(--muted); border-color: var(--line-strong); }
.chip-no { background: var(--loss-wash); color: var(--loss); border-color: var(--loss-line); }

.pager { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-top: 1rem; }
.pager > :last-child { justify-self: end; }
.pager > :first-child { justify-self: start; }
.pager-where { color: var(--muted); font-size: 0.9rem; }

/* ---------- One expense ---------- */

.detail-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 0.5rem 1.5rem; margin-bottom: 0.75rem; }
.detail-sub { color: var(--muted); margin: 0.3rem 0 0; }
.detail-amount { font-weight: 700; font-size: clamp(1.9rem, 1.4rem + 2.4vw, 2.6rem); line-height: 1; margin: 0; letter-spacing: -0.02em; }

.facts { margin: 1.1rem 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.facts > div { display: grid; grid-template-columns: 9.5rem minmax(0, 1fr); gap: 0.75rem; padding: 0.6rem 1rem; }
.facts > div + div { border-top: 1px solid var(--line); }
.facts dt { color: var(--muted); font-size: 0.9rem; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts-tight { margin: 0.75rem 0 0; }
@media (max-width: 420px) { .facts > div { grid-template-columns: 1fr; gap: 0; } }

.decide { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: flex-start; margin: 1rem 0; }
.reject[open] { flex-basis: 100%; }
.reject[open] > summary { margin-bottom: 0.75rem; }
.reject .form { padding: 1rem; background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius); max-width: 34rem; }

.receipt { display: block; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #0a0c12; }
.receipt img { display: block; width: 100%; height: auto; max-height: 46rem; object-fit: contain; }

.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 1.4rem 0 0; padding-top: 1.2rem; border-top: 1px solid var(--line); }

.history { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line-strong); }
.history li { padding: 0.15rem 0 0.75rem 1rem; position: relative; display: grid; }
.history li::before { content: ""; position: absolute; left: -6px; top: 0.5rem; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
.history-when { color: var(--muted); font-size: 0.86rem; }

/* ---------- Approvals ---------- */

.queue { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 25rem), 1fr)); align-items: start; }
.queue-item { background: var(--surface); border: 1px solid var(--line); border-top: 2px solid var(--wait); border-radius: var(--radius-lg); padding: 1rem 1.1rem; }
.queue-item p { margin-bottom: 0.4rem; }
.queue-top { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.queue-title { font-weight: 700; font-size: 1.08rem; color: var(--text); text-decoration: none; letter-spacing: -0.01em; }
.queue-title:hover { color: var(--accent-bright); }
.queue-meta { color: var(--muted); font-size: 0.9rem; }
.queue-amount { font-weight: 700; font-size: 1.35rem; line-height: 1.1; white-space: nowrap; letter-spacing: -0.02em; }
.queue-cat { color: var(--muted); font-size: 0.92rem; }
.queue .decide { margin: 0.8rem 0 0; }
.queue .notice { margin: 0.5rem 0; padding: 0.5rem 0.75rem; font-size: 0.92rem; }

.owed-groups { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 28rem), 1fr)); align-items: start; }
/* ---------- Bank ---------- */

.week-seg { flex-wrap: wrap; }
.week-seg a { gap: 0.4rem; }
.week-seg a.is-empty { color: var(--faint); font-weight: 500; }
.week-seg a[aria-current] .count { background: var(--accent-ink); color: var(--accent-bright); }
.week-account { display: flex; gap: 0.4rem; align-items: center; }
.week-account select { width: auto; min-width: 11rem; }
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.3rem 1rem; }
.section-head h2 { margin-bottom: 0.3rem; }
.section-hint { margin-bottom: 0.9rem; }
.bank-desc { color: var(--text); overflow-wrap: anywhere; margin: 0 0 0.15rem; }
.bank-link { margin: 0.7rem 0 0; padding: 0.75rem 0.85rem 0.85rem; background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius); display: grid; gap: 0.6rem; justify-items: start; }
.bank-link legend { margin-bottom: 0.2rem; }
.bank-link .choice { padding: 0.2rem 0; }
.bank-peek { margin-left: 0.35rem; font-size: 0.88rem; white-space: nowrap; }
.bank-row { display: grid; gap: 0.15rem 1rem; align-items: center; padding: 0.6rem 1rem; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "main amount" "date status" "undo undo"; }
.bank-row .row-title { color: var(--text); white-space: normal; overflow-wrap: anywhere; }
.bank-row a.row-title { text-decoration: none; }
.bank-row a.row-title:hover { color: var(--accent-bright); text-decoration: underline; }
.bank-row .row-status { display: flex; flex-wrap: wrap; gap: 0.3rem; justify-content: flex-end; }
.bank-undo { grid-area: undo; justify-self: end; }
.bank-undo .btn { min-height: 2.1rem; padding-block: 0.25rem; }
@container (min-width: 44rem) {
  .bank-row { grid-template-columns: 6rem minmax(0, 1fr) auto 7.5rem 6.5rem; grid-template-areas: "date main status amount undo"; }
}
.bank-admin { margin-top: 2rem; }
.bank-span { font-size: 0.86rem; flex: 0 1 auto; }
.bank-confirm { margin: 0 0 1.5rem; }
.bank-swap { padding: 0 1rem 0.6rem; font-size: 0.88rem; }
.sign-groups { display: grid; gap: 1rem 2rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); margin-top: 0.8rem; }
.sign-group ul { margin: 0 0 0.7rem; padding-left: 1.1rem; color: var(--muted); }
.sign-group p { margin-bottom: 0.4rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Removing lines: tick boxes, the bar under the lists, and the Removed list. */
.section-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.75rem; }
.tick-all { display: inline-flex; align-items: center; gap: 0.45rem; color: var(--muted); font-size: 0.9rem; font-weight: 600; cursor: pointer; padding: 0.3rem 0; }
.tick-all[hidden] { display: none; }
.tick-all:hover { color: var(--text); }
.bank-tick { grid-area: tick; display: flex; align-items: center; justify-content: center; width: 1.75rem; min-height: 2rem; cursor: pointer; }
.bank-tick input, .tick-all input { width: 1.1rem; height: 1.1rem; margin: 0; flex: none; accent-color: var(--accent); cursor: pointer; }
.bank-top { justify-content: flex-start; }
.bank-top-main { flex: 1; min-width: 0; }
.bank-top .bank-tick { flex: none; margin: -0.2rem 0 0 -0.4rem; }
.bank-top .queue-amount { margin-left: auto; }
.bank-undo { display: flex; flex-wrap: wrap; gap: 0.2rem; justify-content: flex-end; }
.bank-row.has-tick { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "tick main amount" "tick date status" "tick undo undo"; }
@container (min-width: 44rem) {
  .bank-row.has-tick { grid-template-columns: 1.75rem 6rem minmax(0, 1fr) auto 7.5rem 11.5rem; grid-template-areas: "tick date main status amount undo"; }
}
.bulk-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem;
  margin: 1.5rem 0 0; padding: 0.6rem 0.75rem 0.6rem 1rem;
  background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius-lg);
}
.bulk-text { margin: 0; color: var(--muted); font-size: 0.92rem; }
.bulk-actions { display: flex; gap: 0.4rem; margin-left: auto; }
.bulk-actions .btn[hidden] { display: none; }
.bulk-bar.is-active {
  position: sticky; z-index: 15; bottom: calc(var(--tabs-height) + env(safe-area-inset-bottom) + 0.6rem);
  border-style: solid; border-color: var(--accent-line); background: var(--raised);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.bulk-bar.is-active .bulk-text { color: var(--text); font-weight: 600; }
@media (min-width: 900px) { .bulk-bar.is-active { bottom: 1rem; } }
.bank-removed { margin-top: 2.25rem; }
.bank-removed > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 0.5rem; width: fit-content; }
.bank-removed > summary::-webkit-details-marker { display: none; }
.bank-removed > summary::before {
  content: ""; width: 0.5rem; height: 0.5rem; flex: none; margin-top: -0.15rem;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg);
}
.bank-removed[open] > summary::before { transform: rotate(45deg); margin-top: -0.4rem; }
.bank-removed > summary h2 { margin: 0; color: var(--muted); font-size: 1.05rem; }
.bank-removed > summary:hover h2 { color: var(--text); }
.bank-removed[open] > summary { margin-bottom: 0.6rem; }
.bank-removed .row-title { color: var(--muted); }
.removed-rows .row-sub { white-space: normal; }
.bank-removed-all { margin: 0.8rem 0 0; font-size: 0.92rem; }
p.bank-removed-all { margin-top: 2rem; }
.bank-removed p.bank-removed-all { margin-top: 0.8rem; }

/* The backup reminder across the top of the page. */
.backup-nag {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.9rem;
  margin: 0 0 1.4rem; padding: 0.45rem 0.6rem 0.45rem 0.8rem;
  border: 1px solid var(--wait-line); border-radius: var(--radius); background: var(--wait-wash);
  color: #dfe3ff; font-size: 0.9rem;
}
.backup-nag-icon { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--wait); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.backup-nag-text { flex: 1 1 14rem; }
.backup-nag .btn { min-height: 2rem; }
.backup-nag-more { color: var(--muted); font-size: 0.86rem; }
.backup-nag-more:hover { color: var(--text); }
.backup-last { color: var(--muted); }
.backup-last strong { color: var(--text); }
.backup-remind { margin-top: 1.25rem; padding-top: 1.1rem; border-top: 1px solid var(--line); }
.inline-pick { display: flex; gap: 0.5rem; align-items: center; }
.inline-pick select { width: auto; flex: 0 1 14rem; }

.owed-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem 1rem; margin-bottom: 0.6rem; }

/* ---------- Receipts uploaded in bulk ---------- */

.upload-page { max-width: 52rem; }
.upload-form { margin-top: 1.25rem; }
.upload-form > * { min-width: 0; }
.upload-form select { max-width: 100%; }
.drop {
  display: grid; justify-items: center; gap: 0.55rem; text-align: center;
  padding: 1.6rem 1.25rem; border: 1px dashed var(--accent-line); border-radius: var(--radius-lg); background: var(--accent-wash);
}
.drop.is-over { border-style: solid; border-color: var(--accent); background: rgba(142, 228, 196, 0.18); }
.drop > svg { width: 30px; height: 30px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.drop-title { font-weight: 700; font-size: 1.05rem; }
.drop input[type="file"] { max-width: 100%; color: var(--text); }
.drop .hint { max-width: 36rem; margin: 0; }
.upload-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.upload-list[hidden] { display: none; }
.upload-list li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.15rem 1rem; padding: 0.5rem 0.85rem; font-size: 0.92rem; }
.upload-list li + li { border-top: 1px solid var(--line); }
.upload-name { overflow-wrap: anywhere; min-width: 0; }
.upload-note { color: var(--muted); }
.upload-list .is-busy .upload-note { color: var(--text); }
.upload-list .is-ok .upload-note { color: var(--gain); }
.upload-list .is-warn .upload-note { color: var(--wait); }
.upload-status { margin: 0; font-weight: 500; }
.upload-status:empty { display: none; }

.reading-progress { display: grid; gap: 0.5rem; margin-bottom: 1.25rem; }
.reading-progress p { margin: 0; }
.reading-progress progress { width: 100%; height: 0.6rem; accent-color: var(--accent); }

.confirm-clean {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem 1.25rem;
  padding: 0.85rem 1rem 0.85rem 1.15rem; margin-bottom: 1.1rem;
  background: linear-gradient(180deg, var(--accent-wash), transparent 85%), var(--surface);
  border: 1px solid var(--accent-line); border-radius: var(--radius-lg);
}
.confirm-clean p { margin: 0; flex: 1 1 22rem; }

.drafts { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.drafts > li + li { border-top: 1px solid var(--line); }
.draft { display: grid; grid-template-columns: 3.5rem minmax(0, 1fr) auto; gap: 0.2rem 0.9rem; align-items: center; padding: 0.65rem 1rem; color: var(--text); text-decoration: none; }
.draft:hover { background: var(--raised); color: var(--text); }
.draft-thumb { width: 3.5rem; height: 3.5rem; border-radius: 6px; overflow: hidden; background: #0a0c12; border: 1px solid var(--line); display: grid; place-items: center; }
.draft-thumb img { width: 100%; height: 100%; object-fit: cover; }
.draft-thumb span { color: var(--muted); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; }
.draft-main { display: grid; gap: 0.15rem; min-width: 0; }
.draft-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-sub { color: var(--muted); font-size: 0.86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.15rem; }
.draft-amount { font-weight: 650; text-align: right; align-self: start; padding-top: 0.1rem; }

.review-form { display: grid; gap: 1.25rem; align-items: start; margin-top: 0.5rem; }
.review-receipt { display: grid; gap: 0.75rem; justify-items: start; }
.review-receipt .receipt { width: 100%; }
.review-receipt .receipt img { max-height: 30rem; }
.pdf-pages { display: grid; gap: 0.6rem; width: 100%; }
.pdf-pages:empty { display: none; }
.pdf-pages canvas { display: block; width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; }
.review-bank { padding: 0.8rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.review-flags ul { margin: 0.2rem 0 0; padding-left: 1.2rem; }
.review-flags li + li { margin-top: 0.15rem; }
@media (min-width: 1100px) {
  .review-form {
    grid-template-columns: minmax(0, 1fr) minmax(20rem, 30rem); gap: 1.5rem;
    grid-template-areas: "fields receipt" "bank receipt" "actions receipt";
    grid-template-rows: auto auto 1fr;
  }
  .review-form > .expense-fields { grid-area: fields; }
  .review-form > .review-bank { grid-area: bank; }
  .review-form > .form-actions { grid-area: actions; align-self: start; }
  .review-form > .review-receipt { grid-area: receipt; position: sticky; top: 1.5rem; max-height: calc(100vh - 3rem); overflow-y: auto; }
  .review-receipt .receipt img { max-height: none; }
}

/* ---------- Splits, shared charges, recurring bills ---------- */

/* Splitting one expense across categories (on the expense form). */
.splits { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); padding: 0 1.05rem; min-width: 0; }
.splits > summary { cursor: pointer; padding: 0.75rem 0; font-weight: 600; font-size: 0.92rem; color: var(--link); width: fit-content; }
.splits > summary:hover { color: var(--link-bright); }
.splits[open] > summary { color: var(--text); padding-bottom: 0.35rem; }
.splits-body { display: grid; gap: 0.7rem; padding-bottom: 1.05rem; }
.split-rows { display: grid; gap: 0.55rem; }
.split-row { display: grid; gap: 0.45rem; grid-template-columns: minmax(0, 1fr) 7rem; grid-template-areas: "cat cat" "sub amount"; }
.split-row [data-split-category] { grid-area: cat; }
.split-row [data-split-sub] { grid-area: sub; }
.split-row input { grid-area: amount; text-align: right; font-variant-numeric: tabular-nums; }
.split-rows .split-row + .split-row { padding-top: 0.55rem; border-top: 1px solid var(--line); }
@media (min-width: 640px) {
  .split-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 7rem; grid-template-areas: "cat sub amount"; }
  .split-rows .split-row + .split-row { padding-top: 0; border-top: 0; }
}
.split-foot { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: center; }
.split-foot .btn[hidden] { display: none; }

/* One bank charge that paid for several expenses. */
.link-several { margin-top: 0.6rem; }
.link-several > summary { cursor: pointer; color: var(--link); font-weight: 600; font-size: 0.92rem; width: fit-content; }
.link-several > summary:hover { color: var(--link-bright); }
.link-several[open] > summary { margin-bottom: 0.1rem; }
.link-several .bank-link { margin-top: 0.5rem; }
.bank-row .row-title a { color: inherit; text-decoration: none; }
.bank-row .row-title a:hover { color: var(--accent-bright); text-decoration: underline; }

/* Recurring bills */
.bills-due { margin-bottom: 2rem; }
.bills-due .queue-item { display: grid; gap: 0.5rem; }
.due-enter { margin-top: 0.3rem; gap: 0.8rem; }
.due-enter .form-actions { margin-top: 0; }
.recurring-rows .row-amount { white-space: nowrap; }

/* ---------- Budget ---------- */

.month-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.75rem; margin: 0 0 0.4rem; }
.month-nav-title { margin: 0; font-size: 1.15rem; min-width: 8.5rem; text-align: center; }
.month-nav-now { font-size: 0.9rem; font-weight: 600; margin-left: auto; }
.month-note { color: var(--muted); font-size: 0.9rem; margin: 0 0 1rem; }

.budget-list { list-style: none; margin: 0 0 2rem; padding: 0; display: grid; gap: 0.6rem; }
.budget-row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 0.85rem 1.05rem 0.9rem; display: grid; gap: 0.5rem; }
.budget-row.is-over { border-color: var(--loss-line); }
.budget-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0.2rem 1rem; }
.budget-name { font-weight: 650; font-size: 1.02rem; color: var(--text); text-decoration: none; }
.budget-name:hover { color: var(--accent-bright); text-decoration: underline; }
.budget-left { margin: 0; font-weight: 650; color: var(--gain); }
.budget-row.is-tight .budget-left { color: var(--wait); }
.budget-row.is-over .budget-left { color: var(--loss); }
.budget-sub { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.2rem 0.9rem; color: var(--muted); font-size: 0.88rem; }
.budget-sub .num { color: var(--text); }

/* The bar: spent, then what's waiting, against the month's budget. */
.meter { display: block; width: 100%; height: 0.6rem; border-radius: 999px; background: var(--raised); border: 1px solid var(--line); overflow: hidden; }
.meter-spent { fill: var(--accent); }
.meter-waiting { fill: var(--wait); opacity: 0.55; }
.is-over .meter-spent { fill: var(--loss); }

@container (min-width: 38rem) {
  .row.budget-plain { grid-template-columns: minmax(0, 1fr) 7.5rem; grid-template-areas: "main amount"; }
}

/* Setting the amounts */
.budget-form { max-width: 52rem; margin-top: 1.25rem; }
.budget-applies { gap: 0.2rem; }
.budget-table { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; container-type: inline-size; }
.budget-head { display: none; }
.budget-line { display: grid; gap: 0.3rem 1rem; padding: 0.75rem 1rem; grid-template-columns: minmax(0, 1fr) 9rem; grid-template-areas: "cat input" "recent input"; align-items: center; }
.budget-line + .budget-line { border-top: 1px solid var(--line); }
.budget-cat { grid-area: cat; display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; font-size: 0.98rem; }
.budget-recent { grid-area: recent; display: flex; flex-wrap: wrap; gap: 0.1rem 0.9rem; color: var(--muted); font-size: 0.85rem; }
.budget-recent .num { color: var(--text); }
.budget-input { grid-area: input; display: grid; gap: 0.25rem; }
.budget-input input { text-align: right; font-variant-numeric: tabular-nums; }
@container (min-width: 40rem) {
  .budget-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) 9rem; gap: 1rem; padding: 0.6rem 1rem; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 0.82rem; font-weight: 600; }
  .budget-head span:last-child { text-align: right; }
  .budget-line { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) 9rem; grid-template-areas: "cat recent input"; }
}

/* What's left, under the category on the expense form, and on approvals */
.budget-left[data-budget-left] { margin: -0.4rem 0 0; font-weight: 500; font-size: 0.9rem; color: var(--gain); }
.budget-left[data-budget-left][hidden] { display: none; }
.budget-left[data-budget-left].is-over { color: var(--wait); }
.queue-budget { color: var(--gain); font-size: 0.9rem; }
.queue-budget.is-over { color: var(--wait); }

/* ---------- Inventory ---------- */

.btn-small { min-height: 2.1rem; padding: 0.25rem 0.75rem; font-size: 0.88rem; }
.inv-section { margin-top: 2.25rem; }
.inv-page { max-width: 46rem; }
.inv-form { margin-top: 1rem; }
.cell-sub { display: block; color: var(--muted); font-size: 0.8rem; font-weight: 400; white-space: normal; }

/* Wide tables scroll inside their box, so the page itself never gets wider than the screen. */
.table-scroll { position: relative; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); margin-bottom: 1rem; }
.plain.inv-table th, .plain.inv-table td { vertical-align: middle; padding: 0.55rem 0.65rem; }
.plain.inv-table thead th { white-space: normal; line-height: 1.25; }
.plain.inv-table tbody th { color: var(--text); font-size: 0.92rem; white-space: normal; min-width: 9rem; }
.plain.inv-table td:nth-child(2) { white-space: normal; min-width: 7rem; }
.inv-table tbody th a { font-weight: 650; }
.inv-table td { white-space: nowrap; }
.inv-table tbody tr:target { background: var(--accent-wash); }
.inv-actions { text-align: right; }
.ext { width: 0.7rem; height: 0.7rem; margin-left: 0.3rem; vertical-align: baseline; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }

/* Cost, qty and the unit price worked out from them. */
.inv-price { display: grid; gap: 0.8rem; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
.inv-price input { text-align: right; }
.inv-unit { gap: 0.35rem; }
.inv-unit-label { font-weight: 600; font-size: 0.9rem; }
.inv-unit-value { display: flex; align-items: center; justify-content: flex-end; min-height: 2.6rem; padding: 0.5rem 0.75rem; border-radius: var(--radius); background: var(--accent-wash); border: 1px solid var(--accent-line); color: var(--accent-bright); font-weight: 700; }
.inv-price-hint { margin-top: -0.5rem; }
@media (max-width: 419px) { .inv-price { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .inv-unit { grid-column: 1 / -1; } }

.inv-dialog { width: min(40rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); overflow-y: auto; }
.dialog .form { gap: 0.95rem; }

/* Where the money goes: the controls, then the pie beside its table. */
.inv-controls { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 0.75rem; }
.inv-empty { padding: 1.25rem 1.5rem; }
.pie-figure { margin: 0; display: grid; gap: 1.25rem; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.25rem; }
.pie { display: block; width: 100%; max-width: 16rem; height: auto; margin: 0 auto; overflow: visible; }
.pie-slice { stroke: var(--surface); stroke-width: 2; stroke-linejoin: round; cursor: default; }
.pie-slice:hover, .pie-slice:focus-visible { opacity: 0.85; outline: none; }
.pie-slice:focus-visible { stroke: var(--text); }
.pie-total-label { font-family: var(--font); font-size: 12px; fill: var(--muted); }
.pie-total { font-family: var(--font); font-size: 19px; font-weight: 700; fill: var(--text); }
.plain.pie-legend tbody th, .plain.pie-legend tfoot th { color: var(--text); font-size: 0.92rem; white-space: normal; }
.plain.pie-legend tfoot th, .plain.pie-legend tfoot td { border-top: 1px solid var(--line-strong); font-weight: 700; }
.legend-name { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.swatch { width: 0.75rem; height: 0.75rem; flex: none; }
.pie-legend .cell-sub { padding-left: 1.25rem; }
@media (min-width: 760px) { .pie-figure { grid-template-columns: minmax(12rem, 16rem) minmax(0, 1fr); } }

/* The weekly adjustment. */
.adjust-form { margin-top: 1.25rem; max-width: 60rem; }
.adjust-when { max-width: 40rem; }
.plain.adjust-table tbody th { color: var(--text); font-size: 0.92rem; white-space: normal; min-width: 9rem; }
.adjust-table tbody th label { font-weight: 650; }
.plain.adjust-table tfoot th, .plain.adjust-table tfoot td { border-top: 1px solid var(--line-strong); font-weight: 700; color: var(--text); }
.plain.adjust-table td, .plain.adjust-table th { vertical-align: middle; }
.adjust-input input { width: 6.5rem; text-align: right; }
.adjust-input .error { display: block; white-space: normal; text-align: left; }
.adjust-total { text-align: right; }
.adjust-total .tile-label { margin: 0 0 0.3rem; }
.inv-history a { color: var(--link); }

/* Importing items. */
.import-columns { margin: 1.25rem 0 0.5rem; }
.import-columns h2 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.import-list { margin: 0.75rem 0 0; display: grid; gap: 0.45rem; }
.import-list > div { display: grid; grid-template-columns: 12rem minmax(0, 1fr); gap: 0.75rem; font-size: 0.9rem; }
.import-list dt { font-weight: 650; }
.import-list dd { margin: 0; color: var(--muted); }
@media (max-width: 519px) { .import-list > div { grid-template-columns: 1fr; gap: 0; } }
.import-paste { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.85rem; white-space: pre; overflow-x: auto; }
.input-date { max-width: 14rem; }
.import-confirm { margin: 0 0 1.25rem; max-width: 56rem; }
.plain.import-table th, .plain.import-table td { vertical-align: top; }
.plain.import-table tbody th { color: var(--text); font-size: 0.92rem; white-space: normal; min-width: 9rem; }
.plain.import-table td { white-space: nowrap; }
.import-problem th, .import-problem td { background: var(--loss-wash); }
.plain.import-table tr:has(+ .import-note-row) > * { border-bottom: 0; padding-bottom: 0.2rem; }
.plain.import-table .import-note-row td { white-space: normal; padding-top: 0; }
.import-notes { margin: 0; padding-left: 1.1rem; color: #ffd5d0; font-size: 0.86rem; max-width: 60rem; }
.import-notes .import-warn { color: var(--wait); }
.import-notes .import-same { color: var(--muted); }
.empty-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }

/* ---------- Profit & loss ---------- */

.pnl-controls { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: center; margin-bottom: 1.4rem; }
.pnl-move { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-left: auto; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.seg a { padding: 0.4rem 0.8rem; min-height: 2.2rem; display: flex; align-items: center; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 0.9rem; white-space: nowrap; border-radius: 7px; }
.seg a:hover { color: var(--text); background: var(--raised); }
.seg a[aria-current] { background: var(--accent); color: var(--accent-ink); }

.headline { margin-bottom: 1.5rem; }
.headline .tiles { margin-bottom: 0.6rem; }
.headline-when { color: var(--muted); margin-bottom: 0.5rem; font-weight: 600; font-size: 0.9rem; }
.headline-note { color: var(--muted); font-size: 0.9rem; margin: 0; }

.chart { margin: 0 0 1.5rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1rem 1.15rem 0.6rem; }
.chart figcaption { font-weight: 700; font-size: 1rem; letter-spacing: -0.01em; margin-bottom: 0.5rem; }
.chart-scroll { overflow-x: auto; }
.chart svg { display: block; width: 100%; min-width: 56rem; height: auto; max-height: 24rem; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis-zero { stroke: var(--line-strong); stroke-width: 1; }
.chart .tick { font-family: var(--font); font-size: 13px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; }
.chart .col:hover .hit, .chart .col:focus-visible .hit { fill: rgba(170, 180, 255, 0.07); }
.chart .col:focus-visible { outline: none; }
.chart .col:focus-visible .hit { stroke: var(--accent); stroke-width: 2; }
/* On very wide screens the chart is drawn larger, so its labels are set smaller to match. */
@container main (min-width: 88rem) { .chart .tick { font-size: 11px; } }
/* Periwinkle and red stay distinguishable with red-green colour blindness; green and red don't. */
.chart .bar-gain { fill: #7b86e8; }
.chart .bar-loss { fill: #e8604f; }

.tip {
  position: fixed; z-index: 40; pointer-events: none;
  background: #f1f2f8; color: #12141d; padding: 0.35rem 0.6rem; border-radius: 6px;
  font-size: 0.84rem; font-weight: 500; font-variant-numeric: tabular-nums; max-width: 16rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}
.tip[hidden] { display: none; }

.ledger-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); margin-bottom: 0.75rem; }
.ledger { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; font-size: 0.93rem; }
.ledger th, .ledger td { padding: 0.45rem 0.8rem; white-space: nowrap; text-align: right; border-bottom: 1px solid var(--line); }
.ledger thead th { font-weight: 600; color: var(--muted); font-size: 0.84rem; border-bottom: 1px solid var(--line-strong); background: var(--surface); padding-block: 0.65rem; }
.ledger thead a { color: var(--link); text-decoration: none; }
.ledger thead a:hover { color: var(--link-bright); text-decoration: underline; }
.ledger .ledger-label {
  text-align: left; position: sticky; left: 0; z-index: 1; background: var(--surface);
  font-weight: 500; min-width: 8rem; max-width: 9.5rem; white-space: normal; line-height: 1.25;
  border-right: 1px solid var(--line);
}
.ledger .ledger-total { font-weight: 650; border-left: 1px solid var(--line); background: var(--surface); }
@media (min-width: 720px) {
  .ledger .ledger-label { max-width: 16rem; min-width: 12rem; }
  .ledger .ledger-total { position: sticky; right: 0; }
}
.ledger .is-current { background: var(--raised); }
.ledger thead .is-current { box-shadow: inset 0 2px 0 var(--accent); }
.ledger thead .is-current a { color: var(--accent-bright); }
.ledger-section th.ledger-label { font-weight: 700; font-size: 0.98rem; padding-top: 1.1rem; color: var(--text); }
.ledger-cat th.ledger-label { font-weight: 600; }
.ledger-sub th.ledger-label { padding-left: 1.75rem; font-weight: 400; color: var(--muted); }
.ledger-sub td { color: var(--muted); }
.ledger-none th.ledger-label { font-weight: 400; color: var(--muted); }
.ledger-sum th, .ledger-sum td { font-weight: 700; border-top: 1px solid var(--line-strong); }
.ledger-sum th.ledger-label { font-weight: 700; }
.ledger-net th, .ledger-net td {
  font-weight: 700; font-size: 1.02rem; padding-block: 0.75rem; color: var(--text);
  border-top: 3px double var(--accent); border-bottom: 3px double var(--accent);
}
.ledger-net th.ledger-label { font-weight: 700; color: var(--accent-bright); }
.ledger-net td.neg { color: var(--loss); }
.ledger-margin td, .ledger-margin th.ledger-label, .ledger-pending td, .ledger-pending th.ledger-label { color: var(--muted); font-weight: 400; }
.ledger tbody:last-child tr:last-child > * { border-bottom: 0; }
.ledger tbody tr:hover > td, .ledger tbody tr:hover > th { background: var(--raised); }
.ledger tbody tr.ledger-section:hover > * { background: var(--surface); }

.plain { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.plain th, .plain td { padding: 0.5rem 0.9rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.plain th { color: var(--muted); font-weight: 600; white-space: nowrap; font-size: 0.84rem; }
.plain tr:last-child td { border-bottom: 0; }
.plain .num { text-align: right; white-space: nowrap; }
.problems { color: var(--text); padding-left: 1.2rem; }

/* ---------- Reports ---------- */

.reports { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); }
.reports > li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.report-form { display: grid; gap: 0.9rem; padding: 1.15rem 1.2rem 1.25rem; height: 100%; grid-template-rows: 1fr auto auto auto; }
.report-what h2 { margin: 0 0 0.3rem; font-size: 1.1rem; }
.report-form .btn { width: 100%; }

.export { display: grid; gap: 1.1rem 2rem; margin-top: 1.5rem; align-items: start; }
.export h2 { margin: 0 0 0.4rem; font-size: 1.1rem; }
.export p { margin: 0 0 0.5rem; max-width: 70ch; }
.export-form { display: grid; gap: 0.9rem; }
@media (min-width: 900px) { .export { grid-template-columns: minmax(0, 1fr) minmax(17rem, 22rem); } }

/* ---------- Team, lists, menus ---------- */

.people, .cats, .items, .subs, .menu { list-style: none; margin: 0; padding: 0; }
.people, .cats, .items { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.people > li + li, .cats > li + li, .items > li + li { border-top: 1px solid var(--line); }
.person summary, .cats summary { cursor: pointer; padding: 0.8rem 1rem; display: flex; flex-wrap: wrap; gap: 0.1rem 0.75rem; align-items: baseline; list-style: none; }
.person summary:hover, .cats summary:hover { background: var(--raised); }
.person summary::after, .cats summary::after { content: "Edit"; margin-left: auto; color: var(--link); font-size: 0.86rem; font-weight: 600; }
.person details[open] > summary::after, .cats details[open] > summary::after { content: "Close"; }
.person summary::-webkit-details-marker, .cats summary::-webkit-details-marker { display: none; }
.person-name, .cat-name { font-weight: 600; }
.person-meta, .cat-count { color: var(--muted); font-size: 0.88rem; }
.person-off .person-name, .is-off .cat-name { color: var(--faint); text-decoration: line-through; }
.person-form { padding: 0.5rem 1rem 0.6rem; }
.person .form-danger { margin: 0.5rem 1rem 1rem; }

/* The lists page lays its sections out side by side when there's room. */
.list-grid { columns: 30rem; column-gap: 1.5rem; }
.list-section { break-inside: avoid; margin-bottom: 2rem; }
.list-section h2 { margin-top: 0; }
.list-section > .hint { margin-bottom: 0.75rem; }
.item-form { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; padding: 0.5rem 1rem; }
.item-form input:not([type="checkbox"]) { flex: 1 1 10rem; width: auto; min-height: 2.35rem; }
.item-form .btn { min-height: 2.35rem; }
.item-form .check { align-items: center; font-size: 0.9rem; color: var(--muted); }
.item-form .check input { margin: 0; }
.item-add { padding-inline: 0; margin-top: 0.6rem; }
.subs { margin: 0 0 0.5rem 1rem; border-left: 2px solid var(--line); }
.subs .item-add { padding-inline: 1rem; margin-top: 0; }
.is-off input:not([type="checkbox"]) { color: var(--faint); }
#vendors details { margin-bottom: 0.5rem; }
#vendors details[open] > summary { margin-bottom: 0.6rem; }

.menu { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); margin: 1rem 0 1.5rem; overflow: hidden; }
.menu-group-h { font-size: 0.8rem; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 1.5rem 0 0.5rem; }
.menu-group-h + .menu { margin-top: 0; }
.more-page h1 { margin-bottom: 0.5rem; }
.more-out { margin-top: 1.5rem; }
.menu li + li { border-top: 1px solid var(--line); }
.menu a { display: grid; padding: 0.8rem 1rem; text-decoration: none; color: var(--text); font-weight: 600; }
.menu a span { font-weight: 400; color: var(--muted); font-size: 0.88rem; }
.menu a:hover { background: var(--raised); }

.steps { padding-left: 1.3rem; margin: 0 0 1.5rem; display: grid; gap: 0.5rem; max-width: 65ch; }

/* ---------- Deleting a category ---------- */

.delete-sub { margin-bottom: 1.25rem; }
.delete-page .panel + .panel, .delete-page .panel + .form { margin-top: 1rem; }
.delete-page .panel h2 { margin: 0 0 0.6rem; font-size: 1.05rem; }
.delete-page .panel .hint + .hint { margin-top: 0.5rem; }
.delete-lines { margin: 0 0 0.8rem; padding-left: 1.2rem; display: grid; gap: 0.2rem; }
.delete-lines li::marker { color: var(--faint); }
.item-form select { width: auto; flex: 0 1 11rem; min-height: 2.35rem; }

/* ---------- Documents ---------- */

.field[hidden], .doc-zoom[hidden], .doc-fallback[hidden] { display: none; }
.doc-dialog { width: min(34rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow-y: auto; }

.doc-attention { max-width: none; }
.doc-attention h2 { margin: 0 0 0.5rem; font-size: 1rem; color: var(--text); }
.doc-attention ul { list-style: none; margin: 0 0 0.6rem; padding: 0; display: grid; gap: 0.35rem; }
.doc-attention li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.6rem; }
.doc-attention li a { color: var(--text); }
.doc-attention-sub { color: var(--muted); font-size: 0.86rem; }
.doc-attention .hint { color: #c8cdf2; }

/* Categories down the side on wide screens; a row to scroll on narrow ones. */
.doc-layout { display: grid; gap: 1.25rem; align-items: start; }
.doc-main { min-width: 0; }
.doc-cats {
  display: flex; gap: 0.4rem; overflow-x: auto; padding-bottom: 0.25rem; margin: 0 -1rem; padding-inline: 1rem;
  scrollbar-width: thin;
}
.doc-cats a {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  padding: 0.45rem 0.8rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-weight: 600; font-size: 0.9rem; text-decoration: none;
}
.doc-cats a:hover { color: var(--text); background: var(--raised); }
.doc-cats a[aria-current] { color: var(--accent-bright); background: var(--accent-wash); border-color: var(--accent-line); }
.doc-cat-name { display: grid; line-height: 1.25; }
.doc-vis { display: none; font-size: 0.75rem; font-weight: 500; color: var(--faint); }
.doc-cat-n { font-size: 0.8rem; font-weight: 600; color: var(--faint); font-variant-numeric: tabular-nums; }
.doc-cats a[aria-current] .doc-cat-n { color: var(--accent); }
@container main (min-width: 52rem) {
  .doc-layout { grid-template-columns: 15rem minmax(0, 1fr); gap: 1.75rem; }
  .doc-cats {
    flex-direction: column; gap: 2px; overflow: visible; margin: 0; padding: 0.4rem;
    position: sticky; top: 1.5rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  }
  .doc-cats a { border: 0; border-radius: var(--radius); background: transparent; padding: 0.5rem 0.7rem; }
  .doc-cats a:first-child { margin-bottom: 0.25rem; }
  .doc-vis { display: block; }
}

.doc-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.25rem; }
.doc-tools input[type="search"] { flex: 1 1 14rem; width: auto; }
.doc-tools select { flex: 0 1 13rem; width: auto; }
.doc-group + .doc-group { margin-top: 1.75rem; }
.doc-group h2 { margin: 0 0 0.6rem; font-size: 1.05rem; display: flex; align-items: baseline; }
.doc-group h2 a { color: var(--text); text-decoration: none; }
.doc-group h2 a:hover { color: var(--accent-bright); }
.doc-group-hint { margin: -0.3rem 0 0.7rem; }
.doc-none { margin: 0; }

.doc-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "badge main" "badge end";
  gap: 0.15rem 0.85rem; align-items: center; padding: 0.7rem 1rem; color: var(--text); text-decoration: none;
}
.doc-row:hover { background: var(--raised); color: var(--text); }
.doc-row > .doc-badge { grid-area: badge; }
.doc-row > .row-main { grid-area: main; }
.doc-row-end { grid-area: end; }
.doc-row-end:empty { display: none; }
@container (min-width: 36rem) {
  .doc-row { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "badge main end"; }
  .doc-row-end { justify-self: end; }
}

/* The file type, as a small label: PDFs warm, pictures green, office files blue. */
.doc-badge {
  display: inline-grid; place-items: center; width: 2.75rem; height: 2.1rem; border-radius: 6px;
  font-size: 0.68rem; font-weight: 750; letter-spacing: 0.04em;
  color: var(--muted); background: var(--raised); border: 1px solid var(--line-strong);
}
.doc-badge-pdf { color: #ffb4ab; background: var(--loss-wash); border-color: var(--loss-line); }
.doc-badge-image { color: var(--gain); background: var(--gain-wash); border-color: var(--gain-line); }
.doc-badge-text, .doc-badge-table { color: var(--wait); background: var(--wait-wash); border-color: var(--wait-line); }
.doc-badge-big { width: 4rem; height: 3rem; font-size: 0.85rem; margin-bottom: 0.9rem; }

/* One document: the file on the left, its details on the right. */
.doc-split { margin-top: 0.75rem; }
@media (min-width: 1100px) { .doc-split { grid-template-columns: minmax(0, 1fr) minmax(17rem, 22rem); } }
.doc-show .detail-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.doc-side .facts { margin-top: 0; }
.doc-side .facts dd .cell-sub { margin-top: 0.1rem; }
.doc-step { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 0.5rem; margin-top: 0.75rem; }
.doc-step > :last-child { justify-self: end; }
.doc-step .btn { max-width: 100%; }
.doc-step-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-step-where { color: var(--muted); font-size: 0.86rem; white-space: nowrap; }
.doc-delete { margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--line); }

.doc-viewer { background: #0a0c12; border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: clip; }
.doc-viewer-bar {
  position: sticky; top: 0; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.5rem 0.75rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
.doc-viewer-status { color: var(--muted); font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.doc-zoom { display: flex; gap: 0.35rem; }
.doc-zoom .btn:disabled { opacity: 0.45; cursor: default; }
/* On a phone the pages run down the page itself; on a wide screen they scroll inside a frame beside the details. */
.doc-pages { display: block; padding: 0.75rem; overflow-x: auto; }
@media (min-width: 900px) { .doc-pages { max-height: max(28rem, calc(100vh - 13rem)); overflow-y: auto; } }
.doc-page { width: 100%; margin: 0 auto 0.75rem; background: #f4f4f6; border-radius: 3px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45); overflow: hidden; }
.doc-page:last-child { margin-bottom: 0; }
.doc-pages.is-zoomed .doc-page { margin-left: 0; }
.doc-page canvas { display: block; width: 100%; height: auto; }
.doc-page.has-problem { display: grid; align-content: center; }
.doc-page-problem { margin: 0; padding: 1.5rem 1rem; text-align: center; color: #3a3f52; font-size: 0.92rem; }
.doc-page-problem a { color: #2d3580; }
.doc-fallback { padding: 0.5rem 0.75rem 0.75rem; }
.doc-image { display: block; background: #0a0c12; border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 0.5rem; }
.doc-image img { display: block; width: 100%; height: auto; max-height: 80vh; object-fit: contain; border-radius: var(--radius); }
.doc-text {
  margin: 0 0 0.75rem; max-height: 75vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
  font-family: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; font-size: 0.86rem; line-height: 1.55;
}
.doc-table-wrap { max-height: 75vh; overflow: auto; }
.doc-table th, .doc-table td { white-space: nowrap; max-width: 22rem; overflow: hidden; text-overflow: ellipsis; }
.doc-table thead th { position: sticky; top: 0; background: var(--surface); }
.doc-noview { text-align: center; display: grid; justify-items: center; padding-block: 2.5rem; }
.doc-noview p { max-width: 50ch; }

/* Roles: the list under Team, and the form that sets what a role can do. */
.role-list .role-item { display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; align-items: center; justify-content: space-between; padding: 0.9rem 1rem; }
.role-main { min-width: 0; flex: 1 1 22rem; }
.role-name { margin: 0; font-size: 1.05rem; }
.role-summary { margin: 0.25rem 0 0; color: var(--muted); max-width: 70ch; }
.role-meta { margin: 0.4rem 0 0; font-size: 0.86rem; color: var(--faint); display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.role-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.role-actions .hint { max-width: 24ch; }
.role-foot { margin-top: 0.9rem; }
.role-form { gap: 1.4rem; }
.role-form-page .page-sub { margin-bottom: 1.25rem; }
.perm-table > .hint { margin-bottom: 0.4rem; }
.perm-row { display: grid; gap: 0.55rem 1.25rem; padding: 0.8rem 0; border-top: 1px solid var(--line); }
@media (min-width: 640px) { .perm-row { grid-template-columns: minmax(0, 1fr) auto; align-items: center; } }
.perm-name { display: block; font-weight: 600; color: var(--text); }
.perm-about { display: block; font-size: 0.85rem; color: var(--muted); margin-top: 0.15rem; max-width: 60ch; }
.perm-choice { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.perm-whose select { width: auto; min-height: 2.35rem; }
.perm-whose[hidden] { display: none; }
.seg-radio label { position: relative; display: flex; }
.seg-radio input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg-radio span { padding: 0.4rem 0.85rem; min-height: 2.2rem; display: flex; align-items: center; color: var(--muted); font-weight: 600; font-size: 0.9rem; white-space: nowrap; border-radius: 7px; }
.seg-radio label:hover span { color: var(--text); background: var(--raised); }
.seg-radio input:checked + span { background: var(--accent); color: var(--accent-ink); }
/* None chosen: plain, so green always means "allowed". */
.seg-radio input[value="none"]:checked + span { background: var(--hover); color: var(--text); }
.seg-radio input:focus-visible + span { outline: 2px solid var(--accent-bright); outline-offset: 2px; }
.check-grid { display: grid; gap: 0.4rem 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr)); }

.doc-cat-list .item-form { padding-block: 0.6rem; }
.doc-cat-count { font-size: 0.86rem; color: var(--muted); white-space: nowrap; }
.doc-cat-add select { flex: 0 1 11rem; }
.doc-cat-form .doc-cat-roles { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; flex: 1 1 100%; border: 0; margin: 0; padding: 0; min-width: 0; }
.doc-cat-form .doc-cat-buttons { display: flex; gap: 0.4rem; margin-left: auto; }
.doc-cat-foot { margin-top: 0.9rem; }
.doc-cat-intro { margin: 0.6rem 0 1.1rem; }

/* Sub-categories under each category on the Categories page. */
.doc-subcats { margin: -0.15rem 1rem 0.7rem; }
.doc-subcats > summary {
  cursor: pointer; list-style: none; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.1rem 0.6rem;
  padding: 0.35rem 0.6rem; border-radius: var(--radius); font-size: 0.9rem;
}
.doc-subcats > summary::-webkit-details-marker { display: none; }
.doc-subcats > summary::before { content: "▸"; color: var(--faint); font-size: 0.8rem; width: 0.7rem; }
.doc-subcats[open] > summary::before { content: "▾"; }
.doc-subcats > summary:hover { background: var(--raised); }
.doc-subcats-label { font-weight: 600; color: var(--link); }
.doc-subcats-names { color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.doc-subcats .subs { margin: 0.3rem 0 0.4rem 0.95rem; }
.doc-subcats .subs .item-form { padding-block: 0.4rem; }
.doc-subcats .doc-cat-buttons { display: flex; gap: 0.4rem; margin-left: auto; }
.doc-subcats-sort { margin: 0 0 0.3rem 0.95rem; }

/* Sub-categories of the chosen category, above its documents. */
.doc-subs { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-bottom: 1rem; }
.doc-subs > a {
  display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.35rem 0.75rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-weight: 600; font-size: 0.88rem; text-decoration: none;
}
.doc-subs > a:hover { color: var(--text); background: var(--raised); }
.doc-subs > a[aria-current] { color: var(--accent-bright); background: var(--accent-wash); border-color: var(--accent-line); }
.doc-subs > a[aria-current] .doc-cat-n { color: var(--accent); }
.doc-subs-tools { display: inline-flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; margin-left: auto; font-size: 0.88rem; }
.doc-subs-tools:empty { display: none; }
.doc-subs-tool { font-weight: 600; white-space: nowrap; }

/* A sub-category's heading inside a category's list: the same look and spacing as a category's. */
.doc-group .doc-sub-h { margin: 1.75rem 0 0.6rem; font-size: 1.05rem; display: flex; align-items: baseline; }
.doc-sub-h a { color: var(--text); text-decoration: none; }
.doc-sub-h a:hover { color: var(--accent-bright); }
.doc-sub-h a:hover .doc-sub-parent { color: inherit; }
.doc-sub-parent { color: var(--muted); font-weight: 600; }
/* Straight under the category's heading (nothing filed in the category itself): no big gap. */
.doc-group > h2 + .doc-sub-h, .doc-group > .doc-group-hint + .doc-sub-h { margin-top: 0.9rem; }

/* Sorting a category's documents: a choice beside each. */
.doc-sort-page .form { margin-top: 1rem; }
.doc-sort-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "badge main" "badge pick";
  gap: 0.4rem 0.85rem; align-items: center; padding: 0.65rem 1rem;
}
.doc-sort-row > .doc-badge { grid-area: badge; align-self: start; }
.doc-sort-row > .row-main { grid-area: main; display: grid; min-width: 0; }
.doc-sort-row > select { grid-area: pick; width: 100%; }
@container (min-width: 34rem) {
  .doc-sort-row { grid-template-columns: auto minmax(0, 1fr) minmax(9rem, 14rem); grid-template-areas: "badge main pick"; }
  .doc-sort-row > .doc-badge { align-self: center; }
}

/* ---------- Invoices ---------- */

.bill-steps { margin: 0.75rem 0 0; padding-left: 1.25rem; display: grid; gap: 0.5rem; max-width: 70ch; }
.bill-steps a { font-weight: 600; }
.bill-states { flex-wrap: wrap; margin-bottom: 0.75rem; max-width: 100%; }
.seg-n { margin-left: 0.4rem; font-size: 0.78rem; font-weight: 600; opacity: 0.75; font-variant-numeric: tabular-nums; }
.bill-void-amount { color: var(--faint); text-decoration: line-through; }
.bill-count { font-size: 0.86rem; white-space: nowrap; }
.bill-hidden { margin-top: 1.25rem; }
.bill-hidden > summary { cursor: pointer; font-weight: 600; color: var(--link); padding: 0.35rem 0 0.6rem; width: fit-content; }

/* The invoice form: details and lines on the left, tax, totals and the printed text on the right. */
.bill-form { display: grid; gap: 1.25rem; align-items: start; }
.bill-main, .bill-side { display: grid; gap: 1.25rem; min-width: 0; }
@media (min-width: 1100px) {
  .bill-form { grid-template-columns: minmax(0, 1fr) minmax(19rem, 24rem); gap: 1.5rem; }
  .bill-side { position: sticky; top: 1.5rem; }
}
.bill-grid { container-type: inline-size; display: grid; gap: 0.45rem; }
.bill-rows { display: grid; gap: 0; }
.bill-row {
  display: grid; gap: 0.4rem; align-items: center;
  grid-template-columns: 4rem minmax(0, 1fr) auto 6rem;
  grid-template-areas: "desc desc desc remove" "qty price taxed amount";
  padding: 0.6rem 0;
}
.bill-row + .bill-row { border-top: 1px solid var(--line); }
.bill-row:first-child { padding-top: 0; }
.bill-desc { grid-area: desc; }
.bill-qty { grid-area: qty; }
.bill-price { grid-area: price; }
.bill-taxed { grid-area: taxed; }
.bill-amount { grid-area: amount; }
.bill-row .line-remove { grid-area: remove; justify-self: end; }
.bill-row input.num { text-align: right; font-variant-numeric: tabular-nums; }
.bill-amount { text-align: right; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bill-taxed { display: flex; align-items: center; gap: 0.35rem; font-weight: 500; font-size: 0.86rem; color: var(--muted); cursor: pointer; padding-inline: 0.2rem; }
.bill-taxed input { width: 1.1rem; height: 1.1rem; margin: 0; accent-color: var(--accent); }
.bill-line-head { display: none; }
.no-tax .bill-taxed, .no-tax .bill-taxed-head { display: none; }
.no-tax .bill-row { grid-template-areas: "desc desc desc remove" "qty price price amount"; }
@container (min-width: 34rem) {
  .bill-row, .bill-line-head {
    grid-template-columns: minmax(0, 1fr) 3.6rem 6.25rem 2.6rem 6.5rem 2.4rem;
    grid-template-areas: "desc qty price taxed amount remove";
    padding: 0.25rem 0;
  }
  .bill-row + .bill-row { border-top: 0; }
  .bill-line-head { display: grid; gap: 0.4rem; color: var(--faint); font-size: 0.8rem; font-weight: 600; padding: 0; }
  .bill-line-head > :nth-child(2), .bill-line-head > :nth-child(3), .bill-line-head > :nth-child(5) { text-align: right; }
  .bill-line-head > :nth-child(4) { text-align: center; }
  .bill-line-head > :nth-child(1) { grid-area: desc; }
  .bill-line-head > :nth-child(2) { grid-area: qty; }
  .bill-line-head > :nth-child(3) { grid-area: price; }
  .bill-line-head > :nth-child(4) { grid-area: taxed; }
  .bill-line-head > :nth-child(5) { grid-area: amount; }
  .bill-line-head > :nth-child(6) { grid-area: remove; }
  .bill-taxed { justify-content: center; }
  .bill-taxed span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .bill-row .line-remove { min-width: 2.4rem; }
  .no-tax .bill-row, .no-tax .bill-line-head {
    grid-template-columns: minmax(0, 1fr) 3.6rem 6.25rem 6.5rem 2.4rem;
    grid-template-areas: "desc qty price amount remove";
  }
}
.bill-row [aria-invalid="true"] { border-color: var(--loss) !important; }
.input-unit { display: flex; align-items: center; gap: 0.5rem; }
.input-unit input { max-width: 8rem; text-align: right; }
.input-unit span { color: var(--muted); font-weight: 600; }
.bill-totals { margin: 0; display: grid; gap: 0.35rem; border-top: 1px solid var(--line); padding-top: 0.85rem; }
.bill-totals > div { display: flex; justify-content: space-between; gap: 1rem; color: var(--muted); }
.bill-totals > div[hidden] { display: none; }
.bill-totals dd { margin: 0; color: var(--text); font-weight: 600; }
.bill-totals .bill-total { color: var(--text); font-weight: 700; font-size: 1.15rem; border-top: 1px solid var(--line-strong); padding-top: 0.45rem; margin-top: 0.2rem; }
.bill-totals .bill-total dd { font-weight: 700; }

/* One invoice */
.bill-state { display: flex; flex-wrap: wrap; gap: 0.4rem 0.75rem; align-items: center; }
.bill-actions { margin: 0.25rem 0 1.25rem; }
.bill-pay { margin-bottom: 1.25rem; }
.bill-pay h2 { font-size: 1.05rem; margin-bottom: 0.75rem; }
.bill-undo { margin: -0.5rem 0 1rem; }
.bill-table td:first-child { white-space: normal; }
.bill-no-tax { display: block; color: var(--muted); font-size: 0.8rem; }
.bill-text { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 0.75rem 1rem; max-width: 70ch; }
.bill-danger { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.bill-aside-action { margin-top: 1rem; }

/* Invoice details: the logo is shown on white, as it prints. */
.bill-logo { display: grid; gap: 0.5rem; justify-items: start; margin-bottom: 1rem; }
.bill-logo img { display: block; max-width: min(100%, 16rem); max-height: 7rem; width: auto; height: auto; object-fit: contain; background: #fff; padding: 0.6rem; border-radius: var(--radius); }
.bill-logo figcaption { color: var(--muted); font-size: 0.88rem; }
.bill-number { max-width: 10rem; font-variant-numeric: tabular-nums; }
.bill-setup > .page-sub { margin-bottom: 1.25rem; }

/* ---------- Events ---------- */

.plan-page { max-width: 62rem; }
.plan-page > .page-sub { margin-bottom: 1.25rem; }
.plan-form { gap: 1.25rem; }
.plan-fieldset { min-width: 0; }
.plan-fieldset > legend { float: left; width: 100%; padding: 0; margin: 0 0 0.25rem; font-size: 1.05rem; font-weight: 700; }
.plan-date { max-width: 12rem; }
.plan-side-h { font-size: 1.05rem; margin: 0; }

/* Rows that repeat: one row on a wide screen, two on a phone. */
.plan-grid { container-type: inline-size; display: grid; gap: 0.45rem; }
.plan-rows { display: grid; }
.plan-row { display: grid; gap: 0.4rem; align-items: center; padding: 0.55rem 0; }
.plan-row + .plan-row { border-top: 1px solid var(--line); }
.plan-row:first-child { padding-top: 0; }
.plan-row .line-remove { grid-area: remove; justify-self: end; }
.plan-row input.num { text-align: right; font-variant-numeric: tabular-nums; }
.plan-row [aria-invalid="true"] { border-color: var(--loss) !important; }
.plan-desc { grid-area: desc; }
.plan-amount { grid-area: amount; }
.plan-cat { grid-area: cat; }
.plan-day-input { grid-area: day; }
.plan-time-input { grid-area: time; }
.plan-who { grid-area: who; }
.plan-name { grid-area: name; }
.plan-role { grid-area: role; }
.plan-line-head { display: none; }
.plan-sum { margin: 0; color: var(--muted); font-size: 0.92rem; }
.plan-sum:empty { display: none; }

.plan-income .plan-row { grid-template-columns: minmax(0, 1fr) 6.5rem 2.4rem; grid-template-areas: "desc amount remove"; }
.plan-cost .plan-row { grid-template-columns: minmax(0, 1fr) 6.5rem 2.4rem; grid-template-areas: "desc desc remove" "cat amount ."; }
.plan-schedule .plan-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 2.4rem; grid-template-areas: "day time remove" "desc desc ."; }
.plan-people-rows .plan-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 2.4rem; grid-template-areas: "who who remove" "name role ."; }
.plan-task-rows .plan-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 2.4rem; grid-template-areas: "desc desc remove" "who day ."; }
.plan-task-rows .plan-row.is-done .plan-desc { text-decoration: line-through; color: var(--muted); }
.plan-people-rows .plan-row:has(.plan-name[hidden]) .plan-role { grid-column: name-start / role-end; }

@container (min-width: 38rem) {
  .plan-row { padding: 0.25rem 0; }
  .plan-row + .plan-row { border-top: 0; }
  .plan-line-head { display: grid; gap: 0.4rem; color: var(--faint); font-size: 0.8rem; font-weight: 600; }
  .plan-cost .plan-row { grid-template-columns: minmax(0, 1fr) 11rem 6.5rem 2.4rem; grid-template-areas: "desc cat amount remove"; }
  .plan-schedule .plan-row, .plan-schedule .plan-line-head { grid-template-columns: 10rem 8rem minmax(0, 1fr) 2.4rem; grid-template-areas: "day time desc remove"; }
  .plan-people-rows .plan-row, .plan-people-rows .plan-line-head { grid-template-columns: 13rem minmax(0, 1fr) 11rem 2.4rem; grid-template-areas: "who name role remove"; }
  .plan-people-rows .plan-row:has(.plan-name[hidden]) .plan-role { grid-column: role; }
  .plan-task-rows .plan-row, .plan-task-rows .plan-line-head { grid-template-columns: minmax(0, 1fr) 11rem 10rem 2.4rem; grid-template-areas: "desc who day remove"; }
}

/* One event */
.plan-status { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0 0 1.5rem; }
.plan-invoice { margin-bottom: 1.25rem; display: grid; gap: 0.6rem; }
.plan-invoice p, .plan-invoice form { margin: 0; }
.plan-invoice form { display: flex; flex-wrap: wrap; gap: 0.5rem 0.9rem; align-items: center; }
.plan-tiles { margin-bottom: 1.75rem; }
.plan-section { margin-top: 2.25rem; }
.plan-section h3 { font-size: 0.98rem; margin: 1.4rem 0 0.6rem; color: var(--text); }
.plan-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.4rem; }
.plan-head h2 { margin: 0; }
.plan-table tbody th, .plan-table tfoot th { color: var(--text); font-weight: 600; font-size: 0.92rem; }
.plan-table-wrap { overflow-x: auto; }
@media (max-width: 519px) {
  .plan-table th, .plan-table td { padding-inline: 0.5rem; font-size: 0.86rem; }
  .plan-table th:first-child, .plan-table td:first-child { padding-left: 0.75rem; }
  .plan-table thead th, .plan-table tbody th { white-space: normal; }
}
.plan-hint { margin-top: 0.6rem; }
.plan-add { margin: 0 0 0.9rem; }
.plan-day { font-size: 0.95rem !important; margin: 1rem 0 0.4rem !important; color: var(--muted) !important; font-weight: 600; }
.plan-times, .plan-people, .plan-tasks { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.plan-times li { display: grid; grid-template-columns: 5.5rem minmax(0, 1fr); gap: 0.75rem; padding: 0.55rem 1rem; }
.plan-times li + li, .plan-people li + li, .plan-tasks li + li { border-top: 1px solid var(--line); }
.plan-time { color: var(--muted); }
.plan-people li { padding: 0.55rem 1rem; display: flex; flex-wrap: wrap; gap: 0.25rem 0.6rem; align-items: center; }
.plan-tasks li { display: grid; grid-template-columns: 2.4rem minmax(0, 1fr); gap: 0.6rem; align-items: start; padding: 0.55rem 1rem 0.55rem 0.6rem; }
.plan-tasks form { margin: 0; }
.plan-tick {
  display: grid; place-items: center; width: 2.2rem; height: 2.2rem; padding: 0; cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--raised); color: transparent;
}
.plan-tick svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
button.plan-tick:hover { border-color: var(--accent-line); color: var(--faint); }
.is-done .plan-tick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.plan-tick:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 2px; }
.plan-task-text { display: grid; gap: 0.1rem; padding-top: 0.3rem; }
.is-done .plan-task-text > span:first-child { text-decoration: line-through; color: var(--muted); }
.plan-task-meta { color: var(--muted); font-size: 0.86rem; }
.plan-aside h2 { font-size: 1.05rem; }
.plan-aside h2 + .facts { margin-top: 0.6rem; }
.plan-aside .facts > div { grid-template-columns: 7rem minmax(0, 1fr); }
.bill-events-h { font-size: 1.05rem; margin-top: 1.5rem; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .row, .side-nav a, .tile, .seg a, input, select, textarea { transition: background-color 0.12s, border-color 0.12s, color 0.12s; }
}

/* Printed pages go back to dark ink on white paper. */
@media print {
  :root {
    color-scheme: light;
    --bg: #fff; --surface: #fff; --raised: #fff; --hover: #fff; --line: #d5d7e0; --line-strong: #9a9eb0;
    --text: #14161f; --muted: #4c5165; --faint: #7a7f93; --accent: #1f7a64; --accent-bright: #16604e; --link: #2d3580;
    --gain: #156a43; --loss: #a8261d;
  }
  .side, .tabs, .pnl-controls, .filters, .btn, .back { display: none !important; }
  html, body, body.shell { display: block; background: #fff; }
  .main { padding: 0; max-width: none; }
  .ledger-wrap, .chart-scroll { overflow: visible; }
  .ledger .ledger-label, .ledger .ledger-total { position: static; }
}

/* ---------- Signatures ---------- */

.label-like { font-weight: 600; font-size: 0.92rem; }
.notice-ok { background: var(--gain-wash); border-color: var(--gain-line); color: #c9f2de; }
.notice-ok a, .notice-wait a { color: inherit; }
.sign-email-note { margin-bottom: 1.25rem; max-width: none; }
.sign-yours { margin-bottom: 1.25rem; max-width: none; }
.sign-yours h2 { margin: 0 0 0.4rem; font-size: 1rem; color: var(--text); }
.sign-yours ul { margin: 0; padding-left: 1.1rem; }
.sign-tabs { margin-bottom: 1rem; max-width: 100%; overflow-x: auto; }
.sign-tabs .doc-cat-n { margin-left: 0.35rem; }
.sign-tabs a[aria-current] .doc-cat-n { color: inherit; }

.sign-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.2rem 1rem; align-items: center; padding: 0.75rem 1rem; color: var(--text); text-decoration: none; }
a.sign-row:hover { background: var(--raised); color: var(--text); }
.sign-row-end { display: grid; justify-items: end; gap: 0.2rem; }
.sign-template { display: grid; gap: 0.6rem; padding: 0.8rem 1rem; }
.sign-template-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.sign-template-actions form { display: contents; }
@container (min-width: 40rem) {
  .sign-template { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
}

/* The new-request form. */
.sign-source { display: grid; gap: 0.45rem; }
.sign-source legend { font-weight: 600; font-size: 0.92rem; margin-bottom: 0.35rem; }
.sign-source-part { margin: 0 0 0.4rem 1.7rem; display: grid; gap: 0.35rem; }
.sign-source-part[hidden], [data-signer-outside][hidden] { display: none; }
.sign-source-fixed { margin: 0; }
.sign-signers, .sign-roles { display: grid; gap: 0.6rem; }
.sign-signer-rows { display: grid; gap: 0.6rem; }
.sign-signer, .sign-role { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; padding: 0.6rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.sign-signer-label:empty { display: none; }
.sign-signer-label { flex: 1 1 100%; font-weight: 650; font-size: 0.9rem; color: var(--accent); }
.sign-signer select, .sign-signer input, .sign-role input, .sign-role select { width: auto; min-height: 2.35rem; }
.sign-who { flex: 1 1 12rem; }
.sign-outside { display: flex; flex-wrap: wrap; gap: 0.45rem; flex: 1 1 100%; }
.sign-outside input { flex: 1 1 10rem; min-width: 0; }
.sign-outside select { flex: 1 1 12rem; }
.sign-role input { flex: 1 1 12rem; }
.sign-role select { flex: 1 1 12rem; }
.sign-signer .line-remove, .sign-role .line-remove { margin-left: auto; }

/* One request. */
.sign-show-main h2 { margin: 1.75rem 0 0.7rem; font-size: 1.1rem; display: flex; align-items: baseline; }
.sign-next { display: grid; gap: 0.75rem; margin-top: 1rem; }
.sign-next p { margin: 0; }
.sign-next .head-actions { justify-content: flex-start; }
.sign-next form { display: inline-flex; }
.sign-problem { color: #ffd5d0; font-weight: 600; }
.sign-done { border-color: var(--gain-line); }
.sign-people { container-type: inline-size; }
.sign-person { padding: 0.8rem 1rem; display: grid; gap: 0.5rem; }
.sign-person-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.5rem; align-items: start; }
.sign-person-head .row-title { white-space: normal; }
.sign-person .hint { margin: 0; }
.sign-link { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.sign-link form { display: contents; }
.sign-link-input { flex: 1 1 16rem; min-width: 0; font-size: 0.86rem; font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--muted); }
.sign-link-actions { display: flex; flex-wrap: wrap; gap: 0.4rem 0.8rem; align-items: center; margin: 0; }
.sign-manage { display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; align-items: center; justify-content: space-between; margin-top: 1rem; }
.sign-by-form { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; font-size: 0.9rem; }
.sign-by-form input { width: auto; min-height: 2.1rem; }
.sign-history { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.45rem; font-size: 0.9rem; }
.sign-history li { display: grid; gap: 0.1rem; }
.sign-history-when { color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.sign-hash { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.78rem; overflow-wrap: anywhere; color: var(--muted); }
.verify-result { margin-top: 1rem; max-width: none; display: grid; gap: 0.4rem; }
.verify-result p { margin: 0; }

/* Pages with places on them: the editor, and the signing page. Pages are white paper whatever the theme. */
.sign-editor-page, .sign-page {
  position: relative; width: 100%; margin: 0 auto 1rem; background: #fff; border-radius: 4px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45); overflow: hidden;
}
.sign-editor-page > canvas, .sign-page > canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.sign-layer { position: absolute; inset: 0; }
.sign-layer > * { position: absolute; box-sizing: border-box; }
.sign-page-label { position: absolute; right: 0.4rem; bottom: 0.3rem; font-size: 0.72rem; color: #6b7186; background: rgba(255, 255, 255, 0.85); padding: 0 0.3rem; border-radius: 3px; pointer-events: none; }

/* The editor. */
.sign-editor-screen { max-width: 60rem; }
.sign-editor { display: grid; gap: 0.75rem; max-width: 60rem; }
.sign-editor-bar {
  position: sticky; top: 0; z-index: 4; display: grid; gap: 0.55rem; padding: 0.7rem 0.8rem;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.sign-editor-who { display: flex; gap: 0.5rem; align-items: center; font-weight: 600; font-size: 0.9rem; }
.sign-editor-who select { width: auto; flex: 1 1 auto; max-width: 22rem; min-height: 2.25rem; }
.sign-editor-tools { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.sign-tool[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.sign-tool-icon { display: inline-block; width: 0.7rem; height: 0.7rem; margin-right: 0.35rem; border-radius: 2px; border: 1.5px solid currentColor; }
.sign-tool-signature { width: 1rem; border-bottom-width: 3px; }
.sign-tool-checkbox { border-radius: 1px; }
.sign-editor-status { margin: 0; font-size: 0.86rem; color: var(--muted); }
.sign-editor-selected {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; padding: 0.55rem 0.8rem; font-size: 0.88rem;
  border: 1px solid var(--accent-line); border-radius: var(--radius); background: var(--accent-wash);
}
.sign-editor-selected[hidden], .sign-editor-selected [hidden] { display: none; }
.sign-editor-selected label { display: inline-flex; gap: 0.4rem; align-items: center; }
.sign-editor-selected select, .sign-editor-selected input:not([type="checkbox"]) { width: auto; min-height: 2rem; }
.sign-editor-selected-what { font-weight: 650; }
.sign-editor-pages { touch-action: pan-y; }
.sign-editor-save {
  position: sticky; bottom: 0; z-index: 4; display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; justify-content: flex-end;
  max-width: 60rem; padding: 0.7rem 0.8rem; margin-top: 0.5rem;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-lg);
}
.sign-editor-save .hint { margin-right: auto; }
@media (max-width: 47.99rem) { .sign-editor-save { bottom: calc(var(--tabs-height) + env(safe-area-inset-bottom, 0px)); } }

.sign-place {
  --c: #2fa58a; --wash: rgba(47, 165, 138, 0.16);
  border: 2px solid var(--c); background: var(--wash); border-radius: 3px; cursor: move; touch-action: none;
  display: flex; align-items: center; overflow: hidden; color: #10131c;
}
.sign-place:focus-visible { outline: 3px solid #1d4ed8; outline-offset: 1px; }
.sign-place.is-selected { box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.55); }
.sign-place-text { font-size: 0.68rem; font-weight: 650; padding: 0 0.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.sign-place-handle { position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px; background: var(--c); cursor: nwse-resize; border-radius: 3px 0 2px 0; }
.sign-place-checkbox .sign-place-handle { width: 9px; height: 9px; }
.owner-c0 { --c: #1f8f75; --wash: rgba(31, 143, 117, 0.18); }
.owner-c1 { --c: #4f5bd5; --wash: rgba(79, 91, 213, 0.16); }
.owner-c2 { --c: #c27c0e; --wash: rgba(194, 124, 14, 0.17); }
.owner-c3 { --c: #c0367a; --wash: rgba(192, 54, 122, 0.15); }
.owner-c4 { --c: #0a7fae; --wash: rgba(10, 127, 174, 0.16); }
.owner-c5 { --c: #5f8f12; --wash: rgba(95, 143, 18, 0.18); }

/* The signing page. */
body.bare:has(.sign-shell) .bare-main { padding-top: 1.25rem; }
.sign-shell { max-width: 56rem; margin: 0 auto; }
.sign-shell > .panel, .sign-intro { max-width: 38rem; margin: 0 auto; display: grid; gap: 0.8rem; }
.sign-intro h1 { margin: 0; }
.sign-intro p { margin: 0; }
.sign-brand { margin: 0 0 0.6rem; font-weight: 700; color: var(--accent); font-size: 0.92rem; text-align: center; }
.sign-message { margin: 0; padding: 0.6rem 0.8rem; border-left: 3px solid var(--accent-line); background: var(--bg); border-radius: 0 var(--radius) var(--radius) 0; }
.sign-consent { align-items: flex-start; gap: 0.6rem; font-size: 0.98rem; }
.sign-consent input { margin-top: 0.2rem; flex: none; }
.sign-about summary { cursor: pointer; color: var(--link); font-weight: 600; font-size: 0.9rem; }
.sign-about p { margin-top: 0.5rem; font-size: 0.9rem; color: var(--muted); }
.sign-code input { font-size: 1.4rem; letter-spacing: 0.2em; max-width: 12rem; font-variant-numeric: tabular-nums; }
.sign-resend { margin: 0; }
.sign-big { font-size: 1.1rem; font-weight: 600; }
.sign-foot { text-align: center; margin: 1.25rem auto 0; }
.sign-doc { display: grid; gap: 0.9rem; }
.sign-top {
  position: sticky; top: 0; z-index: 4; display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; justify-content: space-between;
  padding: 0.65rem 0.9rem; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.sign-top .sign-brand { text-align: left; margin: 0; font-size: 0.8rem; }
.sign-top h1 { margin: 0; font-size: 1.05rem; }
.sign-top-text { min-width: 0; }
.sign-top-actions { display: flex; gap: 0.75rem; align-items: center; margin-left: auto; }
.sign-progress { font-size: 0.86rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sign-instructions { margin: 0; }
.sign-finish { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; justify-content: space-between; padding: 0.9rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.sign-finish .hint { margin: 0; }
.sign-decline summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.sign-decline .form { margin-top: 0.6rem; max-width: 30rem; }

.sign-mine {
  border: 2px solid #e0a100; background: rgba(255, 214, 92, 0.32); border-radius: 3px; color: #10131c;
  display: flex; align-items: stretch;
}
.sign-mine.is-needed { animation: sign-pulse 2.4s ease-in-out infinite; }
.sign-mine.is-done { border-color: #1f8f75; background: rgba(31, 143, 117, 0.08); animation: none; }
.sign-mine-date, .sign-mine-name { border-style: dotted; background: rgba(31, 143, 117, 0.06); border-color: #1f8f75; }
@keyframes sign-pulse { 50% { background: rgba(255, 214, 92, 0.55); } }
@media (prefers-reduced-motion: reduce) { .sign-mine.is-needed { animation: none; } }
.sign-stamp {
  all: unset; box-sizing: border-box; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; cursor: pointer;
  font: 700 0.78rem/1 var(--font); color: #7a4d00; text-transform: uppercase; letter-spacing: 0.04em;
}
.sign-stamp:focus-visible, .sign-check:focus-visible, .sign-input:focus-visible { outline: 3px solid #1d4ed8; outline-offset: 1px; }
.sign-stamp img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; object-position: left center; margin-right: auto; }
/* Typed straight onto the paper: none of the app's own input look (its rule is more specific, so this repeats the attribute). */
.sign-layer input.sign-input:not([type="checkbox"]):not([type="radio"]):not([type="file"]) {
  all: unset; box-sizing: border-box; width: 100%; height: 100%; padding: 0 0.25rem; color: #10131c; font-family: Helvetica, Arial, sans-serif; font-size: 12px;
  background: transparent; border: 0; border-radius: 0; min-height: 0;
}
.sign-layer input.sign-input::placeholder { color: #7a6a3a; }
.sign-layer input.sign-input:hover { border: 0; }
.sign-check { all: unset; box-sizing: border-box; position: relative; width: 100%; height: 100%; display: grid; place-items: center; cursor: pointer; color: #10131c; font-weight: 800; }
/* Tick boxes are small on a phone: the area that takes the tap is bigger than the box. */
.sign-check::before, .sign-stamp::before { content: ""; position: absolute; inset: -10px; }
.sign-stamp { position: relative; }
.sign-auto { display: flex; align-items: center; padding: 0 0.25rem; color: #10131c; font-family: Helvetica, Arial, sans-serif; white-space: nowrap; overflow: hidden; }
.sign-other {
  border: 1.5px dashed #9aa0b4; background: rgba(154, 160, 180, 0.14); border-radius: 3px; color: #4a5068;
  font-size: 0.64rem; font-weight: 600; padding: 0 0.2rem; display: flex; align-items: center; overflow: hidden; white-space: nowrap;
}
.sign-other.is-done { border-style: solid; color: #1f6d5a; }

/* Adopting a signature. */
.sign-adopt { width: min(36rem, calc(100vw - 1.5rem)); }
.sign-adopt .form { gap: 0.8rem; }
.sign-adopt-tabs { width: fit-content; }
.sign-adopt-tabs button { all: unset; padding: 0.4rem 0.8rem; border-radius: 7px; font-weight: 600; font-size: 0.9rem; color: var(--muted); cursor: pointer; }
.sign-adopt-tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.sign-adopt-tabs button:focus-visible { outline: 2px solid var(--accent-bright); }
.sign-adopt-preview, .sign-pad { display: block; width: 100%; height: auto; margin-top: 0.5rem; background: #fff; border-radius: var(--radius); border: 1px solid var(--line-strong); }
.sign-pad { touch-action: none; cursor: crosshair; }
.plan-sign { display: grid; gap: 0.6rem; margin: 0 0 1rem; }
.plan-sign p { margin: 0; }
.plan-sign form { display: flex; flex-wrap: wrap; gap: 0.5rem 0.9rem; align-items: center; }
/* These rows lay out their own columns, not the list's named areas. */
.sign-row > .row-main, .sign-person-head > .row-main, .sign-template > .row-main { grid-area: auto; }
.sign-by-form input { max-width: 11rem; }
.sign-signer .line-remove[hidden], .sign-role .line-remove[hidden] { display: none; }
.sign-signers, .sign-roles, .sign-signer, .sign-role { min-width: 0; max-width: 100%; }
