/* Freelume/ components
 * Colours, radii, shadows, spacing, timings and font families come only from the --ff-* custom properties.
 * Font sizes are literal px values, but only the steps of the type scale (12, 13, 14, 16, 18, 20, 24, 32),
 * which ships as .ff-type-* styles rather than single tokens. Other literal lengths are component dimensions.
 * Breakpoints are literal because media queries can't read custom properties:
 *   tablet  = min-width 640px  (ff-bp-tablet)
 *   desktop = min-width 1024px (ff-bp-desktop)
 * Class names keep the existing app's names where the pattern already existed.
 */

/* ---------- Base ---------- */
/* Spacing comes from the components (gap, padding), never from the browser's defaults. */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  margin: 0;
  background: var(--ff-surface-page);
  color: var(--ff-text-body);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.43;
  -webkit-font-smoothing: antialiased;
  /* The footer sits at the bottom of the screen when a page is shorter than it. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
/* Components set display, which would beat the browser's own [hidden] rule. */
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; color: var(--ff-text-strong); text-wrap: balance; }
a { color: var(--ff-action-hover); text-decoration: none; }
:focus-visible { outline: 2px solid var(--ff-focus-ring); outline-offset: 2px; }
.mono, .money { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.text-pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.money { font-weight: 600; color: var(--ff-text-strong); white-space: nowrap; }
/* A total the server is still recalculating (ffAskTotals): shown, but quieter until the answer is in. */
[aria-busy="true"]:not(form, section, [role]) { opacity: 0.5; }
.inline-icon { width: var(--ff-icon-sm); height: var(--ff-icon-sm); flex-shrink: 0; vertical-align: -3px; }

/* ---------- Layout ---------- */
.container {
  box-sizing: border-box;
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--ff-container-max);
  margin: 0 auto;
  padding: var(--ff-space-4) var(--ff-space-4) var(--ff-space-8);
}
/* Plain block flow, not flex: sections keep the full width whatever their margins, and the
   space between them collapses with any margin a section brings instead of adding to it. */
.container > * + *,
.page > * + * { margin-top: var(--ff-space-6); }
/* Title and action share one centre line: a button is a shape, not text, so it never sits on a baseline. */
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--ff-space-3); }
.page-header h1 { font-size: 24px; line-height: 32px; font-weight: 600; letter-spacing: -0.3px; }
.page.is-form { max-width: var(--ff-form-max); }
/* A page without navigation (login) sits in the middle. */
.page.is-centred { margin-inline: auto; }
.page-header .subtitle { margin: var(--ff-space-1) 0 0; color: var(--ff-text-muted); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--ff-space-4); }
.split { display: flex; flex-wrap: wrap; gap: var(--ff-space-4); align-items: flex-start; }
.split > .split-main { flex: 999 1 560px; min-width: 0; }
.split > .split-side { flex: 1 1 320px; min-width: 0; }

.card {
  background: var(--ff-surface-card);
  border-radius: var(--ff-radius-lg);
  box-shadow: var(--ff-shadow-card);
  padding: var(--ff-space-4);
  display: flex;
  flex-direction: column;
  gap: var(--ff-space-4);
  min-width: 0;
}
.card-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--ff-space-3); }
.card-header h2, .card-header h3 { display: flex; align-items: center; gap: var(--ff-space-3); font-size: 18px; line-height: 26px; font-weight: 600; }
.card-empty { margin: 0; color: var(--ff-text-muted); }
.card-subheading { margin: 0; font-size: 14px; line-height: 20px; font-weight: 600; color: var(--ff-text-strong); }
/* One total under a heading: the ex-btw figure, then inc btw as a quiet second figure. */
.total-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--ff-space-1) var(--ff-space-3); margin: 0; font-size: 16px; line-height: 24px; }
.total-line-secondary { font-weight: 400; font-size: 14px; color: var(--ff-text-muted); }
/* Filters above a list: a segmented control that takes the room, then compact selects. */
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ff-space-3); }
.filter-row > .segmented-control { flex: 1 1 320px; }
.filter-row > .form-group { flex: 0 1 160px; }
/* Children stacked with even space between them. */
.stack { display: flex; flex-direction: column; gap: var(--ff-space-4); }

@media (min-width: 640px) {
  .container { padding-inline: var(--ff-space-8); padding-top: var(--ff-space-8); }
  .card { padding: var(--ff-space-6); }
}
@media (min-width: 1024px) {
  .container { padding: var(--ff-space-12) var(--ff-space-6) var(--ff-space-16); }
  .container > * + *,
  .page > * + * { margin-top: var(--ff-space-8); }
}

/* ---------- Buttons (tiers 1-3 + harvest) ---------- */
.btn-primary, .btn-secondary, .btn-danger, .harvest-btn {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ff-space-2);
  min-height: var(--ff-control-height);
  padding: 0 var(--ff-space-6);
  border: 0;
  border-radius: var(--ff-radius-pill);
  font: 600 14px/20px var(--font-sans);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary { background: var(--ff-action); color: var(--ff-text-on-action); }
.btn-secondary { background: var(--ff-secondary-bg); color: var(--ff-secondary-text); }
.btn-danger { background: var(--ff-danger); color: var(--ff-text-on-action); }
.harvest-btn { background: linear-gradient(180deg, var(--ff-harvest-top), var(--ff-harvest-bottom)); color: var(--ff-harvest-text); }
/* The last day of the month: one short shake, a second after load. */
@media (prefers-reduced-motion: no-preference) {
  .harvest-jiggle { animation: ff-harvest-shake var(--ff-duration-attention) ease-in-out var(--ff-delay-attention) 1; }
}
@keyframes ff-harvest-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-3px) rotate(-1deg); }
  30% { transform: translateX(3px) rotate(1deg); }
  45% { transform: translateX(-2px) rotate(-0.5deg); }
  60% { transform: translateX(2px) rotate(0.5deg); }
  75% { transform: translateX(-1px); }
}
.btn-small { min-height: 36px; padding: 0 var(--ff-space-4); }
.btn-block { width: 100%; }
.btn-primary:hover { background: var(--ff-action-hover); }
.btn-secondary:hover { background: var(--ff-secondary-bg-hover); }
.btn-danger:hover { background: var(--ff-danger-hover); }
.btn-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  box-sizing: border-box;
  border: 2px solid var(--ff-spinner-track-on-fill);
  border-top-color: var(--ff-text-on-action);
  border-radius: var(--ff-radius-pill);
  animation: ff-spin var(--ff-duration-spin) linear infinite;
}
.btn-secondary.btn-loading::after { border-color: var(--ff-spinner-track); border-top-color: var(--ff-text-label); }
@keyframes ff-spin { to { transform: rotate(360deg); } }
.btn-primary:disabled, .btn-secondary:disabled, .btn-danger:disabled {
  background: var(--ff-disabled);
  color: var(--ff-text-label);
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ---------- Tier 4: text action ---------- */
.detail-link {
  display: inline-flex;
  align-items: center;
  gap: var(--ff-space-2);
  min-height: var(--ff-tap-target);
  padding: 0 var(--ff-space-3);
  border: 0;
  border-radius: var(--ff-radius-pill);
  background: transparent;
  color: var(--ff-text-label);
  font: 500 14px/20px var(--font-sans);
  text-decoration: none;
  cursor: pointer;
}
.detail-link:hover { background: var(--ff-hover-wash); color: var(--ff-text-strong); }
.detail-link-warning { color: var(--ff-feedback-warning-text); }
.detail-link-warning:hover { color: var(--ff-feedback-warning-text); }
/* Several text actions side by side; they wrap on a narrow screen. */
.detail-links { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--ff-space-1); }

