/* Facturo design system — hand-rolled, mobile-first, no build step (no
   Tailwind/Node; ARCHITECTURE.md §1). --brand is overridden per-tenant (injected as an
   inline <style> in base.html from core/context_processors.py); the value below is the
   placeholder default for anonymous/platform-staff pages.

   Breakpoint convention used throughout this file: base rules target mobile (stacked
   layout); a single `@media (max-width: 640px)` block per pattern holds the
   mobile-specific overrides. 640px is the one breakpoint for the whole app. */

:root {
  --brand: #2f6b3c;
  --brand-contrast: #ffffff;

  --neutral-50: #f8f9f7;
  --neutral-100: #eef0ec;
  --neutral-200: #dde1d8;
  --neutral-300: #c2c8bb;
  --neutral-500: #767d6f;
  --neutral-700: #454a41;
  --neutral-900: #22251f;

  --danger: #b3261e;
  --warning: #b06d00;
  --success: #2f6b3c;
  --info: #2a5c8a;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;

  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
  /* Soft card elevation (§7.2 "soft surfaces over hard borders") — a faint contact
     shadow plus a wider ambient one lifts cards off the neutral page without a border. */
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 16px rgba(0, 0, 0, 0.06);

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tap-target: 44px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--neutral-900);
  background: var(--neutral-50);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Typography ---------- */

h1, h2, h3 {
  line-height: 1.25;
  margin: 0 0 var(--space-4);
}

h1 { font-size: 1.625rem; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.0625rem; }

p {
  margin: 0 0 var(--space-4);
}

/* ---------- Accessibility utilities ---------- */

/* Visually hidden but reachable by screen readers (icon-only buttons, redundant labels). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* First focusable element on every page; jumps straight to <main> for keyboard/screen-
   reader users, skipping the header/nav. */
.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -3rem;
  background: var(--neutral-900);
  color: #fff;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  z-index: 2000;
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: var(--space-2);
}

/* Alpine convention: hide `x-cloak` elements until Alpine has initialized, so
   interactive-only markup (e.g. an unopened slide-over) never flashes visible. Not used
   on content that must stay visible with JS disabled (toasts, form errors). */
[x-cloak] {
  display: none !important;
}

/* ---------- Layout shell ---------- */

/* White header, green as accent (§7.2) — a neutral bar with a hairline underline, not a
   wall of brand color. Green shows up only on the active-nav indicator, the logo, and
   primary buttons. This also makes per-tenant --brand robust: an arbitrarily light tenant
   color no longer has to carry white header text. */
.site-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: #fff;
  color: var(--neutral-900);
  border-bottom: 1px solid var(--neutral-200);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.brand__logo {
  height: 32px;
  width: auto;
  border-radius: var(--radius-sm);
}

.brand__name {
  color: var(--neutral-900);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.125rem;
}

/* Nav itself: a right-aligned flex row that wraps naturally at desktop width. Collapses
   to a hidden, toggleable panel under 640px (see media block below) via Alpine's
   `navOpen` (declared on .site-header) toggling `.site-nav--open`. */
.site-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--space-4);
  flex: 1 1 auto;
}

.site-nav__list {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav__link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-target);
  color: var(--neutral-700);
  text-decoration: none;
  font-weight: 600;
  /* Reserve the indicator's 2px so active/inactive never shift the row. */
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.site-nav__link:hover {
  color: var(--neutral-900);
}

.site-nav__link.is-active {
  color: var(--neutral-900);
  border-bottom-color: var(--brand);
}

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

