/* ---------------------------------------------------------------------------
   Bokhald stylesheet.

   Plain CSS, no build step and no framework: what you read here is exactly
   what the browser gets. Colours are defined once as variables at the top,
   so changing the look means editing a handful of lines.
   --------------------------------------------------------------------------- */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #dfe3e8;
  --border-strong: #c4cbd4;
  --text: #16202b;
  --text-muted: #5d6b7a;
  --text-faint: #8a97a5;

  --brand: #1d4e78;
  --brand-dark: #143854;
  --brand-light: #e8f0f7;

  --ok: #14804a;
  --ok-bg: #e7f5ee;
  --warn: #9a6200;
  --warn-bg: #fdf3e2;
  --bad: #b3261e;
  --bad-bg: #fdecea;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1620;
    --surface: #17202c;
    --surface-2: #1c2733;
    --border: #2a3644;
    --border-strong: #3a4858;
    --text: #e6ecf2;
    --text-muted: #a3b1c0;
    --text-faint: #7d8b9a;
    --brand: #6aa6d8;
    --brand-dark: #8fc0e8;
    --brand-light: #1b2c3d;
    --ok: #5fd39a;
    --ok-bg: #14301f;
    --warn: #e8b45c;
    --warn-bg: #33280f;
    --bad: #f2837c;
    --bad-bg: #3a1c1a;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }

/* --------------------------------------------------------------- layout -- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: .6rem;
  padding: 0 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: .75rem;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: .95rem; flex: 0 0 34px;
}
.brand-text { min-width: 0; }
.brand-name { font-weight: 600; font-size: .95rem; }
.brand-sub {
  font-size: .72rem; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.nav-group { padding: .4rem 0; }
.nav-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); padding: .4rem 1.25rem .2rem; font-weight: 600;
}
.nav a {
  display: flex; align-items: center; gap: .6rem;
  padding: .45rem 1.25rem;
  color: var(--text-muted); font-size: .9rem;
  border-left: 3px solid transparent;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active {
  background: var(--brand-light); color: var(--brand);
  border-left-color: var(--brand); font-weight: 600;
}
.nav .icon { width: 18px; text-align: center; opacity: .85; flex: 0 0 18px; }
.nav .badge { margin-left: auto; }

.sidebar-foot { margin-top: auto; padding: 1rem 1.25rem 0; border-top: 1px solid var(--border); }
.sidebar-foot .who { font-size: .78rem; color: var(--text-faint); margin-bottom: .5rem; word-break: break-all; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.75rem; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar h1 { margin: 0; }
.topbar .spacer { flex: 1; }

.content { padding: 1.5rem 1.75rem 3rem; max-width: 1180px; width: 100%; }

/* ---------------------------------------------------------------- cards -- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: .75rem;
  padding: .85rem 1.15rem; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card-head h2 { margin: 0; font-size: .98rem; }
.card-head .spacer { flex: 1; }
.card-body { padding: 1.15rem; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* ------------------------------------------------------------ key stats -- */

.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.15rem; box-shadow: var(--shadow);
}
.stat .label {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); font-weight: 600; margin-bottom: .35rem;
}
.stat .value { font-size: 1.55rem; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: .85rem; font-weight: 500; color: var(--text-faint); margin-left: .2rem; }
.stat .hint { font-size: .78rem; color: var(--text-muted); margin-top: .25rem; }
.stat.good .value { color: var(--ok); }
.stat.bad .value { color: var(--bad); }
.stat.brand .value { color: var(--brand); }

/* --------------------------------------------------------------- tables -- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .55rem .8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); font-weight: 600; background: var(--surface-2);
  white-space: nowrap; position: sticky; top: 0;
}
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.mono, .mono { font-family: var(--mono); font-size: .84em; }
tfoot td { font-weight: 600; background: var(--surface-2); border-top: 2px solid var(--border-strong); }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions form { display: inline; }

.empty { padding: 2.5rem 1.15rem; text-align: center; color: var(--text-faint); }
.empty .big { font-size: 1.6rem; margin-bottom: .4rem; }

/* --------------------------------------------------------------- badges -- */

