/* ============================================================================
   polish.css — dashboard consistency pass (loaded AFTER style.css).
   Goals:
     1. NO glass/transparency: every panel is a solid surface with a real border.
        (backdrop-filter + rgba backgrounds rendered as blurry "smudges" on
        machines without GPU compositing, and text became unreadable.)
     2. One rhythm: 14px radius, 1px border, one shadow scale, 12/16/24 spacing.
     3. Stat cards the same height, numbers tabular and calm.
     4. Clean toolbar, tabs, table, modal. Works in light AND dark.
   Rollback: remove the <link href="/static/css/polish.css"> line from index.html.
   ========================================================================== */

/* ---------------------------------------------------------------- tokens -- */
:root {
  --p-surface: #ffffff;
  --p-surface-2: #f7f8fb;
  --p-surface-3: #eef1f7;
  --p-border: #e3e7ef;
  --p-border-strong: #d3d9e5;
  --p-ink: #0f172a;
  --p-body: #475569;
  --p-muted: #6b7688;
  --p-accent: #5b21b6;
  --p-accent-ink: #4c1d95;
  --p-accent-soft: #f3efff;
  --p-green: #0f7b52;
  --p-green-soft: #e9f8f1;
  --p-red: #b42318;
  --p-red-soft: #fdf0ee;
  --p-amber: #92400e;
  --p-amber-soft: #fff7e8;
  --p-radius: 14px;
  --p-radius-sm: 10px;
  --p-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 12px 24px -18px rgba(15, 23, 42, .22);
  --p-shadow-hover: 0 2px 6px rgba(15, 23, 42, .06), 0 18px 32px -20px rgba(15, 23, 42, .28);
}

html.dark {
  --p-surface: #0f1626;
  --p-surface-2: #131c2e;
  --p-surface-3: #1a2438;
  --p-border: #22304a;
  --p-border-strong: #2d3d5a;
  --p-ink: #e8eefb;
  --p-body: #b9c4d8;
  --p-muted: #8794ab;
  --p-accent: #a78bfa;
  --p-accent-ink: #c4b5fd;
  --p-accent-soft: #1c1a3a;
  --p-green: #34d399;
  --p-green-soft: #10261f;
  --p-red: #fb7185;
  --p-red-soft: #2a1418;
  --p-amber: #fbbf24;
  --p-amber-soft: #2a2010;
  --p-shadow: 0 1px 0 rgba(255, 255, 255, .03), 0 14px 28px -22px #000;
  --p-shadow-hover: 0 2px 8px rgba(0, 0, 0, .35);
}

/* ------------------------------------------------------------- no glass -- */
/* Kill every backdrop blur on the app shell; keep the surfaces opaque. */
.header,
.sidebar,
.hero-panel,
.stat-card,
.card,
.card-header,
.table-wrapper,
.donut-card,
.chart-section,
.chart-card,
.invoice-preview,
.modal-content,
.modal-overlay,
.nav-item,
.filter-btn,
.toolbar,
#payment-modal .modal-content {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

.header {
  background: var(--p-surface) !important;
  border-bottom: 1px solid var(--p-border) !important;
}

.sidebar {
  background: var(--p-surface) !important;
  border-right: 1px solid var(--p-border) !important;
}

.hero-panel {
  background: var(--p-surface) !important;
  border: 1px solid var(--p-border) !important;
  box-shadow: var(--p-shadow) !important;
  padding: 18px 22px !important;
  border-radius: var(--p-radius) !important;
}

.hero-glow { display: none !important; }          /* blur blob = smudge on weak GPUs */
.hero-eyebrow { color: var(--p-muted) !important; letter-spacing: .16em !important; }
.hero-title { color: var(--p-ink) !important; font-size: 1.5rem !important; line-height: 1.25 !important; }
.hero-title span { color: var(--p-muted) !important; -webkit-text-fill-color: var(--p-muted) !important; }
.hero-sub { color: var(--p-body) !important; font-size: 13px !important; }
.hero-btn { box-shadow: none !important; }
.hero-btn-ghost {
  background: var(--p-surface-2) !important;
  border: 1px solid var(--p-border) !important;
  color: var(--p-ink) !important;
}
.hero-btn-ghost:hover { background: var(--p-surface-3) !important; }

