/* ==========================================================================
   FUSION CARWASH — CLIENT POLISH LAYER
   Loaded last (after portal.css and the inline theme engine in index.html).
   Uses only the existing tokens (--accent, --ink, --muted, --line, --card…),
   so both themes follow automatically and no second palette is introduced.
   Every rule here fixes something visible on a real screen; see the comment
   above each block for which one.
   ========================================================================== */

/* ── Card titles ────────────────────────────────────────────────────────────
   "VEHICLES THROUGH THE YARD" in heavy all-caps read as shouting on every card.
   Sentence case (the markup already is) with a firm weight reads as a heading. */
#fin-portal .fin-titles h3,
#fin-portal .fin-card > h3,
#fin-portal .card-head h3 {
  text-transform: none !important;
  font-family: "Plus Jakarta Sans", Inter, system-ui, sans-serif !important;
  font-size: var(--fs-lg) !important;
  font-weight: var(--fw-bold) !important;
  letter-spacing: -0.01em !important;
  line-height: var(--lh-tight) !important;
}

/* ── KPI tiles ──────────────────────────────────────────────────────────────
   Money figures ("KES 6,000") broke onto two lines in the light theme. Keep a
   figure on one line and let it shrink with the tile instead. A thin accent
   rail gives the row of tiles a clear top edge. */
#fin-portal .kpi {
  position: relative !important;
  overflow: hidden !important;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease !important;
}
#fin-portal .kpi::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 35%, transparent));
  opacity: 0.85;
}
#fin-portal .kpi:hover {
  transform: translateY(-2px) !important;
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line)) !important;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14) !important;
}
#fin-portal .kpi .k-fig {
  white-space: nowrap !important;
  font-size: clamp(1.35rem, 1.9vw, 1.75rem) !important;
  letter-spacing: -0.02em !important;
  font-variant-numeric: tabular-nums;
}
/* Two tiles a row on a phone: the figure has ~150px, so it scales with the viewport. */
@media (max-width: 640px) {
  #fin-portal .kpi .k-fig { font-size: clamp(1.05rem, 5.2vw, 1.5rem) !important; }
}
#fin-portal .kpi .k-label {
  font-weight: var(--fw-semibold) !important;
  color: var(--muted) !important;
}

/* ── Ledgers / tables ───────────────────────────────────────────────────────
   Rows get a hover and zebra so the eye can follow a long row across to its
   actions. Wrapping stays as it was: forcing one line pushed the row actions
   off the right edge on a 1440px screen. Text only breaks between words. */
#fin-portal table.ledger td {
  vertical-align: middle !important;
  word-break: normal !important;
  overflow-wrap: normal !important;
}
#fin-portal table.ledger tbody tr {
  transition: background-color 0.12s ease !important;
}
#fin-portal table.ledger tbody tr:nth-child(even) td {
  background-color: color-mix(in srgb, var(--ink) 2.5%, transparent) !important;
}
#fin-portal table.ledger tbody tr:hover td {
  background-color: var(--accent-soft) !important;
}
#fin-portal table.ledger th {
  font-size: var(--fs-xs) !important;
  font-weight: var(--fw-semibold) !important;
  letter-spacing: 0.02em !important;
  color: var(--muted) !important;
}

/* ── Check-in form ──────────────────────────────────────────────────────────
   The "+ Add" buttons beside Customer / Make / Class stacked their label over
   two lines and sat shorter than the input, squeezing the input to half width. */