/* ---------- Tier 5: icon button ---------- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--ff-tap-target);
  height: var(--ff-tap-target);
  padding: 0;
  border: 0;
  border-radius: var(--ff-radius-pill);
  background: transparent;
  color: var(--ff-icon-quiet);
  cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { color: var(--ff-text-strong); background: var(--ff-hover-wash); }
/* An active toggle (a shortcut star) shows by its shape: filled, in ink. */
.icon-btn.is-on { color: var(--ff-text-strong); }
.icon-btn.is-on svg { fill: currentColor; }

@media (prefers-reduced-motion: no-preference) {
  .btn-primary, .btn-secondary, .btn-danger, .harvest-btn, .detail-link, .icon-btn {
    transition: background var(--ff-duration-fast) var(--ff-ease), color var(--ff-duration-fast) var(--ff-ease), transform var(--ff-duration-fast) var(--ff-ease), box-shadow var(--ff-duration-fast) var(--ff-ease);
  }
  .btn-primary:hover, .btn-secondary:hover, .btn-danger:hover, .harvest-btn:hover { transform: translateY(-1px); box-shadow: var(--ff-shadow-lift); }
  .icon-btn:hover { transform: scale(1.08); }
}

/* ---------- Fields ---------- */
.form-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-group > label, .form-label { font-size: 13px; line-height: 18px; font-weight: 500; color: var(--ff-text-label); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--ff-space-3); }
/* Fields side by side line up: label, control and hint each share a row across the columns, so a
   label that wraps to two lines moves its neighbours' controls down with it. A field has at most
   these three parts. */
.form-row > .form-group { display: grid; grid-row: span 3; grid-template-rows: subgrid; row-gap: 6px; align-content: start; }
/* No hint in the row: no hint track either, so the row ends right under its controls. */
.form-row:not(:has(.field-hint:not([hidden]), .field-error:not([hidden]))) > .form-group { grid-row: span 2; }
.form-row > .form-group > :is(label, .form-label) { align-self: end; }
.input,
.form-group input[type="text"], .form-group input[type="email"], .form-group input[type="date"],
.form-group input[type="password"], .form-group input[type="search"],
.form-group input[type="number"], .form-group input[type="tel"], .form-group input[type="url"], .form-group select, .form-group textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: var(--ff-control-height-touch);
  padding: 0 14px;
  border: 1px solid var(--ff-border-strong);
  border-radius: var(--ff-radius-md);
  background: var(--ff-surface-card);
  color: var(--ff-text-strong);
  font: 400 16px/24px var(--font-sans);
}
.form-group textarea { padding: 10px 14px; min-height: 96px; resize: vertical; }
/* Shown for context, not editable (the client of a logged work item): a quiet ground, no input border. */
.form-group input[readonly] { background: var(--ff-surface-group); border-color: transparent; color: var(--ff-text-label); }
.form-group input::placeholder, .form-group textarea::placeholder { color: var(--ff-text-muted); }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus, .input:focus {
  outline: none;
  border: 2px solid var(--ff-focus-ring);
  padding-left: 13px;
  box-shadow: 0 0 0 3px var(--ff-focus-halo);
}
.form-group.has-error input, .form-group.has-error select, .form-group.has-error textarea { border-color: var(--ff-danger); }
.field-hint { font-size: 12px; line-height: 16px; color: var(--ff-text-muted); }
/* A checkbox with a full tap target: <label class="check"><input type="checkbox"> optional text</label>. */
.check { display: inline-flex; align-items: center; justify-content: flex-start; gap: var(--ff-space-2); min-width: var(--ff-tap-target); min-height: var(--ff-tap-target); cursor: pointer; }
/* Several of many: a group box of full-width checkbox rows that scrolls past about six. */
.check-list {
  display: flex;
  flex-direction: column;
  max-height: 272px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--ff-space-3);
  border-radius: var(--ff-radius-md);
  background: var(--ff-surface-group);
}
.check-list > .check { width: 100%; }
.check-list > .check + .check { border-top: 1px solid var(--ff-border); }
/* A lone checkbox among row actions keeps its tap target centred. */
.list-row-actions > .check { justify-content: center; }
.check input[type="checkbox"], .check input[type="radio"], .list-row-check input[type="checkbox"] { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--ff-action); cursor: pointer; }
/* Label and value pairs, read-only: what is about to be sent, an invoice's details. */
.summary-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--ff-space-2) var(--ff-space-4); margin: 0; }
.summary-list dt { color: var(--ff-text-label); }
.summary-list dd { margin: 0; color: var(--ff-text-strong); overflow-wrap: anywhere; }
/* Totals under a list of lines: figures right-aligned in mono, the last pair (the total) strong. */
.summary-list.is-totals { grid-template-columns: minmax(0, 1fr) auto; padding-top: var(--ff-space-3); border-top: 1px solid var(--ff-border); }
.summary-list.is-totals dd { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.summary-list.is-totals dt:last-of-type, .summary-list.is-totals dd:last-of-type { font-weight: 700; color: var(--ff-text-strong); }
/* A short list of what will happen (inside a confirmation). */
.bullet-list { display: flex; flex-direction: column; gap: var(--ff-space-1); margin: 0; padding-left: 1.25em; }
.field-error { font-size: 12px; line-height: 16px; color: var(--ff-danger-hover); }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
@media (min-width: 640px) {
  .input,
  .form-group input[type="text"], .form-group input[type="email"], .form-group input[type="date"],
  .form-group input[type="password"], .form-group input[type="search"],
.form-group input[type="number"], .form-group input[type="tel"], .form-group input[type="url"], .form-group select {
    min-height: var(--ff-control-height);
    font-size: 14px;
    line-height: 20px;
  }
}

/* Euro input */
.euro-input-wrapper { position: relative; }
.euro-input-wrapper .euro-sign {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ff-text-muted);
  pointer-events: none;
}
/* Outranks every generic input rule (`.form-group input[type="text"]`, `.modal-content input[type="text"]`),
   so the € always keeps its room. Markup: the .euro-sign span directly before an input with a type. */