/* Hamburger toggle — hidden at desktop width; a CSS-only 3-bar icon (no icon font/SVG). */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--tap-target);
  height: var(--tap-target);
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.nav-toggle__icon {
  position: relative;
  display: inline-block;
  width: 22px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.nav-toggle__icon::before,
.nav-toggle__icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 22px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.nav-toggle__icon::before { top: -7px; }
.nav-toggle__icon::after { top: 7px; }

@media (max-width: 640px) {
  .nav-toggle {
    display: inline-flex;
    order: 2;
  }

  .brand {
    order: 1;
  }

  .site-nav {
    display: none;
    order: 3;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .site-nav.site-nav--open {
    display: flex;
  }

  .site-nav__list {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }

  .site-nav__link {
    padding: var(--space-2) var(--space-3);
    /* In the stacked panel the bottom indicator would read as a row separator; use a
       left bar + tint instead so the active section is unambiguous on mobile. */
    border-bottom: none;
    border-left: 3px solid transparent;
    border-radius: var(--radius-sm);
  }

  .site-nav__link.is-active {
    border-bottom-color: transparent;
    border-left-color: var(--brand);
    background: var(--neutral-100);
  }

  .site-nav__actions {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
    padding-top: var(--space-3);
    margin-top: var(--space-2);
    border-top: 1px solid var(--neutral-200);
  }
}

.site-main {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-4);
}

.site-footer {
  max-width: 960px;
  margin: var(--space-8) auto 0;
  padding: var(--space-4);
  color: var(--neutral-500);
  font-size: 0.875rem;
  text-align: center;
}

/* ---------- Language toggle (EN/ES two-letter buttons, ARCHITECTURE.md §9) ---------- */

.lang-toggle {
  display: inline-flex;
  gap: var(--space-1);
  margin: 0;
}

.lang-toggle__btn {
  min-width: var(--tap-target);
  min-height: var(--tap-target);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--neutral-700);
  font: inherit;
  font-weight: 700;
  font-size: 0.8125rem;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.lang-toggle__btn.is-active {
  background: var(--brand);
  color: var(--brand-contrast);
  border-color: var(--brand);
}

/* ---------- Auth pages (login/signup card) ---------- */

.auth-card {
  max-width: 420px;
  margin: var(--space-6) auto;
}

/* ---------- Page header pattern (list/detail page title + primary actions) ---------- */

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

.page-header__title {
  margin: 0;
}

.page-header__actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .page-header__actions {
    flex-direction: column;
    width: 100%;
  }

  .page-header__actions .btn {
    width: 100%;
  }
}

/* ---------- Forms ---------- */

/* Two-tone hierarchy (§7.2): small muted field labels sit quietly above darker values. */
label {
  display: block;
  font-weight: 500;
  font-size: 0.8125rem;
  color: var(--neutral-500);
  margin-bottom: var(--space-1);
}

input,
select,
textarea {
  width: 100%;
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-3);
  font: inherit;
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius);
  background: #fff;
  color: var(--neutral-900);
}

textarea {
  min-height: 6rem;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

/* Money/qty inputs get a numeric keypad on mobile (ARCHITECTURE.md §0 rule 9). */
input[inputmode="decimal"] {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Checkbox/radio: don't stretch to the blanket input rule above; Django's
   RadioSelect/CheckboxSelectMultiple render a plain <ul><li><label> — reset that list and
   keep each option a touch-friendly row without a bespoke widget subclass. */
input[type="checkbox"],
input[type="radio"] {
  width: 1.25rem;
  height: 1.25rem;
  min-height: 0;
  margin: 0 var(--space-2) 0 0;
  vertical-align: middle;
}

.field ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}

.field ul label {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-target);
  font-size: 1rem;
  font-weight: 400;
  color: var(--neutral-900);
  margin-bottom: 0;
}

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

.field--error input,
.field--error select,
.field--error textarea {
  border-color: var(--danger);
}

.help-text {
  color: var(--neutral-500);
  font-size: 0.875rem;
  margin-top: var(--space-1);
}

.error-text {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: var(--space-1);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  background: var(--neutral-200);
  color: var(--neutral-900);
  transition: filter 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  filter: brightness(0.97);
}

.btn--primary {
  background: var(--brand);
  color: var(--brand-contrast);
}

.btn--danger {
  background: var(--danger);
  color: #fff;
}

.btn--ghost {
  background: transparent;
  border-color: var(--neutral-300);
}

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

/* Compact button for inline table-row actions (list Edit/Delete). Below the 44px tap
   target on purpose — these are secondary, mouse-first controls in a dense table row. */
.btn--sm {
  min-height: 0;
  padding: var(--space-1) var(--space-3);
  font-size: 0.875rem;
}

/* ---------- Save-status indicator (builder autosave/explicit-save feedback) ---------- */

/* Empty by default (no state to announce). A leading dot gives a glanceable colour cue;
   text carries the meaning for everyone, including screen readers via aria-live. */
