/* Spruce UI components — buttons, forms, modals, cards, toasts */
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;
}
.auth-gate {
  position: fixed; inset: 0; z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: var(--background);
}
html.staff-supabase-auth .auth-gate { display: none !important; }
.staff-auth-loading {
  position: fixed; inset: 0; z-index: 9999;
  display: none; align-items: center; justify-content: center;
  padding: 20px; background: var(--background);
  font-size: var(--type-body-size); font-weight: var(--type-caption-weight);
  color: var(--text-mid);
}
html.staff-supabase-auth .staff-auth-loading { display: flex; }
html.staff-supabase-auth.staff-auth-ready .staff-auth-loading { display: none; }
.auth-gate-card {
  width: 100%; max-width: 400px;
  background: var(--light-card); border: 1px solid var(--border); border-radius: 16px;
  padding: 22px 22px 20px; box-shadow: 0 12px 40px rgba(16, 24, 40, 0.08);
}
.auth-gate-title { margin-bottom: 6px; }
.auth-gate-sub { font-size: var(--type-ui-size); color: var(--text-light); line-height: 1.45; margin-bottom: 18px; }
.auth-gate-error { font-size: var(--type-ui-size); color: var(--error); margin-bottom: 12px; min-height: 1.2em; }
.auth-gate-step2 { display: none; }
.auth-gate.auth-step2 .auth-gate-step1 { display: none; }
.auth-gate.auth-step2 .auth-gate-step2 { display: block; }
.auth-gate-remember { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: var(--type-body-size); color: var(--text-mid); cursor: pointer; }
.auth-gate-remember input { width: auto; margin: 0; }

.content-card {
  background: transparent; border: none; border-radius: 0;
  padding: 0; margin-bottom: 28px; box-shadow: none;
}
.content-card--paper {
  background: var(--surface-paper); border-radius: 16px;
  padding: 18px 20px; margin-bottom: 28px;
}
.content-title { font-size: var(--type-h2-size); margin-bottom: 6px; }
.content-sub { font-size: var(--type-ui-size); color: var(--text-mid); line-height: 1.55; margin-bottom: 14px; }

/* ── KPI & stat metric cards (semantic roles) ── */
.kpi-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  margin: 12px 0 32px;
  padding: 6px 0;
}
@media (min-width: 700px) { .kpi-strip { grid-template-columns: repeat(4, 1fr); } }
.kpi-strip.is-hidden { display: none; }

.kpi-card,
.stat-card {
  background: var(--card-bg);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 13px;
  box-shadow: none;
  transition: var(--button-transition);
}
.kpi-card.clickable,
.stat-card-interactive { cursor: pointer; }
.kpi-card.clickable:hover,
.stat-card-interactive:hover { filter: brightness(0.98); }
.kpi-card.clickable:active,
.stat-card-interactive:active { transform: scale(0.995); }

/* Semantic surface roles */
.kpi-card.kpi-neutral,
.stat-card.kpi-neutral { background: var(--surface-stone); border-color: transparent; }
.kpi-card.kpi-stone,
.stat-card.kpi-stone { background: var(--surface-stone); border-color: transparent; }
.kpi-card.kpi-context,
.stat-card.kpi-context { background: var(--surface-context); border-color: transparent; }
.kpi-card.kpi-positive,
.stat-card.kpi-positive { background: var(--surface-positive); border-color: transparent; }
.kpi-card.kpi-attention,
.stat-card.kpi-attention { background: var(--surface-attention); border-color: transparent; }
.kpi-card.kpi-warning,
.stat-card.kpi-warning { background: var(--surface-warning); border-color: transparent; }

/* Quiet empty / all-clear state */
.kpi-card.kpi-empty,
.stat-card.kpi-empty {
  background: var(--surface-pebble);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
}
.kpi-card.kpi-filter-active,
.stat-card.kpi-filter-active { background: var(--surface-context); border-color: transparent; }

/* Legacy class aliases */
.kpi-card.gdpr-due { background: var(--surface-warning); border-color: transparent; }
.kpi-card.gdpr-due:hover { filter: brightness(0.98); }

.kpi-label { display: block; margin-bottom: 6px; }
.kpi-val, .kpi-value,
.stat-value {
  font-family: var(--font-primary);
  font-size: 18px;
  font-weight: var(--type-h1-weight);
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text-primary);
}
@media (min-width: 400px) { .kpi-val, .kpi-value, .stat-value { font-size: 20px; } }

/* Accent text off semantic cards (tables, lists, pebble/paper bg) */
.kpi-val.income, .kpi-value.teal, .kpi-value.primary,
.stat-value.income, .stat-value.primary { color: var(--accent-focus); }
.kpi-val.expense, .kpi-value.coral, .kpi-value.accent,
.stat-value.expense, .stat-value.accent { color: var(--accent-warning); }
.kpi-val.outstanding, .stat-value.outstanding { color: var(--accent-attention); }
.kpi-val.profit, .kpi-val.appts, .kpi-val.neutral,
.stat-value.neutral { color: var(--text-primary); }

