/* ==========================================================================
   Bookhouder — Monarch-inspired light/dark theme.
   Design language: warm paper canvas, white elevated cards, a muted sage
   accent for actions, one coral highlight reserved for "create", and soft
   settled/open status tints. All colour, elevation, spacing, and type are
   token-driven so light and dark stay in lockstep.

   Accessibility notes baked into the values (WCAG AA):
   - Coral (--accent-2) NEVER carries white text (3.01:1) — fills pair with
     --on-accent-2 (dark ink), coral-as-text uses the darker --accent-2-text.
   - Sage as TEXT uses --primary-text (differs from the fill token in dark,
     where #3C8272 reads 3.49:1); sage as FILL keeps white --on-primary.
   - Spec literals that missed AA were nudged: muted #6B7280→#656E7B on the
     canvas, unsettled chip ink #B25B32→#A04E26 on its tint.
   ========================================================================== */

@font-face {
  font-family: "Inter";
  src: url("fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;

  /* Surfaces */
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --border: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.14);

  /* Text */
  --text: #1f2933;
  --text-2: #3e4c59;
  --muted: #656e7b;

  /* Brand + semantics */
  --primary: #2f6f62;
  --primary-hover: #285e53;
  --primary-weak: #e9f1ee;
  --primary-text: #2f6f62;
  --on-primary: #ffffff;
  --ring: rgba(47, 111, 98, 0.35);

  --accent-2: #e8734a;
  --accent-2-hover: #de6438;
  --on-accent-2: #1f2933;
  --accent-2-text: #bf4e22;

  --positive: #2f6f4c;
  --positive-weak: #e7f1ec;
  --danger: #b42318;
  --danger-weak: #fbeae8;
  --warning: #a04e26;
  --warning-weak: #fbeae2;
  --on-warning: #ffffff;

  /* Status chips (settled / open) */
  --status-settled-fg: #2f6f4c;
  --status-settled-bg: #e7f1ec;
  --status-open-fg: #a04e26;
  --status-open-bg: #fbeae2;

  /* Elevation */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);

  /* Shape */
  --radius: 16px;
  --radius-sm: 8px;

  /* Spacing scale — the only gaps/paddings/margins allowed */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Type scale (Inter; headings semibold) */
  --font-body: 0.9375rem;  /* 15px */
  --font-h1: 1.75rem;      /* 28px */
  --font-h2: 1.5rem;       /* 24px */
  --font-h3: 1.25rem;      /* 20px */
  --font-small: 0.8125rem; /* 13px */
  --font-tiny: 0.75rem;    /* 12px */

  /* Motion: fade/slide only, ease-out */
  --duration: 180ms;
  --ease: cubic-bezier(0, 0, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #14181c;
    --surface: #1d2329;
    --surface-2: #232a31;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);

    --text: #edeff1;
    --text-2: #c3cbd3;
    --muted: #9aa4ae;

    --primary: #3c8272;
    --primary-hover: #45927f;
    --primary-weak: rgba(60, 130, 114, 0.18);
    --primary-text: #5fb3a1;
    --on-primary: #ffffff;
    --ring: rgba(95, 179, 161, 0.45);

    --accent-2: #e3835f;
    --accent-2-hover: #e9946f;
    --on-accent-2: #14181c;
    --accent-2-text: #e3835f;

    --positive: #86c9a5;
    --positive-weak: #1e2e26;
    --danger: #f97066;
    --danger-weak: rgba(249, 112, 102, 0.14);
    --warning: #f7b27a;
    --warning-weak: rgba(247, 178, 122, 0.14);
    --on-warning: #14181c;

    --status-settled-fg: #86c9a5;
    --status-settled-bg: #1e2e26;
    --status-open-fg: #e39a70;
    --status-open-bg: #2e241e;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.55);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-7);
}

/* --- Top bar ---------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand__logo {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand__name {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand__tagline {
  font-size: 0.82rem;
  color: var(--muted);
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* --- Page head (project identity strip above the workspace) ----------------- */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}