.euro-input-wrapper .euro-sign + input[type] { padding-left: 32px; font-family: var(--font-mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.euro-input-wrapper .euro-sign + input[type]:focus { padding-left: 31px; }

/* ---------- Segmented control ---------- */
.segmented-control {
  display: flex;
  padding: 2px;
  background: var(--ff-surface-sunken);
  border-radius: var(--ff-radius-md);
}
.segment {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: var(--ff-radius-sm);
  background: transparent;
  color: var(--ff-text-label);
  font: 500 14px/20px var(--font-sans);
  cursor: pointer;
}
a.segment { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.segment.active { background: var(--ff-surface-card); color: var(--ff-text-strong); box-shadow: var(--ff-shadow-segment); }
.segment:disabled { opacity: 0.5; cursor: not-allowed; }
.segment.dirty::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: var(--ff-radius-pill);
  background: var(--ff-action);
  vertical-align: middle;
}

/* ---------- Disclosure ---------- */
details.disclosure > summary {
  display: inline-flex;
  align-items: center;
  gap: var(--ff-space-2);
  min-height: var(--ff-tap-target);
  color: var(--ff-action-hover);
  font: 500 14px/20px var(--font-sans);
  cursor: pointer;
  list-style: none;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary svg { width: var(--ff-icon-sm); height: var(--ff-icon-sm); }
details.disclosure[open] > summary svg { transform: rotate(90deg); }
.disclosure-body {
  display: flex;
  flex-direction: column;
  gap: var(--ff-space-3);
  padding: var(--ff-space-4);
  border-radius: var(--ff-radius-md);
  background: var(--ff-surface-group);
}

/* ---------- Companies ---------- */
.company-section { display: flex; flex-direction: column; gap: var(--ff-space-4); }
.company-heading {
  margin: 0;
  font: 600 13px/18px var(--font-sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ff-text-muted);
}
/* A company's rows inside a card that lists several companies: on the group ground, so it is clear
   where one company ends and the next begins; no row needs a label. The company-heading row above
   (a .list-group-total when it carries the company's total) keeps its amount in line with the rows. */
.company-section-body { padding: var(--ff-space-1) var(--ff-space-4); border-radius: var(--ff-radius-md); background: var(--ff-surface-group); }
.company-section:has(> .company-section-body) > .list-group-total { padding-right: var(--ff-space-4); }
/* Over plain rows the total keeps no chevron space; over rows that end in an action, one action's width. */
.company-section:has(> .company-section-body > .list) > .list-group-total::after { display: none; }
.company-section:has(> .company-section-body > .list .list-row-actions) > .list-group-total::after { display: block; width: var(--ff-tap-target); }
/* From 640px rows space their columns by --ff-space-4 where this row uses --ff-space-3. */
@media (min-width: 640px) { .company-section:has(> .company-section-body > .list .list-row-actions) > .list-group-total::after { width: calc(var(--ff-tap-target) + var(--ff-space-4) - var(--ff-space-3)); } }
/* The ground ends the block: a folded last group draws no line along its bottom edge. */
.company-section-body > .list-group:last-child > .list-group-header[aria-expanded="false"] { border-bottom-color: transparent; }

/* ---------- Tabs (page sections) ---------- */
/* Tabs only ever scroll sideways: overflow-x alone also allows a vertical scroll of a few
   pixels on touch screens, so y is hidden, the gesture is pan-x and the scroll never chains. */
.tab-bar {
  display: flex;
  gap: var(--ff-space-6);
  border-bottom: 1px solid var(--ff-border);
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0;
  padding: var(--ff-space-3) 0;
  color: var(--ff-text-muted);
  font: 500 14px/20px var(--font-sans);
  text-decoration: none;
  white-space: nowrap;
}
.tab:hover { color: var(--ff-text-strong); }
.tab.active { color: var(--ff-text-strong); font-weight: 600; box-shadow: inset 0 -2px 0 var(--ff-action); }
button.tab { border: 0; background: none; cursor: pointer; }
/* Tabs inside a modal sit between header and body, lined up with both. */
.modal-content > .tab-bar { flex-shrink: 0; margin: 0 20px; }
@media (min-width: 640px) { .modal-content > .tab-bar { margin: 0 var(--ff-space-6); } }
/* Switching tabs never resizes the modal: with tabs it takes its full height, the body fills it and scrolls. */
.modal-content:has(> .tab-bar:not([hidden])) { height: calc(100% - var(--ff-space-8)); }
.modal-content:has(> .tab-bar:not([hidden])) > .modal-body { flex: 1 1 auto; }
@media (min-width: 640px) { .modal-content:has(> .tab-bar:not([hidden])) { height: min(calc(100% - var(--ff-space-12)), 760px); } }

/* ---------- Badge (status pill) ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--ff-space-1);
  padding: 2px 10px;
  border-radius: var(--ff-radius-pill);
  font: 500 13px/18px var(--font-sans);
  white-space: nowrap;
  background: var(--ff-status-draft-bg);
  color: var(--ff-status-draft-text);
}
.badge svg { width: 13px; height: 13px; }
.badge-unbilled { background: var(--ff-stage-unbilled-bg); color: var(--ff-stage-unbilled-text); }
.badge-draft { background: var(--ff-status-draft-bg); color: var(--ff-status-draft-text); }
.badge-sent { background: var(--ff-status-sent-bg); color: var(--ff-status-sent-text); }
.badge-overdue { background: var(--ff-status-overdue-bg); color: var(--ff-status-overdue-text); }
.badge-paid { background: var(--ff-status-paid-bg); color: var(--ff-status-paid-text); }
.badge-credit { background: var(--ff-status-credit-bg); color: var(--ff-status-credit-text); }
.badge-booked { background: var(--ff-status-booked-bg); color: var(--ff-status-booked-text); }

/* ---------- Icon chip ---------- */
.icon-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: var(--ff-chip-size);
  height: var(--ff-chip-size);
  border-radius: var(--ff-radius-pill);
  background: var(--ff-status-draft-bg);
  color: var(--ff-status-draft-text);
}
.icon-chip svg { width: var(--ff-icon-sm); height: var(--ff-icon-sm); }
.icon-chip-sm { width: 28px; height: 28px; }
.icon-chip-sm svg { width: 14px; height: 14px; }
.icon-chip-unbilled { background: var(--ff-stage-unbilled-bg); color: var(--ff-stage-unbilled-icon); }
.icon-chip-sent { background: var(--ff-status-sent-bg); color: var(--ff-status-sent-icon); }
.icon-chip-overdue { background: var(--ff-status-overdue-bg); color: var(--ff-status-overdue-icon); }
.icon-chip-paid { background: var(--ff-status-paid-bg); color: var(--ff-status-paid-icon); }
.icon-chip-booked { background: var(--ff-status-booked-bg); color: var(--ff-status-booked-icon); }
.icon-chip-success { background: var(--ff-feedback-success-bg); color: var(--ff-feedback-success-icon); }
.icon-chip-warning { background: var(--ff-feedback-warning-bg); color: var(--ff-feedback-warning-icon); }
.icon-chip-error { background: var(--ff-feedback-error-bg); color: var(--ff-feedback-error-icon); }
.icon-chip-info { background: var(--ff-feedback-info-bg); color: var(--ff-feedback-info-icon); }

/* ---------- Stage tile (replaces stat-card) ---------- */
.stage-tile {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: var(--ff-space-1);
  padding: var(--ff-space-4);
  border-radius: var(--ff-radius-lg);
  background: var(--ff-surface-card);
  box-shadow: var(--ff-shadow-card);
  color: inherit;
  text-decoration: none;
  min-width: 0;
}
.stage-tile-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--ff-space-2);
  font: 500 13px/18px var(--font-sans);
  color: var(--ff-text-label);
}
.stage-tile-value {
  font: 600 32px/40px var(--font-mono);
  letter-spacing: -0.5px;
  color: var(--ff-text-strong);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stage-tile-value.is-text { font: 600 18px/40px var(--font-sans); letter-spacing: 0; }
.stage-tile-meta { font-size: 13px; line-height: 18px; color: var(--ff-text-muted); }
/* A stage tile inside a card or a modal is the compact one: group ground, smaller figure. */
:is(.card, .modal-content) .stage-tile-value { font-size: 18px; line-height: 26px; letter-spacing: 0; }
.stage-tile:hover { box-shadow: var(--ff-shadow-popover); }
/* Inside a card or a modal (one level of cards only): flat on the group ground, compact figure, narrower columns. */
:is(.card, .modal-content) .grid-auto { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--ff-space-3); }
:is(.card, .modal-content) .stage-tile { background: var(--ff-surface-group); box-shadow: none; border-radius: var(--ff-radius-md); }
@media (min-width: 640px) { .stage-tile { padding: 20px var(--ff-space-6); } }