/* On semantic cards: primary text for values, accent for supporting labels only */
.kpi-card.kpi-attention .kpi-val,
.kpi-card.kpi-attention .kpi-value,
.kpi-card.kpi-warning .kpi-val,
.kpi-card.kpi-warning .kpi-value,
.kpi-card.kpi-positive .kpi-val,
.kpi-card.kpi-positive .kpi-value,
.kpi-card.kpi-context .kpi-val,
.kpi-card.kpi-context .kpi-value,
.stat-card.kpi-attention .stat-value,
.stat-card.kpi-warning .stat-value,
.stat-card.kpi-positive .stat-value,
.stat-card.kpi-context .stat-value { color: var(--text-primary); }

.kpi-sub, .stat-sub { font-size: var(--type-caption-size); color: var(--text-muted); margin-top: 4px; }
.kpi-card.kpi-attention .kpi-sub-accent,
.kpi-card.kpi-warning .kpi-sub-accent { color: var(--accent-warning); }
.kpi-delta { font-size: var(--type-caption-size); font-weight: var(--type-ui-weight); margin-top: 3px; }
.kpi-delta.up { color: var(--accent-focus); }
.kpi-delta.down { color: var(--accent-warning); }
.kpi-delta.neutral { color: var(--text-mid); }

/* ── Illustrated empty states ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px 20px 32px;
  background: var(--surface-paper);
  border: none;
  border-radius: 14px;
  color: var(--text-primary);
}
.empty-state--inline {
  padding: 24px 20px 28px;
}
.empty-state-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: 100%;
}
.empty-state-img {
  width: min(120px, 42vw);
  height: auto;
  margin: 0 auto 16px;
  opacity: 0.92;
  filter: saturate(0.92);
  display: block;
}
.empty-state-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.35;
  margin-bottom: 6px;
}
.empty-state-body {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  max-width: 34ch;
  margin-left: auto;
  margin-right: auto;
}
.empty-state-action { margin-top: 12px; }
.empty-state-action a,
.empty-state-action button {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
}
.settings-logout-btn {
  width: 100%;
  text-align: left;
  color: var(--accent-warning) !important;
  margin-top: 4px;
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  margin: 12px 0 32px;
  padding: 6px 0;
}
@media (min-width: 520px) { .stat-row { grid-template-columns: repeat(3, 1fr); } }

.stat-label { display: block; margin-bottom: 6px; }

/* ── Badges (semantic) ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 99px;
  font-family: var(--font-primary);
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-paid,
.badge-matched,
.badge-filed { background: var(--surface-positive); color: var(--text-primary); }
.badge-outstanding,
.badge-sent,
.badge-ready { background: var(--surface-attention); color: var(--accent-attention); }
.badge-overdue { background: var(--surface-warning); color: var(--accent-warning); }
.badge-neutral,
.badge-draft,
.badge-unmatched,
.badge-progress,
.badge-cancel,
.badge-void { background: var(--surface-stone); color: var(--text-primary); }
.badge-attended { background: var(--surface-positive); color: var(--text-primary); }
.badge-dna { background: var(--surface-warning); color: var(--accent-warning); }
.badge-upcoming { background: var(--surface-context); color: var(--text-primary); }
.badge-pending { background: var(--surface-stone); color: var(--text-muted); }
.badge-locked { background: var(--surface-attention); color: var(--accent-attention); }

.badge,
.dd-badge,
.appt-badge,
.meta-chip,
.gs-meta-chip {
  color: var(--text-primary);
}

/* ── Empty states ── */
.empty-state,
.state-empty {
  padding: 32px 16px;
  text-align: center;
  background: var(--surface-paper);
  border: none;
  border-radius: 12px;
  color: var(--text-primary);
}
.empty-state svg,
.state-empty svg { margin-bottom: 10px; opacity: 0.35; }
.empty-state p,
.state-empty p { font-size: 13px; color: var(--text-muted); }

/* Elevated card surface — lighter than page background (e.g. list panels on dashboards) */
.surface-card-light,
.card-light {
  background: var(--surface-card-light);
}

/* ── Modals ── */
.modal-overlay {
  position: fixed; inset: 0; background: var(--overlay);
  backdrop-filter: blur(5px); z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
@media (min-width: 600px) { .modal-overlay { align-items: center; } }
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--light-card); border-radius: 18px 18px 0 0;
  width: 100%; max-height: 96dvh; overflow-y: auto;
  box-shadow: 0 -8px 48px rgba(0, 0, 0, 0.18);
  transform: translateY(24px); transition: transform 0.26s cubic-bezier(0.34, 1.22, 0.64, 1);
}
@media (min-width: 600px) {
  .modal { border-radius: 18px; width: 480px; max-height: 95dvh; transform: translateY(12px) scale(0.97); box-shadow: 0 24px 72px rgba(0, 0, 0, 0.2); }
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }

