/* Vineyard Finances — one hand-written stylesheet, in the Metro style
   (Windows 8 / Office 2013): square, flat, thin lowercase headings, colour tiles.
   Colours and fonts are custom properties: light at :root, dark in
   :root[data-theme="dark"]. */

:root {
  color-scheme: light;

  /* colours (light: "Metro Office", after Office 2013 / Excel) */
  --bg: #ffffff;
  --bg-image: none;
  --panel: #ffffff;
  --panel-image: none;
  --text: #262626;
  --muted: #6a6a6a;
  --line: #d4d4d4;
  --panel-border: transparent;
  --accent: #217346;
  --accent-text: #ffffff;
  --accent-soft: #e2efe7;
  --link: #217346;
  --ok: #1d7a3e;
  --error: #b42318;
  --warn-bg: #fff4ce;
  --row-hover: #e9f3ed;
  --backdrop: rgb(0 0 0 / 45%);

  /* shape: square, flat */
  --radius: 0;
  --radius-sm: 0;
  --border-w: 2px;
  --shadow: none;
  --shadow-dialog: none;

  /* type: Segoe UI, big thin lowercase headings. Macs without Segoe UI Light
     get Helvetica Neue Light for the headings. */
  --font: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-head: "Segoe UI Light", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-num: var(--font);
  --font-size: 15px;
  --h1-size: 2.6rem;
  --head-weight: 200;
  --head-transform: lowercase;
  --head-spacing: -.01em;
  --head-color: var(--accent);
  --head-shadow: none;

  /* sidebar and phone top bar */
  --sidebar: 228px;
  --sidebar-bg: #f3f3f3;
  --sidebar-image: none;
  --sidebar-text: var(--text);
  --sidebar-muted: var(--muted);
  --sidebar-border: #e1e1e1;
  --sidebar-hover: #e2e2e2;
  --sidebar-active-bg: var(--accent);
  --sidebar-active-image: none;
  --sidebar-active-text: #ffffff;
  --sidebar-link: var(--link);
  --topbar-bg: var(--sidebar-bg);
  --topbar-text: var(--sidebar-text);

  /* controls */
  --btn-bg: var(--panel);
  --btn-image: none;
  --btn-text: var(--text);
  --btn-border: #ababab;
  --btn-shadow: none;
  --btn-text-shadow: none;
  --primary-bg: var(--accent);
  --primary-image: none;
  --primary-text: var(--accent-text);
  --primary-border: var(--accent);
  --input-bg: var(--panel);
  --input-border: #ababab;
  --input-shadow: none;

  /* tables */
  --th-bg: #f3f3f3;
  --th-image: none;
  --th-text: #444444;
  --th-transform: none;
  --th-spacing: normal;

  /* tiles: the home page's two big actions (1, 2) and the number tiles (3–5),
     in the Office app colours */
  --tile-text: #ffffff;
  --tile-1: #217346;
  --tile-2: #d24726;
  --tile-3: #2b579a;
  --tile-4: #0072c6;
  --tile-5: #7719aa;

  font-family: var(--font);
  font-size: var(--font-size);
  line-height: 1.45;
  color: var(--text);
  background: var(--bg-image), var(--bg);
  background-attachment: fixed;
}