#fin-portal .field > div:has(> #ciQuickAddCustomer),
#fin-portal .field > div:has(> #ciMakeNewBtn),
#fin-portal .field > div:has(> #ciClassNewBtn) {
  display: flex !important;
  align-items: stretch !important;
  gap: 8px !important;
}
#fin-portal .field > div:has(> #ciQuickAddCustomer) > input,
#fin-portal .field > div:has(> #ciMakeNewBtn) > input,
#fin-portal .field > div:has(> #ciClassNewBtn) > input {
  flex: 1 1 auto !important;
  min-width: 0 !important;
}
#fin-portal #ciQuickAddCustomer,
#fin-portal #ciMakeNewBtn,
#fin-portal #ciClassNewBtn {
  flex: 0 0 auto !important;
  white-space: nowrap !important;
  height: auto !important;
  min-height: 0 !important;
  padding: 0 10px !important;
  font-size: var(--fs-xs) !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 4px !important;
}
/* "Pay Before Release (Default)" was cut to "Pay Before Release (D" — the Terms
   select gets the width its longest option needs. */
#fin-portal .field:has(> #ciTerms) {
  min-width: 15.5rem !important;
}
#fin-portal #ciTerms {
  text-overflow: ellipsis !important;
}

/* ── Buttons & focus ────────────────────────────────────────────────────────
   Same colours as before; a little depth on the primary action and a visible
   keyboard focus ring everywhere (there was none on most controls). */
#fin-portal .btn.primary {
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 30%, transparent) !important;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease !important;
}
#fin-portal .btn.primary:hover:not(:disabled) {
  transform: translateY(-1px) !important;
  filter: brightness(1.06) !important;
}
#fin-portal .btn:active:not(:disabled) {
  transform: translateY(0) !important;
}
#fin-portal :is(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent) !important;
  outline-offset: 2px !important;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────
   The active item was a flat block; a rounded pill with the accent rail reads
   as "you are here" without adding a colour. */
#fin-portal #finSidebar .nav a.active,
#fin-portal #finSidebar a[aria-current="page"] {
  border-radius: 10px !important;
  font-weight: var(--fw-semibold) !important;
}

/* ── Status chips ───────────────────────────────────────────────────────────
   Slightly more padding so "Ready for Pickup" and "Paid" read as chips, not text. */
#fin-portal .chip,
#fin-portal .pill,
#fin-portal .badge {
  letter-spacing: 0.01em !important;
}

/* ── PWA install prompt ─────────────────────────────────────────────────────
   It is appended to <body>, outside #fin-portal, so it inherited the browser's
   default serif font and none of the portal's colours. */
.fin-install-toast {
  font-family: "Plus Jakarta Sans", Inter, system-ui, -apple-system, "Segoe UI", sans-serif !important;
  font-size: 0.9375rem !important;
  border-radius: 14px !important;
  border: 1px solid rgba(148, 163, 184, 0.25) !important;
  box-shadow: 0 18px 40px rgba(2, 6, 23, 0.35) !important;
}
.fin-install-toast .fin-install-msg {
  font-weight: 600 !important;
}
.fin-install-toast .fin-install-btn {
  font-family: inherit !important;
  font-weight: 700 !important;
  border-radius: 10px !important;
}

/* ── Motion preferences ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #fin-portal .kpi,
  #fin-portal .btn.primary,
  #fin-portal table.ledger tbody tr { transition: none !important; }
  #fin-portal .kpi:hover,
  #fin-portal .btn.primary:hover:not(:disabled) { transform: none !important; }
}

/* ── Reports: use the whole screen ──────────────────────────────────────────
   Report results sat in the shared 22rem scroll box — about half the screen — so a
   report was read through a letterbox. The result now fills the viewport below the
   filter bar; the header row stays pinned while the body scrolls. */
#fin-portal #view-report_runner .fin-scroll {
  max-height: calc(100vh - 15.5rem) !important;
  min-height: 24rem !important;
}
@media (max-width: 640px) {
  #fin-portal #view-report_runner .fin-scroll { max-height: calc(100vh - 20rem) !important; }
}

/* ── Report colours ─────────────────────────────────────────────────────────
   Used by reportCell(): money owed red, money in green, zeros faded, percentages
   with a small bar, and a banded header so the columns read as a table. */