/* Finance date-range popover (anchored to trigger button) */
.dp-popover-overlay {
  position: fixed; inset: 0; z-index: 250;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.dp-popover-overlay.open { opacity: 1; pointer-events: all; }
.dp-scrim {
  position: absolute; inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(5px);
}
.dp-popover {
  position: fixed; z-index: 251;
  width: min(320px, calc(100vw - 28px));
  background: var(--light-card);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.16);
  overflow: hidden;
}
.dp-popover-head {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
}
.dp-popover-title { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.dp-popover-body { padding: 10px 12px; max-height: min(60dvh, 420px); overflow-y: auto; }
.dp-popover-foot {
  padding: 8px 12px;
  border-top: 1px solid var(--border-light);
}
.dp-foot-actions { display: flex; gap: 6px; margin-bottom: 0; margin-top: 0; }
.dp-foot-actions:only-child { margin-top: 0; }
.dp-repeat-row + .dp-foot-actions,
.dp-presets + .dp-foot-actions,
.dp-presets + .dp-repeat-row + .dp-foot-actions { margin-top: 8px; }
.dp-range-display[hidden],
.dp-single-display[hidden] { display: none !important; }
.dp-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 0; }
.dp-preset {
  padding: 6px 11px;
  border: 1px solid color-mix(in srgb, var(--text-primary) 12%, transparent);
  border-radius: 999px;
  font-family: var(--font-primary);
  font-size: 12px; font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  background: var(--surface-stone-light);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.dp-preset:hover {
  background: var(--surface-context);
  color: var(--text-primary);
  border-color: color-mix(in srgb, var(--accent-focus) 28%, transparent);
}
.dp-preset.active {
  background: var(--surface-context);
  color: var(--text-primary);
  border-color: color-mix(in srgb, var(--accent-focus) 35%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-focus) 18%, transparent);
}
.dp-range-display {
  display: flex; align-items: center; gap: 0; margin-bottom: 8px;
  background: var(--surface-context);
  border: 1px solid color-mix(in srgb, var(--accent-focus) 22%, transparent);
  border-radius: 10px; overflow: hidden;
}
.dp-range-field { flex: 1; padding: 7px 10px; }
.dp-range-label {
  font-family: var(--font-secondary);
  font-size: 9px; font-weight: 700; letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 3px;
}
.dp-range-val { font-size: 13px; font-weight: 700; color: var(--text-primary); min-height: 17px; }
.dp-range-input {
  width: 100%; border: none; background: transparent;
  font-family: inherit; font-size: 13px; font-weight: 700;
  color: var(--text-primary); min-height: 17px; padding: 0; outline: none; border-radius: 4px;
}
.dp-range-input::placeholder { color: var(--text-muted); opacity: 0.85; }
.dp-range-input:focus { outline: 2px solid color-mix(in srgb, var(--accent-focus) 40%, transparent); outline-offset: 1px; }
.dp-range-input.dp-range-input-invalid { outline: 2px solid var(--accent-warning); outline-offset: 1px; }
.dp-range-sep { width: 1px; background: color-mix(in srgb, var(--accent-focus) 22%, transparent); margin: 10px 0; flex-shrink: 0; }
.dp-single-display {
  margin-bottom: 8px;
  background: var(--surface-context);
  border: 1px solid color-mix(in srgb, var(--accent-focus) 22%, transparent);
  border-radius: 10px; padding: 7px 10px;
}
.dp-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 5px; }
.dp-month-label-btn {
  border: none; background: transparent; font-family: inherit;
  font-size: 13px; font-weight: 700; color: var(--text-primary);
  cursor: pointer; padding: 4px 10px; border-radius: 8px; transition: background 0.1s;
}
.dp-month-label-btn:hover { background: var(--surface-stone-light); }
.dp-month-year-panel {
  display: flex; gap: 8px; margin-bottom: 8px; padding: 8px 10px;
  background: var(--surface-stone-light); border-radius: 10px;
  border: 1px solid var(--border-light);
}
.dp-month-year-panel[hidden] { display: none; }
.dp-month-year-select {
  flex: 1; min-width: 0; font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--text-primary); padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--light-card);
}
.dp-nav-btn {
  width: 28px; height: 28px; border: none; background: transparent; border-radius: 7px;
  cursor: pointer; color: var(--accent-focus); font-size: 16px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.1s; -webkit-tap-highlight-color: transparent;
}
.dp-nav-btn:hover { background: var(--surface-context); }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.dp-day-name {
  font-family: var(--font-secondary); font-size: 9px; font-weight: 700;
  color: var(--text-muted); text-align: center; padding: 2px 0 4px; letter-spacing: 0.04em;
}
.dp-day {
  appearance: none; -webkit-appearance: none; border: none; background: transparent;
  width: 100%; height: 32px; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-primary); font-size: 12px; font-weight: 500; color: var(--text-primary);
  border-radius: 999px; cursor: pointer; transition: all 0.1s; position: relative; z-index: 0;
  -webkit-tap-highlight-color: transparent;
}
.dp-day:hover:not(:disabled) { background: color-mix(in srgb, var(--accent-focus) 14%, transparent); color: var(--text-primary); }
.dp-day.is-today { color: var(--accent-attention); font-weight: 800; }
.dp-day.is-today::after {
  content: ''; position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; background: var(--accent-attention); border-radius: 50%;
}
.dp-day.in-range { background: color-mix(in srgb, var(--accent-focus) 10%, transparent); border-radius: 0; }
.dp-day.range-start, .dp-day.range-end, .dp-day.is-selected {
  background: var(--accent-focus); color: #fff; font-weight: 700; border-radius: 999px;
}
.dp-day.range-start.in-range { border-radius: 999px 0 0 999px; }
.dp-day.range-end.in-range { border-radius: 0 999px 999px 0; }
.dp-day.range-start.range-end, .dp-day.is-selected.range-start.range-end { border-radius: 999px; }
.dp-day.other-month { opacity: 0.3; }
.dp-day:disabled { opacity: 0.2; cursor: default; }
.dp-repeat-row {
  display: flex; flex-direction: column; gap: 4px;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid var(--border-light);
}
.dp-repeat-label {
  font-family: var(--font-secondary); font-size: 9px; font-weight: 700;
  letter-spacing: 0.13em; text-transform: uppercase; color: var(--text-secondary);
}
.dp-repeat-select { font-size: 13px; }