.badge {
  display: inline-block; padding: .1rem .5rem; border-radius: 999px;
  font-size: .72rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.brand { background: var(--brand-light); color: var(--brand); border-color: transparent; }

/* -------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem .9rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: .87rem; font-weight: 500;
  cursor: pointer; font-family: inherit; line-height: 1.4;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.small { padding: .25rem .6rem; font-size: .8rem; }
.btn.link { border-color: transparent; background: transparent; color: var(--brand); padding: .25rem .4rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- forms -- */

.field { margin-bottom: 1rem; }
.field label, .label {
  display: block; font-size: .82rem; font-weight: 600;
  margin-bottom: .3rem; color: var(--text);
}
.field .help { font-size: .78rem; color: var(--text-muted); margin-top: .3rem; }

input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], input[type=search], select, textarea {
  width: 100%; padding: .5rem .65rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: .9rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand);
}
input[type=file] { font-size: .85rem; }
textarea { min-height: 80px; resize: vertical; }

.field-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.check { display: flex; align-items: flex-start; gap: .5rem; margin-bottom: .6rem; }
.check input { margin-top: .25rem; flex: 0 0 auto; width: auto; }
.check label { font-weight: 500; margin: 0; }

.radio-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.radio-row label {
  display: flex; align-items: center; gap: .4rem;
  padding: .4rem .75rem; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); cursor: pointer; font-weight: 500; font-size: .87rem;
  margin: 0;
}
.radio-row input { width: auto; }
.radio-row label:has(input:checked) { border-color: var(--brand); background: var(--brand-light); color: var(--brand); }