/* ---------- List row ---------- */
.list { display: flex; flex-direction: column; }
.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "main amount" "meta status";
  gap: 2px var(--ff-space-3);
  align-items: center;
  padding: var(--ff-space-3) 0;
  border-bottom: 1px solid var(--ff-border);
  color: inherit;
  text-decoration: none;
}
.list-row:last-child { border-bottom: 0; }
a.list-row:hover .list-row-title { color: var(--ff-action-hover); }
.list-row-title { grid-area: main; font-weight: 600; color: var(--ff-text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-meta { grid-area: meta; min-width: 0; overflow-wrap: anywhere; font-size: 13px; line-height: 18px; color: var(--ff-text-muted); }
.list-row-status { grid-area: status; justify-self: end; }
.list-row-amount { grid-area: amount; justify-self: end; font: 600 14px/20px var(--font-mono); color: var(--ff-text-strong); font-variant-numeric: tabular-nums; }
.list-row.is-credit { background: var(--ff-status-credit-bg); border-radius: var(--ff-radius-md); padding-inline: var(--ff-space-3); }
/* In select mode the checkbox column already gives the tint its room: boxes stay in one line. */
.list-row.is-credit:has(> .list-row-check) { padding-left: 0; }
.list-row.is-excluded .list-row-title { color: var(--ff-text-muted); }
.list-row.is-excluded .list-row-amount { color: var(--ff-text-muted); text-decoration: line-through; }
/* Row actions (edit, exclude, send, a paid checkbox) sit after the amount. */
.list-row:has(.list-row-actions) { grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "main amount actions" "meta status actions"; }
.list-row-actions { grid-area: actions; display: flex; align-items: center; justify-content: flex-end; position: relative; z-index: 1; }
/* A row that opens a record but also holds actions: the title is the link and stretches over the row. */
.list-row:has(.list-row-link) { position: relative; }
.list-row-link { color: inherit; text-decoration: none; }
.list-row-link::after { content: ""; position: absolute; inset: 0; }
.list-row:has(.list-row-link:hover) .list-row-title { color: var(--ff-action-hover); }
.list-row-link:focus-visible { outline: none; }
.list-row:has(.list-row-link:focus-visible) { outline: 2px solid var(--ff-focus-ring); outline-offset: 2px; border-radius: var(--ff-radius-md); }
/* Select mode: a checkbox first; the row is a <label>, so a tap anywhere on it ticks the box. */
.list-row:has(> .list-row-check) { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "check main amount" "check meta status"; cursor: pointer; }
.list-row-check { grid-area: check; display: flex; align-items: center; justify-content: center; min-width: var(--ff-tap-target); align-self: stretch; }
@media (min-width: 640px) {
  .list-row {
    grid-template-columns: minmax(0, 1fr) auto 120px;
    grid-template-areas: "main status amount" "meta status amount";
    gap: 2px var(--ff-space-4);
  }
  .list-row:has(.list-row-actions) {
    grid-template-columns: minmax(0, 1fr) auto 120px auto;
    grid-template-areas: "main status amount actions" "meta status amount actions";
  }
  .list-row:has(> .list-row-check) {
    grid-template-columns: auto minmax(0, 1fr) auto 120px;
    grid-template-areas: "check main status amount" "check meta status amount";
  }
}

/* ---------- List group (a collapsible group of list rows, e.g. one client's ongefactureerd work) ---------- */
.list-group-header {
  display: flex;
  align-items: center;
  gap: var(--ff-space-3);
  width: 100%;
  min-height: var(--ff-tap-target);
  padding: var(--ff-space-3) 0;
  border: 0;
  border-bottom: 1px solid var(--ff-border);
  background: transparent;
  color: var(--ff-text-strong);
  font: 600 16px/24px var(--font-sans);
  text-align: left;
  cursor: pointer;
}
.list-group-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* How many rows a group holds ("41 facturen"), quiet, after the title. */
.list-group-count { flex: none; font: 400 13px/18px var(--font-sans); color: var(--ff-text-muted); }
/* The total above a run of list groups (one company's ongefactureerd): the header's row with the
   title as a company heading and no chevron; a spacer of the chevron's width keeps the amounts in
   one column with the groups below. */
.list-group-total { display: flex; align-items: center; gap: var(--ff-space-3); padding: var(--ff-space-3) 0; }
.list-group-total > .company-heading { flex: 1; min-width: 0; }
.list-group-total::after { content: ""; flex: none; width: var(--ff-icon-sm); }
.list-group-amount { display: flex; flex-direction: column; align-items: flex-end; font: 600 14px/20px var(--font-mono); font-variant-numeric: tabular-nums; }
.list-group-amount-secondary { font: 400 12px/16px var(--font-mono); color: var(--ff-text-muted); }
.list-group-amount-unit { font-family: var(--font-sans); }
.list-group-header > svg { flex: none; width: var(--ff-icon-sm); height: var(--ff-icon-sm); color: var(--ff-text-muted); }
.list-group-header[aria-expanded="false"] > svg { transform: rotate(-90deg); }
/* A header that selects (a checkbox for the whole group) is a row, not a button: the collapse is its own icon button. */
/* A header that selects (holds a .check) instead of folding the group: is-static. */
.list-group-header.is-static { cursor: default; }
.list-group-header > .check { flex: 1; min-width: 0; font: inherit; }
.list-group-header .icon-btn[aria-expanded="false"] svg { transform: rotate(-90deg); }
.list-group-body { padding-left: var(--ff-space-3); }
@media (prefers-reduced-motion: no-preference) { .list-group-header > svg { transition: transform var(--ff-duration-fast) var(--ff-ease); } }

/* ---------- Chip (a quick pick: a client's shortcut services) ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: var(--ff-space-2); }
.chip {
  display: inline-flex;
  align-items: center;
  min-height: var(--ff-tap-target);
  padding: 0 var(--ff-space-4);
  border: 0;
  border-radius: var(--ff-radius-pill);
  background: var(--ff-surface-sunken);
  color: var(--ff-text-body);
  font: 500 14px/20px var(--font-sans);
  cursor: pointer;
}
.chip:hover { color: var(--ff-text-strong); background: var(--ff-secondary-bg-hover); }
.chip[aria-pressed="true"] { background: var(--ff-action); color: var(--ff-text-on-action); }

/* ---------- Autocomplete (a searchable select: clients, services) ---------- */
.autocomplete { position: relative; }
.autocomplete-list {
  position: absolute;
  top: calc(100% + var(--ff-space-1));
  left: 0;
  right: 0;
  z-index: var(--ff-z-popover);
  max-height: 320px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--ff-space-1);
  border-radius: var(--ff-radius-md);
  background: var(--ff-surface-card);
  box-shadow: var(--ff-shadow-popover);
}
/* Flipped above the input when there is no room below it (ffCombobox decides). */
.autocomplete-list.is-above { top: auto; bottom: calc(100% + var(--ff-space-1)); }
.autocomplete-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ff-space-3);
  min-height: var(--ff-tap-target);
  padding: 0 var(--ff-space-3);
  border-radius: var(--ff-radius-sm);
  color: var(--ff-text-strong);
  cursor: pointer;
}
.autocomplete-option:hover, .autocomplete-option.is-active { background: var(--ff-hover-wash); }
.autocomplete-option-meta { flex: none; font-size: 13px; line-height: 18px; color: var(--ff-text-muted); }
.autocomplete-option-meta.money { color: var(--ff-text-label); }
.autocomplete-option.is-add { color: var(--ff-action-hover); justify-content: flex-start; gap: var(--ff-space-2); }
.autocomplete-empty { padding: var(--ff-space-3); color: var(--ff-text-muted); }
/* The choice once made: the value, and a text action to change it. */
.autocomplete-selection {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ff-space-3);
  min-height: var(--ff-control-height-touch);
  padding: 0 var(--ff-space-1) 0 14px;
  border-radius: var(--ff-radius-md);
  background: var(--ff-surface-group);
  color: var(--ff-text-strong);
  font: 600 16px/24px var(--font-sans);
}
@media (min-width: 640px) {
  .autocomplete-selection { min-height: var(--ff-control-height); font-size: 14px; }
  .chip { min-height: 36px; }
}