.date-field-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left; cursor: pointer;
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
}
.date-field-btn svg { flex-shrink: 0; opacity: 0.62; color: var(--text-secondary); }
.date-field-btn span { flex: 1; min-width: 0; font-weight: 600; color: var(--text-primary); }
.modal-form-required .date-field-btn.is-field-empty span { color: var(--text-muted); font-weight: 500; }
.modal-form-required .date-field-btn.field-calculated,
.modal-form-required .date-field-btn.field-calculated span { color: var(--text-primary); }
.date-field-btn:disabled {
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
}

.modal-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 10px auto 0; }
@media (min-width: 600px) { .modal-handle { display: none; } }

.modal-header { padding: 16px 22px 14px; border-bottom: 1px solid color-mix(in srgb, var(--surface-stone) 45%, transparent); display: flex; align-items: flex-start; justify-content: space-between; }
.modal-eyebrow { margin-bottom: 3px; }
.modal-title { line-height: 1.1; }
.modal-header-actions { display: flex; align-items: flex-start; justify-content: flex-end; gap: 10px; margin-left: 10px; min-width: 0; }
.modal-header-ref { font-size: var(--type-caption-size); line-height: 1.15; color: var(--text-light); font-weight: 500; text-align: right; letter-spacing: 0.02em; white-space: nowrap; padding-top: 2px; }
.modal-title.modal-title-sm { font-size: 20px; }
.modal-sub { font-size: 12px; color: var(--text-light); margin-top: 2px; font-weight: 500; }

.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 8px;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-light); transition: color 0.14s, background 0.14s;
  flex-shrink: 0; -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover  { color: var(--text-mid); background: var(--surface-field-list); }
.icon-btn:active { color: var(--text); background: var(--surface-field-needed); }
.icon-btn.on-dark { color: var(--chrome-mid); }
.icon-btn.on-dark:hover  { color: var(--chrome-text); background: var(--chrome-hover); }
.icon-btn.on-dark:active { color: #fff; background: rgba(255, 255, 255, 0.2); }

.modal-close {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 7px;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-light); transition: color 0.14s, background 0.14s;
  flex-shrink: 0; margin-left: 0; -webkit-tap-highlight-color: transparent;
}
.modal-close:hover  { color: var(--text-mid); background: var(--surface-field-list); }
.modal-close:active { color: var(--text); background: var(--surface-field-needed); }

.modal-body { padding: 18px 22px; }

.modal-footer {
  padding: 12px 22px 18px; display: flex; gap: 8px;
  border-top: 1px solid color-mix(in srgb, var(--surface-stone) 45%, transparent);
}
@media (max-width: 599px) { .modal-footer { padding-bottom: max(18px, env(safe-area-inset-bottom, 18px)); } }

.filter-select {
  padding: 9px 32px 9px 11px;
  border: 1px solid var(--border); border-radius: 9px;
  background-color: var(--field-bg); cursor: pointer;
  color: var(--field-text);
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23488574'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  transition: border-color 0.14s, background-color 0.14s;
}
.filter-select:focus {
  border-color: var(--field-border-focus);
  box-shadow: var(--focus-ring);
  outline: none;
}

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 5px; }

.form-control,
.search-input,
.pane-search,
.settings-select {
  width: 100%; padding: 10px 13px;
  background: var(--field-bg); border: 1px solid transparent;
  border-radius: 9px; outline: none;
  color: var(--field-text);
  transition: border-color 0.14s, background 0.14s;
  appearance: none; -webkit-appearance: none;
}