#fin-portal #view-report_runner table.ledger thead th {
  background: color-mix(in srgb, var(--accent) 14%, var(--card-solid)) !important;
  color: var(--ink) !important;
  border-bottom: 2px solid color-mix(in srgb, var(--accent) 55%, transparent) !important;
}
#fin-portal #view-report_runner table.ledger tbody td:first-child { font-weight: var(--fw-semibold) !important; }
#fin-portal .rr-dim { color: var(--muted) !important; opacity: 0.6; }
#fin-portal .rr-owed { color: var(--debit) !important; font-weight: var(--fw-bold) !important; }
#fin-portal .rr-earned { color: var(--credit) !important; font-weight: var(--fw-semibold) !important; }
#fin-portal .rr-neg { color: var(--debit) !important; font-weight: var(--fw-bold) !important; }
#fin-portal .rr-pct { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
#fin-portal .rr-bar {
  display: inline-block; width: 56px; height: 6px; border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 12%, transparent); overflow: hidden;
}
#fin-portal .rr-bar i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
#fin-portal .rr-bar.ok i { background: var(--credit); }
#fin-portal .rr-bar.warn i { background: var(--warn); }
#fin-portal .rr-bar.err i { background: var(--debit); }

/* ── Dialogs (New bay, New attendant, rates, customers …) ───────────────────
   modal() renders .fin-dlg-h, but the base stylesheet only styles .fin-dlg-hd, so
   dialog titles were dark-on-dark and invisible; the form grid inherited a page
   outline with no inner spacing, labels touched the border and narrow dialogs
   squeezed and cut words. One consistent dialog: readable title, real padding,
   a grid that drops to one column when narrow, labels that wrap. */
#fin-portal .fin-dlg {
  width: min(620px, calc(100vw - 32px)) !important;
  max-width: none !important;
  max-height: calc(100vh - 48px) !important;
  display: flex !important;
  flex-direction: column !important;
  background: var(--card-solid) !important;
  color: var(--ink) !important;
  border: 1px solid var(--line) !important;
  border-radius: 16px !important;
  box-shadow: 0 24px 64px rgba(2, 6, 23, 0.45) !important;
  overflow: hidden !important;
  padding: 0 !important;
}
#fin-portal .fin-dlg.fin-dlg-wide { width: min(880px, calc(100vw - 32px)) !important; }
#fin-portal .fin-dlg-h {
  display: flex !important; align-items: center !important; justify-content: space-between !important;
  gap: 12px !important; padding: 18px 22px !important; border-bottom: 1px solid var(--line) !important;
  flex: 0 0 auto !important;
}
#fin-portal .fin-dlg-h h3 {
  margin: 0 !important; color: var(--ink) !important; opacity: 1 !important;
  font: 700 1.125rem/1.3 "Plus Jakarta Sans", Inter, system-ui, sans-serif !important;
  text-transform: none !important; letter-spacing: -0.01em !important; white-space: normal !important;
}
#fin-portal .fin-dlg-x {
  flex: 0 0 auto !important; width: 34px !important; height: 34px !important; border-radius: 10px !important;
  font-size: 20px !important; line-height: 1 !important; color: var(--muted) !important;
  background: transparent !important; border: 1px solid var(--line) !important; cursor: pointer !important;
}
#fin-portal .fin-dlg-b { padding: 20px 22px !important; overflow-y: auto !important; flex: 1 1 auto !important; }
#fin-portal .fin-dlg-f {
  display: flex !important; justify-content: flex-end !important; gap: 10px !important; flex-wrap: wrap !important;
  padding: 14px 22px !important; border-top: 1px solid var(--line) !important; flex: 0 0 auto !important;
}
#fin-portal .fin-dlg-b .form-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) !important;
  gap: 16px 18px !important;
  border: 0 !important; outline: 0 !important; box-shadow: none !important;
  padding: 0 !important; margin: 0 !important; background: transparent !important;
}
#fin-portal .fin-dlg-b .form-grid > .field { margin: 0 !important; min-width: 0 !important; }
#fin-portal .fin-dlg-b .form-grid > .field-wide,
#fin-portal .fin-dlg-b .form-grid > .field[style*="span 2"] { grid-column: 1 / -1 !important; }
#fin-portal .fin-dlg-b .field label {
  white-space: normal !important; overflow: visible !important; text-overflow: clip !important;
  color: var(--muted) !important; font-size: var(--fs-xs) !important; font-weight: 600 !important;
  letter-spacing: 0.03em !important; line-height: 1.35 !important;
}
#fin-portal .fin-dlg-b .field input,
#fin-portal .fin-dlg-b .field select,
#fin-portal .fin-dlg-b .field textarea { width: 100% !important; min-width: 0 !important; }
/* inline "+" buttons beside a select (New designation, etc.) */
#fin-portal .fin-dlg-b .field > div[style*="display:flex"] { align-items: stretch !important; gap: 8px !important; }
#fin-portal .fin-dlg-b .field > div[style*="display:flex"] > select,
#fin-portal .fin-dlg-b .field > div[style*="display:flex"] > input { flex: 1 1 auto !important; min-width: 0 !important; }
#fin-portal .fin-dlg-b .field > div[style*="display:flex"] > .btn {
  flex: 0 0 auto !important; min-width: 42px !important; height: auto !important; font-size: 18px !important; padding: 0 12px !important;
}
#fin-portal .fin-dlg-b .hint { margin-top: 12px !important; color: var(--muted) !important; }
@media (max-width: 640px) {
  #fin-portal .fin-dlg, #fin-portal .fin-dlg.fin-dlg-wide { width: calc(100vw - 16px) !important; max-height: calc(100vh - 16px) !important; }
  #fin-portal .fin-dlg-b .form-grid { grid-template-columns: 1fr !important; }
}