/* Dark: "Metro Graphite", after the 2011 Xbox dashboard. js/mode.js sets
   data-theme from the toggle, or from the system setting until it's used. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1b1b1b;
  --panel: #262626;
  --text: #f0f0f0;
  --muted: #a8a8a8;
  --line: #383838;
  --accent: #52b043;
  --accent-text: #0b1a08;
  --accent-soft: #1f3a1a;
  --link: #6cc95c;
  --row-hover: #303030;
  --ok: #6cc95c;
  --error: #ff7b6b;
  --warn-bg: #3d3414;
  --backdrop: rgb(0 0 0 / 65%);
  --head-color: var(--text);
  --sidebar-bg: #107c10;
  --sidebar-border: #107c10;
  --sidebar-text: #ffffff;
  --sidebar-muted: #b5dcb0;
  --sidebar-hover: rgb(255 255 255 / 12%);
  --sidebar-active-bg: #f0f0f0;
  --sidebar-active-text: #107c10;
  --sidebar-link: #ffffff;
  --btn-bg: #333333;
  --btn-text: #f0f0f0;
  --btn-border: #4a4a4a;
  --input-bg: #1b1b1b;
  --input-border: #4a4a4a;
  --th-bg: var(--panel);
  --th-text: var(--accent);
  --th-transform: lowercase;
  --tile-1: #107c10;
  --tile-2: #3c3c3c;
  --tile-3: #107c10;
  --tile-4: #2d6e2d;
  --tile-5: #4a4a4a;
}

* { box-sizing: border-box; }
body { margin: 0; }
h1, h2, h3 {
  font-family: var(--font-head);
  font-weight: var(--head-weight);
  text-transform: var(--head-transform);
  letter-spacing: var(--head-spacing);
  color: var(--head-color);
  text-shadow: var(--head-shadow);
}
h1 { font-size: var(--h1-size); margin: 0; }
h2 { font-size: 1.1rem; margin: 1.2em 0 .5em; }
h3 { font-size: 1rem; margin: 1em 0 .4em; }
a { color: var(--link); }
.muted { color: var(--muted); }
.small { font-size: .82em; }
.error { color: var(--error); }
.ok { color: var(--ok); }
.num { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.stack > * + * { margin-top: .75rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.boot { padding: 2rem; }

/* ------------------------------------------------------------ controls */
button, .button {
  font: inherit;
  border: var(--border-w) solid var(--btn-border);
  background: var(--btn-image), var(--btn-bg);
  color: var(--btn-text);
  box-shadow: var(--btn-shadow);
  text-shadow: var(--btn-text-shadow);
  border-radius: var(--radius-sm);
  padding: .42rem .8rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  white-space: nowrap;
}
button:hover:not(:disabled), .button:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
button[data-busy]::after { content: "…"; }
button.primary, .button.primary {
  background: var(--primary-image), var(--primary-bg);
  border-color: var(--primary-border);
  color: var(--primary-text);
  font-weight: 600;
}
button.danger { color: var(--error); }
button.danger.primary { background: var(--error); border-color: var(--error); color: #fff; }
button.link { border: none; background: none; box-shadow: none; text-shadow: none; color: var(--link); padding: .2rem 0; }
button.icon { border: none; background: none; box-shadow: none; text-shadow: none; color: inherit; padding: .3rem .5rem; }
button.wide { width: 100%; justify-content: center; padding: .65rem; }
button.small { padding: .2rem .5rem; font-size: .85rem; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--input-bg);
  border: var(--border-w) solid var(--input-border);
  box-shadow: var(--input-shadow);
  border-radius: var(--radius-sm);
  padding: .42rem .55rem;
  min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible, tr:focus-visible, th:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { width: 100%; min-height: 4.5rem; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); box-shadow: none; }

.field { display: flex; flex-direction: column; gap: .25rem; }
.field-label { font-weight: 600; font-size: .9rem; }
.field input, .field select, .field textarea { width: 100%; }
.field input[type="checkbox"], .field input[type="radio"], .choice input { width: 1.05rem; flex: none; margin: 0; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .75rem 1rem; align-items: end; }
.category-field { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.inline-field { display: inline-flex; align-items: center; gap: .4rem; }
.inline-field input, .inline-field select { width: auto; }

/* ------------------------------------------------------------ layout */
.topbar { display: none; }
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  flex: none;
  background: var(--sidebar-image), var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right: var(--border-w) solid var(--sidebar-border);
  padding: 1rem .6rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar-brand { font-family: var(--font-head); font-weight: var(--head-weight); text-transform: var(--head-transform); letter-spacing: var(--head-spacing); padding: .2rem .6rem .4rem; font-size: 1.05rem; }
.nav-group h2 { font-family: var(--font); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--sidebar-muted); text-shadow: none; margin: 1rem .6rem .3rem; }
.sidebar a {
  display: flex;
  gap: .55rem;
  align-items: center;
  padding: .38rem .6rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
}
.sidebar a:hover { background: var(--sidebar-hover); }
.sidebar a.active { background: var(--sidebar-active-image), var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: 600; }
.sidebar .muted { color: var(--sidebar-muted); }
.sidebar button.link { color: var(--sidebar-link); }
.nav-user { margin-top: auto; padding: 1rem .6rem 0; border-top: var(--border-w) solid var(--sidebar-border); display: flex; flex-direction: column; align-items: flex-start; gap: .15rem; }
.content { flex: 1; min-width: 0; padding: 1.4rem 1.8rem 3rem; outline: none; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }

.card, .panel, .kpi, .big-action, .table-wrap, .grid-wrap {
  background: var(--panel-image), var(--panel);
  border: var(--border-w) solid var(--panel-border);
  border-radius: var(--radius);
}
.card { box-shadow: var(--shadow); padding: 1.2rem; }
.login { width: min(380px, 100%); display: flex; flex-direction: column; gap: .9rem; }
.login h1 { text-align: center; }
.notice { background: var(--warn-bg); padding: .6rem .8rem; border-radius: var(--radius-sm); margin: 0; }