/* ---------- Calendar (pick one or more days; the month before is shown too where both fit) ---------- */
.calendar { position: relative; display: flex; flex-direction: column; gap: var(--ff-space-2); container-type: inline-size; }
/* The arrows sit on the month titles' row, at its outer ends; the titles centre between them. */
.calendar-header { position: absolute; inset: 0 0 auto; height: var(--ff-tap-target); display: flex; align-items: center; justify-content: space-between; pointer-events: none; }
.calendar-header > * { pointer-events: auto; }
.calendar-months { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--ff-space-6); }
/* Too narrow for two months side by side: only the current one; the arrows reach the others. */
@container (max-width: 559px) {
  .calendar-months { grid-template-columns: minmax(0, 1fr); }
  .calendar-month:first-child { display: none; }
}
.calendar-month { display: flex; flex-direction: column; gap: var(--ff-space-2); min-width: 0; }
.calendar-month-title { display: flex; align-items: center; justify-content: center; min-height: var(--ff-tap-target); margin: 0; font-size: 16px; line-height: 24px; font-weight: 600; text-transform: capitalize; color: var(--ff-text-strong); }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.calendar-weekday { padding-bottom: var(--ff-space-1); text-align: center; font-size: 12px; line-height: 16px; font-weight: 500; color: var(--ff-text-muted); }
.calendar-day {
  position: relative;
  min-height: var(--ff-tap-target);
  border: 0;
  border-radius: var(--ff-radius-md);
  background: transparent;
  color: var(--ff-text-strong);
  font: 500 14px/20px var(--font-sans);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.calendar-day:hover { background: var(--ff-hover-wash); }
.calendar-day.is-today { box-shadow: inset 0 0 0 1px var(--ff-border-strong); }
/* Work already logged and not yet billed: the day has the ongefactureerd ground (picking it again makes a duplicate). */
.calendar-day.has-unbilled { background: var(--ff-stage-unbilled-bg); color: var(--ff-stage-unbilled-text); }
.calendar-day[aria-pressed="true"] { background: var(--ff-action); color: var(--ff-text-on-action); box-shadow: none; }
/* Work already billed that day: one quiet dot under the number, paid or not. */
.calendar-day.has-billed::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 5px;
  width: 6px;
  height: 6px;
  border-radius: var(--ff-radius-pill);
  background: var(--ff-icon-quiet);
  transform: translateX(-50%);
}
.calendar-day[aria-pressed="true"]::after { background: var(--ff-text-on-action); }
.calendar-footer { font-size: 13px; line-height: 18px; color: var(--ff-text-muted); }