.save-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--neutral-500);
}
.save-status:empty {
  display: none;
}
.save-status::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.save-status--dirty {
  color: var(--warning);
}
.save-status--saving {
  color: var(--info);
}
/* Pulse the dot while a save is in flight so "Saving…" reads as active, not stuck. */
.save-status--saving::before {
  animation: save-pulse 0.9s ease-in-out infinite;
}
.save-status--ok {
  color: var(--success);
}
.save-status--error {
  color: var(--danger);
}
@keyframes save-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
@media (prefers-reduced-motion: reduce) {
  .save-status--saving::before { animation: none; }
}

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

.card {
  background: #fff;
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}

.card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-3);
}

/* ---------- Responsive tables: collapse to stacked cards under 640px ---------- */
/* Shared pattern D-phases reuse for every list view (clients, price sheet, quotes,
   invoices, payments). Give each <td> a `data-label` attribute matching its column
   header — that label is what shows on mobile once the real <thead> is hidden. */

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

.responsive-table th,
.responsive-table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--neutral-200);
}

@media (max-width: 640px) {
  .responsive-table thead {
    display: none;
  }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table tr {
    border: 1px solid var(--neutral-200);
    border-radius: var(--radius);
    margin-bottom: var(--space-3);
    padding: var(--space-2);
  }

  .responsive-table td {
    border-bottom: none;
    padding: var(--space-1) var(--space-2);
  }

  .responsive-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--neutral-500);
  }
}

/* ---------- Badges (document display_status colors, ARCHITECTURE.md §5) ---------- */
/* Fixed hues regardless of tenant --brand — status meaning must read the same for every
   tenant. Class names mirror the display_status values verbatim. */

/* Status as soft pills (§7.2): rounded tinted chips in sentence case — the tints below
   carry the meaning, so no ALL-CAPS/heavy weight shouting is needed. */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge--draft {
  background: var(--neutral-200);
  color: var(--neutral-700);
}

.badge--sent {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge--viewed {
  background: #ede9fe;
  color: #6d28d9;
}

.badge--partially-paid {
  background: #fef3c7;
  color: #92400e;
}

.badge--paid {
  background: #dcfce7;
  color: #15803d;
}

.badge--overdue {
  background: #fee2e2;
  color: #b91c1c;
}

/* Quote-lifecycle statuses (accepted/expired/declined) — promoted from billing's
   base_billing.html in Phase F so every badge hue has one home (§5). */
.badge--accepted {
  background: #dcfce7;
  color: #15803d;
}

.badge--expired {
  background: var(--neutral-200);
  color: var(--neutral-700);
}

.badge--declined {
  background: #fee2e2;
  color: #b91c1c;
}

/* ---------- Toasts (Django messages) ---------- */

.toasts {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: calc(100vw - 2 * var(--space-4));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  background: var(--neutral-900);
  color: #fff;
}

.toast__text {
  flex: 1;
}

.toast__dismiss {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  min-height: 0;
}

.toast--success {
  background: var(--success);
}

.toast--error {
  background: var(--danger);
}

.toast--warning {
  background: var(--warning);
  color: var(--neutral-900);
}

.toast--info {
  background: var(--info);
}

@media (max-width: 640px) {
  .toasts {
    left: var(--space-4);
    right: var(--space-4);
    max-width: none;
  }
}

/* ---------- Empty state (icon/title/hint/action — ARCHITECTURE.md §15) ---------- */

.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--neutral-700);
}

.empty-state__icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-3);
}

.empty-state__title {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--neutral-900);
  margin-bottom: var(--space-2);
}

.empty-state__hint {
  color: var(--neutral-500);
  max-width: 40ch;
  margin: 0 auto var(--space-4);
}

.empty-state__action {
  margin-top: var(--space-2);
}

/* ---------- Tooltip (CSS-only, ARCHITECTURE.md §15 contextual tooltips) ---------- */
/* Trigger is a real <button data-tip="..."> (partials/_tooltip.html) so tapping reveals
   it via :focus — touch devices have no :hover. Content comes from the attribute so no
   JS is needed. */

.tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  min-height: 0;
  border: 1px solid var(--neutral-300);
  border-radius: 50%;
  background: var(--neutral-100);
  color: var(--neutral-700);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: help;
  vertical-align: middle;
}

.tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  width: max-content;
  max-width: 240px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--neutral-900);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 10;
}

.tip:hover::after,
.tip:focus::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 640px) {
  .tip::after {
    left: auto;
    right: 0;
    transform: translateX(0) translateY(4px);
  }

  .tip:hover::after,
  .tip:focus::after {
    transform: translateX(0) translateY(0);
  }
}