/* Settings cards & modals — stone fill instead of borders on paper */
.content-card .form-control:not(.field-optional):not(.field-calculated):not([readonly]):not(:disabled),
.content-card .filter-select,
.content-card .settings-select,
.modal-body .form-control:not(.field-optional):not(.field-calculated):not([readonly]):not(:disabled),
.modal-body .filter-select,
.modal-body .settings-select {
  background: var(--surface-field-fill);
  border-color: transparent;
}
.content-card .form-control.field-optional,
.content-card .form-control.field-calculated,
.content-card .form-control[readonly],
.content-card .form-control:disabled,
.modal-body .form-control.field-optional,
.modal-body .form-control.field-calculated,
.modal-body .form-control[readonly],
.modal-body .form-control:disabled {
  background: var(--surface-field-optional);
  border-color: transparent;
}
.content-card .form-control:focus,
.content-card .filter-select:focus,
.content-card .settings-select:focus,
.modal-body .form-control:focus,
.modal-body .filter-select:focus,
.modal-body .settings-select:focus {
  border-color: var(--field-border-focus);
  box-shadow: var(--focus-ring);
}

/* Everyday-use modals: stone-light until filled, context when complete */
.modal-form-required {
  --field-bg: var(--surface-field-needed);
  --field-bg-focus: var(--surface-field-needed);
  --field-text: var(--text-on-field-needed);
}
.modal-form-required .picker-btn.is-field-empty {
  background: var(--surface-stone-light);
  border-color: transparent;
  color: var(--text);
}
.modal-form-required .picker-btn.is-field-filled {
  background: var(--surface-field-complete);
  border-color: transparent;
  color: var(--text);
}
.modal-form-required .form-control.field-calculated,
.modal-form-required .form-control.field-optional,
.modal-form-required .form-control[readonly],
.modal-form-required .form-control:disabled {
  border-color: transparent;
}

/* Border only when the control sits on page background (optional / paper) */
.form-control.field-optional,
.form-control.field-calculated,
.form-control[readonly],
.form-control:disabled,
.settings-select.field-optional,
.search-input.field-optional,
.pane-search.field-optional,
.picker-btn.is-on-background {
  border-color: transparent;
}
.search-input, .pane-search { width: auto; }

.form-control:focus,
.search-input:focus,
.pane-search:focus,
.settings-select:focus {
  border-color: var(--field-border-focus);
  background: var(--field-bg-focus);
  box-shadow: var(--focus-ring);
}

.form-control[readonly],
.form-control:disabled,
.form-control.field-optional,
.form-control.field-calculated,
.search-input.field-optional,
.settings-select.field-optional {
  background: var(--field-bg-optional);
  color: var(--text);
  border-color: transparent;
  cursor: default;
}

.modal-form-required .form-control:not(select):not(:placeholder-shown):not(:focus):not(:disabled):not([readonly]):not(.field-optional):not(.field-calculated),
.modal-form-required .search-input:not(:placeholder-shown):not(:focus):not(.field-optional),
.modal-form-required .pane-search:not(:placeholder-shown):not(:focus):not(.field-optional) {
  background: var(--field-bg-filled);
  border-color: transparent;
  color: var(--text);
}

.form-control.is-error,
.form-control:invalid:not(:placeholder-shown):not(:focus) {
  border-color: var(--field-border-error);
  background: var(--accent-pale);
  color: var(--text);
}

.form-control::placeholder,
.search-input::placeholder,
.pane-search::placeholder { color: var(--field-placeholder); font-weight: 400; }

/* Reusable row/card families
   - .spr-ledger-row: plain finance/document rows with simple dividers.
   - .spr-action-row: Today-style paper rows with a subtle pebble fill.
   - .spr-entity-row: larger editable settings/entity rows, optional swatch + chevron.
   - .spr-form-slab: setup/onboarding form cards, paper with internal pebble borders.
   Modifiers: --clickable, --active, --context-hover, --stone-hover, --with-swatch, --archived.
*/
.spr-ledger-list { background: transparent; }
.spr-ledger-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-primary);
}
.spr-ledger-row:last-child { border-bottom: none; }
.spr-ledger-row--clickable { cursor: pointer; transition: background 0.12s ease; }
.spr-ledger-row--clickable:hover { background: color-mix(in srgb, var(--surface-stone-light) 52%, transparent); }
.spr-action-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface-paper);
  border-radius: 14px;
  padding: 8px;
}
.spr-action-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface-pebble) 25%, transparent);
  color: inherit;
}
.spr-action-row--clickable { cursor: pointer; transition: background 0.12s ease; }
.spr-action-row--context-hover:hover,
.spr-action-row--active { background: color-mix(in srgb, var(--surface-context) 26%, var(--surface-paper)); }
.spr-action-row--stone-hover:hover { background: color-mix(in srgb, var(--surface-stone-light) 70%, var(--surface-paper)); }
.spr-entity-list { background: var(--surface-list-panel); border-radius: 0; padding: 0; }
.spr-entity-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: none;
  border-radius: 12px;
  margin-bottom: 10px;
  background: var(--surface-list-card);
  color: var(--text-primary);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--text-primary) 4%, transparent);
}
.spr-entity-row:last-child { margin-bottom: 0; }
.spr-entity-row--clickable { cursor: pointer; transition: background 0.12s ease; }
.spr-entity-row--clickable:hover { background: color-mix(in srgb, var(--surface-list-card) 92%, var(--text-primary) 8%); }
.spr-entity-row--archived { opacity: 0.82; background: var(--surface-field-optional); color: var(--text-on-field-optional); }
.spr-entity-row__swatch { width: 4px; height: 44px; border-radius: 3px; flex-shrink: 0; background: var(--surface-context); }
.spr-entity-row__chevron { flex-shrink: 0; font-size: 18px; line-height: 1; color: var(--text); font-weight: 700; }
.spr-form-slab {
  background: var(--surface-paper);
  border: none;
  border-radius: 14px;
  overflow: hidden;
}
.spr-form-slab__row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 13px 20px;
  border-bottom: 2px solid var(--surface-pebble);
}
.spr-form-slab__row:last-child { border-bottom: none; }