.page-head__title {
  margin: 0;
  font-size: var(--font-h2);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.page-head__date {
  margin: var(--space-1) 0 0;
  color: var(--muted);
  font-size: var(--font-small);
}

.page-head__status {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Same recipe as the dashboard's card chips, so status reads identically
   everywhere. */
.status-chip {
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: var(--font-tiny);
  font-weight: 600;
  white-space: nowrap;
}

.status-chip--settled {
  background: var(--status-settled-bg);
  color: var(--status-settled-fg);
}

.status-chip--open {
  background: var(--status-open-bg);
  color: var(--status-open-fg);
}

/* --- Workspace grid (form + sticky results) -------------------------------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr);
  gap: var(--space-5);
  align-items: start;
}

.klus-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  min-width: 0;
}

.results-col {
  position: sticky;
  top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

/* --- Cards ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.card__head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.card__heading {
  min-width: 0;
}

.card__title {
  margin: 0;
  font-size: var(--font-h3);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card__hint {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

/* --- Fields ----------------------------------------------------------------- */

.field {
  margin-bottom: var(--space-4);
}

.field:last-child {
  margin-bottom: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: var(--space-4);
}

.field-row .field {
  margin-bottom: 0;
}

.field__label {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--text-2);
  font-size: var(--font-small);
  font-weight: 600;
}

.field__control {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.field__control:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

.field__prefix,
.field__suffix {
  display: flex;
  align-items: center;
  padding: 0 0.8rem;
  color: var(--muted);
  background: var(--surface-2);
  font-weight: 600;
  user-select: none;
}

.field__prefix {
  border-right: 1px solid var(--border);
}

.field__suffix {
  border-left: 1px solid var(--border);
}

.field__input {
  flex: 1;
  min-width: 0;
  width: 100%;
  min-height: 2.75rem; /* 44px touch target */
  padding: var(--space-2) var(--space-3);
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}

.field__input::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

/* Free-form notes: a multi-line variant of the standard field input. */
.field__textarea {
  resize: vertical;
  min-height: 3.25rem;
  line-height: 1.4;
}

/* Bare inputs (not wrapped in a .field__control) carry their own frame. */
.roster__name,
.roster__add .field__input,
.category-row__name {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.roster__name:focus,
.roster__add .field__input:focus,
.category-row__name:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

.field__error {
  min-height: 1.05rem;
  margin: 0.35rem 0 0;
  color: var(--danger);
  font-size: 0.8rem;
  font-weight: 500;
}

.field--invalid .field__control,
.field--invalid .field__input {
  border-color: var(--danger);
}

.field--invalid .field__control:focus-within {
  box-shadow: 0 0 0 3px var(--danger-weak);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 2.75rem; /* 44px touch target */
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background var(--duration) var(--ease), border-color var(--duration) var(--ease),
    box-shadow var(--duration) var(--ease), transform 150ms var(--ease);
}

.btn:hover {
  background: var(--primary-hover);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.btn--ghost {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
}

.btn--ghost:hover {
  background: var(--surface-2);
  border-color: var(--muted);
}

.btn--danger {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
  font-weight: 500;
  box-shadow: none;
  padding: 0.5rem 0.7rem;
}

.btn--danger:hover {
  background: var(--danger-weak);
}

/* The editor's primary Save button; the base .btn is already primary-coloured,
   so this just makes the intent explicit. */
.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

.btn--primary:hover {
  background: var(--primary-hover);
}

/* Save turns amber while the editor has unsaved changes, so it is impossible to
   forget to persist. Paired with the "Unsaved changes" badge. */
.btn--attention {
  background: var(--warning);
  border-color: var(--warning);
  color: var(--on-warning);
  box-shadow: 0 0 0 3px var(--warning-weak);
}

.btn--attention:hover {
  background: var(--warning);
  filter: brightness(0.94);
}

/* The create-project call to action — the ONE coral element per screen. Coral
   fails AA under white text (3.01:1), so it always pairs with dark ink. */
.btn--cta {
  background: var(--accent-2);
  border-color: transparent;
  color: var(--on-accent-2);
}

.btn--cta:hover {
  background: var(--accent-2-hover);
}

.dirty-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--warning);
  background: var(--warning-weak);
  border: 1px solid var(--warning);
}

.topbar__status {
  font-size: 0.85rem;
  color: var(--text-2);
}

/* --- Expenses / custom categories ------------------------------------------ */

.category-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-bottom: 0.85rem;
}

.category-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 8.5rem auto auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.category-row__amount-control {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.category-row--cost {
  border-left-color: var(--danger);
}

.category-row--addition {
  border-left-color: var(--positive);
}

/* The sign IS the type control: one click to flip, and its value is readable
   in colour without opening anything (the old <select> cost two clicks). */
.category-row__sign {
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.category-row__sign[data-type="cost"] {
  background: var(--danger-weak);
  color: var(--danger);
}

.category-row__sign[data-type="addition"] {
  background: var(--positive-weak);
  color: var(--positive);
}

.category-row__sign:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

.category-row__remove {
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.category-row__remove:hover {
  background: var(--danger-weak);
  color: var(--danger);
}

.category-row__remove:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

/* Quick-add chips: the expense names that recur on every klus. */
.expense-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.chip--add {
  font-size: 0.83rem;
  padding: 0.4rem 0.7rem;
}

.chip--custom,
.chip--all {
  border-style: dashed;
}

/* --- People chips ----------------------------------------------------------- */

.people-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.chip {
  min-height: 2.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.94rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--duration) var(--ease), border-color var(--duration) var(--ease), color var(--duration) var(--ease);
}

.chip:hover {
  border-color: var(--primary);
  color: var(--primary-text);
}

.chip:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

.chip--present {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

.chip--present:hover {
  background: var(--primary-hover);
  color: var(--on-primary);
}

/* --- Split-method segmented control ----------------------------------------- */

.split-toggle {
  display: inline-flex;
  padding: 0.2rem;
  margin-bottom: 1rem;
  gap: 0.2rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-2);
}

.split-toggle__option {
  margin: 0;
  cursor: pointer;
}

.split-toggle__input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.split-toggle__label {
  display: inline-block;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  color: var(--text-2);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}

.split-toggle__input:checked + .split-toggle__label {
  background: var(--primary);
  color: var(--on-primary);
}

.split-toggle__input:focus-visible + .split-toggle__label {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

/* --- Hours per day + time (days & hours) rows ------------------------------ */

/* Split method + the hours-per-day setting share one line: the toggle is the
   decision, the pill is a setting that should not look like a step. */
.split-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.hpd {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.hpd:focus-within {
  border-color: var(--primary);
  color: var(--primary-text);
}

.hpd[hidden] {
  display: none;
}

.hpd__input {
  width: 3rem;
  padding: 0.1rem 0.2rem;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.hpd__input:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--ring);
}

.hpd__input::-webkit-outer-spin-button,
.hpd__input::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
}

.hpd__input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* One line of coaching: teaches that the seeded rows are already correct. */
.split-hint {
  margin: 0.7rem 0 0;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.82rem;
}

/* Each present person is one compact card: name + live total on a header line,
   then Days and Hours side by side, then a quiet action row.
   NOTE: this row must NOT carry the .share__row class — that rule is a
   `grid-template-columns: 1fr 7.5rem` two-column layout defined later in this
   file, which would win on source order and crush these controls. */
.time__row {
  display: block;
  padding: 0.75rem 0.85rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

/* The collapsed summary line: name · duration · payout · chevron. This is the
   whole row on the common path — the controls live behind it. */
.time__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.55rem 0.15rem;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.time__head:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
  border-radius: var(--radius-sm);
}

.time__name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The duration reads quietly while a person has no hours logged yet, and firms
   up once they have at least one timesheet entry. */
.time__readout {
  flex: none;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-weight: 600;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.time__readout[data-empty="1"] {
  border-style: dashed;
  color: var(--muted);
}

.time__pay {
  flex: none;
  min-width: 5.2rem;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.time__pay--negative {
  color: var(--danger);
}

.time__chev {
  color: var(--muted);
  font-size: 0.75rem;
  transition: transform var(--duration) var(--ease);
}

.time__row[data-open="1"] .time__chev {
  transform: rotate(180deg);
}

.time__body {
  display: none;
  padding-top: 0.5rem;
  margin-top: 0.35rem;
  border-top: 1px dashed var(--border);
}

.time__row[data-open="1"] .time__body {
  display: block;
}

/* Timesheet entry log — one row per day/session inside an expanded person row. */
.time__entries {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Date | Days | Hours | Note | ✕ — a responsive grid that stacks the four
   fields onto their own rows only when the column is genuinely too narrow. */
.entry-row {
  display: grid;
  grid-template-columns: minmax(8rem, 1.4fr) minmax(0, 0.7fr) minmax(0, 0.7fr) minmax(6rem, 1.6fr) auto;
  align-items: end;
  gap: 0.4rem 0.5rem;
  padding: 0.5rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.entry-row__cell {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.entry-row__label {
  color: var(--text-2);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.entry-row .field__input {
  width: 100%;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  font-variant-numeric: tabular-nums;
}

.entry-row__note .field__input {
  font-variant-numeric: normal;
}

/* The delete affordance sits at the end of the row, aligned to the inputs. */
.entry-row__remove {
  align-self: end;
  height: 2.1rem;
  width: 2.1rem;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease), border-color var(--duration) var(--ease);
}

.entry-row__remove:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--on-primary, #fff);
}

.entry-row__remove:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

/* The prominent "Add entry" button under the log. */
.time__add-entry {
  margin-top: 0.65rem;
}

.btn--add-entry {
  width: 100%;
  justify-content: center;
  border-style: dashed;
}

.time__add-entry:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* On a narrow column, drop the ✕ to a full-width track under the fields. */
@media (max-width: 520px) {
  .entry-row {
    grid-template-columns: 1fr 1fr;
  }
  .entry-row__cell--date,
  .entry-row__cell--note {
    grid-column: 1 / -1;
  }
  .entry-row__remove {
    grid-column: 1 / -1;
    width: 100%;
  }
}

/* --- Per-person share rows -------------------------------------------------- */

.shares-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.share__row {
  display: grid;
  grid-template-columns: 1fr 7.5rem;
  gap: 0.75rem;
  align-items: center;
}

.share__name {
  font-weight: 600;
}

.share__percent-control {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

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

.allocation-counter {
  position: relative;
  margin: 0;
  padding: 0.7rem 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
}

/* Track + fill sit flush along the bottom edge; the fill width is driven by the
   --alloc custom property that app.js updates (0–100). */
.allocation-counter::before,
.allocation-counter::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
}

.allocation-counter::before {
  right: 0;
  background: var(--border);
}

.allocation-counter::after {
  width: calc(var(--alloc, 0) * 1%);
  background: var(--primary);
  transition: width var(--duration) var(--ease);
}

.allocation-counter--over {
  color: var(--danger);
  border-color: var(--danger);
}

.allocation-counter--over::after {
  background: var(--danger);
}

/* --- Company cut toggle switch ---------------------------------------------- */

.company-cut {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  user-select: none;
}

.switch-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch {
  flex: none;
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background var(--duration) var(--ease);
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform var(--duration) var(--ease);
}

.switch-input:checked + .switch {
  background: var(--primary);
}

.switch-input:checked + .switch::after {
  transform: translateX(18px);
}

.switch-input:focus-visible + .switch {
  box-shadow: 0 0 0 3px var(--ring);
}

.switch-label {
  color: var(--text-2);
  font-weight: 500;
}

.company-cut__field {
  margin-top: 0.9rem;
  margin-bottom: 0;
  max-width: 12rem;
}

/* --- Roster editor ---------------------------------------------------------- */

.people-manage {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.9rem;
}

.people-manage > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.people-manage > summary::-webkit-details-marker {
  display: none;
}

.people-manage > summary::before {
  content: "▸";
  transition: transform var(--duration) var(--ease);
  display: inline-block;
}

.people-manage[open] > summary::before {
  transform: rotate(90deg);
}

.people-manage[open] > summary {
  margin-bottom: 0.85rem;
}

.roster__list {
  list-style: none;
  margin: 0 0 0.85rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.roster__item {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.roster__item .roster__name {
  flex: 1;
}

.roster__add {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.roster__add .field__input {
  flex: 1;
}

/* --- Not-ready hint (missing required fields / over-allocation) ------------- */

.klus-form--not-ready .card:first-child {
  box-shadow: var(--shadow-sm), inset 3px 0 0 var(--warning);
}

/* --- Settled klus: read-only editor + banner -------------------------------- */

.settled-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin-bottom: 0;
  border: 1px solid var(--positive);
  border-radius: var(--radius);
  background: var(--positive-weak);
  color: var(--status-settled-fg);
  /* Third child of the two-column workspace grid — span the full row so the
     form/overview columns keep their places below it. */
  grid-column: 1 / -1;
}

/* `display: flex` above outranks the UA's `[hidden] { display: none }` (author
   origin wins), so the hidden state needs its own rule. */
.settled-banner[hidden] {
  display: none;
}

.settled-banner__text {
  margin: 0;
  font-weight: 600;
}

/* Belt-and-braces on top of the JS `disabled` sweep: dim the frozen form and
   swallow pointer input. The server 409 is the real lock; this is UX only. */
.klus-form--readonly {
  opacity: 0.7;
  pointer-events: none;
}

/* --- Overview stat tiles ----------------------------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  margin: var(--space-4) 0;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
}

.stat-tile__label {
  color: var(--muted);
  font-size: var(--font-tiny);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-tile__value {
  font-size: var(--font-h3);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat-tile__value--positive {
  color: var(--positive);
}

.stat-tile__value--negative {
  color: var(--danger);
}

/* --- Results placeholder ---------------------------------------------------- */

.results-placeholder {
  display: none;
  text-align: center;
  padding: 2.25rem 1.5rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
}

/* Shown only while the results section is still hidden (before first calc). */
.results-col:has(#results[hidden]) .results-placeholder {
  display: block;
}

.results-placeholder__icon {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--primary-weak);
  color: var(--primary-text);
  margin-bottom: 0.75rem;
}

.results-placeholder__title {
  margin: 0 0 0.3rem;
  color: var(--text);
  font-weight: 600;
}

.results-placeholder__hint {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.5;
}

/* --- Results ---------------------------------------------------------------- */

.results {
  box-shadow: var(--shadow-md);
}

.results__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}

.results__meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4rem 0.75rem;
  margin: 0 0 1.1rem;
}

.results__title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.results__title:empty {
  display: none;
}

.results__tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.results__tags span:empty {
  display: none;
}

.results__tags span {
  padding: 0.1rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}

.results-table {
  width: 100%;
  border-collapse: collapse;
}

.results-table__caption {
  text-align: left;
  padding-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.breakdown__row {
  border-bottom: 1px solid var(--border);
}

.breakdown__row:last-child {
  border-bottom: none;
}

.breakdown__label {
  padding: 0.45rem 0;
  color: var(--text-2);
}

.breakdown__amount {
  padding: 0.45rem 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.breakdown__amount--negative {
  color: var(--danger);
}

.loss-warning {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  background: var(--danger-weak);
  color: var(--danger);
  font-weight: 600;
  font-size: 0.88rem;
}

.payout__row {
  border-bottom: 1px solid var(--border);
}

.payout__name {
  padding: 0.5rem 0;
  font-weight: 600;
}

.payout__percent {
  padding: 0.5rem 0.6rem;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.payout__amount {
  padding: 0.5rem 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.payout__row--company,
.payout__row--unallocated {
  color: var(--muted);
}

.payout__row--company .payout__name,
.payout__row--unallocated .payout__name {
  color: var(--muted);
  font-weight: 500;
}

.payout__row--unallocated {
  color: var(--warning);
}

.payout__row--unallocated .payout__name,
.payout__row--unallocated .payout__percent,
.payout__row--unallocated .payout__amount {
  color: var(--warning);
}

.results__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1.25rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
}

.results__copy-status {
  color: var(--positive);
  font-size: 0.85rem;
  font-weight: 600;
}

/* --- Footer ----------------------------------------------------------------- */

.app__foot {
  margin-top: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

/* --- Responsive ------------------------------------------------------------- */

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .results-col {
    position: static;
    /* Overview-first on mobile: the calculated summary stacks above the form. */
    order: -1;
  }
  /* …but the settled banner outranks everything — it must stay on top. */
  .settled-banner {
    order: -2;
  }
  /* On a single column the placeholder is redundant — the form is right there. */
  .results-placeholder {
    display: none !important;
  }
}

@media (max-width: 520px) {
  .app {
    padding: var(--space-4) var(--space-3) var(--space-6);
  }
  .topbar {
    margin-bottom: var(--space-4);
  }
  .card {
    padding: var(--space-4);
  }
  .field-row {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }
  /* Narrow: the name takes its own line; amount + the two square icon buttons
     share the next one. The icons must stay square, never stretch. */
  .category-row {
    grid-template-columns: minmax(0, 1fr) auto auto;
  }
  .category-row__name {
    grid-column: 1 / -1;
  }
  .category-row__amount-control {
    width: 100%;
  }
  .share__row {
    grid-template-columns: 1fr 6.5rem;
  }
  .results__actions .btn {
    flex: 1 1 auto;
  }
}

/* --- Print: summary only ---------------------------------------------------- */
/* #results keeps its `hidden` latch, so an uncalculated klus prints nothing
   extra. We only strip chrome and flatten the layout for paper. */
@media print {
  .topbar,
  #klus-form,
  .results-placeholder,
  .results__actions,
  .app__foot {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .app {
    max-width: none;
    padding: 0;
  }

  .workspace {
    display: block;
  }

  .results-col {
    position: static;
  }

  .card,
  .results {
    background: #fff;
    border: none;
    box-shadow: none;
    padding: 0;
  }

  .stat-tile {
    background: none;
    border: 1px solid #ccc;
  }

  .stat-tile__value--positive,
  .payout__amount {
    color: #000;
  }

  .stat-tile__value--negative,
  .breakdown__amount--negative,
  .payout__row--unallocated .payout__amount {
    color: #8a0000;
  }
}

/* --- Phase 6: backlog (history) page --------------------------------------- */

.unlock__row {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
}

.unlock__row .field__control {
  flex: 1;
}

.select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  cursor: pointer;
}

.select:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

.backlog-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.backlog-controls__row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem;
}

.backlog-controls__row .field {
  margin-bottom: 0;
}

.backlog-status {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- Shared dashboard states (error / empty) --------------------------------- */

.state-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-4) 0;
  padding: var(--space-6);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center;
}

.state-panel[hidden] {
  display: none;
}

.state-panel__title {
  margin: 0;
  color: var(--text);
  font-size: var(--font-h3);
  font-weight: 600;
}

.state-panel__hint {
  margin: 0;
  color: var(--muted);
}

.state-panel .btn {
  margin-top: var(--space-2);
}

/* --- Loading skeleton: shimmering card shapes, no spinner -------------------- */

.skeleton-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 150px;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.skeleton-bar {
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    var(--border) 50%,
    var(--surface-2) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s var(--ease) infinite;
}

.skeleton-bar--title {
  width: 60%;
  height: 16px;
}

.skeleton-bar--date {
  width: 40%;
}

.skeleton-bar--meta {
  width: 75%;
}

.skeleton-bar--actions {
  width: 50%;
  margin-top: auto;
}

@keyframes skeleton-shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* --- Bento grid ------------------------------------------------------------
   Uniform tiles in an auto-filling grid: 3-up on a wide screen, folding to 2 and
   then 1 as the viewport narrows, with no explicit breakpoint needed. `auto-fill`
   (not `auto-fit`) keeps a lone card at one column's width instead of stretching
   it across the whole row. Mirrors the .backlog-controls__row pattern above. */
.bento-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-4);
  align-items: stretch;
}

/* Below ~600px a 260px minimum would still try to fit two cramped columns on
   some phones; force a single column so the cards stay readable. */
@media (max-width: 600px) {
  .bento-grid {
    grid-template-columns: 1fr;
  }
}

/* The grid's own "add" affordance — a real <button>, so it is focusable and
   keyboard-activated for free. Uniform size: it is just another tile. */
.bento-tile-new {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 150px;
  padding: var(--space-4);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  transition: border-color var(--duration) var(--ease), color var(--duration) var(--ease),
    background var(--duration) var(--ease);
}

/* The create affordance is the ONE coral element on the dashboard. */
.bento-tile-new:hover {
  border-color: var(--accent-2);
  color: var(--accent-2-text);
  background: var(--warning-weak);
}

.bento-tile-new:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.bento-tile-new__plus {
  font-size: 1.75rem;
  line-height: 1;
  font-weight: 300;
}

.bento-tile-new__label {
  font-size: 0.9rem;
  font-weight: 600;
}

/* A card is a column so its action row can be pinned to the tile's bottom edge
   (margin-top:auto below), which is what makes ragged content read as an even
   grid. `cursor: pointer` advertises that the body is a click target for Open. */
.backlog-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: var(--space-4);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.backlog-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* Settled projects read differently before any text does: a sage accent edge
   and a slightly receded surface. The chip carries the words. */
.backlog-card--settled {
  background: var(--surface-2);
  box-shadow: inset 3px 0 0 var(--positive), var(--shadow-sm);
}

.backlog-card--settled:hover {
  box-shadow: inset 3px 0 0 var(--positive), var(--shadow-md);
}

/* The nested controls are their own targets — don't inherit the card's affordance. */
.backlog-card button,
.backlog-card input {
  cursor: auto;
}

.backlog-card button {
  cursor: pointer;
}

.backlog-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.backlog-card__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

/* Headline: the klus date the user set. The largest thing after the title. */
.backlog-card__project-date {
  margin: 0.45rem 0 0;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* A klus saved before the date field existed shows its savedAt here instead —
   muted, because it is inferred rather than stated. */
.backlog-card__project-date--inferred {
  color: var(--muted);
  font-weight: 600;
}

/* The small secondary "saved …" line. Hidden when it would repeat the headline. */
.backlog-card__date {
  margin: var(--space-1) 0 0;
  color: var(--muted);
  font-size: var(--font-tiny);
}

.backlog-card__date[hidden] {
  display: none;
}

/* One quiet line of essentials: net amount · worker count. */
.backlog-card__meta-row {
  margin: var(--space-3) 0 0;
  color: var(--text-2);
  font-size: var(--font-small);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* --- Version history (server-owned last 20 snapshots) ---------------------- */

.backlog-card__history {
  margin: 0.6rem 0 0;
}

.backlog-card__history[hidden] {
  display: none;
}

.backlog-card__history-toggle {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
}

.backlog-card__history-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.backlog-card__history-list[hidden] {
  display: none;
}

.version-row {
  border-top: 1px solid var(--border);
  padding: 0.4rem 0 0;
}

.version-row__head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.version-row__net--negative {
  color: var(--danger, #c0392b);
}

.version-row__people {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.version-row__person {
  font-variant-numeric: tabular-nums;
}

/* --- Printable export container (hidden on screen; shown while printing) ---- */

.export-root {
  display: none;
  color: #000;
}

.export__title {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
}

.export__generated {
  margin: 0 0 1rem;
  color: #444;
  font-size: 0.9rem;
}

.export-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.export-table th,
.export-table td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid #ccc;
}

.export-table th {
  border-bottom: 2px solid #000;
}

.export-table th:nth-child(4),
.export-table th:nth-child(5),
.export-table td:nth-child(4),
.export-table td:nth-child(5) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.export-total td {
  font-weight: 700;
  border-top: 2px solid #000;
  border-bottom: none;
}

/* While exporting the backlog, hide the interactive page and print only the
   export table + totals. The is-exporting class is toggled by dashboard.js. */
@media print {
  body.is-exporting > .app {
    display: none !important;
  }
  body.is-exporting .export-root {
    display: block !important;
  }
}

/* --- Create-project modal (native <dialog>) ---------------------------------- */

dialog.modal {
  width: min(420px, calc(100vw - var(--space-5)));
  padding: var(--space-5);
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
}

dialog.modal::backdrop {
  background: rgba(20, 24, 28, 0.5);
}

/* Fade/slide in on open — the spec's one sanctioned entrance motion. */
dialog.modal[open] {
  animation: modal-in var(--duration) var(--ease);
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal__title {
  margin: 0 0 var(--space-4);
  font-size: var(--font-h3);
  font-weight: 600;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

/* --- Undo toast (New klus is destructive; give it a way back) --------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: var(--space-5);
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  max-width: calc(100vw - var(--space-6));
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: 0.88rem;
}

.toast[hidden] {
  display: none;
}

.toast__text {
  color: var(--text-2);
}

.toast__action {
  padding: 0.25rem 0.7rem;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font: inherit;
  font-size: 0.83rem;
  font-weight: 700;
  cursor: pointer;
}

.toast__action:hover {
  background: var(--primary-hover);
}

.toast__action:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

@media print {
  .toast { display: none !important; }
}

/* Kill ALL motion (transitions, shimmer, dialog slide, chevrons, hover lifts —
   present and future) for users who asked for less of it. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Crew ledger: what each person is owed across the shown klussen --------- */

.ledger {
  margin: 0 0 var(--space-5);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.ledger[hidden] {
  display: none;
}

.ledger__head {
  margin-bottom: 0.75rem;
}

.ledger__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.ledger__hint {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.ledger__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.ledger__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.ledger__row:last-child {
  border-bottom: 0;
}

.ledger__name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger__klussen {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.ledger__amount {
  min-width: 6rem;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ledger__amount--negative {
  color: var(--danger);
}

.ledger__total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin: 0.85rem 0 0;
  padding-top: 0.7rem;
  border-top: 2px solid var(--border-strong);
  color: var(--text-2);
  font-size: 0.88rem;
  font-weight: 600;
}

.ledger__total strong {
  font-size: 1.1rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Card actions: Open / Duplicate / Delete, pinned to the bottom of the tile.
   `margin-top: auto` eats the slack in a short card, so every action row in the
   grid lines up on the same baseline however ragged the content above it. */
.backlog-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: auto;
  padding-top: 0.75rem;
}

/* --- Settlement: selection checkbox + status badge ------------------------- */

/* The checkbox rides inside a padded label so the touch target reaches 44px
   without inflating the visible box. The negative margin re-absorbs the
   padding so the card's text alignment is unchanged. */
.backlog-card__select-wrap {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
  margin: calc(-1 * var(--space-3));
  cursor: pointer;
}

.backlog-card__select {
  flex: none;
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  cursor: pointer;
  accent-color: var(--primary);
}

.backlog-card__select:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.backlog-card__select:disabled {
  cursor: default;
}

/* Let the title take the free space so the badge/actions sit to the right. */
.backlog-card__head .backlog-card__title {
  flex: 1 1 auto;
}

/* Status chip — ALWAYS present, one variant per state, so settled vs open
   never relies on the presence/absence of text alone. */
.backlog-card__status {
  flex: none;
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: var(--font-tiny);
  font-weight: 600;
  white-space: nowrap;
}

.backlog-card__status--settled {
  background: var(--status-settled-bg);
  color: var(--status-settled-fg);
}

.backlog-card__status--open {
  background: var(--status-open-bg);
  color: var(--status-open-fg);
}