.filters {
  display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end;
  padding: .85rem 1.15rem; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.filters .field { margin: 0; }
.filters input, .filters select { min-width: 140px; }

/* ------------------------------------------------------------- messages -- */

.alert {
  padding: .7rem 1rem; border-radius: var(--radius-sm);
  margin-bottom: 1rem; font-size: .88rem; border: 1px solid transparent;
}
.alert.success { background: var(--ok-bg); color: var(--ok); }
.alert.error { background: var(--bad-bg); color: var(--bad); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.info { background: var(--brand-light); color: var(--brand); }
.alert ul { margin: .3rem 0 0; padding-left: 1.2rem; }

.note {
  background: var(--surface-2); border-left: 3px solid var(--brand);
  padding: .7rem .9rem; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: .85rem; color: var(--text-muted); margin-bottom: 1rem;
}
.note strong { color: var(--text); }

/* ------------------------------------------------------------ deadlines -- */

.deadline {
  display: flex; gap: .9rem; align-items: flex-start;
  padding: .8rem 1.15rem; border-bottom: 1px solid var(--border);
}
.deadline:last-child { border-bottom: none; }
.deadline .when {
  flex: 0 0 78px; text-align: center;
  border-radius: var(--radius-sm); padding: .3rem; background: var(--surface-2);
}
.deadline .when .day { font-size: 1.15rem; font-weight: 700; line-height: 1.1; }
.deadline .when .mon { font-size: .7rem; text-transform: uppercase; color: var(--text-faint); }
.deadline .what { flex: 1; min-width: 0; }
.deadline .what .t { font-weight: 600; font-size: .92rem; }
.deadline .what .d { font-size: .82rem; color: var(--text-muted); }
.deadline .side { text-align: right; white-space: nowrap; }
.deadline.is-overdue .when { background: var(--bad-bg); }
.deadline.is-overdue .when .day { color: var(--bad); }
.deadline.is-soon .when { background: var(--warn-bg); }
.deadline.is-soon .when .day { color: var(--warn); }
.deadline.is-done { opacity: .55; }
.deadline.is-done .what .t { text-decoration: line-through; }

/* ---------------------------------------------------------------- chart -- */

.chart { display: flex; align-items: flex-end; gap: .35rem; height: 150px; padding: 0 .25rem; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .25rem; height: 100%; }
.chart .bars { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart .bar { width: 45%; border-radius: 2px 2px 0 0; min-height: 2px; }
.chart .bar.inc { background: var(--brand); }
.chart .bar.exp { background: var(--border-strong); }
.chart .lab { font-size: .68rem; color: var(--text-faint); }
.legend { display: flex; gap: 1rem; font-size: .78rem; color: var(--text-muted); margin-top: .6rem; }
.legend span { display: flex; align-items: center; gap: .35rem; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* ---------------------------------------------------------------- meter -- */

.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: .5rem 0 .35rem; }
.meter .fill { height: 100%; background: var(--brand); border-radius: 999px; }
.meter .fill.warn { background: var(--warn); }
.meter .fill.bad { background: var(--bad); }

/* ------------------------------------------------------------ auth page -- */

.auth-page {
  min-height: 100vh; display: grid; place-items: center;
  padding: 2rem 1rem; background: var(--bg);
}
.auth-box {
  width: 100%; max-width: 430px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(16, 24, 40, .08); padding: 2rem;
}
.auth-box.wide { max-width: 560px; }
.auth-box h1 { text-align: center; margin-bottom: .35rem; }
.auth-box .sub { text-align: center; color: var(--text-muted); font-size: .88rem; margin-bottom: 1.5rem; }
.auth-logo {
  width: 48px; height: 48px; border-radius: 12px; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-weight: 700;
  font-size: 1.15rem; margin: 0 auto 1rem;
}
.code-input {
  font-family: var(--mono); font-size: 1.5rem; letter-spacing: .4em;
  text-align: center; padding: .6rem;
}
.qr-box { text-align: center; padding: 1rem; background: #fff; border-radius: var(--radius-sm); margin-bottom: 1rem; }
.qr-box img { display: block; margin: 0 auto; }
.secret {
  font-family: var(--mono); font-size: .82rem; word-break: break-all;
  background: var(--surface-2); padding: .6rem; border-radius: var(--radius-sm);
  text-align: center; border: 1px dashed var(--border-strong);
}
.codes-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem;
  font-family: var(--mono); font-size: .95rem; margin: 1rem 0;
}
.codes-grid div {
  padding: .45rem; background: var(--surface-2); border-radius: var(--radius-sm);
  text-align: center; border: 1px solid var(--border);
}

.steps { counter-reset: step; list-style: none; padding: 0; margin: 0 0 1rem; }
.steps li {
  counter-increment: step; position: relative; padding-left: 2.1rem;
  margin-bottom: .8rem; font-size: .88rem;
}
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--brand-light); color: var(--brand);
  display: grid; place-items: center; font-size: .75rem; font-weight: 700;
}

/* ---------------------------------------------------------------- guide -- */

.guide { max-width: 820px; }
.guide h2 {
  margin-top: 2rem; padding-bottom: .4rem; border-bottom: 2px solid var(--border);
  font-size: 1.2rem;
}
.guide h3 { margin-top: 1.4rem; color: var(--brand); }
.guide ul, .guide ol { margin: 0 0 1rem; padding-left: 1.3rem; }
.guide li { margin-bottom: .35rem; }
.guide .fo { color: var(--text-faint); font-style: italic; }
.toc { background: var(--surface-2); border-radius: var(--radius-sm); padding: 1rem 1rem 1rem 2.2rem; }
.toc li { margin-bottom: .25rem; }

dl.facts { margin: 0; }
dl.facts div {
  display: flex; gap: 1rem; padding: .5rem 0; border-bottom: 1px solid var(--border);
}
dl.facts div:last-child { border-bottom: none; }
dl.facts dt { flex: 0 0 42%; font-weight: 600; font-size: .85rem; margin: 0; }
dl.facts dd { flex: 1; margin: 0; font-size: .88rem; color: var(--text-muted); }

/* -------------------------------------------------------------- invoice -- */

.invoice-paper {
  background: #fff; color: #16202b; padding: 2.5rem;
  max-width: 800px; margin: 0 auto; border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.invoice-head { display: flex; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.invoice-head .who { font-size: .85rem; line-height: 1.6; }
.invoice-head h1 { font-size: 1.8rem; margin-bottom: .25rem; }
.invoice-meta { text-align: right; font-size: .85rem; line-height: 1.7; }
.invoice-parties { display: flex; justify-content: space-between; gap: 2rem; margin-bottom: 1.5rem; }
.invoice-total-row { display: flex; justify-content: flex-end; margin-top: 1rem; }
.invoice-totals { min-width: 280px; font-size: .9rem; }
.invoice-totals div { display: flex; justify-content: space-between; padding: .35rem 0; }
.invoice-totals div.grand {
  border-top: 2px solid #16202b; margin-top: .3rem; padding-top: .5rem;
  font-weight: 700; font-size: 1.05rem;
}
.invoice-foot { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid #dfe3e8; font-size: .8rem; color: #5d6b7a; }

/* ------------------------------------------------------------ utilities -- */

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: .82rem; }
.tiny { font-size: .74rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.strong { font-weight: 600; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.mb0 { margin-bottom: 0; }
.flex { display: flex; gap: .6rem; align-items: center; }
.flex-between { display: flex; gap: .6rem; align-items: center; justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.hidden { display: none; }

/* ------------------------------------------------- phone / home-screen app */

/* Installed on an iPhone there is no browser chrome, so the app itself has to
   keep clear of the notch and the home indicator. env() is 0 in a normal
   browser window, so these are harmless on desktop. */
@supports (padding: max(0px)) {
  .sidebar { padding-top: max(1.25rem, env(safe-area-inset-top)); }
  .topbar  { padding-top: max(1rem, env(safe-area-inset-top)); }
  .content {
    padding-left: max(1.75rem, env(safe-area-inset-left));
    padding-right: max(1.75rem, env(safe-area-inset-right));
    padding-bottom: max(3rem, calc(env(safe-area-inset-bottom) + 2rem));
  }
  .auth-page { padding-bottom: max(2rem, calc(env(safe-area-inset-bottom) + 1rem)); }
}

/* The one control that matters on a phone: big enough to hit without looking. */
.snap { max-width: 460px; margin: 0 auto; }

.snap-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-height: 210px;
  padding: 2rem 1rem;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition: background .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.snap-button:active {
  background: var(--brand-light);
  border-color: var(--brand);
}
.snap-icon { font-size: 3rem; line-height: 1; }
.snap-label { font-weight: 600; font-size: 1.05rem; color: var(--brand); }
.snap-sub { font-size: .8rem; color: var(--text-faint); }

.install-hint { position: relative; }

/* ------------------------------------------------------------- responsive */

/* The phone bar and the slide-in menu only exist below the phone breakpoint. */
.tabbar, .nav-scrim, .nav-close { display: none; }

/* --- tablet: the sidebar lies down across the top ------------------------ */

@media (min-width: 701px) and (max-width: 1040px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    border-right: none; border-bottom: 1px solid var(--border); padding-bottom: .5rem;
  }
  .nav { display: flex; flex-wrap: wrap; gap: .2rem; padding: 0 .75rem; }
  .nav a { border-left: none; border-radius: var(--radius-sm); padding: .5rem .7rem; }
  .nav a.active { border-left: none; }
  .nav-label { display: none; }
  .sidebar-foot { margin-top: .75rem; }
  .content, .topbar { padding-left: 1rem; padding-right: 1rem; }
}

/* --- phone --------------------------------------------------------------- */

@media (max-width: 700px) {
  .shell { flex-direction: column; }

  /* The sidebar becomes a sheet that slides in from the left. It is closed by
     default and opened by the "Meira" tab linking to #nav - CSS only, so it
     works before any script loads, and the back button closes it. */
  .sidebar {
    position: fixed; z-index: 60; top: 0; bottom: 0; left: 0;
    width: min(86vw, 320px); flex: none; height: 100dvh;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .28);
    padding-top: calc(1rem + env(safe-area-inset-top));
    overscroll-behavior: contain;
  }
  .sidebar:target { transform: translateX(0); }

  .nav-scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(10, 18, 26, .5);
    opacity: 0; pointer-events: none; transition: opacity .22s ease;
  }
  .sidebar:target ~ .nav-scrim { opacity: 1; pointer-events: auto; }

  .nav-close {
    display: grid; place-items: center;
    position: absolute; top: .5rem; right: .5rem;
    width: 44px; height: 44px; border-radius: 50%;
    color: var(--text-muted); font-size: 1.1rem; text-decoration: none;
  }
  .nav-close:hover { background: var(--surface-2); }

  /* Room for a thumb, not a mouse pointer. */
  .nav a { padding: .7rem 1.1rem; font-size: .95rem; }

  .topbar {
    padding: .85rem 1rem;
    position: sticky; top: 0; z-index: 40;
    background: var(--surface);
    padding-top: calc(.85rem + env(safe-area-inset-top));
  }
  .topbar h1 { font-size: 1.05rem; line-height: 1.25; }

  .content {
    padding: 1rem .9rem 1rem;
    /* Clear the bar at the bottom, plus the home indicator on an iPhone. */
    padding-bottom: calc(5.25rem + env(safe-area-inset-bottom));
  }

  /* One column. Two 180px columns on a 390px screen is not two columns, it is
     two things too narrow to read. */
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; gap: .75rem; }

  .card { border-radius: var(--radius-sm); }
  .card-body { padding: .9rem; }
  .card-head { padding: .7rem .9rem; }

  /* 16px exactly. Below that, Safari zooms the whole page in when you tap a
     field and leaves you scrolled sideways - the single most irritating thing
     a web app can do on an iPhone. */
  input[type=text], input[type=email], input[type=password], input[type=date],
  input[type=number], input[type=search], select, textarea {
    font-size: 16px; padding: .65rem .7rem;
  }

  /* Apple's guidance is 44px; these were about 32. */
  .btn { padding: .65rem 1rem; font-size: .95rem; min-height: 44px; }
  .btn.small { padding: .5rem .8rem; font-size: .88rem; min-height: 38px; }
  .btn-row { gap: .5rem; }
  .btn-row .btn { flex: 1 1 auto; justify-content: center; }

  .check input[type=checkbox], .radio-row input[type=radio] {
    width: 22px; height: 22px;
  }

  .deadline { flex-wrap: wrap; }
  .stat .value { font-size: 1.5rem; }

  /* --- tables become stacked rows -------------------------------------- */
  /* A ledger is unreadable through a 390px-wide sideways scroll. Each row
     turns into its own little block, with the column heading carried down
     from data-label on the cell. Tables whose cells carry no data-label are
     left to scroll, which is the right answer for a wide numeric grid. */
  .table-stack thead { display: none; }
  .table-stack table, .table-stack tbody, .table-stack tfoot,
  .table-stack tr, .table-stack td {
    display: block; width: 100%;
  }
  .table-stack tr {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: .6rem .75rem; margin-bottom: .6rem; background: var(--surface);
  }
  .table-stack td {
    border: none; padding: .2rem 0; text-align: left !important;
    display: flex; gap: .75rem; align-items: baseline;
  }
  .table-stack td::before {
    content: attr(data-label);
    flex: 0 0 8.5rem;
    font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-faint); font-weight: 600;
  }
  .table-stack td[data-label=""]::before,
  .table-stack td:not([data-label])::before { content: none; }
  .table-stack td.num { justify-content: flex-start; }
  .table-stack tfoot tr { background: var(--surface-2); font-weight: 600; }
  /* Whether the class sits on the wrapper or above it, stop the sideways
     scroll - there is nothing left to scroll once the rows are stacked. */
  .table-stack.table-wrap, .table-stack .table-wrap { overflow-x: visible; }

  /* --- the bar at the bottom -------------------------------------------- */
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: .15rem; padding: .5rem .2rem .55rem;
    min-height: 56px;
    color: var(--text-muted); text-decoration: none; font-size: .68rem;
  }
  .tabbar a.active { color: var(--brand); }
  .tabbar a:hover { text-decoration: none; }
  .tabbar .ticon { font-size: 1.15rem; line-height: 1; }
  .tabbar .tlabel { line-height: 1; }
  .tabbar .tab-snap .ticon { font-size: 1.35rem; }
  .tabbar .tab-snap.active { color: var(--brand); }
  .tabbar .tdot {
    position: absolute; top: .45rem; right: 50%; margin-right: -.9rem;
    width: 8px; height: 8px; border-radius: 50%; background: var(--warn, #c47f17);
  }

  /* The snap page's own big camera button is the primary action there, so the
     bar stays - it is how you get back out again. */
}

@media (max-width: 700px) and (prefers-color-scheme: dark) {
  .nav-scrim { background: rgba(0, 0, 0, .6); }
}

/* ---------------------------------------------------------------- print -- */

/* ---------------------------------------------------------------- print -- */

@media print {
  .sidebar, .topbar, .no-print, .btn,
  .tabbar, .nav-scrim, .nav-close { display: none !important; }
  body, .invoice-paper { background: #fff; color: #000; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .invoice-paper { box-shadow: none; border: none; padding: 0; max-width: none; }
}