/* Settings list rows — paper cards on pebble panel */
.settings-entity-list,
.lookup-table.settings-entity-list {
  background: var(--surface-list-panel);
  border-radius: 0;
  padding: 0;
}
.settings-type-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border: none; border-radius: 12px;
  margin-bottom: 10px; background: var(--surface-list-card);
  color: var(--text-primary);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--text-primary) 4%, transparent);
}
.settings-type-row--clickable { cursor: pointer; }
.settings-type-row--clickable:hover { background: color-mix(in srgb, var(--surface-list-card) 92%, var(--text-primary) 8%); }
.settings-type-row--clickable:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.settings-type-row--archived { opacity: 0.82; background: var(--surface-field-optional); color: var(--text-on-field-optional); }
.settings-type-row-chevron {
  flex-shrink: 0; font-size: 18px; line-height: 1;
  color: var(--text); font-weight: 700;
}
.settings-type-row-price {
  flex-shrink: 0; font-size: 18px; font-weight: 700;
  color: var(--text-primary); letter-spacing: -0.02em; line-height: 1; margin-right: 2px;
}
.settings-type-row-price--variable { font-size: 12px; font-weight: 600; color: var(--text-mid); letter-spacing: 0; }
.settings-type-row:last-child { margin-bottom: 0; }

/* Primary + secondary text lines (list rows, pickers, type lists) */
.text-line-primary,
.settings-type-name {
  font-family: var(--font-primary);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}
.text-line-secondary,
.settings-type-detail {
  font-family: var(--font-primary);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-mid);
  line-height: 1.35;
  margin-top: 2px;
}
.settings-type-row-chevron,
.picker-btn-chevron,
.list-row-chevron {
  flex-shrink: 0;
  color: var(--text);
  font-weight: 700;
}

/* Explicit field fill states (selects, pickers — placeholder rules don’t apply) */
.modal-form-required .form-control.is-field-empty:not(:focus):not(.field-calculated),
.modal-form-required .picker-btn.is-field-empty {
  background: var(--surface-stone-light);
  border-color: transparent;
  color: var(--text);
}
.modal-form-required .form-control.is-field-filled:not(:focus),
.modal-form-required .picker-btn.is-field-filled {
  background: var(--surface-field-complete);
  border-color: transparent;
  color: var(--text);
}
.form-control.field-calculated,
.form-control.field-calculated:focus {
  background: var(--surface-field-optional);
  border-color: transparent;
  color: var(--text);
  box-shadow: none;
}
.picker-btn.is-field-empty .picker-btn-placeholder { color: var(--text-mid); }
.picker-btn.is-field-filled .picker-btn-placeholder { color: var(--text); }

/* Filter / date chips — soft tint, primary text (not teal-on-teal) */
.date-range-btn:hover,
.date-range-btn.has-range,
.doc-filter-chip:hover,
.doc-filter-chip.active,
.fp-inline-chip:hover,
.fp-inline-chip.active,
.rpt-pill:hover,
.rpt-pill.active,
.filter-pill,
.show-all-btn.show-all-active {
  background: var(--surface-chip-active);
  color: var(--text);
  border-color: var(--border);
}
#section-emails textarea.form-control { resize: none; overflow: hidden; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Lookup / account rows (Finance settings) ── */
.lookup-table {
  border: none;
  border-radius: 14px;
  overflow: visible;
  margin-bottom: 16px;
}
.lookup-table.settings-entity-list { padding: 8px; }
.lookup-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  border: none;
  border-radius: 12px;
  margin-bottom: 8px;
  background: var(--surface-list-card);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--text-primary) 4%, transparent);
}
.lookup-row:last-child { margin-bottom: 0; }
.lookup-row-clickable { cursor: pointer; transition: background 0.12s; }
.lookup-row-clickable:hover { background: color-mix(in srgb, var(--surface-list-card) 92%, var(--text-primary) 8%); }
.lookup-row-body { flex: 1; min-width: 0; }
.lookup-row-name { font-size: 13px; font-weight: 700; color: var(--text); }
.lookup-row-sub { font-size: 11px; color: var(--text-light); margin-top: 2px; }
.lookup-row-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Buttons (tiers: low → standard → cta-outline → cta) ── */
.btn-sm { padding: 7px 12px; font-size: 12px; }
.btn-block { width: 100%; }