/* ---------- Wizard progress pill (onboarding wizard, ARCHITECTURE.md §15) ---------- */
/* Steps are plain URLs (no session-heavy WizardView) — this is purely presentational;
   the view passes which step is current/done. Markup: <ul class="wizard-progress">
   <li class="wizard-progress__step wizard-progress__step--done">...</li> ... */

.wizard-progress {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  list-style: none;
  margin: 0 0 var(--space-5);
  padding: 0;
}

.wizard-progress__step {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  background: var(--neutral-100);
  color: var(--neutral-500);
  font-size: 0.8125rem;
  font-weight: 600;
}

.wizard-progress__step--done {
  background: var(--success);
  color: #fff;
}

.wizard-progress__step--current {
  background: var(--brand);
  color: var(--brand-contrast);
}

/* ---------- Slide-over panel (D2's price-sheet picker, ARCHITECTURE.md §10) ---------- */
/* Alpine toggles `.slide-over--open` on the outer element; full-screen below 640px, a
   right-anchored drawer above it. Markup convention:
     <div class="slide-over" :class="{ 'slide-over--open': open }" x-cloak>
       <div class="slide-over__backdrop" @click="open = false"></div>
       <div class="slide-over__panel" role="dialog" aria-modal="true">
         <div class="slide-over__header">…heading + close button…</div>
         <div class="slide-over__body">…scrollable content…</div>
       </div>
     </div> */

.slide-over {
  position: fixed;
  inset: 0;
  z-index: 1100;
  visibility: hidden;
  pointer-events: none;
}

.slide-over--open {
  visibility: visible;
  pointer-events: auto;
}

.slide-over__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.slide-over--open .slide-over__backdrop {
  opacity: 1;
}

.slide-over__panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 420px;
  background: #fff;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.slide-over--open .slide-over__panel {
  transform: translateX(0);
}

.slide-over__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--neutral-200);
}

.slide-over__body {
  padding: var(--space-4);
  overflow-y: auto;
  flex: 1;
}

@media (max-width: 640px) {
  .slide-over__panel {
    max-width: none;
  }
}

/* ============================================================================
   Dashboard infographic (dashboard/templates/dashboard/home.html + partials)
   ----------------------------------------------------------------------------
   Hand-rolled charts on top of .card — bar geometry arrives from the view as
   percentages (--pct / inline width), so this section is pure presentation.
   Chart series colors are dataviz-validated against white cards and are fixed
   hex values on purpose: only the current-month column wears --brand, and the
   aging severity ramp is tenant-invariant (like status badges). Text never
   wears series colors. All classes are dash-prefixed; one 640px breakpoint at
   the end, matching the rest of this file.
   ============================================================================ */

/* Wider canvas for the dashboard only (base.html main_modifier block). */
.site-main--wide { max-width: 1160px; }

/* Authed-nav logo reads as a tidy square tile whatever shape the tenant uploads.
   Scoped with a modifier: bare .brand__logo is also the public client-facing pages'
   logo (public/base_public.html), where cropping a wide wordmark would mangle it. */
.brand__logo--nav {
  width: 30px;
  height: 30px;
  object-fit: cover;
  border-radius: var(--radius);
}

/* ---------- Hero band ---------- */

.dash-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4) var(--space-5);
  margin-bottom: var(--space-4);
  /* Brand wash: a light mix with dark text — never --brand as a large surface
     with white text (arbitrary tenant colors). Plain white fallback first. */
  background: #fff;
  background: color-mix(in srgb, var(--brand) 8%, white);
}

.dash-hero__intro {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-width: 0;
}

.dash-hero__logo {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  object-fit: cover;
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow);
}

.dash-hero__greeting {
  margin: 0;
  color: var(--neutral-700);
  font-size: 0.9375rem;
}

.dash-hero__title {
  margin: 0;
  font-size: 1.625rem;
}

.dash-hero__date {
  margin: var(--space-1) 0 0;
  color: var(--neutral-500);
  font-size: 0.875rem;
}

.dash-hero__figure {
  text-align: right;
}

.dash-hero__label {
  margin: 0;
  font-weight: 500;
  font-size: 0.8125rem;
  color: var(--neutral-500);
}

/* Hero + KPI values keep proportional figures (tabular-nums is reserved for
   table columns and axis labels). */