/* ---------- Contract progress ---------- */
.contract-progress-item { display: flex; flex-direction: column; gap: 6px; }
.contract-progress-header { display: flex; justify-content: space-between; gap: var(--ff-space-3); font-size: 14px; }
.contract-progress-header .cp-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--ff-text-strong); white-space: nowrap; }
.contract-progress-bar { height: 8px; border-radius: var(--ff-radius-pill); background: var(--ff-surface-sunken); overflow: hidden; display: flex; }
.contract-progress-fill { height: 100%; border-radius: var(--ff-radius-pill); background: var(--ff-action); }
.contract-progress-fill.is-warning { background: var(--ff-feedback-warning-fill); }
.contract-progress-fill.is-danger { background: var(--ff-danger); }
/* The part of the progress that comes from compensation, drawn after the work itself. */
.contract-progress-fill:has(+ .is-comp) { border-radius: var(--ff-radius-pill) 0 0 var(--ff-radius-pill); }
.contract-progress-fill.is-comp { background: var(--ff-feedback-warning-fill); opacity: 0.6; border-radius: 0 var(--ff-radius-pill) var(--ff-radius-pill) 0; }
.contract-progress-meta { display: flex; justify-content: space-between; gap: var(--ff-space-3); font-size: 12px; line-height: 16px; color: var(--ff-text-muted); }
/* A date range never breaks inside a date. */
.contract-progress-meta .mono { white-space: nowrap; }
.contract-progress-meta .is-warning { color: var(--ff-feedback-warning-text); font-weight: 500; }

/* ---------- Bar list (a small bar chart: one row per item) ---------- */
.bar-list { display: flex; flex-direction: column; gap: var(--ff-space-2); }
.bar-row { display: grid; grid-template-columns: 56px minmax(0, 1fr) 88px; align-items: center; gap: var(--ff-space-3); }
.bar-list.is-names .bar-row { grid-template-columns: minmax(0, 120px) minmax(0, 1fr) 88px; }
.bar-label { font-size: 12px; line-height: 16px; color: var(--ff-text-muted); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-list.is-names .bar-label { font-size: 14px; line-height: 20px; color: var(--ff-text-body); text-align: left; }
.bar-track { display: flex; height: 18px; border-radius: var(--ff-radius-sm); background: var(--ff-surface-sunken); overflow: hidden; }
.bar-fill { height: 100%; min-width: 2px; background: var(--ff-chart-billed); }
.bar-fill.is-unbilled { background: var(--ff-chart-unbilled); }
.bar-amount { font: 600 12px/16px var(--font-mono); font-variant-numeric: tabular-nums; color: var(--ff-text-body); text-align: right; white-space: nowrap; }
.bar-legend { display: flex; flex-wrap: wrap; gap: var(--ff-space-1) var(--ff-space-4); margin-top: var(--ff-space-3); font-size: 12px; line-height: 16px; color: var(--ff-text-muted); }
.bar-legend-item { display: inline-flex; align-items: center; gap: var(--ff-space-2); }
.bar-legend-swatch { width: 10px; height: 10px; border-radius: var(--ff-radius-xs); background: var(--ff-chart-billed); }
.bar-legend-swatch.is-unbilled { background: var(--ff-chart-unbilled); }

/* ---------- Group box ---------- */
.settings-group-box {
  display: flex;
  flex-direction: column;
  gap: var(--ff-space-3);
  padding: var(--ff-space-4);
  border-radius: var(--ff-radius-md);
  background: var(--ff-surface-group);
}

/* ---------- Action card ---------- */
.settings-template-cards { display: flex; flex-direction: column; gap: var(--ff-space-2); }
.settings-template-card {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: var(--ff-tap-target);
  padding: var(--ff-space-4) 20px;
  border-radius: var(--ff-radius-md);
  background: var(--ff-surface-group);
  color: var(--ff-text-body);
  text-decoration: none;
  cursor: pointer;
}
.settings-template-card-icon { color: var(--ff-icon-quiet); width: var(--ff-icon-md); height: var(--ff-icon-md); flex-shrink: 0; }
.settings-template-card-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.settings-template-card-text strong { font-weight: 600; color: var(--ff-text-strong); }
.settings-template-card-text span { font-size: 13px; line-height: 18px; color: var(--ff-text-muted); }
.settings-template-card-arrow { color: var(--ff-icon-quiet); flex-shrink: 0; }
.settings-template-card:hover { background: var(--ff-surface-sunken); }
.settings-template-card:hover .settings-template-card-arrow { color: var(--ff-text-label); }

/* ---------- Alert (attention row) ---------- */
.alert {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ff-space-3);
  padding: 14px var(--ff-space-4);
  border-radius: var(--ff-radius-lg);
  background: var(--ff-feedback-warning-bg);
  color: var(--ff-feedback-warning-text);
}
.alert-text { flex: 1 1 260px; min-width: 0; }
.alert-overdue { background: var(--ff-status-overdue-bg); color: var(--ff-status-overdue-text); }
.alert .icon-chip { background: var(--ff-surface-card); }
.alert-overdue .icon-chip { color: var(--ff-status-overdue-icon); }
.alert-warning .icon-chip { color: var(--ff-feedback-warning-icon); }
.alert .btn-secondary { background: var(--ff-surface-card); color: inherit; }