.btn,
.btn-low, .btn-standard, .btn-outline, .btn-line,
.btn-ghost, .btn-cta, .btn-teal, .btn-primary,
.btn-cta-outline, .btn-teal-outline,
.btn-attention, .btn-coral, .btn-accent,
.btn-warning, .btn-danger, .btn-delete {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px; border-radius: 9px;
  cursor: pointer; transition: var(--button-transition);
  border: none; -webkit-tap-highlight-color: transparent; letter-spacing: 0.01em;
  text-decoration: none; white-space: nowrap;
  font-family: var(--font-primary);
  font-size: var(--type-ui-size);
  font-weight: var(--type-ui-weight);
}
a.btn, a.btn-teal, a.btn-primary, a.btn-outline, a.btn-cta, a.btn-standard, a.btn-line { text-decoration: none; }

/* Low — text-only / minimal chrome */
.btn-low {
  background: var(--button-ghost-bg);
  color: var(--text-mid);
  border: 1px solid transparent;
  box-shadow: none;
}
.btn-low:hover  { background: var(--button-ghost-bg-hover); color: var(--text); }
.btn-low:active { background: var(--surface-stone); }

/* Secondary — paper surface with border */
.btn-standard, .btn-outline, .btn-line {
  background: var(--button-secondary-bg);
  color: var(--button-secondary-text);
  border: 1px solid var(--button-secondary-border);
  box-shadow: none;
}
.btn-standard:hover, .btn-outline:hover, .btn-line:hover {
  background: var(--button-secondary-bg-hover);
  border-color: var(--button-secondary-border-hover);
  color: var(--button-secondary-text);
}
.btn-standard:active, .btn-outline:active, .btn-line:active {
  background: var(--surface-stone);
  border-color: transparent;
}

/* Ghost — transparent with material hover */
.btn-ghost {
  background: var(--button-ghost-bg);
  color: var(--button-ghost-text);
  border: 1px solid var(--button-secondary-border);
  box-shadow: none;
}
.btn-ghost:hover {
  background: var(--button-ghost-bg-hover);
  border-color: transparent;
  color: var(--button-ghost-text);
}
.btn-ghost:active { background: var(--surface-stone); border-color: transparent; }

.btn-danger, .btn-delete {
  background: var(--button-warning-bg);
  color: var(--button-warning-text);
  border: 1px solid var(--button-warning-border);
  box-shadow: none;
}
.btn-danger:hover, .btn-delete:hover { background: var(--button-warning-bg-hover); }
.btn-danger:active, .btn-delete:active { filter: brightness(0.96); }

/* Focus outline button */
.btn-cta-outline, .btn-teal-outline {
  background: transparent;
  color: var(--accent-focus);
  border: 1.5px solid var(--accent-focus);
  box-shadow: none;
}
.btn-cta-outline:hover, .btn-teal-outline:hover {
  background: var(--surface-context);
  color: var(--accent-focus);
}

/* Primary — forest green with cream text */
.btn-cta, .btn-teal, .btn-primary {
  background: var(--button-primary-bg);
  color: var(--button-primary-text);
  border: none;
  box-shadow: none;
  flex: 1;
}
.btn-cta:hover, .btn-teal:hover, .btn-primary:hover {
  background: var(--button-primary-bg-hover);
  color: var(--button-primary-text);
}
.btn-cta:active, .btn-teal:active, .btn-primary:active {
  background: var(--button-primary-bg-active);
  color: var(--button-primary-text);
}

/* Attention — sparing use */
.btn-attention, .btn-coral, .btn-accent {
  background: var(--button-attention-bg);
  color: var(--button-attention-text);
  border: 1px solid var(--button-attention-border);
  box-shadow: none;
  flex: 1;
}
.btn-attention:hover, .btn-coral:hover, .btn-accent:hover {
  background: var(--button-attention-bg-hover);
  color: var(--button-attention-text);
}

/* Warning / destructive filled */
.btn-warning {
  background: var(--button-warning-bg);
  color: var(--button-warning-text);
  border: 1px solid var(--button-warning-border);
  box-shadow: none;
}
.btn-warning:hover { background: var(--button-warning-bg-hover); }

/* ── Staff confirm / prompt modals (shared markup) ── */
.staff-modal-overlay {
  position: fixed; inset: 0; background: var(--overlay);
  backdrop-filter: blur(5px); z-index: 300;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
@media (min-width: 600px) { .staff-modal-overlay { align-items: center; } }
.staff-modal-overlay.open { opacity: 1; pointer-events: all; }
.staff-modal {
  background: var(--light-card); border-radius: 20px 20px 0 0;
  width: 100%; max-width: 480px; max-height: 88dvh;
  display: flex; flex-direction: column;
  box-shadow: 0 -8px 48px rgba(0, 0, 0, 0.18);
  transform: translateY(32px); transition: transform 0.26s cubic-bezier(0.34, 1.22, 0.64, 1);
}
@media (min-width: 600px) { .staff-modal { border-radius: 18px; transform: translateY(12px) scale(0.97); } }
.staff-modal-overlay.open .staff-modal { transform: translateY(0) scale(1); }
.staff-modal-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 10px auto 0; }
@media (min-width: 600px) { .staff-modal-handle { display: none; } }
.staff-modal-header { padding: 16px 20px 13px; border-bottom: 1px solid var(--border-light); display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.staff-modal-eyebrow { margin-bottom: 2px; }
.staff-modal-title { line-height: 1.15; }
.staff-modal-close { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 7px; background: transparent; border: none; cursor: pointer; color: var(--text-light); }
.staff-modal-body { padding: 16px 20px; font-size: var(--type-body-size); color: var(--text-mid); line-height: 1.55; }
.staff-modal-warning { font-size: var(--type-ui-size); color: var(--accent); line-height: 1.5; margin-top: 12px; }
.staff-modal-footer { padding: 12px 20px max(18px, env(safe-area-inset-bottom, 18px)); display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--border-light); }
.staff-modal-footer .btn-teal, .staff-modal-footer .btn-primary, .staff-modal-footer .btn-ghost { flex: 0 0 auto; }