/* ── Checkboxes and radios ──────────────────────────────────────────────────
   The theme engine sizes every input as a full-width text box, checkboxes included,
   so a tick box rendered as a large empty field with its label pushed underneath
   (Generate payout run, bay "In service", carpet "Offered"). Keep them native size. */
#fin-portal input[type="checkbox"],
#fin-portal input[type="radio"] {
  width: 18px !important; height: 18px !important; min-width: 18px !important; min-height: 0 !important;
  padding: 0 !important; margin: 0 !important; flex: 0 0 auto !important;
  appearance: auto !important; -webkit-appearance: auto !important;
  border-radius: 4px !important; box-shadow: none !important; accent-color: var(--accent) !important;
  background: transparent !important; cursor: pointer;
}
#fin-portal .fin-dlg-b label.chk {
  display: flex !important; flex-direction: row !important; align-items: flex-start !important; gap: 12px !important;
  text-transform: none !important; letter-spacing: 0 !important; color: var(--ink) !important;
  font-size: var(--fs-sm) !important; font-weight: 500 !important; cursor: pointer;
}
#fin-portal .fin-dlg-b label.chk input { margin-top: 2px !important; }
#fin-portal .fin-dlg-b label.chk span { display: grid; gap: 2px; }
#fin-portal .fin-dlg-b label.chk small { color: var(--muted); font-size: var(--fs-xs); font-weight: 400; line-height: 1.4; }
#fin-portal .fin-dlg-b label.chk.is-off { opacity: 0.5; cursor: not-allowed; }

/* Generate payout run: live preview of what will be paid, then the options. */
#fin-portal .py-preview {
  margin: 18px 0 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}
#fin-portal .py-preview .empty { color: var(--muted); }
#fin-portal .py-sum { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; color: var(--muted); font-size: var(--fs-sm); }
#fin-portal .py-sum b { color: var(--credit); font-size: 1.35rem; font-variant-numeric: tabular-nums; }
#fin-portal .py-preview table.ledger { width: 100%; }
#fin-portal .py-opts { display: grid; gap: 14px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
#fin-portal .fin-dlg-f .btn:disabled { opacity: 0.5; cursor: not-allowed; }