/* ---------- Toast ---------- */
.ff-toast-stack {
  position: fixed;
  z-index: var(--ff-z-toast);
  left: var(--ff-space-4);
  right: var(--ff-space-4);
  bottom: calc(var(--ff-space-4) + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: var(--ff-space-2);
  pointer-events: none;
}
/* Above the tab bar, on pages that have one, clear of the raised + and its ring. */
.mobile-tab-bar ~ .ff-toast-stack { bottom: calc(var(--ff-tabbar-height) + var(--ff-fab-rise) + var(--ff-fab-ring) + var(--ff-space-3) + env(safe-area-inset-bottom, 0px)); }
.ff-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--ff-space-3);
  padding: 10px var(--ff-space-2) 10px var(--ff-space-3);
  border-radius: var(--ff-radius-lg);
  background: var(--ff-surface-card);
  box-shadow: var(--ff-shadow-popover);
  color: var(--ff-text-strong);
}
.ff-toast-message { flex: 1; min-width: 0; }
.ff-toast-action { border: 0; background: transparent; color: var(--ff-action-hover); font: 600 14px/20px var(--font-sans); min-height: var(--ff-tap-target); padding: 0 var(--ff-space-2); cursor: pointer; }
@media (min-width: 1024px) {
  .ff-toast-stack { left: auto; right: var(--ff-space-6); top: calc(var(--ff-topbar-height) + var(--ff-space-4)); bottom: auto; width: 380px; }
}
@media (prefers-reduced-motion: no-preference) {
  .ff-toast { animation: ff-toast-in var(--ff-duration-base) var(--ff-ease); }
}
@keyframes ff-toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Modal / sheet ---------- */
/* Hidden until opened with the is-open class. Legacy pages that still set
   style.display on a modal keep working, because the inline style wins. */
.modal {
  position: fixed;
  overscroll-behavior: contain; /* scrolling past a modal's end never moves the page behind it */
  inset: 0;
  margin: 0; /* a modal sits in the page flow; section spacing must not move its backdrop */
  z-index: var(--ff-z-modal);
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: var(--ff-overlay);
}
.modal.is-open { display: flex; }
.modal-content {
  box-sizing: border-box;
  width: 100%;
  max-height: calc(100% - var(--ff-space-8));
  display: flex;
  flex-direction: column;
  background: var(--ff-surface-card);
  border-radius: var(--ff-radius-lg) var(--ff-radius-lg) 0 0;
  box-shadow: var(--ff-shadow-modal);
}
.modal-content::before {
  content: "";
  align-self: center;
  width: 36px;
  height: 5px;
  margin-top: var(--ff-space-2);
  border-radius: var(--ff-radius-pill);
  background: var(--ff-border-strong);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: var(--ff-space-2); padding: var(--ff-space-1) var(--ff-space-2) var(--ff-space-1) 20px; }
.modal-header h2 { font-size: 18px; line-height: 26px; font-weight: 600; }
/* A sub-view inside a modal (one contract rule): back, title, one action. */
.subview-header { display: flex; align-items: center; gap: var(--ff-space-2); margin-left: calc(-1 * var(--ff-space-3)); }
.subview-header > h3 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* One quiet line under the title: a number, a ranking. */
.modal-subtitle { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ff-space-2); margin: 2px 0 0; font-size: 13px; line-height: 18px; color: var(--ff-text-muted); }
.modal-body { padding: var(--ff-space-2) 20px 20px; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: var(--ff-space-4); }
/* Footers of modals and pages. Write the buttons in DOM order danger, secondary, primary.
   Phones: one full-width button per row, primary on top, danger last. From 640px: one row,
   a danger action (modal-footer-start) on the far left, secondary left of primary. */
.modal-footer, .form-actions {
  display: flex;
  flex-direction: column-reverse;
  gap: var(--ff-space-3);
}
.modal-footer {
  padding: var(--ff-space-3) 20px calc(var(--ff-space-3) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--ff-border);
}
.modal-footer > .btn-primary, .modal-footer > .btn-secondary, .modal-footer > .btn-danger,
.form-actions > .btn-primary, .form-actions > .btn-secondary, .form-actions > .btn-danger {
  width: 100%;
  min-height: var(--ff-control-height-touch);
}
@media (min-width: 640px) {
  .modal-footer, .form-actions { flex-direction: row; justify-content: flex-end; }
  .modal-footer > .btn-primary, .modal-footer > .btn-secondary, .modal-footer > .btn-danger,
  .form-actions > .btn-primary, .form-actions > .btn-secondary, .form-actions > .btn-danger {
    width: auto;
    min-height: var(--ff-control-height);
  }
  .modal-footer > .modal-footer-start, .form-actions > .modal-footer-start { margin-right: auto; }
  .modal { align-items: center; padding: var(--ff-space-6); }
  .modal-content { max-width: var(--ff-modal-max); border-radius: var(--ff-radius-lg); max-height: calc(100% - var(--ff-space-12)); }
  .modal-content::before { display: none; }
  .modal-header { padding: 20px var(--ff-space-3) var(--ff-space-1) var(--ff-space-6); }
  .modal-body { padding: var(--ff-space-2) var(--ff-space-6) var(--ff-space-6); }
  .modal-footer { padding: var(--ff-space-4) var(--ff-space-6); }
  .modal-large .modal-content { max-width: var(--ff-modal-max-large); }
}
@media (prefers-reduced-motion: no-preference) {
  .modal-content { animation: ff-sheet-in var(--ff-duration-slow) var(--ff-ease); }
}
@keyframes ff-sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Action bar (a page's own actions: a flow's next step, a form's Opslaan) ---------- */
/* At the bottom of the screen, in place of the tab bar while it shows (see the end of this file).
   Phones: one full-width button per row, primary on top, as in a modal footer, and in the page flow
   (sticky), so it is as tall as its buttons need. From 640px: fixed, one row at the right; on desktop
   lined up with the content column. */
.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--ff-z-nav);
  display: flex;
  justify-content: flex-end;
  gap: var(--ff-space-3);
  padding: var(--ff-space-3) var(--ff-space-4) calc(var(--ff-space-3) + env(safe-area-inset-bottom, 0px));
  background: var(--ff-surface-card);
  box-shadow: var(--ff-shadow-popover);
}
@media (max-width: 639.98px) {
  .action-bar { position: sticky; flex-direction: column-reverse; margin-inline: calc(-1 * var(--ff-space-4)); }
  .action-bar > .btn-primary, .action-bar > .btn-secondary { min-height: var(--ff-control-height-touch); }
}
@media (min-width: 640px) {
  .action-bar > .btn-primary, .action-bar > .btn-secondary { flex: 0 0 auto; min-height: var(--ff-control-height); }
}
@media (min-width: 1024px) {
  .action-bar {
    bottom: 0;
    padding: var(--ff-space-3) max(var(--ff-space-6), calc((100% - var(--ff-container-max)) / 2 + var(--ff-space-6))) calc(var(--ff-space-3) + env(safe-area-inset-bottom, 0px));
  }
}