/* ── File upload zone (receipt, logo, brand icon) ── */
.file-upload-zone {
  position: relative;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 16px 14px;
  background: var(--surface-field-optional, var(--surface-stone-light));
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.file-upload-zone:hover, .file-upload-zone.is-dragover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 6%, var(--surface-field-optional, var(--surface-stone-light)));
}
.file-upload-zone input[type="file"] {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}
.file-upload-zone-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-mid);
  text-align: center;
  pointer-events: none;
}
.file-upload-zone-empty svg { opacity: 0.55; flex-shrink: 0; }
.file-upload-zone-empty span { font-size: 13px; font-weight: 600; }
.file-upload-zone-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}
.file-upload-zone-preview {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 8px;
  flex-shrink: 0;
  background: var(--background);
}
.file-upload-zone-meta { min-width: 0; flex: 1; }
.file-upload-zone-name { font-size: 13px; font-weight: 600; color: var(--text); word-break: break-word; }
.file-upload-zone-sub { margin-top: 3px; font-size: 11px; color: var(--text-light); }
.file-upload-zone-actions { display: flex; gap: 8px; flex-shrink: 0; }
.staff-modal-wide { max-width: min(640px, 96vw); }
#staff-confirm-go:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: max(22px, env(safe-area-inset-bottom, 22px)); left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface-paper); color: var(--text-primary);
  padding: 10px 18px; border-radius: 10px; font-size: var(--type-ui-size); font-weight: var(--type-caption-weight);
  z-index: 999; transition: transform 0.32s cubic-bezier(0.34, 1.4, 0.64, 1);
  white-space: nowrap; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
  display: flex; align-items: center; gap: 8px; border-left: 3px solid var(--accent-focus);
}
.toast.success { border-left-color: var(--accent-focus); }
.toast.error { border-left-color: var(--accent-warning); background: var(--surface-warning); color: var(--text-primary); }
.toast-icon {
  width: 18px; height: 18px; border-radius: 999px; flex: 0 0 18px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; line-height: 1; font-weight: 800;
  background: var(--surface-context); color: var(--accent-focus);
}
.toast.error .toast-icon { background: var(--surface-warning); color: var(--accent-warning); }
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Dark mode component tweaks ── */
@media (prefers-color-scheme: dark) {
  .form-control, .filter-select, .search-input, .settings-select, .pane-search {
    color: var(--text);
    background: var(--field-bg);
    border-color: transparent;
  }
  .form-control.field-optional, .form-control.field-calculated,
  .form-control[readonly], .form-control:disabled,
  .settings-select.field-optional, .picker-btn.is-on-background {
    border-color: var(--field-border);
  }
  .form-control[readonly], .form-control:disabled,
  .form-control.field-optional, .form-control.field-calculated {
    background: var(--field-bg-optional);
    color: var(--text);
  }
  .modal-form-required .form-control:not(select):not(:placeholder-shown):not(:focus):not(:disabled):not([readonly]):not(.field-optional):not(.field-calculated) {
    background: var(--field-bg-filled);
    border-color: transparent;
    color: var(--text);
  }
  .form-control::placeholder, .search-input::placeholder, .pane-search::placeholder { color: var(--field-placeholder); }
  .settings-type-row { background: var(--surface-list-card); color: var(--text-primary); }
  .settings-type-row--archived { background: var(--surface-field-optional); color: var(--text-on-field-optional); }
  .lookup-row { background: var(--surface-list-card); }
  .btn-ghost { background: transparent; border-color: var(--field-border); color: var(--field-text); }
  .btn-ghost:hover { background: var(--surface-field-list); }
  .modal, .dp-popover, .staff-modal { background: var(--light-card); }
  .modal-header, .modal-footer, .staff-modal-header, .staff-modal-footer { border-color: var(--border); }
  .sidebar, .acct-dropdown, .module-dropdown { background: var(--surface-pebble); }
  .sb-nav-btn:hover { background: color-mix(in srgb, var(--surface-nav-highlight) 40%, transparent); }
  .sb-nav-btn.active { background: color-mix(in srgb, var(--surface-nav-highlight) 70%, transparent); }
}
