/* Farmland UI — tokens adapted from the AgriCore reference: flat surfaces,
   hairline borders, one deep-green action colour, lime only as a signal dot. */
:root {
  --canvas: #f6fbf4;
  --surface: #ffffff;
  --surface-2: #f0f5ee;
  --surface-3: #e5e9e3;
  --border: #e3e8e1;
  --text: #181d19;
  --text-2: #5b655a;
  --primary: #006e17;
  --primary-hover: #00530f;
  --accent: #66ff69;
  --danger: #ba1a1a;
  --danger-bg: #ffdad6;
  --warn-bg: #fff1d6;
  --warn-text: #5a4321;
  --ok-bg: #e3f6e1;
  --ok-text: #00530f;
  --radius: 4px;
  --radius-lg: 8px;
  --sidebar-w: 240px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 14px/1.45 var(--font); background: var(--canvas); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin: 0; line-height: 1.3; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--text-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; white-space: nowrap; }
th.num { text-align: right; }
input.num { text-align: right; }
.hidden { display: none !important; }

/* ── Shell ──────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }
.sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 40; transition: transform .2s ease; }
.sidebar-brand { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.25rem; font-weight: 700; font-size: 17px; color: var(--text); border-bottom: 1px solid var(--border); }
.sidebar-brand:hover { text-decoration: none; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 6px; background: var(--primary); color: #fff; font-size: 14px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem .75rem 1rem; }
.nav-group { margin-bottom: 1.1rem; }
.nav-group-title { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); padding: 0 .6rem; margin-bottom: .35rem; }
.nav-link { display: block; padding: .5rem .6rem; border-radius: var(--radius); color: var(--text); font-weight: 500; font-size: 14px; }
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.sidebar-foot { border-top: 1px solid var(--border); padding: .85rem 1.25rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.user-chip { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-chip strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip small { color: var(--text-2); font-size: 12px; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(23, 26, 24, .4); z-index: 30; }
.shell-main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; height: 52px; padding: 0 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-title { font-weight: 600; font-size: 14px; }
.topbar-user { margin-left: auto; color: var(--text-2); font-size: 13px; }
.icon-btn { display: none; background: none; border: 1px solid var(--border); border-radius: var(--radius); width: 36px; height: 36px; font-size: 18px; cursor: pointer; color: var(--text); }
.container { width: 100%; max-width: 1240px; margin: 0 auto; padding: 1.5rem 2rem 3rem; }
.container-auth { padding-top: 10vh; }
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .shell-main { margin-left: 0; }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
  .container { padding: 1rem 1rem 5rem; }
}

/* ── Page header ────────────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-header h1 { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.page-desc { color: var(--text-2); margin: .25rem 0 0; max-width: 60ch; }
.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.inline-form { display: inline-flex; gap: .4rem; align-items: center; }
.section-title { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); margin: 1.25rem 0 .5rem; }

/* ── Cards, stats ───────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat { display: flex; flex-direction: column; gap: .35rem; padding: .9rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); color: var(--text); min-width: 0; }
.stat:hover { text-decoration: none; border-color: var(--text-2); }
.stat-label { order: -1; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); }
.stat-value { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.stat-ok { background: var(--ok-bg); border-color: #cfe9cb; }
.stat-warn { background: var(--warn-bg); border-color: #f1dfb8; }
.empty { color: var(--text-2); padding: 2.5rem 1rem; text-align: center; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius-lg); }

/* ── Tables ─────────────────────────────────────────────────────── */
.table-wrap { padding: 0; overflow-x: auto; }
.table-title { padding: .9rem 1.25rem 0; margin: 0 0 .5rem; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { height: 36px; padding: 0 .75rem; background: var(--surface-2); text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { height: 44px; padding: .4rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(240, 245, 238, .5); }
.row-warn { background: var(--warn-bg); }
.row-muted { color: var(--text-2); }
td.actions, th.actions { text-align: right; white-space: nowrap; }
td.actions a, td.actions form { margin-left: .75rem; }
.inline { display: inline; }
td:first-child a { font-weight: 500; }
td:first-child, .nowrap { white-space: nowrap; }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: .4rem; padding: .15rem .55rem; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--text-2); }
.badge-paid::before, .badge-done::before, .badge-harvested::before, .badge-active::before { background: var(--accent); }
.badge-partial::before, .badge-in_progress::before, .badge-growing::before { background: #e3a400; }
.badge-unpaid::before, .badge-pending::before { background: var(--danger); }
.badge-cancelled, .badge-failed { color: var(--text-2); }

/* ── Buttons, alerts ────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: .4rem; height: 36px; padding: 0 .9rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.danger-btn { color: var(--danger); border-color: #e9b8b4; }
.danger-btn:hover { background: var(--danger-bg); }
button.link { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; color: var(--primary); cursor: pointer; }
button.link:hover { text-decoration: underline; }
button.link.danger { color: var(--danger); }
.alert { padding: .6rem .9rem; border-radius: var(--radius); margin: 0 0 1rem; border: 1px solid transparent; font-size: 13px; }
.alert-ok { background: var(--ok-bg); color: var(--ok-text); border-color: #cfe9cb; }
.alert-error { background: var(--danger-bg); color: #93000a; border-color: #f3c4c0; }
.segmented { display: inline-flex; padding: 2px; background: var(--surface-3); border-radius: var(--radius-lg); }
.segmented a { padding: .3rem .7rem; border-radius: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.segmented a:hover { color: var(--text); text-decoration: none; }
.segmented a.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(23, 26, 24, .08); }

/* ── Forms ──────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.span-2 { grid-column: span 2; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } .span-2 { grid-column: auto; } }
label { display: flex; flex-direction: column; gap: .3rem; font-size: 13px; }
label > span { font-weight: 600; }
label em { color: var(--danger); font-style: normal; }
label.checkbox { flex-direction: row; align-items: center; gap: .5rem; }
label.checkbox > span { font-weight: 400; }
input, select, textarea { font: inherit; font-size: 14px; height: 36px; padding: 0 .6rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
textarea { height: auto; padding: .5rem .6rem; }
input[type="checkbox"] { height: 16px; width: 16px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--text); box-shadow: 0 0 0 2px var(--accent); }
input:disabled { background: var(--surface-2); color: var(--text-2); }
input::placeholder { color: #8d968b; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.error-text { color: var(--danger); font-size: 12px; }
.form-actions { display: flex; gap: .5rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 0; }
.details dt { color: var(--text-2); }
.details dd { margin: 0; }
#items-table input { width: 100%; min-width: 5.5rem; }
#items-table .item-unit { min-width: 3.5rem; }
#items-table select { max-width: 15rem; }

/* ── Auth & error pages ─────────────────────────────────────────── */
.auth-card { max-width: 380px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 2rem; }
.auth-card h1 { color: var(--primary); margin-bottom: .25rem; }
.error-card { max-width: 640px; margin: 8vh auto 0; text-align: center; }
.error-card h1 { font-size: 3rem; color: var(--text-2); }
.stack-trace { text-align: left; overflow: auto; background: #181d19; color: #eef2ec; padding: 1rem; border-radius: var(--radius); font-size: 12px; }

/* ── Design review fixes ────────────────────────────────────────── */
:root { --loss: #b3261e; --loss-bg: #fdecea; }

/* Brand mark: a leaf instead of a letter. */
svg.brand-mark { width: 28px; height: 28px; padding: 5px; border-radius: 6px; background: var(--primary); stroke: #fff; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* The top bar is only the phone menu bar; desktop already shows title and user. */
.topbar { display: none; }
.topbar-brand { font-weight: 700; color: var(--text); }
@media (max-width: 1023px) { .topbar { display: flex; } }

/* Readable small labels (12px, not 11px). */
.stat-label, .nav-group-title, th, .section-title { font-size: 12px; }
.eyebrow { margin: 0 0 .15rem; font-size: 13px; }
.eyebrow a { color: var(--text-2); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Colour meaning: red = loss, amber = money owed, green = profit. */
.stat-loss { background: var(--loss-bg); border-color: #f4c7c3; }
.stat-loss .stat-value, .loss { color: var(--loss); }

/* Layout: grid children may shrink, so wide tables scroll inside their card. */
.page-header > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.grid-2 > * { min-width: 0; }
.stack > .card { margin-bottom: 0; }
.stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.table-wrap { max-width: 100%; }
.total-row td { font-weight: 600; border-top: 1px solid var(--border); }

/* Clickable rows open the record; delete lives on the edit page. */
.rows-link tbody tr[data-href] { cursor: pointer; }
.rows-link tbody tr[data-href]:hover { background: var(--surface-2); }
td.actions a.muted { color: var(--text-2); font-size: 13px; }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-top: .5rem; padding: .9rem 1.25rem; border: 1px dashed #e9b8b4; border-radius: var(--radius-lg); background: var(--surface); }

/* Statement */
.statement .month-row th { height: auto; padding: .65rem .75rem; background: #f7f9f6; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); white-space: normal; border-top: 1px solid var(--border); }
.month-name { font-weight: 600; margin-right: .75rem; }
.month-sum { color: var(--text-2); font-weight: 400; font-variant-numeric: tabular-nums; }
.month-sum strong { color: var(--text); }
.kind { display: inline-block; padding: .1rem .45rem; border-radius: var(--radius); font-size: 12px; font-weight: 600; white-space: nowrap; }
.kind-in { background: #e3f1e6; color: #1f5f30; }
.kind-paid { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.show-sm { display: none; }

/* Period control */
.period-control { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin: -0.25rem 0 1.25rem; }
.date-range input[type="date"] { width: 9.5rem; }

/* Live value on forms */
.form-product { display: flex; flex-direction: column; gap: .2rem; padding: .75rem 1rem; background: var(--surface-2); border-radius: var(--radius); }
.form-product .stat-value { font-size: 20px; }

/* Chart */
.chart { margin: 0; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .baseline { stroke: #b8c2b6; }
.chart .axis { font-size: 12px; fill: var(--text-2); font-family: var(--font); }
.chart .hit { fill: transparent; }
.chart .bar-group:hover .hit { fill: rgba(23, 26, 24, .04); }
.chart-legend { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin: 0 0 .75rem; font-size: 13px; color: var(--text-2); }
.chart-legend strong { color: var(--text); margin-left: .25rem; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .4rem; vertical-align: 0; }

/* Phone */
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .show-sm { display: table-cell; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
  .stat { padding: .7rem .8rem; }
  .stat-value { font-size: 18px; }
  .page-header { flex-direction: column; align-items: stretch; }
  .toolbar { width: 100%; }
  .toolbar .btn { flex: 1 1 auto; justify-content: center; }
  .period-control, .date-range { width: 100%; }
  .segmented { width: 100%; overflow-x: auto; }
  .segmented a { flex: 1 0 auto; text-align: center; }
  .date-range input[type="date"] { flex: 1; width: auto; min-width: 0; }
  .month-sum { display: block; margin-top: .15rem; }
  td, th { padding-left: .6rem; padding-right: .6rem; }
  h1 { font-size: 21px; }
}

/* Chart drawn at real size; table view stands in without JavaScript. */
.month-chart { width: 100%; min-height: 220px; }
.month-chart svg { display: block; }
@media (max-width: 640px) {
  .table-compact td, .table-compact th { padding-left: .45rem; padding-right: .45rem; font-size: 13px; }
}
.show-sm-inline { display: none; }
@media (max-width: 640px) { .show-sm-inline { display: inline; } }
.sidebar-nav { min-height: 0; }

/* ── Accounting ─────────────────────────────────────────────────── */
.state { display: inline-flex; align-items: center; gap: .35rem; padding: .12rem .5rem; border-radius: var(--radius); font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.state-draft { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
.state-unpaid, .state-issued { background: #fff1d6; color: #7a5300; }
.state-partial { background: #e8eefb; color: #2c4fa3; }
.state-paid, .state-posted { background: #e3f1e6; color: #1f5f30; }
.state-overdue { background: var(--loss-bg); color: var(--loss); }
.state-void { background: var(--surface-2); color: var(--text-2); text-decoration: line-through; }
.doc-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem 1.5rem; }
.doc-head dt { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); }
.doc-head dd { margin: .15rem 0 0; }
.doc-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
details.danger-zone { display: block; }
details.danger-zone summary { cursor: pointer; color: var(--loss); font-weight: 600; font-size: 13px; }
.void-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem; margin: .75rem 0 .25rem; }
.void-form label { flex: 1 1 260px; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: -0.5rem 0 1.25rem; }
.filters select { min-width: 10rem; }
.totals-line td { font-weight: 600; background: var(--surface-2); }
.lines-table input { width: 100%; min-width: 5.5rem; }
.lines-table .desc { min-width: 12rem; }
.hint { font-size: 12px; color: var(--text-2); }
.alloc-summary { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; padding: .75rem 1.25rem; border-top: 1px solid var(--border); font-size: 13px; }
.alloc-summary strong { font-variant-numeric: tabular-nums; }
.acct-group th { background: transparent; font-size: 13px; color: var(--text); text-transform: none; letter-spacing: 0; padding-top: 1rem; }
.flow { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem; margin: 0 0 1.25rem; counter-reset: step; }
.flow li { list-style: none; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 13px; }
.flow li strong { display: block; }
.flow li.done { border-color: #cfe9cb; background: var(--ok-bg); }
.flow li.now { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }

/* Pager */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin: -0.25rem 0 1.25rem; font-size: 13px; }
.pager-links { display: inline-flex; align-items: center; gap: .5rem; }
.pager .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }

/* Choice cards (e.g. increase or decrease a balance) */
fieldset.choice { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
fieldset.choice legend { font-weight: 600; font-size: 13px; margin-bottom: .4rem; padding: 0; }
.choice-option { flex-direction: row; align-items: flex-start; gap: .6rem; padding: .75rem .9rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.choice-option:has(input:checked) { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); background: #f5faf4; }
.choice-option input { height: 16px; width: 16px; margin-top: .15rem; }
.choice-option span { font-weight: 400; display: flex; flex-direction: column; gap: .2rem; }
.choice-option small { color: var(--text-2); font-size: 12px; line-height: 1.4; }
@media (max-width: 640px) { fieldset.choice { grid-template-columns: 1fr; } }

/* ── Calmer, plainer UI (UX review) ─────────────────────────────── */
/* Sentence-case labels instead of tiny uppercase; quieter table headers. */
.stat-label, th, .nav-group-title, .section-title, .doc-head dt { text-transform: none; letter-spacing: 0; font-size: 13px; }
th { font-weight: 600; color: var(--text-2); background: var(--surface); border-bottom: 1px solid var(--border); }
h1 { font-size: 22px; }
h2 { font-size: 16px; }

/* Status as a coloured word, not a pill with a dot. */
.state { background: none !important; border: 0 !important; padding: 0; font-size: 13px; font-weight: 600; text-decoration: none; }
.state::before { display: none; }
.state-paid, .state-posted, .state-saved { color: #1f6b33; }
.state-unpaid, .state-issued { color: #8a5a00; }
.state-partial { color: #2c4fa3; }
.state-overdue { color: var(--loss); }
.state-draft, .state-void { color: var(--text-2); }
.kind { background: none !important; border: 0 !important; padding: 0; font-weight: 500; color: var(--text-2); }

/* One headline figure per page, next to the title. */
.headline { display: flex; flex-direction: column; align-items: flex-end; gap: .1rem; text-align: right; }
.headline .label { font-size: 13px; color: var(--text-2); }
.headline .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; white-space: nowrap; }
.headline .value.owed { color: #8a5a00; }
.headline .value.loss { color: var(--loss); }
.headline .value.good { color: #1f6b33; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: -0.5rem 0 1.25rem; }
.summary-line { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; margin: 0 0 1.25rem; font-size: 14px; color: var(--text-2); }
.summary-line strong { color: var(--text); font-variant-numeric: tabular-nums; }
.lead-note { margin: 0 0 1rem; padding: .7rem .9rem; border-left: 3px solid var(--border); background: var(--surface); border-radius: var(--radius); font-size: 14px; }
@media (max-width: 640px) {
  .headline { align-items: flex-start; text-align: left; }
  .headline .value { font-size: 22px; }
}

/* Home page */
.home-figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 1.25rem; }
.home-figures a, .home-figures div { background: var(--surface); padding: .9rem 1.1rem; color: var(--text); display: flex; flex-direction: column; gap: .15rem; }
.home-figures a:hover { background: var(--surface-2); text-decoration: none; }
.home-figures .label { font-size: 13px; color: var(--text-2); }
.home-figures .value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Menu: accountant tools fold away. */
details.nav-fold > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; padding: 0 .6rem; margin-bottom: .35rem; font-size: 13px; font-weight: 600; color: var(--text-2); }
details.nav-fold > summary::-webkit-details-marker { display: none; }
details.nav-fold > summary::after { content: "▸"; font-size: 11px; }
details.nav-fold[open] > summary::after { content: "▾"; }
.lang-switch { display: flex; gap: .5rem; font-size: 12px; padding: 0 1.25rem .75rem; }
.lang-switch a { color: var(--text-2); }
.lang-switch a.active { color: var(--text); font-weight: 600; text-decoration: underline; }

/* Paid-now box on the sale form */
.paid-now { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; align-items: end; }
details.more { margin-top: .25rem; }
details.more > summary { cursor: pointer; color: var(--text-2); font-size: 13px; }

/* Headline sits under the title as its own block. */
.headline { align-items: flex-start; text-align: left; margin: 0 0 .9rem; }
.headline .value { font-size: 30px; }
.headline + .summary-line { margin-top: -0.4rem; }
.owed { color: #8a5a00; }
.good { color: #1f6b33; }
.loss { color: var(--loss); }
.home-figures .value.loss { color: var(--loss); }
.paid-now details.more, .form-grid details.more { grid-column: 1 / -1; }
details.more > .form-grid { margin-top: .75rem; }
details.card.more { padding: 0; }
details.card.more > summary { list-style: none; padding: .9rem 1.1rem; display: flex; gap: .75rem; align-items: baseline; color: var(--text); font-weight: 600; font-size: 15px; }
details.card.more > summary::-webkit-details-marker { display: none; }
details.card.more > summary::after { content: "▸"; margin-left: auto; color: var(--text-2); font-size: 12px; }
details.card.more[open] > summary::after { content: "▾"; }
details.card.more > summary .muted { font-weight: 400; font-size: 13px; }
details.card.more > table, details.card.more > form, details.card.more > .alloc-summary, details.card.more > p, details.card.more > .pager { margin: 0 1.1rem .9rem; }
.form-actions .link.muted { margin-left: auto; color: var(--text-2); font-size: 14px; }
.choice { display: flex; gap: .75rem; flex-wrap: wrap; border: 0; padding: 0; }
.choice .choice-option { flex: 1 1 160px; }
@media (max-width: 640px) { .headline .value { font-size: 26px; } }

.paid-now { align-items: start; }
.paid-now label > span { min-height: 0; }
.table-title.small { padding-top: .6rem; padding-bottom: .8rem; }

.page-header .summary-line { display: block; margin: .2rem 0 0; }

/* Sale lines stack on phones: produce on top, kg and price side by side. */
@media (max-width: 640px) {
  #lines thead { display: none; }
  #lines, #lines tbody, #lines tfoot { display: block; width: 100%; }
  #lines tr.line { display: grid; grid-template-columns: 1fr 1fr auto; gap: .5rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
  #lines tr.line td { display: block; padding: 0; border: 0; }
  #lines tr.line td:first-child { grid-column: 1 / -1; }
  #lines tr.line td.amount { grid-column: 1 / 3; text-align: left; color: var(--text-2); }
  #lines tr.line input { width: 100%; }
  #lines tfoot tr { display: flex; justify-content: space-between; padding: .75rem 1rem; }
  #lines tfoot td { padding: 0; border: 0; background: none; }
  #lines tfoot tr { background: var(--surface-2); }
  #lines tfoot td:empty { display: none; }
}

/* ── Reports ─────────────────────────────────────────────────────── */
.report-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; align-items: start; }
.report-list ul { list-style: none; margin: 0; padding: 0 0 .4rem; }
.report-list li a { display: flex; flex-direction: column; gap: .1rem; padding: .7rem 1.25rem; color: var(--text); border-top: 1px solid var(--border); }
.report-list li a:hover { background: var(--surface-2); text-decoration: none; }
.report-list li strong { font-weight: 600; color: var(--primary); }
.report-list li span { font-size: 13px; color: var(--text-2); }
.report-table { margin-bottom: 1rem; }
.report-table tfoot td { font-weight: 600; }
.report-table .grand-total td { border-top: 2px solid var(--text); font-weight: 700; background: var(--surface); }
.report-table .subtotal-line td { font-weight: 600; background: var(--surface-2); }
.report-table .section-line th { text-align: left; padding-top: 1rem; background: none; border-bottom: 0; color: var(--text); font-size: 14px; }
.report-table td.indent { padding-left: 2rem; }
.statement-narrow { max-width: 760px; }
.statement-party { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: 0 0 1rem; }
.statement-party > div { display: flex; flex-direction: column; gap: .1rem; }
.statement-party .label { font-size: 13px; color: var(--text-2); }
.statement-party strong { font-size: 18px; }
.statement-owed { text-align: right; }
.statement-owed strong { font-size: 26px; font-variant-numeric: tabular-nums; }
td .what { font-weight: 600; }
td .detail { display: block; font-size: 13px; color: var(--text-2); }
.share-bar { display: block; height: 4px; margin-top: .35rem; border-radius: 2px; background: linear-gradient(90deg, var(--primary) var(--share), var(--surface-2) var(--share)); max-width: 240px; }
.print-head { display: none; }
.table-title .small { font-weight: 400; margin-left: .5rem; }
@media (max-width: 640px) {
  .statement-owed { text-align: left; }
}

@media print {
  @page { size: A4; margin: 14mm 12mm; }
  body { background: #fff !important; color: #000; font-size: 11pt; }
  .sidebar, .sidebar-backdrop, .topbar, .report-tools, .period-control, .pager, .alert { display: none !important; }
  .shell-main { margin-left: 0 !important; }
  .container { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; border-radius: 0; background: #fff; }
  details.more { display: none; }
  .print-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 2rem; padding-bottom: .6rem; margin-bottom: 1rem; border-bottom: 2px solid #000; }
  .print-head > div { display: flex; flex-direction: column; gap: .15rem; font-size: 10pt; color: #333; }
  .print-head .print-farm strong { font-size: 16pt; color: #000; }
  .print-head .print-title { text-align: right; }
  .print-head .print-title strong { font-size: 13pt; color: #000; text-transform: uppercase; letter-spacing: .03em; }
  .headline .value, .statement-owed strong { color: #000 !important; }
  a { color: inherit; text-decoration: none; }
  th { background: #fff !important; color: #000; border-bottom: 1px solid #000; }
  td, th { padding: 4px 6px !important; }
  tr { break-inside: avoid; }
  thead { display: table-header-group; }
  tfoot { display: table-row-group; }
  .report-table .grand-total td { background: #fff; }
  .table-wrap { overflow: visible; }
  .row-muted { color: #666; }
}

.summary-line { display: block; }

.show-sm { display: none; }
@media (max-width: 640px) {
  .show-sm { display: block; }
  .report-table td, .report-table th { padding-left: .5rem; padding-right: .5rem; }
}

/* ── Sidebar, second pass: a deep field-green column with the farm's name ──
   No logo tile, no filled pill. The current page is marked with a thin
   pepper-yellow rule; accountant pages sit folded at the bottom. */
:root {
  --canvas: #f7f6f2;
  --surface-2: #f0eee8;
  --surface-3: #e6e3dc;
  --border: #e4e1d9;
  --text-2: #5f625a;
  --side-bg: #1e3326;
  --side-text: #ece7d9;
  --side-muted: #9fab9b;
  --side-line: rgba(236, 231, 217, .12);
  --side-hover: rgba(236, 231, 217, .07);
  --side-mark: #e2b13c;
  --sidebar-w: 224px;
}
.sidebar { background: var(--side-bg); border-right: 0; color: var(--side-text); }
.sidebar-brand { display: block; padding: 1.5rem 1.4rem 1.25rem; border-bottom: 0; color: var(--side-text); font-size: 18px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.25; overflow-wrap: anywhere; }
.sidebar-brand:hover { color: #fff; text-decoration: none; }
.sidebar-nav { display: flex; flex-direction: column; padding: 0 0 1rem; }
.sidebar .nav-group { margin: 0 0 1.25rem; }
.sidebar .nav-group-title { padding: 0 1.4rem; margin: 0 0 .3rem; font-size: 12px; font-weight: 500; color: var(--side-muted); text-transform: none; letter-spacing: 0; }
.sidebar .nav-link { position: relative; display: block; padding: .45rem 1.4rem; border-radius: 0; color: var(--side-text); font-size: 15px; font-weight: 400; opacity: .82; }
.sidebar .nav-main .nav-link { font-size: 15.5px; padding-top: .5rem; padding-bottom: .5rem; }
.sidebar .nav-link:hover { background: var(--side-hover); opacity: 1; text-decoration: none; }
.sidebar .nav-link.active { background: transparent; color: #fff; font-weight: 600; opacity: 1; }
.sidebar .nav-link.active::before { content: ""; position: absolute; left: 0; top: .45rem; bottom: .45rem; width: 3px; border-radius: 0 2px 2px 0; background: var(--side-mark); }
/* Folded groups gather at the bottom, smaller and quieter. */
.sidebar .nav-group:not(.nav-fold) + details.nav-fold { margin-top: auto; padding-top: .75rem; border-top: 1px solid var(--side-line); }
.sidebar details.nav-fold { margin: 0 0 .25rem; }
.sidebar details.nav-fold > summary { padding: .4rem 1.4rem; margin: 0; font-size: 13px; font-weight: 500; color: var(--side-muted); }
.sidebar details.nav-fold > summary:hover { color: var(--side-text); }
.sidebar details.nav-fold > summary::after { content: "+"; font-size: 14px; font-weight: 400; }
.sidebar details.nav-fold[open] > summary::after { content: "−"; }
.sidebar details.nav-fold .nav-link { font-size: 13.5px; padding: .35rem 1.4rem .35rem 1.9rem; }
.sidebar details.nav-fold .nav-link.active::before { left: .9rem; }
.sidebar-foot { border-top: 1px solid var(--side-line); padding: .9rem 1.4rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.sidebar-user { display: flex; flex-direction: column; gap: .1rem; min-width: 0; font-size: 13px; }
.sidebar-user > span { color: var(--side-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user button.link { color: var(--side-muted); font-size: 12px; text-align: left; }
.sidebar-user button.link:hover { color: var(--side-text); }
.sidebar .lang-switch { display: inline-flex; padding: 0; gap: 0; border: 1px solid var(--side-line); border-radius: 999px; overflow: hidden; }
.sidebar .lang-switch a { padding: .15rem .55rem; font-size: 11px; font-weight: 600; color: var(--side-muted); text-decoration: none; }
.sidebar .lang-switch a.active { background: var(--side-text); color: var(--side-bg); text-decoration: none; }
.sidebar-backdrop { background: rgba(20, 30, 23, .45); }
/* Phone top bar matches the sidebar. */
.topbar { background: var(--side-bg); border-bottom: 0; }
.topbar-brand { color: var(--side-text); font-weight: 700; }
.topbar .icon-btn { border-color: var(--side-line); color: var(--side-text); background: transparent; }
.sidebar ::-webkit-scrollbar { width: 6px; }
.sidebar ::-webkit-scrollbar-thumb { background: var(--side-line); border-radius: 3px; }

/* Action colour tuned to sit with the sidebar green. */
:root { --primary: #23633b; --primary-hover: #1a4c2d; }