/* ---------- Top bar (desktop) ---------- */
.navbar { display: none; }
@media (min-width: 1024px) {
  .navbar {
    display: block;
    position: sticky;
    top: 0;
    z-index: var(--ff-z-nav);
    background: var(--ff-surface-card);
    border-bottom: 1px solid var(--ff-border);
  }
  .navbar-inner {
    box-sizing: border-box;
    max-width: var(--ff-container-max);
    margin: 0 auto;
    padding: 0 var(--ff-space-6);
    min-height: var(--ff-topbar-height);
    display: flex;
    align-items: center;
    gap: var(--ff-space-1);
  }
  .navbar-spacer { flex: 1; }
  .navbar .btn-primary, .navbar .harvest-btn { min-height: 40px; padding: 0 18px; margin-left: var(--ff-space-2); }
}
/* The wordmark large (login): type, not a drawn logo; the slash takes the action blue. */
.ff-type-wordmark { margin: 0; font: 700 32px/40px var(--font-mono); color: var(--ff-text-strong); }
.ff-type-wordmark .slash { color: var(--ff-action); }
.nav-brand { font: 700 20px/28px var(--font-mono); color: var(--ff-text-strong); margin-right: 20px; text-decoration: none; }
.nav-brand .slash { color: var(--ff-action); }
.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--ff-radius-pill);
  color: var(--ff-text-label);
  font: 500 14px/20px var(--font-sans);
  text-decoration: none;
}
.nav-link:hover { color: var(--ff-text-strong); background: var(--ff-hover-wash); }
.nav-link.active { background: var(--ff-action-subtle); color: var(--ff-action-hover); font-weight: 600; }

/* ---------- Mobile header (phone + tablet) ---------- */
.mobile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--ff-space-3) + env(safe-area-inset-top, 0px)) var(--ff-space-4) var(--ff-space-2);
}
@media (min-width: 640px) { .mobile-header { padding-inline: var(--ff-space-8); } }
@media (min-width: 1024px) { .mobile-header { display: none; } }

/* ---------- Tab bar (phone + tablet) ---------- */
.mobile-tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--ff-z-nav);
  box-sizing: border-box;
  height: calc(var(--ff-tabbar-height) + env(safe-area-inset-bottom, 0px));
  padding: 0 max(var(--ff-space-2), env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(var(--ff-space-2), env(safe-area-inset-left, 0px));
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: center;
  background: var(--ff-surface-card);
  border-top: 1px solid var(--ff-border);
}
.mobile-tab-bar a {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--ff-tap-target);
  color: var(--ff-text-muted);
  font: 500 12px/16px var(--font-sans);
  text-decoration: none;
}
.mobile-tab-bar a svg { width: var(--ff-icon-lg); height: var(--ff-icon-lg); }
.mobile-tab-bar a.active { color: var(--ff-action-hover); font-weight: 600; }
/* The raised +: its top sits --ff-fab-rise above the bar, its ring --ff-fab-ring around it. The
   toasts above the bar read the same tokens, so they always clear it. */
.mobile-tab-bar .tab-werk {
  justify-self: center;
  align-self: start;
  width: var(--ff-fab-size);
  height: var(--ff-fab-size);
  margin-top: calc(-1 * var(--ff-fab-rise));
  border-radius: var(--ff-radius-pill);
  background: var(--ff-action);
  color: var(--ff-text-on-action);
  box-shadow: 0 0 0 var(--ff-fab-ring) var(--ff-surface-card), var(--ff-shadow-raised);
}
.mobile-tab-bar .tab-werk svg { width: 24px; height: 24px; }
.mobile-tab-bar .tab-werk.active { color: var(--ff-text-on-action); }
.mobile-harvest-badge {
  position: absolute;
  top: 2px;
  right: calc(50% - 15px);
  width: 8px;
  height: 8px;
  border-radius: var(--ff-radius-pill);
  background: var(--ff-harvest-bottom);
  box-shadow: 0 0 0 2px var(--ff-surface-card);
}
@media (min-width: 640px) { .mobile-tab-bar { padding-inline: var(--ff-space-12); } }
@media (min-width: 1024px) { .mobile-tab-bar { display: none; } }

/* ---------- Test mode banner ---------- */
.test-mode-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--ff-space-1) var(--ff-space-3);
  padding: var(--ff-space-2) var(--ff-space-4);
  background: var(--ff-feedback-warning-bg);
  color: var(--ff-feedback-warning-text);
  font-size: 13px;
  line-height: 18px;
  text-align: center;
}
.test-mode-label { font: 700 12px/16px var(--font-mono); letter-spacing: 0.5px; }

/* ---------- Footer ---------- */
.site-footer { padding: var(--ff-space-6) var(--ff-space-4); text-align: center; font-size: 12px; line-height: 16px; color: var(--ff-text-muted); }
.site-footer .footer-brand { font-family: var(--font-mono); font-weight: 600; color: var(--ff-text-body); }
/* The page ends with the footer, so the footer clears the fixed tab bar (only where there is one). */
@media (max-width: 1023.98px) {
  .mobile-tab-bar ~ .site-footer { padding-bottom: calc(var(--ff-space-6) + var(--ff-tabbar-height) + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- While an action bar shows (kept last: it outranks the footer and toast rules above) ---------- */
/* The footer makes room for the fixed bar, and toasts rise above it. */
body:has(.action-bar:not([hidden])) .site-footer { padding-bottom: calc(var(--ff-space-6) + var(--ff-control-height) + var(--ff-space-6) + env(safe-area-inset-bottom, 0px)); }
@media (max-width: 1023.98px) {
  /* It takes the tab bar's place: one bar at the bottom of the screen, not two stacked. */
  body:has(.action-bar:not([hidden])) .mobile-tab-bar { display: none; }
  body:has(.action-bar:not([hidden])) .ff-toast-stack { bottom: calc(var(--ff-control-height) + var(--ff-space-6) + var(--ff-space-3) + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 639.98px) {
  /* Here the bar is in the page flow: the footer needs no room for it, and toasts show at the top. */
  body:has(.action-bar:not([hidden])) .site-footer { padding-bottom: calc(var(--ff-space-6) + env(safe-area-inset-bottom, 0px)); }
  body:has(.action-bar:not([hidden])) .ff-toast-stack { top: calc(var(--ff-space-4) + env(safe-area-inset-top, 0px)); bottom: auto; }
}