/* ---------------------------------------------------------- stat cards --- */
.stats-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)) !important;
  gap: 12px !important;
  margin-bottom: 18px !important;
}

.stat-card {
  background: var(--p-surface) !important;
  border: 1px solid var(--p-border) !important;
  border-radius: var(--p-radius) !important;
  box-shadow: var(--p-shadow) !important;
  padding: 14px 16px !important;
  min-height: 88px !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: space-between !important;
  gap: 8px !important;
  overflow: hidden !important;
  transform: none !important;
}
.stat-card::before {                                     /* old gold/pink top stripe */
  background: var(--p-border) !important;
  height: 1px !important;
  opacity: 0 !important;
}
.stat-card::after { content: none !important; }
.stat-card:hover {
  transform: none !important;
  border-color: var(--p-border-strong) !important;
  box-shadow: var(--p-shadow-hover) !important;
}
.stat-card:hover .stat-card-icon { transform: none !important; }

/* one accent rule per card type — a 3px bar, not a glow */
.stat-card { border-left: 3px solid var(--p-border-strong) !important; }
.stat-card.s-violet, .stat-card.stat-card-total { border-left-color: #7c3aed !important; }
.stat-card.s-blue { border-left-color: #2563eb !important; }
.stat-card.s-green, .stat-card.stat-card-green { border-left-color: #0f7b52 !important; }
.stat-card.s-red, .stat-card.stat-card-red { border-left-color: #b42318 !important; }
.stat-card.s-cyan { border-left-color: #0e7490 !important; }
.stat-card.s-gold, .stat-card.stat-card-collection { border-left-color: #b45309 !important; }
.stat-card-green, .stat-card-red, .stat-card-collection,
.stat-paid-glow, .stat-due-glow { box-shadow: var(--p-shadow) !important; }

.stat-card-header { margin-bottom: 6px !important; }
.stat-info { min-width: 0 !important; }
.stat-card-label,
.stat-card-label em {
  font-size: 10.5px !important;
  font-weight: 700 !important;
  letter-spacing: .09em !important;
  text-transform: uppercase !important;
  color: var(--p-muted) !important;
  font-style: normal !important;
}
.stat-card-value {
  font-size: 20px !important;
  font-weight: 800 !important;
  letter-spacing: -.01em !important;
  color: var(--p-ink) !important;
  font-variant-numeric: tabular-nums !important;
  line-height: 1.2 !important;
  white-space: nowrap !important;
}
.stat-card-value.text-green { color: var(--p-green) !important; }
.stat-card-value.text-red { color: var(--p-red) !important; }
.stat-card-sub {
  font-size: 11px !important;
  color: var(--p-muted) !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}
.stat-card-icon {
  width: 34px !important; height: 34px !important;
  border-radius: 9px !important;
  font-size: 15px !important;
  background: var(--p-surface-3) !important;
  color: var(--p-body) !important;
  border: 1px solid var(--p-border) !important;
}
.stat-card-icon.gold, .stat-card-icon.green, .stat-card-icon.red,
.stat-card-icon.violet, .stat-card-icon.blue, .stat-card-icon.cyan {
  background: var(--p-surface-3) !important;
  color: var(--p-body) !important;
}
.stat-accent { display: none !important; }               /* replaced by border-left */

/* --------------------------------------------------------------- cards --- */
.card, .table-wrapper, .donut-card, .chart-section, .chart-card {
  background: var(--p-surface) !important;
  border: 1px solid var(--p-border) !important;
  border-radius: var(--p-radius) !important;
  box-shadow: var(--p-shadow) !important;
}
.card-header {
  background: var(--p-surface) !important;
  border-bottom: 1px solid var(--p-border) !important;
  padding: 14px 18px !important;
}
.card-title { color: var(--p-ink) !important; font-size: 15px !important; font-weight: 700 !important; }
.chart-title { color: var(--p-ink) !important; font-size: 13px !important; font-weight: 700 !important; }
.donut-card { padding: 14px !important; margin-bottom: 12px !important; }

/* ------------------------------------------------------------- toolbar --- */
.toolbar {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: center !important;
  gap: 8px !important;
  padding: 12px 16px !important;
  background: var(--p-surface-2) !important;
  border-bottom: 1px solid var(--p-border) !important;
}
.toolbar-left, .toolbar-right { gap: 8px !important; }

.filter-btn, .btn, .form-control, select.form-control {
  min-height: 38px !important;
  border-radius: var(--p-radius-sm) !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
}
.filter-btn {
  background: var(--p-surface) !important;
  border: 1px solid var(--p-border) !important;
  color: var(--p-body) !important;
  padding: 7px 14px !important;
  box-shadow: none !important;
}
.filter-btn:hover { border-color: var(--p-border-strong) !important; color: var(--p-ink) !important; }
.filter-btn.active {
  background: var(--p-accent) !important;
  border-color: var(--p-accent) !important;
  color: #fff !important;
  box-shadow: none !important;
}
html.dark .filter-btn.active { color: #0b1020 !important; }

.btn-primary {
  background: var(--p-accent) !important;
  border: 1px solid var(--p-accent) !important;
  color: #fff !important;
  box-shadow: none !important;
}
html.dark .btn-primary { color: #0b1020 !important; }
.btn-primary:hover { filter: brightness(1.06); }

/* --------------------------------------------------------------- table --- */
.table-wrapper { overflow: auto !important; }
.table-wrapper thead th {
  background: var(--p-surface-2) !important;
  backdrop-filter: none !important;
  color: var(--p-muted) !important;
  font-size: 10.5px !important;
  font-weight: 800 !important;
  letter-spacing: .08em !important;
  text-transform: uppercase !important;
  border-bottom: 1px solid var(--p-border) !important;
  padding: 10px 14px !important;
}
.table-wrapper tbody td {
  padding: 10px 14px !important;
  border-bottom: 1px solid var(--p-border) !important;
  color: var(--p-body) !important;
  font-size: 13px !important;
  vertical-align: middle !important;
}
.table-wrapper tbody tr { background: var(--p-surface) !important; }
.table-wrapper tbody tr:hover { background: var(--p-surface-2) !important; }
.table-wrapper tbody td strong, .table-wrapper tbody td b { color: var(--p-ink) !important; }
.money, td[style*="gold"], .table-wrapper td .amount {
  font-variant-numeric: tabular-nums !important;
}

/* --------------------------------------------------------------- modal --- */
.modal-overlay { background: rgba(15, 23, 42, .45) !important; backdrop-filter: none !important; }
.modal-content {
  background: var(--p-surface) !important;
  border: 1px solid var(--p-border) !important;
  border-radius: 16px !important;
  box-shadow: 0 24px 60px -24px rgba(15, 23, 42, .45) !important;
}
.modal-header { border-bottom: 1px solid var(--p-border) !important; }
.modal-title { color: var(--p-ink) !important; }

/* ------------------------------------------------------- theme toggle ---- */
/* the floating moon used to sit on top of table rows */
#themeToggle, .theme-toggle, .dark-toggle, #darkModeToggle {
  bottom: 20px !important;
  right: 20px !important;
  z-index: 60 !important;
  box-shadow: 0 10px 24px -12px rgba(15, 23, 42, .5) !important;
}
@media (max-width: 760px) {
  #themeToggle, .theme-toggle, .dark-toggle, #darkModeToggle {
    bottom: 78px !important;   /* above the mobile nav bar */
    right: 14px !important;
  }
}

/* ------------------------------------------------------------ overflow -- */
.page-content { max-width: 100% !important; overflow-x: hidden !important; }
body, html { background: var(--p-surface-2) !important; }
html.dark body, html.dark { background: #0a1120 !important; }

/* focus visibility (accessibility) */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--p-accent) !important;
  outline-offset: 2px !important;
}

/* -------------------------------------------------------------- mobile --- */
@media (max-width: 760px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
  .stat-card { min-height: 82px !important; padding: 12px !important; }
  .stat-card-value { font-size: 17px !important; }
  .hero-panel { padding: 14px 16px !important; }
  .hero-title { font-size: 1.25rem !important; }
  .toolbar { padding: 10px 12px !important; }
  .filter-btn { min-height: 34px !important; padding: 6px 11px !important; font-size: 12px !important; }
}


/* ============================================================================
   Override block 2 — style.css has `html:not(.dark) .x { … !important }` rules
   (specificity 0,2,1), so plain `.x` overrides above lose. Everything critical
   is repeated here with the same-or-higher specificity.
   ========================================================================== */

html:not(.dark) .header { background: #ffffff !important; border-bottom: 1px solid var(--p-border) !important; backdrop-filter: none !important; }
html.dark .header { background: var(--p-surface) !important; border-bottom: 1px solid var(--p-border) !important; backdrop-filter: none !important; }

html:not(.dark) .sidebar { background: #ffffff !important; border-right: 1px solid var(--p-border) !important; backdrop-filter: none !important; }
html.dark .sidebar { background: var(--p-surface) !important; border-right: 1px solid var(--p-border) !important; backdrop-filter: none !important; }

html:not(.dark) .hero-panel,
html.dark .hero-panel {
  background: var(--p-surface) !important;
  border: 1px solid var(--p-border) !important;
  border-radius: var(--p-radius) !important;
  box-shadow: var(--p-shadow) !important;
  padding: 18px 22px !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
html:not(.dark) .hero-title { color: var(--p-ink) !important; }
html:not(.dark) .hero-eyebrow { background: var(--p-accent-soft) !important; color: var(--p-accent-ink) !important; }

html:not(.dark) .stat-card,
html.dark .stat-card,
html:not(.dark) .card,
html.dark .card,
html:not(.dark) .table-wrapper,
html.dark .table-wrapper,
html:not(.dark) .card-header,
html.dark .card-header,
html:not(.dark) .donut-card,
html.dark .donut-card,
html:not(.dark) .chart-section,
html.dark .chart-section,
html:not(.dark) .chart-card,
html.dark .chart-card {
  background: var(--p-surface) !important;
  border: 1px solid var(--p-border) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

html:not(.dark) .stat-card { box-shadow: var(--p-shadow) !important; }
html:not(.dark) .stat-card, html.dark .stat-card { border-left-width: 3px !important; }
html:not(.dark) .stat-card.s-violet, html:not(.dark) .stat-card.stat-card-total { border-left-color: #7c3aed !important; }
html:not(.dark) .stat-card.s-blue { border-left-color: #2563eb !important; }
html:not(.dark) .stat-card.s-green, html:not(.dark) .stat-card.stat-card-green { border-left-color: #0f7b52 !important; }
html:not(.dark) .stat-card.s-red, html:not(.dark) .stat-card.stat-card-red { border-left-color: #b42318 !important; }
html:not(.dark) .stat-card.s-cyan { border-left-color: #0e7490 !important; }
html:not(.dark) .stat-card.s-gold, html:not(.dark) .stat-card.stat-card-collection { border-left-color: #b45309 !important; }
html.dark .stat-card.s-violet, html.dark .stat-card.stat-card-total { border-left-color: #a78bfa !important; }
html.dark .stat-card.s-blue { border-left-color: #60a5fa !important; }
html.dark .stat-card.s-green, html.dark .stat-card.stat-card-green { border-left-color: #34d399 !important; }
html.dark .stat-card.s-red, html.dark .stat-card.stat-card-red { border-left-color: #fb7185 !important; }
html.dark .stat-card.s-cyan { border-left-color: #22d3ee !important; }
html.dark .stat-card.s-gold, html.dark .stat-card.stat-card-collection { border-left-color: #fbbf24 !important; }

html:not(.dark) .table-wrapper thead th { background: var(--p-surface-2) !important; backdrop-filter: none !important; }
html.dark .table-wrapper thead th { background: var(--p-surface-2) !important; backdrop-filter: none !important; }
html:not(.dark) .table-wrapper tbody tr { background: var(--p-surface) !important; }
html.dark .table-wrapper tbody tr { background: var(--p-surface) !important; }

html .preview-overlay, .preview-overlay { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; background: rgba(15,23,42,.5) !important; }

html:not(.dark) .modal-content { background: #ffffff !important; }
html.dark .modal-content { background: var(--p-surface) !important; }

html:not(.dark) .filter-btn { background: #ffffff !important; color: var(--p-body) !important; }
html:not(.dark) .filter-btn.active { background: var(--p-accent) !important; color: #fff !important; }
html.dark .filter-btn { background: var(--p-surface-2) !important; color: var(--p-body) !important; }
html.dark .filter-btn.active { background: var(--p-accent) !important; color: #0b1020 !important; }


/* ---- leftover "blurred peek" panels (charts hidden) --------------------- */
/* portal-extras injects .pe-blurhide with blur(6px) + 54px max-height at
   runtime; that reads as a smudge on screen. Hide the block cleanly instead. */
html body .pe-blurhide {
  display: none !important;
  max-height: 0 !important;
  filter: none !important;
  opacity: 1 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
}

/* header / sidebar divider — the old token was near-black */
html:not(.dark) .header { border-bottom-color: var(--p-border) !important; }
html:not(.dark) .sidebar { border-right-color: var(--p-border) !important; }
html.dark .header { border-bottom-color: var(--p-border) !important; }
html.dark .sidebar { border-right-color: var(--p-border) !important; }


/* ---- even KPI grid (2 rows of 3 instead of 5 + 1) ----------------------- */
html body .stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 12px !important;
}
@media (max-width: 1180px) {
  html body .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}
@media (max-width: 640px) {
  html body .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
}
html body .stat-card { min-height: 92px !important; }
html body .stat-card-sub {
  white-space: normal !important;
  line-height: 1.35 !important;
  font-size: 11px !important;
  display: -webkit-box !important;
  -webkit-line-clamp: 2 !important;
  -webkit-box-orient: vertical !important;
  overflow: hidden !important;
}

/* ---- compact alert banners (they were 100px tall each) ------------------ */
html body .pe-bn {
  padding: 10px 14px !important;
  margin-bottom: 10px !important;
  border-radius: 12px !important;
}
html body .pe-bn > div:first-child > div:first-child { font-size: 13px !important; line-height: 1.3 !important; }
html body .pe-bn button { min-height: 34px !important; padding: 7px 14px !important; font-size: 12px !important; }

/* ---- invoices card: tighter header / toolbar ---------------------------- */
html body .card > .card-header { padding: 12px 16px !important; }
html body .toolbar { padding: 10px 14px !important; }
html body .table-wrapper table { border-collapse: separate !important; border-spacing: 0 !important; }


/* ---- alert banners: solid tint, compact type --------------------------- */
html body .pe-bn {
  background: #fff8ec !important;
  border: 1px solid #f2d9ae !important;
  box-shadow: none !important;
}
html.dark body .pe-bn {
  background: #241d0f !important;
  border: 1px solid #4a3a17 !important;
}
html body .pe-bn-main { max-width: 74% !important; }
html body .pe-bn-main > div,
html body .pe-bn-main > div > div { font-size: 12.5px !important; line-height: 1.3 !important; }
html body .pe-bn-main > div + div,
html body .pe-bn-main > div > div + div { font-size: 11px !important; margin-top: 2px !important; }
html body .pe-bn-cta { min-height: 32px !important; height: 32px !important; padding: 0 14px !important; }

html body .stat-card { min-height: 108px !important; }
html body .stat-card .stat-card-header { align-items: flex-start !important; }


/* ---- dark mode fixes ---------------------------------------------------- */
/* alert banners: several older rules force a white background with !important */
html.dark #pendingBanner,
html.dark #extrasBanner,
html.dark body .pe-bn#pendingBanner,
html.dark body .pe-bn#extrasBanner {
  background: linear-gradient(160deg, #2a2110, #1b1608) !important;
  border: 1px solid #4a3a17 !important;
}
html.dark #pendingBanner *,
html.dark #extrasBanner * { color: #f6e2b8 !important; }
html.dark #pendingBanner button,
html.dark #extrasBanner button { color: #151007 !important; }

/* ghost buttons: white bg + near-white text = invisible */
html.dark .btn-ghost,
html.dark .btn-ghost.btn-sm,
html.dark button[class*="btn-ghost"] {
  background: #16203423 !important;
  background-color: #182238 !important;
  color: #dbe3f4 !important;
  border: 1px solid var(--p-border) !important;
}
html.dark .btn-ghost:hover { background-color: #1e2a44 !important; }

/* icon-only floating controls keep contrast on dark */
html.dark #themeToggle, html.dark .theme-toggle, html.dark .dark-toggle, html.dark #darkModeToggle {
  background: #16203a !important;
  color: #dbe3f4 !important;
  border: 1px solid var(--p-border) !important;
}

html.dark .stat-card-sub { color: #98a6bf !important; }
html.dark .table-wrapper tbody td { color: #c4cfe2 !important; }

html.dark .btn.btn-ghost,
html.dark .btn.btn-ghost.btn-sm,
html.dark button.btn.btn-ghost {
  background-color: #182238 !important;
  background-image: none !important;
  color: #dbe3f4 !important;
  border: 1px solid var(--p-border) !important;
}

/* dashboard toggle chips — inline styles reference translucent tokens */
html.dark #btn-month-toggle,
html.dark #pe-dash-toggle {
  background-color: #182238 !important;
  color: #dbe3f4 !important;
  border: 1px solid #2b3a55 !important;
}
html:not(.dark) #btn-month-toggle,
html:not(.dark) #pe-dash-toggle {
  background-color: #ffffff !important;
  color: #334155 !important;
  border: 1px solid #e3e7ef !important;
}

/* final contrast pass (dark) */
html.dark .filter-btn:not(.active) {
  background-color: #141d31 !important;
  border-color: #2b3a55 !important;
  color: #c9d3e6 !important;
}
html.dark input::placeholder, html.dark textarea::placeholder { color: #8c9ab4 !important; }
html.dark .search-box input, html.dark .toolbar input { background-color: #141d31 !important; color: #dbe3f4 !important; }
html.dark .stat-card-sub, html.dark .stat-card-label { color: #9fadc6 !important; }


/* ============================================================================
   BENTO LAYER — denser, trading-desk feel: 12-column bento grid, hairline
   borders, mono numerals, motion. Pure CSS on the existing DOM (no markup
   change ⇒ no feature can go missing).
   ========================================================================== */

:root {
  --p-hair: #e8ecf4;
  --p-hair-dark: #212e46;
  --p-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}
html.dark { --p-hair: #212e46; }

/* --- bento grid ---------------------------------------------------------- */
html body .stats-grid {
  grid-template-columns: repeat(12, minmax(0, 1fr)) !important;
  gap: 12px !important;
  align-items: stretch !important;
}
html body .stats-grid > .stat-card { grid-column: span 3 !important; }
html body .stats-grid > .stat-card:nth-child(5),
html body .stats-grid > .stat-card:nth-child(6) { grid-column: span 6 !important; }

@media (max-width: 1180px) {
  html body .stats-grid > .stat-card { grid-column: span 6 !important; }
  html body .stats-grid > .stat-card:nth-child(5),
  html body .stats-grid > .stat-card:nth-child(6) { grid-column: span 6 !important; }
}
@media (max-width: 700px) {
  html body .stats-grid > .stat-card,
  html body .stats-grid > .stat-card:nth-child(5),
  html body .stats-grid > .stat-card:nth-child(6) { grid-column: span 12 !important; }
}

/* card shell: hairline + inner highlight, no drop shadow (trading look) */
html body .stat-card {
  min-height: 104px !important;
  border-radius: 16px !important;
  border: 1px solid var(--p-hair) !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .6) inset !important;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .6), rgba(255, 255, 255, 0)) !important;
  transition: border-color .18s ease, transform .18s ease, background-color .18s ease !important;
}
html.dark body .stat-card {
  box-shadow: 0 1px 0 rgba(255, 255, 255, .03) inset !important;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(255, 255, 255, 0)) !important;
}
html body .stat-card:hover {
  transform: translateY(-2px) !important;
  border-color: var(--p-border-strong) !important;
}

/* numbers: tabular + tight tracking (trading desk) */
html body .stat-card-value {
  font-family: var(--p-mono) !important;
  font-size: 21px !important;
  letter-spacing: -.02em !important;
}
html body .stats-grid > .stat-card:nth-child(5) .stat-card-value,
html body .stats-grid > .stat-card:nth-child(6) .stat-card-value { font-size: 25px !important; }

/* icon chip: flat square, no rotation */
html body .stat-card-icon {
  width: 30px !important; height: 30px !important;
  border-radius: 8px !important;
  background: var(--p-surface-3) !important;
  border: 1px solid var(--p-hair) !important;
}

/* --- hero: compact command bar ------------------------------------------ */
html body .hero-panel {
  border-radius: 16px !important;
  padding: 16px 20px !important;
}
html body .hero-title { font-size: 1.3rem !important; letter-spacing: -.01em !important; }

/* --- invoice card: sticky toolbar, denser rows --------------------------- */
html body .card { border-radius: 16px !important; }
html body .card > .card-header {
  position: sticky !important;
  top: 0 !important;
  z-index: 6 !important;
  background: var(--p-surface) !important;
  border-bottom: 1px solid var(--p-hair) !important;
}
html body .table-wrapper thead th {
  background: var(--p-surface) !important;
  border-bottom: 1px solid var(--p-hair) !important;
  font-size: 10px !important;
  letter-spacing: .1em !important;
}
html body .table-wrapper tbody td {
  border-bottom: 1px solid var(--p-hair) !important;
  font-variant-numeric: tabular-nums !important;
}
html body .table-wrapper tbody tr:hover { background: var(--p-surface-2) !important; }

/* --- motion (respects reduced-motion) ------------------------------------ */
@keyframes bentoIn {
  from { opacity: 0; transform: translateY(8px) scale(.995); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: no-preference) {
  html body .stats-grid > .stat-card,
  html body .hero-panel,
  html body .pe-bn,
  html body .card {
    animation: bentoIn .32s cubic-bezier(.22, 1, .36, 1) both;
  }
  html body .stats-grid > .stat-card:nth-child(1) { animation-delay: .02s; }
  html body .stats-grid > .stat-card:nth-child(2) { animation-delay: .05s; }
  html body .stats-grid > .stat-card:nth-child(3) { animation-delay: .08s; }
  html body .stats-grid > .stat-card:nth-child(4) { animation-delay: .11s; }
  html body .stats-grid > .stat-card:nth-child(5) { animation-delay: .14s; }
  html body .stats-grid > .stat-card:nth-child(6) { animation-delay: .17s; }
  html body .card { animation-delay: .2s; }
  html body .btn, html body .filter-btn, html body .nav-item {
    transition: background-color .16s ease, color .16s ease, border-color .16s ease !important;
  }
}
@media (prefers-reduced-motion: reduce) {
  html body * { animation: none !important; transition: none !important; }
}


/* --- status / type chips in the invoice list ---------------------------- */
html body .status-badge, html body .badge {
  border-radius: 999px !important;
  font-size: 10.5px !important;
  font-weight: 800 !important;
  letter-spacing: .05em !important;
  text-transform: uppercase !important;
  padding: 3px 10px !important;
  border: 1px solid transparent !important;
  box-shadow: none !important;
}
html body .status-badge.status-paid { background: #e9f8f1 !important; color: #0f7b52 !important; border-color: #bfe8d6 !important; }
html body .status-badge.status-pending, html body .status-badge.status-draft { background: #f4f6fa !important; color: #46536a !important; border-color: #dfe4ee !important; }
html body .status-badge.status-partial { background: #eef4ff !important; color: #1d4ed8 !important; border-color: #cddcff !important; }
html body .status-badge.status-credit { background: #fff7e8 !important; color: #92400e !important; border-color: #f2d9ae !important; }
html body .status-badge.status-overdue, html body .status-badge.status-unpaid { background: #fdf0ee !important; color: #b42318 !important; border-color: #f6cfc9 !important; }
html body .badge { background: var(--p-surface-3) !important; color: var(--p-body) !important; border-color: var(--p-hair) !important; }

html.dark body .status-badge.status-paid { background: #10261f !important; color: #34d399 !important; border-color: #1d4a3a !important; }
html.dark body .status-badge.status-pending, html.dark body .status-badge.status-draft { background: #16203a !important; color: #b9c4d8 !important; border-color: #24314b !important; }
html.dark body .status-badge.status-partial { background: #131f3a !important; color: #93b4ff !important; border-color: #24365c !important; }
html.dark body .status-badge.status-credit { background: #2a2010 !important; color: #fbbf24 !important; border-color: #4a3a17 !important; }
html.dark body .status-badge.status-overdue, html.dark body .status-badge.status-unpaid { background: #2a1418 !important; color: #fb7185 !important; border-color: #4d2530 !important; }

/* --- mobile: 2-up bento instead of one long column ---------------------- */
@media (max-width: 700px) {
  html body .stats-grid > .stat-card,
  html body .stats-grid > .stat-card:nth-child(5),
  html body .stats-grid > .stat-card:nth-child(6) { grid-column: span 12 !important; }
  html body .stats-grid > .stat-card:nth-child(-n+4) { grid-column: span 6 !important; min-height: 92px !important; }
  html body .stats-grid > .stat-card:nth-child(-n+4) .stat-card-value { font-size: 16px !important; }
}


/* ============================================================================
   V2 — dark-mode rebuild + pro/viral finish.
   The earlier blanket `#pendingBanner * { color: … }` painted light text on the
   light chips inside the banner (ratio 1.2 = invisible). Everything below is
   explicit per element, so nothing inherits a colour it can't sit on.
   ========================================================================== */

/* ---- reset the over-broad colour rules ---------------------------------- */
html.dark #pendingBanner *,
html.dark #extrasBanner * { color: inherit !important; }

html.dark #pendingBanner,
html.dark #extrasBanner {
  background: linear-gradient(160deg, #221a0d, #151009) !important;
  border: 1px solid #3f3218 !important;
}
html.dark .pe-bn-main { color: #f2e2c2 !important; }
html.dark .pe-bn-lbl { color: #f6d79a !important; letter-spacing: .08em !important; }
html.dark .pe-bn-chip {
  background: #2f2510 !important;
  border: 1px solid #4a3a17 !important;
  color: #ffd88a !important;
}
html.dark .pe-bn-amount {
  background: #3a2c12 !important;
  border: 1px solid #4f3d1a !important;
  color: #ffd88a !important;
}
html.dark .pe-bn-cta { background: #f0b429 !important; color: #1a1300 !important; }

/* toggles container (white box in dark) */
html.dark .pe-seg {
  background: #121a2b !important;
  border: 1px solid #22304a !important;
}
html.dark .pe-seg button { color: #cfd9ea !important; }
html.dark .pe-seg button[style*="background"] { color: inherit; }

/* invoice number chip */
html.dark .inv-chip { background: #1b1a38 !important; color: #c4b5fd !important; border-color: #302b56 !important; }
html:not(.dark) .inv-chip { background: #f3efff !important; color: #5b21b6 !important; border-color: #e2d9ff !important; }

/* muted labels that sat too dark on dark */
html.dark label, html.dark .form-label, html.dark .text-muted,
html.dark .toolbar span, html.dark .toolbar label { color: #9fadc6 !important; }
html.dark select, html.dark option { background: #121a2b !important; color: #dbe3f4 !important; }

/* ---- pro finish: type, spacing, motion --------------------------------- */
html body {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
html body .hero-panel { position: relative !important; overflow: hidden !important; }
html body .hero-panel::before {
  content: "" !important;
  position: absolute !important;
  inset: 0 0 auto 0 !important;
  height: 2px !important;
  background: linear-gradient(90deg, #7c3aed, #2563eb 45%, #0ea5e9 100%) !important;
  opacity: .9 !important;
}
html.dark body .hero-panel::before { opacity: .85 !important; }

html body .card { overflow: hidden !important; }
html body .table-wrapper tbody tr { transition: background-color .14s ease !important; }
html body .nav-item {
  border-radius: 10px !important;
  margin: 2px 8px !important;
  transition: background-color .16s ease, color .16s ease !important;
}
html body .nav-item.active { position: relative !important; }
html body .nav-item.active::before {
  content: "" !important;
  position: absolute !important;
  left: 0 !important; top: 20% !important; bottom: 20% !important;
  width: 3px !important; border-radius: 0 3px 3px 0 !important;
  background: var(--p-accent) !important;
}
html body .btn:active { transform: translateY(1px) !important; }

/* status chips: slightly larger, clearer */
html body .status-badge { padding: 4px 11px !important; font-size: 10px !important; }

/* number cells breathe */
html body .table-wrapper tbody td:nth-child(7) { font-family: var(--p-mono) !important; white-space: nowrap !important; }


/* ---- final polish: consistent KPI internals + contrast ------------------ */
html body .stat-card-header {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 10px !important;
  margin-bottom: 8px !important;
}
html body .stat-card-header .stat-info { order: 1 !important; }
html body .stat-card-header .stat-card-icon, html body .stat-card-header .stat-accent { order: 2 !important; }
html body .stat-card { justify-content: flex-start !important; }

/* placeholders / secondary text contrast (light) */
html:not(.dark) input::placeholder, html:not(.dark) textarea::placeholder { color: #6b7688 !important; }
html:not(.dark) .pe-bn-main > div + div, html:not(.dark) .pe-bn-main > div > div + div { color: #7a5b25 !important; }
html:not(.dark) .pe-seg button { color: #334155 !important; }

/* header breathing room */
html body .header { padding-left: 20px !important; padding-right: 20px !important; }