.dash-hero__value {
  margin: 0;
  font-size: 2.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.dash-hero__sub {
  margin: var(--space-1) 0 0;
}

.dash-hero__overdue {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.9375rem;
  text-decoration: none;
}

.dash-hero__overdue:hover,
.dash-hero__overdue:focus-visible {
  text-decoration: underline;
}

/* ---------- KPI row ---------- */

.dash-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.dash-kpi {
  margin-bottom: 0;
  padding: var(--space-4) var(--space-5);
}

.dash-kpi__label {
  margin: 0 0 var(--space-1);
  font-weight: 500;
  font-size: 0.8125rem;
  color: var(--neutral-500);
}

.dash-kpi__row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.dash-kpi__value {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.2;
}

.dash-kpi__delta {
  font-size: 0.8125rem;
  font-weight: 700;
  white-space: nowrap;
}

.dash-kpi__delta--up { color: #006300; }
.dash-kpi__delta--down { color: var(--danger); }

.dash-kpi__meta {
  margin: var(--space-1) 0 0;
  font-size: 0.8125rem;
  color: var(--neutral-500);
}

.dash-kpi__spark {
  display: block;
  width: 120px;
  height: 32px;
  margin-top: var(--space-3);
  overflow: visible; /* endpoint dot sits on the viewBox edge */
}

/* ---------- Chart grid ---------- */

.dash-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--space-4);
}

.dash-card {
  display: flex;
  flex-direction: column;
  margin-bottom: 0; /* the grid gap owns the rhythm */
}

.dash-card--span-4 { grid-column: span 4; }
.dash-card--span-5 { grid-column: span 5; }
.dash-card--span-7 { grid-column: span 7; }
.dash-card--span-8 { grid-column: span 8; }

.dash-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.dash-card__title {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: 1.0625rem;
}

.dash-card__hint {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--neutral-500);
}

.dash-card__figure {
  margin: 0 0 var(--space-3);
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.2;
}

.dash-card__meta {
  margin: var(--space-3) 0 0;
  font-size: 0.8125rem;
  color: var(--neutral-500);
}

/* Footer links pin to the card bottom so short cards in a row stay aligned. */
.dash-card__footer {
  margin: auto 0 0;
  padding-top: var(--space-3);
  font-size: 0.875rem;
}

.dash-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 var(--space-2);
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 700;
}

.dash-chip--danger {
  background: #fee2e2; /* matches .badge--overdue */
  color: #b91c1c;
}

/* ---------- Column chart (revenue + recurring mini) ---------- */

.dash-plot {
  padding-top: var(--space-6); /* headroom for value pills above 100% bars */
}

.dash-plot__area {
  position: relative;
  height: 200px;
  border-bottom: 1px solid var(--neutral-200); /* zero baseline */
}

.dash-plot--mini .dash-plot__area {
  height: 96px;
}

.dash-gridlines {
  position: absolute;
  inset: 0;
}

.dash-gridline {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid var(--neutral-200); /* hairline */
}

.dash-gridline__label {
  position: absolute;
  right: 0;
  bottom: 2px;
  padding: 0 var(--space-1);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.8); /* stays legible where a bar passes behind */
  font-size: 0.72rem;
  color: var(--neutral-500);
  font-variant-numeric: tabular-nums;
}

.dash-cols {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  gap: var(--space-1);
}