.page { max-width: 1280px; }
.page.narrow { max-width: 640px; }
.page-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .4rem; }
.page-head h1 { flex: 1; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.status { min-height: 1.5rem; margin: .2rem 0 .6rem; font-size: .92rem; }
.page-body > * + * { margin-top: 1rem; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.filters .field { min-width: 140px; }
.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
.split.list-detail { grid-template-columns: minmax(280px, 1fr) minmax(0, 1.6fr); }
.panel { padding: 1rem; }
.panel h2:first-child, .panel h3:first-child { margin-top: 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.section-head h2 { margin-bottom: .3rem; }
.kpis { display: flex; gap: .8rem; flex-wrap: wrap; }
.kpi { padding: .7rem 1rem; min-width: 150px; }
.kpi .label { font-size: .8rem; color: var(--muted); }
.kpi .value { font-size: 1.3rem; font-weight: 600; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: .78rem; padding: .05rem .45rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.grey { background: var(--row-hover); color: var(--muted); }
.badge.warn { background: var(--warn-bg); color: inherit; }

/* ------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: .42rem .65rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th {
  font-weight: 600; font-size: .82rem;
  color: var(--th-text);
  background: var(--th-image), var(--th-bg);
  text-transform: var(--th-transform);
  letter-spacing: var(--th-spacing);
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; }
th[data-sorted="asc"]::after { content: " ▲"; font-size: .7em; }
th[data-sorted="desc"]::after { content: " ▼"; font-size: .7em; }
tbody tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover, tr.selected { background: var(--row-hover); }
tr.selected { box-shadow: inset 3px 0 0 var(--accent); }
td.empty { text-align: center; padding: 1.5rem; }
td.actions { white-space: nowrap; text-align: right; }

/* ------------------------------------------------------------ dialogs */
dialog {
  border: var(--border-w) solid var(--panel-border);
  border-radius: var(--radius);
  padding: 0;
  width: min(560px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  background: var(--panel-image), var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-dialog);
}
dialog.wide { width: min(980px, calc(100vw - 2rem)); }
dialog::backdrop { background: var(--backdrop); }
dialog > header { display: flex; align-items: center; padding: .9rem 1.1rem .4rem; }
dialog > header h2 { flex: 1; margin: 0; }
.dialog-body { padding: .4rem 1.1rem; overflow-y: auto; max-height: calc(100vh - 12rem); }
dialog > .status { padding: 0 1.1rem; }
dialog > footer { display: flex; justify-content: flex-end; gap: .5rem; padding: .6rem 1.1rem 1rem; }

/* ------------------------------------------------------------ forms (submitters) */
.big-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.big-action {
  display: flex; flex-direction: column; gap: .3rem;
  padding: 1.3rem; border-radius: var(--radius); text-decoration: none;
  box-shadow: var(--shadow); color: var(--text);
}
.big-action:hover { border-color: var(--accent); }
.big-action strong { font-size: 1.1rem; font-family: var(--font-head); }
.choice-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .35rem .8rem; }
.choice { display: flex; gap: .5rem; align-items: center; padding: .35rem .5rem; border-radius: var(--radius-sm); border: var(--border-w) solid var(--line); cursor: pointer; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.segmented { display: flex; flex-wrap: wrap; gap: .4rem; }
.segmented label { flex: 1; min-width: 120px; }
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 1rem; text-align: center; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
tr.drop-over td { background: var(--accent-soft); box-shadow: inset 0 2px 0 var(--accent), inset 0 -2px 0 var(--accent); }
.file-list { list-style: none; margin: .5rem 0 0; padding: 0; text-align: left; }
.file-list li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .15rem 0; }
.thumbs { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: .6rem; }
.thumb { position: relative; width: 96px; height: 96px; border-radius: var(--radius-sm); border: 1px solid var(--line); overflow: hidden; display: grid; place-items: center; background: var(--row-hover); font-size: .75rem; text-align: center; color: var(--muted); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 2px; right: 2px; background: rgb(0 0 0 / 55%); color: #fff; border: none; box-shadow: none; border-radius: 50%; width: 1.5rem; height: 1.5rem; padding: 0; justify-content: center; }
.thumb a { position: absolute; inset: 0; }
.mini-thumbs { display: flex; gap: .25rem; }
.mini-thumbs img, .mini-thumbs .file { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); display: grid; place-items: center; font-size: .65rem; color: var(--muted); background: var(--row-hover); }
.receipt-view { display: grid; gap: 1rem; }
.receipt-view img, .receipt-view iframe { width: 100%; max-height: 70vh; object-fit: contain; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.receipt-view iframe { height: 70vh; }
.warnings { background: var(--warn-bg); border-radius: var(--radius-sm); padding: .6rem .9rem; }
.warnings ul { margin: .2rem 0 0; padding-left: 1.2rem; }

/* ------------------------------------------------------------ projections grid */
.grid-wrap { overflow: auto; max-height: calc(100vh - 220px); }
.grid { font-size: .82rem; }
.grid th, .grid td { padding: .25rem .45rem; white-space: nowrap; }
.grid th:first-child, .grid td:first-child { position: sticky; left: 0; background: var(--panel); z-index: 2; }
.grid thead th { z-index: 3; }
.grid td.actual { color: var(--text); }
.grid td.projected { color: var(--muted); font-style: italic; }
.grid td.override { color: var(--accent); font-style: normal; font-weight: 600; }
.grid td.editable { cursor: pointer; }
.grid td.editable:hover { outline: 1px solid var(--accent); outline-offset: -1px; }
.grid tr.subtotal td { font-weight: 600; border-top: 2px solid var(--line); }
.grid tr.group td { background: var(--row-hover); font-weight: 600; }
.grid td.negative { color: var(--error); }
.grid input { width: 6rem; padding: .1rem .3rem; text-align: right; font-size: .82rem; }

/* ------------------------------------------------------------ rules */
.drag-handle { cursor: grab; color: var(--muted); user-select: none; padding: 0 .3rem; }
tr.dragging { opacity: .4; }
tr.drop-before td { box-shadow: inset 0 2px 0 var(--accent); }
tr.disabled td { color: var(--muted); text-decoration: line-through; }
tr.disabled td.actions, tr.disabled td:first-child { text-decoration: none; }

/* ------------------------------------------------------------ Metro details */
.sidebar-brand { font-weight: 200; font-size: 1.6rem; text-transform: lowercase; letter-spacing: -.01em; padding-bottom: .6rem; }
.nav-group h2 { font-family: var(--font-head); text-transform: lowercase; font-size: .95rem; font-weight: 300; letter-spacing: 0; }
.sidebar a.active { font-weight: 600; }
h2 { font-size: 1.35rem; font-weight: 300; }
th { font-size: .9rem; font-weight: 400; }
/* Tiles: solid colour, white text, label at the bottom. */
.big-action { color: var(--tile-text); min-height: 150px; justify-content: flex-end; border: none; }
.big-action:first-child { background: var(--tile-1); }
.big-action:nth-child(2) { background: var(--tile-2); }
.big-action .muted { color: rgb(255 255 255 / 85%); }
.big-action strong { font-weight: 300; font-size: 1.6rem; text-transform: lowercase; }
.kpi { background: var(--tile-3); color: var(--tile-text); border: none; min-height: 96px; display: flex; flex-direction: column; justify-content: space-between; }
.kpi:nth-child(3n+2) { background: var(--tile-4); }
.kpi:nth-child(3n+3) { background: var(--tile-5); }
.kpi .label { color: rgb(255 255 255 / 85%); text-transform: lowercase; }
a.kpi { text-decoration: none; }
/* Hover tooltip on the projections chart. */
.chart-tip { position: absolute; pointer-events: none; padding: .35rem .6rem; background: var(--panel); color: var(--text); border: 2px solid var(--accent); white-space: nowrap; }
.kpi .value { font-family: var(--font-head); color: var(--tile-text); font-weight: 300; font-size: 1.8rem; }
.badge { border-radius: 0; background: var(--accent); color: var(--accent-text); }
.badge.grey { background: var(--row-hover); color: var(--muted); }
.badge.warn { background: var(--warn-bg); color: var(--text); }
button:active:not(:disabled), .big-action:active { transform: scale(.97); }
/* Dialogs: a full-width band across the screen, content centred in it (Windows 8). */
dialog, dialog.wide { width: 100vw; max-width: 100vw; border: none; border-block: 2px solid var(--accent); }
dialog > header, dialog > .dialog-body, dialog > .status, dialog > footer { width: min(720px, 100%); margin-inline: auto; }
dialog.wide > header, dialog.wide > .dialog-body, dialog.wide > .status, dialog.wide > footer { width: min(1000px, 100%); }
dialog > header h2 { font-size: 1.8rem; font-weight: 200; }
:root[data-theme="dark"] dialog { background: #2b2b2b; }

/* Light only (Office 2013): a green line along the top, spreadsheet grid lines. */
:root:not([data-theme="dark"]) .content { border-top: 4px solid var(--accent); }
:root:not([data-theme="dark"]) .table-wrap { border: 1px solid var(--line); }
:root:not([data-theme="dark"]) th, :root:not([data-theme="dark"]) td { border: 1px solid #e1e1e1; }
:root:not([data-theme="dark"]) th { border-color: var(--line); }
:root:not([data-theme="dark"]) tr.clickable:hover td { background: var(--row-hover); }

/* ------------------------------------------------------------ accent picker (Your settings) */
/* Square colour tiles, as in Windows Phone's Settings › theme. */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: .5rem; }
.swatch { aspect-ratio: 1; width: 100%; padding: 0; border: 3px solid transparent; justify-content: center; }
.swatch:hover:not(:disabled) { border-color: var(--muted); }
.swatch[aria-pressed="true"] { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--bg); }
.segmented-buttons { display: flex; gap: .5rem; }
.segmented-buttons button { min-width: 6rem; justify-content: center; }
.segmented-buttons button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* ------------------------------------------------------------ light/dark toggle */
/* Top right of the page (js/mode.js); on phones it's in Your settings instead. */
.mode-toggle { position: absolute; top: 1.5rem; right: 1.8rem; z-index: 15; display: flex; }
.mode-toggle button {
  font-size: .85rem; text-transform: lowercase; padding: .15rem .65rem;
  background: transparent; color: var(--muted); border: 2px solid var(--btn-border);
}
.mode-toggle button + button { margin-left: -2px; }
.mode-toggle button[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); font-weight: 600; }
.page-head { padding-right: 8.5rem; }

/* ------------------------------------------------------------ phones: Windows Phone */
/* Up to 860px the app takes the Windows Phone 8 look (js/ui.js, PHONE): the
   uppercase app title instead of the sidebar, an application bar along the
   bottom (••• opens the screen's other actions and every section), pivots,
   live tiles on Home, jump lists, square text boxes and heavy checkboxes,
   message boxes that drop from the top. Desktop never sees these pieces. */
.start, .pivot, .appbar, .appbar-dim, tr.jump-head, .phone-only { display: none; }

:root { --tile-accent: var(--accent); --appbar-bg: #dddddd; --tb-bg: #dcdcdc; }
:root[data-theme="dark"] { --tile-accent: #107c10; --appbar-bg: #2d2d2d; --tb-bg: #c8c8c8; }

@media (max-width: 860px) {
  /* Buttons: outlined in the text colour, as on the phone. */
  :root, :root[data-theme="dark"] { --btn-bg: transparent; --btn-border: var(--text); --btn-text: var(--text); }

  /* ---- frame: app title on top, no sidebar, room for the app bar */
  .sidebar, .mode-toggle { display: none; }
  /* viewport-fit=cover (index.html): keep clear of the notch, status bar and home indicator. */
  .topbar { display: block; padding: calc(1.1rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0 max(1rem, env(safe-area-inset-left)); }
  .apptitle {
    font-family: var(--font); font-size: .78rem; font-weight: 600; letter-spacing: .04em;
    text-transform: uppercase; color: var(--text); text-decoration: none;
  }
  .apptitle .section { display: none; }
  body:has(.has-pivot) .apptitle .section { display: inline; }
  .content, :root:not([data-theme="dark"]) .content {
    border-top: 0;
    padding: 0 max(1rem, env(safe-area-inset-right)) calc(5.5rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  }
  .page-head { padding-right: 0; margin-bottom: .2rem; }
  .page-head h1 { font-size: 2.9rem; line-height: 1.15; white-space: nowrap; overflow: hidden; margin-left: -.04em; }
  .page-head .toolbar > button, .page-head .toolbar > a.button { display: none; } /* they live in the app bar */
  .page.has-pivot .page-head h1 { display: none; }
  .split, .split.list-detail, .category-field { grid-template-columns: 1fr; }
  input, select, textarea, button { font-size: 16px; } /* stops iOS zooming into fields */
  table.recent .thumbs-cell { display: none; }
  table.recent td { padding-left: .5rem; padding-right: .5rem; }

  /* ---- pivots: big lowercase headings; the others dimmed, running off the edge */
  .pivot { display: flex; gap: 1.2rem; overflow: hidden; white-space: nowrap; margin: 0 -1rem .5rem 0; }
  .pivot button {
    background: none; border: 0; padding: 0; color: var(--text); opacity: .35;
    font-family: var(--font-head); font-weight: var(--head-weight); font-size: 2.6rem; line-height: 1.2;
    text-transform: lowercase; letter-spacing: -.01em;
  }
  .pivot button[aria-selected="true"] { opacity: 1; }
  .pivot button:active { transform: none; }
  .has-pivot .pivot-pane:not(.current) { display: none; }
  .has-pivot .pivot-pane > h2:first-child { display: none; } /* the pivot names it */
  .no-phone { display: none; }

  /* Filter bars wait behind the app bar's filter button. */
  .content:not(.show-filters) .filters { display: none; }

  /* ---- application bar */
  .appbar {
    display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    min-height: 3.7rem;
    padding: .5rem max(1rem, env(safe-area-inset-right)) calc(.45rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    background: var(--appbar-bg); color: var(--text);
  }
  /* iOS Safari can leave a strip below fixed bars while its toolbar collapses
     into the floating address pill: fill it with the bar, not the list. */
  .appbar::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 40vh; background: var(--appbar-bg); }
  .appbar:has(.appbar-buttons:empty) { min-height: 2.4rem; }
  .appbar button { background: none; border: 0; box-shadow: none; color: inherit; padding: 0; }
  .appbar-buttons { display: flex; gap: 1.5rem; }
  .ab { display: flex; flex-direction: column; align-items: center; gap: .25rem; }
  .ab .ring { width: 2.7rem; height: 2.7rem; border: 2px solid currentColor; border-radius: 50%; display: grid; place-items: center; }
  .ab .ico { width: 1.3rem; height: 1.3rem; }
  .ab:active .ring { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
  .ab .lbl { display: none; font-size: .72rem; max-width: 4.6rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .appbar.open .ab .lbl { display: block; }
  .appbar .appbar-more { position: absolute; top: .1rem; right: .5rem; padding: .35rem .6rem; font-size: 1.05rem; letter-spacing: .12em; }
  .appbar-menu { display: none; width: 100%; max-height: min(62vh, calc(100dvh - 9rem)); overflow-y: auto; margin-top: .6rem; text-align: left; }
  .appbar.open .appbar-menu { display: block; }
  .appbar-menu ul { list-style: none; margin: 0; padding: 0; }
  .appbar-menu li > a, .appbar-menu li > button {
    display: block; width: 100%; text-align: left; padding: .4rem 0; color: var(--text);
    font-family: var(--font); font-size: 1.3rem; line-height: 1.3; text-decoration: none;
  }
  .appbar-menu li > button:disabled { opacity: .4; }
  .appbar-menu a.active { color: var(--accent); }
  .appbar-group h2 {
    margin: .9rem 0 .15rem; font-family: var(--font); font-size: .75rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  }
  .appbar-actions { padding-bottom: .4rem !important; border-bottom: 1px solid var(--line); }
  .appbar-user { margin-top: .9rem !important; padding-top: .3rem !important; border-top: 1px solid var(--line); }
  body.appbar-open .appbar-dim { display: block; position: fixed; inset: 0; z-index: 39; background: rgb(0 0 0 / 45%); }

  /* ---- text boxes: grey, white with an accent border while typing */
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea {
    background: var(--tb-bg); color: #111111; border: 2px solid var(--tb-bg); min-height: 2.75rem;
    color-scheme: light; box-shadow: none;
  }
  input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus {
    background: #ffffff; border-color: var(--accent); outline: none;
  }
  input::placeholder, textarea::placeholder { color: #6b6b6b; }
  input:disabled, select:disabled, textarea:disabled { opacity: .5; }

  /* ---- checkboxes and radio buttons: heavy square outlines */
  input[type="checkbox"], input[type="radio"] {
    appearance: none; width: 1.7rem; height: 1.7rem; flex: none; margin: 0;
    display: inline-grid; place-items: center; background: transparent;
    border: 3px solid var(--text); border-radius: 0;
  }
  input[type="radio"] { border-radius: 50%; }
  input[type="checkbox"]:checked { background: var(--text); }
  input[type="checkbox"]:checked::after {
    content: ""; width: .72rem; height: .4rem; transform: translateY(-.08rem) rotate(-45deg);
    border-left: 3px solid var(--bg); border-bottom: 3px solid var(--bg);
  }
  input[type="radio"]:checked { background: radial-gradient(circle, var(--text) 0 42%, transparent 46%); }
  .field input[type="checkbox"], .field input[type="radio"], .choice input { width: 1.7rem; }
  .choice-list { grid-template-columns: 1fr; gap: .15rem; }
  .segmented { flex-direction: column; gap: .15rem; }
  .choice, .choice:has(input:checked) { border: 0; background: none; padding: .4rem 0; gap: .9rem; font-size: 1.15rem; }

  /* ---- buttons */
  button, .button { border-width: 3px; padding: .5rem 1rem; }
  button.small { border-width: 2px; padding: .3rem .7rem; }
  /* Forms save from the app bar. */
  .form-page .form-actions > button[type="submit"] { display: none; }

  /* ---- dialogs drop from the top of the screen */
  dialog, dialog.wide { margin: 0 auto auto; border-top: 0; max-height: 100dvh; }
  .dialog-body { max-height: calc(100dvh - 10rem); }
  dialog > footer { gap: .7rem; }
  dialog > footer button { flex: 1; justify-content: center; min-height: 2.9rem; }
  dialog.msgbox > header { padding-top: 1.4rem; }
  dialog.msgbox > header h2 { font-family: var(--font); font-weight: 600; font-size: 1.4rem; text-transform: none; letter-spacing: 0; }
  dialog.msgbox > header button.icon { display: none; }
  dialog.msgbox p { font-size: 1.05rem; }

  /* ---- Home: the start screen */
  .start { display: block; max-width: 26rem; margin: .5rem 0 1.4rem; }
  .home-todo, .big-actions { display: none; }
  .tiles {
    --cell: calc((min(100vw - 2rem, 26rem) - 3 * .45rem) / 4);
    display: grid; grid-template-columns: repeat(4, var(--cell)); grid-auto-rows: var(--cell); gap: .45rem;
  }
  .tile { position: relative; overflow: hidden; display: block; background: var(--tile-accent); color: #ffffff; text-decoration: none; }
  .tile.m { grid-column: span 2; grid-row: span 2; }
  .tile.w { grid-column: span 4; grid-row: span 2; }
  .tile:active { transform: perspective(600px) rotateX(5deg) scale(.97); }
  .tile-icon { position: absolute; inset: 0 0 1.4rem; display: grid; place-items: center; }
  .tile.s .tile-icon { inset: 0; }
  .tile-icon .ico { width: 2.9rem; height: 2.9rem; stroke-width: 1.4; }
  .tile.s .tile-icon .ico { width: 1.9rem; height: 1.9rem; }
  .tile.live .tile-icon { display: none; }
  .tile-name { position: absolute; left: .6rem; bottom: .45rem; font-size: .82rem; line-height: 1.2; }
  .tile.s .tile-name { display: none; }
  .tile-count { position: absolute; right: .6rem; bottom: .15rem; font-family: var(--font-head); font-weight: 300; font-size: 2.6rem; line-height: 1; }
  .tile.s .tile-count { top: .3rem; bottom: auto; font-family: var(--font); font-size: .85rem; font-weight: 600; }
  .tile-peek { position: absolute; left: .6rem; right: .6rem; top: .55rem; font-size: .85rem; line-height: 1.35; overflow: hidden; }
  .tile.m .tile-peek { right: .6rem; }
  .peek-item strong { display: block; font-size: 1.1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tile.m .peek-item strong { font-family: var(--font-head); font-weight: 300; font-size: 1.7rem; }
  .peek-item { animation: peek-in .45s ease-out; }
  @keyframes peek-in { from { transform: translateY(70%); opacity: 0; } }
  .start-foot { display: flex; justify-content: flex-end; padding-top: .8rem; }
  .allapps {
    width: 2.7rem; height: 2.7rem; padding: 0; border-radius: 50%; border: 2px solid var(--text);
    display: grid; place-items: center; background: none;
  }
  .allapps .ico { width: 1.2rem; height: 1.2rem; }

  /* ---- jump list grid (opened from a letter tile) */
  .jump-grid {
    position: fixed; inset: 0; z-index: 60; overflow-y: auto;
    display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 4.6rem; gap: .5rem; align-content: start;
    padding: 1.4rem 1rem; background: var(--bg);
  }
  .jump-grid button {
    display: flex; align-items: flex-end; justify-content: flex-start; padding: 0 0 .25rem .5rem;
    background: var(--tile-accent); color: #ffffff; border: 0;
    font-family: var(--font-head); font-weight: 300; font-size: 2.1rem; text-transform: lowercase;
  }
  .jump-grid button:disabled { background: var(--line); color: var(--muted); opacity: 1; }

  /* ---- Projections: one month as a list */
  .proj-head { display: grid; grid-template-columns: 1fr 1fr; gap: .2rem 1rem; margin: .2rem 0 .9rem; }
  .proj-head small { display: block; font-size: .75rem; color: var(--muted); }
  .proj-head .big { font-family: var(--font-head); font-weight: 300; font-size: 2.1rem; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .proj-head .accent { color: var(--accent); }
  .proj-head .owed { grid-column: 1 / -1; }
  .proj-head .big.accent { font-weight: 300; }
  .proj-line, button.proj-line {
    display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; width: 100%;
    padding: .32rem 0; border: 0; background: none; color: var(--text); text-align: left;
    font: inherit; font-size: 1.15rem; line-height: 1.3; white-space: normal;
  }
  button.proj-line:active { transform: none; background: var(--row-hover); }
  .proj-line .name { flex: 1; min-width: 0; text-transform: lowercase; overflow-wrap: anywhere; }
  .proj-line .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
  .proj-line .amt.projected { font-style: italic; color: var(--muted); }
  .proj-line .amt.override, .proj-month .accent { color: var(--accent); font-weight: 600; }
  .proj-line.group, button.proj-line.group {
    margin-top: .8rem; padding-bottom: .1rem; font-size: .75rem; font-weight: 600; letter-spacing: .05em;
    text-transform: uppercase; color: var(--muted);
  }
  .proj-line.group .name { text-transform: uppercase; }
  .proj-line.group .amt { font-style: normal; color: var(--muted); }
  .proj-month > p { margin-top: 1rem; }

  @media (prefers-reduced-motion: reduce) {
    .peek-item { animation: none; }
    .tile:active { transform: none; }
  }
}

/* ------------------------------------------------------------ phones: lists */
/* ui.table() marks its tables .cards: on phones each row becomes a Windows
   Phone list item: a big title, its date and amount in the accent colour, other
   values as small labelled items (label from data-label). The column's `phone`
   option adds .ph-title / .ph-full / .ph-plain / .ph-note / .ph-hide /
   .ph-inline. Actions go along the bottom. */
@media (max-width: 860px) {
  /* Filter bars (when shown): two fields a row. */
  .filters { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; align-items: end; }
  .filters .field { min-width: 0; }
  .filters > label.row { padding-bottom: 0 !important; }

  .table-wrap.cards, :root:not([data-theme="dark"]) .table-wrap.cards { overflow: visible; background: none; border: none; }
  .table-wrap.cards table, .table-wrap.cards tbody { display: block; }
  .table-wrap.cards thead { display: none; }
  .table-wrap.cards tr { display: flex; flex-wrap: wrap; align-items: flex-start; gap: .2rem 1.1rem; padding: 0 0 1.3rem; }
  .table-wrap.cards td { display: block; padding: 0; border: none; text-align: left; white-space: normal; min-width: 0; background: none; }
  /* Light theme's grid lines off (only borders here: a display set at this
     specificity would beat .ph-hide and :empty). */
  :root:not([data-theme="dark"]) .table-wrap.cards td { border: none; }
  .table-wrap.cards td:empty { display: none; }
  .table-wrap.cards td[data-label]::before {
    content: attr(data-label); display: block; font-size: .72rem; line-height: 1.3;
    color: var(--muted); text-transform: var(--th-transform);
  }
  .table-wrap.cards td.ph-title { order: -1; flex-basis: 100%; font-size: 1.4rem; line-height: 1.2; }
  .table-wrap.cards td.ph-plain:not(.muted) { color: var(--accent); }
  .table-wrap.cards td.ph-full, .table-wrap.cards td.ph-note { flex-basis: 100%; }
  .table-wrap.cards td.ph-note { font-size: .85rem; color: var(--muted); }
  .table-wrap.cards td.ph-title::before, .table-wrap.cards td.ph-plain::before, .table-wrap.cards td.ph-note::before { content: none; }
  .table-wrap.cards td.ph-hide { display: none; }
  .table-wrap.cards td.actions { flex-basis: 100%; text-align: left; padding-top: .3rem; }
  .table-wrap.cards td.actions::before { content: none; }
  .table-wrap.cards td.actions .row { justify-content: flex-start !important; }
  .table-wrap.cards td.actions.ph-inline { flex-basis: auto; margin-left: auto; padding-top: 0; align-self: flex-end; }
  .table-wrap.cards td.empty { flex-basis: 100%; text-align: center; }
  .table-wrap.cards tr.clickable:hover td, :root:not([data-theme="dark"]) .table-wrap.cards tr.clickable:hover td { background: none; }
  .table-wrap.cards tr.clickable:active { transform: perspective(600px) rotateX(3deg) scale(.98); }
  .table-wrap.cards tr.selected { background: none; box-shadow: inset 4px 0 0 var(--accent); padding-left: .8rem; }

  /* Jump list: letter tiles above each group. */
  .table-wrap.cards tr.jump-head { display: flex; padding: .4rem 0 .9rem; }
  .jump-tile {
    width: 3.1rem; height: 3.1rem; padding: 0 0 .1rem .4rem !important; border: 2px solid var(--accent) !important;
    display: flex; align-items: flex-end; justify-content: flex-start; background: none !important; color: var(--accent);
    font-family: var(--font-head); font-weight: 300; font-size: 1.8rem; line-height: 1; text-transform: lowercase;
  }
}