.dash-col {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.dash-col:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.dash-col__bar {
  width: 100%;
  max-width: 40px;
  height: var(--pct, 0%);
  background: #93bb9b; /* past months */
  border-radius: 4px 4px 0 0;
  transform-origin: bottom;
}

.dash-col__bar--nonzero {
  min-height: 2px; /* a non-zero month never disappears entirely */
}

.dash-col--current .dash-col__bar {
  background: var(--brand);
}

/* Value pill above the bar cap. Shown selectively: current month, peak month
   (dash-col--peak, from the server-computed is_max), and mini charts (all three). */
.dash-col__value {
  display: none;
  position: absolute;
  bottom: calc(var(--pct, 0%) + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 1px var(--space-2);
  border: 1px solid var(--neutral-200);
  border-radius: 999px;
  background: #fff;
  color: var(--neutral-900);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  z-index: 2;
}

.dash-col--current .dash-col__value,
.dash-col--peak .dash-col__value,
.dash-col--show-value .dash-col__value {
  display: block;
}

.dash-plot__labels {
  display: flex;
  gap: var(--space-1);
  margin-top: var(--space-2);
}

.dash-plot__label {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--neutral-500);
}

/* ---------- 100%-stacked aging bar + legend ---------- */

.dash-stack {
  display: flex;
  gap: 2px; /* white surface gaps between segments */
  height: 18px;
  margin-bottom: var(--space-4);
  background: #fff;
}

.dash-stack__seg {
  min-width: 0;
}

/* Zero buckets render no segment, so first/last visible segments carry the
   rounded outer corners. */
.dash-stack__seg:first-child {
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}

.dash-stack__seg:last-child {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

/* Aging severity ramp — fixed ambers, never brand-derived. */
.dash-stack__seg--1, .dash-legend__swatch--1 { background: #dcae57; }
.dash-stack__seg--2, .dash-legend__swatch--2 { background: #c48c2c; }
.dash-stack__seg--3, .dash-legend__swatch--3 { background: #a2690a; }
.dash-stack__seg--4, .dash-legend__swatch--4 { background: #7d4e00; }

.dash-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.dash-legend__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.875rem;
}

.dash-legend__swatch {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.dash-legend__count {
  color: var(--neutral-500);
  font-size: 0.8125rem;
}

.dash-legend__total {
  margin-left: auto;
  font-weight: 600;
  font-variant-numeric: tabular-nums; /* right-aligned money column */
}

/* ---------- Horizontal bars (pipeline, top clients) ---------- */

.dash-hbars {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.dash-hbar__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
  font-size: 0.875rem;
}

.dash-hbar__label {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dash-hbar__count {
  color: var(--neutral-500);
  font-size: 0.8125rem;
}

.dash-hbar__total {
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums; /* right-aligned money column */
}

.dash-hbar__track {
  height: 10px;
  background: var(--neutral-100);
  border-radius: 4px;
  overflow: hidden;
}

.dash-hbar__fill {
  height: 100%;
  border-radius: 4px;
  background: #478255; /* top-clients bars */
  transform-origin: left;
}

/* Funnel ordinal ramp (3 steps), keyed by stage.key. */
.dash-hbar__fill--sent { background: #93bb9b; }
.dash-hbar__fill--accepted { background: #478255; }
.dash-hbar__fill--invoiced { background: #2f6b3c; }

.dash-hbar__meta {
  margin: var(--space-1) 0 0;
  font-size: 0.78rem;
  color: var(--neutral-500);
}

/* ---------- Shared tooltip singleton (built by dashboard.js) ---------- */

.dash-tip {
  position: fixed;
  z-index: 1000; /* toast tier — above cards, below slide-over (1100) */
  max-width: 260px;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--neutral-900);
  color: #fff;
  font-size: 0.8125rem;
  line-height: 1.4;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.dash-tip.is-visible {
  opacity: 1;
}

.dash-tip__label {
  display: block;
  font-weight: 600;
}

/* ---------- Motion ----------
   dashboard.js adds .dash-anim (start state) then .dash-ready (reveal) to the
   root — with JS off or reduced motion the charts simply render complete. */

.dash-anim .dash-col__bar { transform: scaleY(0); }
.dash-anim .dash-hbar__fill { transform: scaleX(0); }
.dash-anim .dash-col__value { opacity: 0; }

.dash-anim.dash-ready .dash-col__bar {
  transform: scaleY(1);
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1) calc(var(--i, 0) * 30ms);
}

.dash-anim.dash-ready .dash-hbar__fill {
  transform: scaleX(1);
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1) calc(var(--i, 0) * 30ms);
}

.dash-anim.dash-ready .dash-col__value {
  opacity: 1;
  transition: opacity 0.3s ease calc(var(--i, 0) * 30ms + 350ms);
}

@media (prefers-reduced-motion: reduce) {
  .dash-anim .dash-col__bar,
  .dash-anim .dash-hbar__fill {
    transform: none;
    transition: none;
  }

  .dash-anim .dash-col__value {
    opacity: 1;
    transition: none;
  }

  .dash-tip {
    transition: none;
  }
}

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
  .dash-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dash-grid > * {
    grid-column: 1 / -1; /* single column; spans would overflow a 1-col grid */
  }

  .dash-plot__area {
    height: 160px;
  }

  .dash-hero {
    flex-direction: column;
    align-items: flex-start;
  }

  .dash-hero__figure {
    text-align: left;
  }

  .dash-hero__value {
    font-size: 2.25rem;
  }
}
