/* ================================================================
   CML Dashboard — Polish Layer
   ----------------------------------------------------------------
   Loaded AFTER /mobile.css. Adds restrained glass-morphism,
   material depth, and reveal animations. UI polish only —
   no layout, no business logic, no data shape changes.

   Cascade order:
     1. inline page <style>     — base layout + tokens
     2. /mobile.css             — phone + tablet overrides
     3. /polish.css (this file) — universal aesthetic polish

   Class prefixes:
     .pr-*    polish-specific utilities
     .js-*    state classes added by polish.js on load
   ================================================================ */

/* ----------------------------------------------------------------
   1. POLISH TOKENS (additive — do not override existing)
   ---------------------------------------------------------------- */
:root {
  /* Glass surface colours */
  --pr-surface:        rgba(26, 30, 39, 0.68);     /* card / panel default */
  --pr-surface-hover:  rgba(28, 33, 43, 0.82);     /* card / panel hover   */
  --pr-surface-strong: rgba(19, 22, 29, 0.92);     /* modal, mobile drawer */
  --pr-surface-header: rgba(19, 22, 29, 0.78);     /* sticky header / nav  */

  /* Borders and highlights */
  --pr-border:         rgba(255, 255, 255, 0.07);
  --pr-border-bright:  rgba(255, 255, 255, 0.13);
  --pr-top-highlight:  rgba(255, 255, 255, 0.05);  /* "brighter top edge"  */
  --pr-inner-glow:     rgba(255, 255, 255, 0.03);

  /* Shadows — soft depth, not heavy drops */
  --pr-shadow-soft:    0 1px 2px rgba(0,0,0,0.25), 0 10px 28px rgba(0,0,0,0.20);
  --pr-shadow-lift:    0 2px 5px rgba(0,0,0,0.30), 0 18px 48px rgba(0,0,0,0.30);
  --pr-shadow-modal:   0 4px 12px rgba(0,0,0,0.35), 0 32px 80px rgba(0,0,0,0.45);

  /* Blur radii — modest by default, reduced on mobile */
  --pr-blur:           10px;
  --pr-blur-modal:     16px;
  --pr-blur-overlay:   8px;

  /* Motion timing — match user-stated budget */
  --pr-t-fast:   120ms cubic-bezier(.4, 0, .2, 1);
  --pr-t-base:   180ms cubic-bezier(.4, 0, .2, 1);
  --pr-t-reveal: 240ms cubic-bezier(.4, 0, .2, 1);
  --pr-t-modal:  220ms cubic-bezier(.16, 1, .3, 1);
}

.cml-status-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  border-bottom: 1px solid var(--pr-border);
  background: rgba(19, 22, 29, 0.72);
  -webkit-backdrop-filter: blur(10px) saturate(130%);
  backdrop-filter: blur(10px) saturate(130%);
  color: var(--text-3);
  font-size: 11px;
  line-height: 1.35;
}

.cml-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(39, 194, 140, 0.10);
  flex: 0 0 auto;
}

.cml-status-strip.is-offline .cml-status-dot {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.12);
}

.cml-status-copy {
  min-width: 0;
  flex: 1;
}

.cml-status-mode {
  flex: 0 0 auto;
  color: var(--orange);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.cml-status-health {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  margin-left: auto;
}
.cml-status-health:hover { color: var(--text); }
.cml-status-strip.is-expanded .cml-status-health { margin-right: 6px; }

/* @supports fallback — backdrop-filter unsupported (older browsers) */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root {
    --pr-surface:        rgba(26, 30, 39, 0.96);
    --pr-surface-hover:  rgba(28, 33, 43, 1);
    --pr-surface-strong: rgba(19, 22, 29, 1);
    --pr-surface-header: rgba(19, 22, 29, 0.98);
  }
}

/* ----------------------------------------------------------------
   2. KPI CARDS — primary glass surface
   ---------------------------------------------------------------- */
.kpi-card {
  background: var(--pr-surface);
  -webkit-backdrop-filter: blur(var(--pr-blur)) saturate(135%);
  backdrop-filter: blur(var(--pr-blur)) saturate(135%);
  border: 1px solid var(--pr-border);
  box-shadow:
    inset 0 1px 0 var(--pr-top-highlight),       /* slightly brighter top edge */
    inset 0 0 0 1px var(--pr-inner-glow),         /* subtle inner glow */
    var(--pr-shadow-soft);
  transition:
    background-color var(--pr-t-base),
    border-color     var(--pr-t-base),
    box-shadow       var(--pr-t-base),
    transform        var(--pr-t-fast);
}

.kpi-card:hover {
  background: var(--pr-surface-hover);
  border-color: var(--pr-border-bright);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.07),
    var(--pr-shadow-lift);
  transform: translateY(-1px);
}

.kpi-card:active {
  transform: translateY(0);
  transition-duration: 80ms;
}

/* KPI cards are intentionally quiet until opened. Full breakdowns live in
   the existing drill-down dialog so the dashboard remains scannable. */
.main .kpi-card .kpi-delta,
.main .kpi-card .kpi-age,
.main .kpi-card .kpi-sub { display: none !important; }
.main .kpi-row { align-items: stretch; }
.main .kpi-card { display: flex; flex-direction: column; justify-content: center; text-align: center; }
.main .kpi-card .kpi-label, .main .kpi-card .kpi-value { width: 100%; }

/* Keep chart axes visually explicit on every chart surface. */
.main .panel-body svg,
.main .bar-chart-area,
.main .price-chart-wrap,
.main [id*="Chart"] {
  border-left: 1px solid rgba(23,32,51,.35);
  border-bottom: 1px solid rgba(23,32,51,.35);
}

/* Detail dialogs should retain the dashboard's light glass language. */
.kd-modal {
  background: linear-gradient(135deg, rgba(226,241,255,.98), rgba(245,235,255,.98) 55%, rgba(255,226,212,.98)) !important;
  color: #172033 !important;
}
.kd-modal .kd-title, .kd-modal .kd-sub, .kd-modal .kd-body { color: #172033; }
.kd-close { display: inline-flex; align-items: center; justify-content: center; }
.kd-head { align-items: center; }
.kd-head .kd-close { margin-left: auto; flex: 0 0 36px; width: 36px; height: 36px; }

/* Shared trader-contact controls stay readable against the glass background. */
.trader-contact-page button, .trader-contact-page .contact-btn,
button[class*="contact" i], a[class*="contact" i] {
  color: #172033 !important;
  background: rgba(255,255,255,.72) !important;
  border-color: rgba(23,32,51,.22) !important;
}

/* Trader call list: show a compact, horizontally scrollable pack of cards
   with two or three visible at desktop widths. */
.pill-row {
  display: flex !important;
  gap: 14px !important;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding: 4px 2px 10px;
}
.pill-row .pill-card {
  flex: 0 0 clamp(260px, 30vw, 360px);
  min-height: 150px;
  scroll-snap-align: start;
  border-radius: 22px !important;
  background: linear-gradient(145deg, rgba(255,255,255,.88), rgba(218,232,255,.7)) !important;
  border: 1px solid rgba(255,255,255,.92) !important;
  box-shadow: 0 14px 30px rgba(31,52,93,.16), inset 0 1px rgba(255,255,255,.75);
}
.pill-row::-webkit-scrollbar { height: 9px; }
.pill-row::-webkit-scrollbar-thumb { background: rgba(23,32,51,.28); border-radius: 99px; }

/* ----------------------------------------------------------------
   3. PANELS — glass surface, slightly more solid than cards
   ---------------------------------------------------------------- */
.panel {
  background: var(--pr-surface);
  -webkit-backdrop-filter: blur(var(--pr-blur)) saturate(130%);
  backdrop-filter: blur(var(--pr-blur)) saturate(130%);
  border: 1px solid var(--pr-border);
  box-shadow:
    inset 0 1px 0 var(--pr-top-highlight),
    var(--pr-shadow-soft);
  transition:
    border-color var(--pr-t-base),
    box-shadow   var(--pr-t-base);
}

.panel:hover {
  border-color: var(--pr-border-bright);
}

/* Panel headers — soft gradient suggesting light source from above */
.panel-head {
  border-bottom: 1px solid var(--pr-border);
  background: linear-gradient(180deg, rgba(255,255,255,0.025), transparent);
}

/* ----------------------------------------------------------------
   4. DRILL MODAL / OVERLAY — dimmed + blurred backing
   ---------------------------------------------------------------- */
.kd-overlay {
  background: rgba(11, 13, 18, 0.55);
  -webkit-backdrop-filter: blur(var(--pr-blur-overlay));
  backdrop-filter: blur(var(--pr-blur-overlay));
  transition: opacity var(--pr-t-modal);
}

.kd-modal {
  background: var(--pr-surface-strong);
  -webkit-backdrop-filter: blur(var(--pr-blur-modal)) saturate(140%);
  backdrop-filter: blur(var(--pr-blur-modal)) saturate(140%);
  border: 1px solid var(--pr-border-bright);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    var(--pr-shadow-modal);
}

.kd-close {
  transition: background-color var(--pr-t-fast), color var(--pr-t-fast);
}

.kd-close:hover {
  background: rgba(255, 255, 255, 0.07);
}

/* ----------------------------------------------------------------
   5. STICKY HEADER (top bar with date-range pills)
   ---------------------------------------------------------------- */
.header {
  background: var(--pr-surface-header);
  -webkit-backdrop-filter: blur(12px) saturate(130%);
  backdrop-filter: blur(12px) saturate(130%);
  border-bottom: 1px solid var(--pr-border);
}

/* ----------------------------------------------------------------
   6. PERIOD PICKER (MTD / YTD / Last Mo …)
   ---------------------------------------------------------------- */
.period-btn {
  transition:
    background-color var(--pr-t-fast),
    border-color     var(--pr-t-fast),
    color            var(--pr-t-fast),
    box-shadow       var(--pr-t-fast);
}

.period-btn:hover {
  border-color: var(--pr-border-bright);
  background: rgba(255, 255, 255, 0.03);
}

.period-btn.active,
.period-btn.is-active,
.period-btn[aria-pressed="true"] {
  background: rgba(242, 106, 46, 0.12);
  border-color: rgba(242, 106, 46, 0.45);
  color: var(--orange);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* ----------------------------------------------------------------
   7. SIDEBAR NAV
   ---------------------------------------------------------------- */
.nav-item {
  transition:
    background-color var(--pr-t-fast),
    color            var(--pr-t-fast),
    box-shadow       var(--pr-t-fast);
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.nav-item.active,
.nav-item.is-active,
.nav-item[aria-current="page"] {
  background: rgba(242, 106, 46, 0.10);
  color: var(--text);
  box-shadow:
    inset 2px 0 0 var(--orange),
    inset 0 1px 0 var(--pr-top-highlight);
}

/* ----------------------------------------------------------------
   8. ICON BUTTONS / GENERIC BUTTONS — focus + hover polish
   ---------------------------------------------------------------- */
.icon-btn,
.kpi-pin {
  transition:
    background-color var(--pr-t-fast),
    border-color     var(--pr-t-fast),
    color            var(--pr-t-fast);
}
.icon-btn:hover,
.kpi-pin:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--pr-border-bright);
}

button:focus-visible,
.nav-item:focus-visible,
.kpi-card:focus-visible,
.period-btn:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid rgba(91, 168, 245, 0.6);
  outline-offset: 2px;
}

/* ----------------------------------------------------------------
   9. BADGES + TAGS — restrained contrast
   ---------------------------------------------------------------- */
.badge,
.tag {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

/* ----------------------------------------------------------------
   10. MOBILE-SPECIFIC OVERRIDES (≤640px)
       - Reduce blur for performance on iPhone Safari
       - Make surfaces less translucent for readability
   ---------------------------------------------------------------- */
@media (max-width: 640px) {
  :root {
    --pr-blur:         5px;
    --pr-blur-modal:   8px;
    --pr-blur-overlay: 4px;
    --pr-surface:        rgba(26, 30, 39, 0.88);
    --pr-surface-hover:  rgba(28, 33, 43, 0.95);
    --pr-surface-strong: rgba(19, 22, 29, 0.98);
    --pr-surface-header: rgba(19, 22, 29, 0.92);
  }

  /* Mobile drawer (sidebar slide-out) */
  .sidebar {
    background: var(--pr-surface-strong);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    backdrop-filter: blur(16px) saturate(140%);
    border-right: 1px solid var(--pr-border);
  }

  /* Disable expensive overlay blur on phone — full-screen modal anyway */
  .kd-overlay {
    background: rgba(11, 13, 18, 0.88);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .kd-modal {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--pr-surface-strong);
  }

  /* Hover transform off on phone (no hover, and removes flicker on tap) */
  .kpi-card:hover {
    transform: none;
  }
}

/* ----------------------------------------------------------------
   11. REVEAL ANIMATIONS
       - Page-shell fade + KPI/panel stagger
       - polish.js adds `.js-polish` to <html>, then `.pr-in` to
         each element when it enters the viewport.
       - Content is VISIBLE BY DEFAULT — if polish.js never runs,
         no class is added and nothing is hidden.
   ---------------------------------------------------------------- */
.js-polish .kpi-card,
.js-polish .panel {
  opacity: 0;
  transform: translateY(6px);
  transition:
    opacity   var(--pr-t-reveal),
    transform var(--pr-t-reveal),
    background-color var(--pr-t-base),
    border-color     var(--pr-t-base),
    box-shadow       var(--pr-t-base);
}

.js-polish .kpi-card.pr-in,
.js-polish .panel.pr-in {
  opacity: 1;
  transform: none;
}

/* KPI grid stagger — first 8 cards only, max ~280ms total */
.js-polish .kpi-row > .kpi-card:nth-child(1) { transition-delay: 0ms; }
.js-polish .kpi-row > .kpi-card:nth-child(2) { transition-delay: 40ms; }
.js-polish .kpi-row > .kpi-card:nth-child(3) { transition-delay: 80ms; }
.js-polish .kpi-row > .kpi-card:nth-child(4) { transition-delay: 120ms; }
.js-polish .kpi-row > .kpi-card:nth-child(5) { transition-delay: 160ms; }
.js-polish .kpi-row > .kpi-card:nth-child(6) { transition-delay: 200ms; }
.js-polish .kpi-row > .kpi-card:nth-child(7) { transition-delay: 240ms; }
.js-polish .kpi-row > .kpi-card:nth-child(n+8) { transition-delay: 280ms; }

/* Page-shell fade — content area only, runs once via .js-polish-loaded */
.js-polish .content {
  animation: prShellFade 160ms cubic-bezier(.4, 0, .2, 1) both;
}
@keyframes prShellFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ----------------------------------------------------------------
   12. REDUCED MOTION — kill all transitions, animations, stagger
   ---------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
  .js-polish .kpi-card,
  .js-polish .panel,
  .js-polish .kpi-row > .kpi-card {
    opacity: 1 !important;
    transform: none !important;
    transition-delay: 0ms !important;
  }
  .js-polish .content {
    animation: none !important;
  }
}

/* ----------------------------------------------------------------
   19. WIDER DESKTOP CONTENT FRAME
   Keep a deliberate gutter while letting production pages use more of
   the available viewport. This is shared layout only; page-specific
   grids and data surfaces remain unchanged.
   ---------------------------------------------------------------- */
.content {
  width: 100%;
  max-width: none;
  margin-inline: 0;
  padding-inline: clamp(18px, 2.5vw, 40px);
}

@media (max-width: 640px) {
  .content {
    padding-inline: 18px;
  }
}

/* ================================================================
   13. CHART REVEAL — grow on first viewport entry
   ----------------------------------------------------------------
   Bars: clip-path wipes up from baseline, so bars appear to grow
         out of the x-axis.
   Lines: stroke-dashoffset draws the path on. polish.js measures
          path length via getTotalLength() and sets --pl per path.
   Both gated by the existing .pr-in class added on reveal.
   ================================================================ */
.js-polish .panel .bar-chart-area,
.js-polish .panel .bar-chart-outer,
.js-polish .panel .chart-area,
.js-polish .panel .chart-wrap {
  clip-path: inset(100% 0 0 0);
  -webkit-clip-path: inset(100% 0 0 0);
  transition:
    clip-path 900ms cubic-bezier(.16, 1, .3, 1) 120ms,
    -webkit-clip-path 900ms cubic-bezier(.16, 1, .3, 1) 120ms;
}
.js-polish .panel.pr-in .bar-chart-area,
.js-polish .panel.pr-in .bar-chart-outer,
.js-polish .panel.pr-in .chart-area,
.js-polish .panel.pr-in .chart-wrap {
  clip-path: inset(0 0 0 0);
  -webkit-clip-path: inset(0 0 0 0);
}

/* Lines/polylines tagged by polish.js with .pr-draw */
.js-polish .panel .pr-draw {
  stroke-dasharray: var(--pl, 2000);
  stroke-dashoffset: var(--pl, 2000);
  transition: stroke-dashoffset 1200ms cubic-bezier(.16, 1, .3, 1) 320ms;
}
.js-polish .panel.pr-in .pr-draw {
  stroke-dashoffset: 0;
}

/* ================================================================
   14. KPI COUNT-UP — running number while polish.js animates
   ----------------------------------------------------------------
   Numbers tick from 0 to their real value. We add a temporary
   .pr-counting class while the rAF loop runs. Used here only to
   tighten letter-spacing slightly so the variable-width tabular
   feel stays consistent while digits change.
   ================================================================ */
.kpi-value {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
}

.kpi-card.pr-counting .kpi-value {
  letter-spacing: -0.005em;
}

/* ================================================================
   15. SKELETON SHIMMER — KPI values that haven't loaded yet
   ----------------------------------------------------------------
   When .pr-loading is on a card (added by polish.js when the
   value text is "—", empty, or "Loading…"), the kpi-value text
   is hidden and replaced with a shimmering bar.
   ================================================================ */
.kpi-card.pr-loading .kpi-value {
  position: relative;
  color: transparent !important;
  user-select: none;
  min-height: 1.1em;
}
.kpi-card.pr-loading .kpi-value::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 62%;
  height: 0.58em;
  min-height: 14px;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.04) 0%,
    rgba(255,255,255,0.11) 50%,
    rgba(255,255,255,0.04) 100%
  );
  background-size: 250% 100%;
  animation: prShimmer 1.6s ease-in-out infinite;
}

@keyframes prShimmer {
  0%   { background-position: 250% 0; }
  100% { background-position: -150% 0; }
}

/* ================================================================
   16. AMBIENT LIGHT SHIFT — fixed background layer behind content
   ----------------------------------------------------------------
   polish.js injects a fixed-position .pr-ambient layer into <body>
   (only if reduced-motion is OFF). Subtle warm + cool wash that
   drifts ~2% over 32s. Sits behind all content via z-index: -1.
   ================================================================ */
.pr-ambient {
  position: fixed;
  inset: -4vh -4vw;
  pointer-events: none;
  /* z-index: -1 keeps the ambient layer behind everything without needing
     .app to have z-index: 1 — which previously created a stacking context
     that trapped the mobile sidebar (z:1000) below the body-level
     backdrop (z:999), blocking clicks on nav items. */
  z-index: -1;
  background:
    radial-gradient(circle 460px at 18% 24%, rgba(242, 106, 46, 0.045), transparent 65%),
    radial-gradient(circle 400px at 84% 76%, rgba(91, 168, 245, 0.040), transparent 65%);
  opacity: 0;
  animation:
    prAmbientFade 1.4s ease 240ms forwards,
    prAmbientShift 32s ease-in-out 1.8s infinite alternate;
  will-change: transform;
}

@keyframes prAmbientFade {
  to { opacity: 1; }
}
@keyframes prAmbientShift {
  to { transform: translate3d(2%, -1.2%, 0); }
}

/* ================================================================
   17. EXTENDED REDUCED-MOTION OVERRIDES (for sections 13–16)
   ================================================================ */
@media (prefers-reduced-motion: reduce) {
  .js-polish .panel .bar-chart-area,
  .js-polish .panel .bar-chart-outer,
  .js-polish .panel .chart-area,
  .js-polish .panel .chart-wrap {
    clip-path: none !important;
    -webkit-clip-path: none !important;
  }
  .js-polish .panel .pr-draw {
    stroke-dasharray: none !important;
    stroke-dashoffset: 0 !important;
  }
  .kpi-card.pr-loading .kpi-value::after {
    animation: none !important;
    background: rgba(255, 255, 255, 0.07) !important;
  }
  .pr-ambient {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}

/* ================================================================
   18. LAYOUT FIX — direct .panel children of .content can collapse
   ----------------------------------------------------------------
   `.content` is `display: flex; flex-direction: column`. Most
   panels are wrapped in `.panel-row` which sizes correctly, but a
   few (notably #plWaterfallPanel on dashboard.html) sit as direct
   `.panel` children of `.content`. In some layouts they collapse to
   ~1px because flex-shrink takes over when total children exceed
   container height. Force them to size to content.
   This is a pre-existing layout quirk surfaced by the polish review.
   ================================================================ */
.content > .panel {
  flex: 0 0 auto;
  min-height: fit-content;
}

/* ================================================================
   19. SCROLLBARS — distinguish main scroll from inner scroll regions
   ----------------------------------------------------------------
   Two scrollbars commonly appear stacked on the right edge:
     - .content (main page scroll)         → wider, neutral
     - .panel-body / .kd-body inner scroll → narrower, orange accent
   The accent makes it obvious which area you're scrolling.
   Hidden on mobile to keep the card-stack flow clean.
   ================================================================ */

/* Main content scroll — neutral / wider */
.content {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.content::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.content::-webkit-scrollbar-track {
  background: transparent;
}
.content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
  transition: background-color 160ms ease;
}
.content::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.28);
  background-clip: padding-box;
}

/* Inner panel scrolls — narrower, warm accent */
.panel-body,
.kd-body,
.panel-body *[class*="scroll"],
.kd-body *[class*="scroll"] {
  scrollbar-width: thin;
  scrollbar-color: rgba(242, 106, 46, 0.40) transparent;
}
.panel-body::-webkit-scrollbar,
.kd-body::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.panel-body::-webkit-scrollbar-track,
.kd-body::-webkit-scrollbar-track {
  background: transparent;
}
.panel-body::-webkit-scrollbar-thumb,
.kd-body::-webkit-scrollbar-thumb {
  background: rgba(242, 106, 46, 0.32);
  border-radius: 3px;
  transition: background-color 160ms ease;
}
.panel-body::-webkit-scrollbar-thumb:hover,
.kd-body::-webkit-scrollbar-thumb:hover {
  background: rgba(242, 106, 46, 0.55);
}

/* Sidebar drawer (mobile) — same neutral as main scroll */
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.10);
  border-radius: 3px;
}

/* Mobile: hide custom scrollbar styling to keep card-stack flow clean.
   iOS Safari already hides scrollbars by default on touch devices. */
@media (max-width: 640px) {
  .content::-webkit-scrollbar,
  .panel-body::-webkit-scrollbar,
  .kd-body::-webkit-scrollbar {
    width: 0;
    height: 0;
  }
}

/* ================================================================
   20. P&L WATERFALL — investment-grade cascade bars
   ----------------------------------------------------------------
   The chart is rendered as SVG <g class="wf-bar wf-rev/wf-cost/wf-gp">
   blocks by renderPLWaterfall(). Hover brightens each bar.
   ================================================================ */
#plWaterfallSvg .wf-bar {
  transition: filter 180ms cubic-bezier(.4, 0, .2, 1);
  transform-box: fill-box;
  transform-origin: center;
}
#plWaterfallSvg .wf-bar:hover {
  filter: brightness(1.15) drop-shadow(0 4px 10px rgba(0, 0, 0, 0.4));
}
#plWaterfallSvg .wf-rev:hover  { filter: brightness(1.18) drop-shadow(0 4px 12px rgba(91, 168, 245, 0.30)); }
#plWaterfallSvg .wf-cost:hover { filter: brightness(1.15) drop-shadow(0 4px 12px rgba(229, 72, 77, 0.30)); }
#plWaterfallSvg .wf-gp:hover   { filter: brightness(1.18) drop-shadow(0 4px 12px rgba(39, 194, 140, 0.35)); }

/* Reduced motion: no filter transition */
@media (prefers-reduced-motion: reduce) {
  #plWaterfallSvg .wf-bar { transition: none !important; }
}

/* ----------------------------------------------------------------
   Lavender Apple Visual Overhaul
   ----------------------------------------------------------------
   Visual-only theme layer. It deliberately keeps existing markup,
   IDs, classes, data hooks, and scripts intact.
   ---------------------------------------------------------------- */
:root {
  --bg: #c9d5ff;
  --surface: rgba(255, 255, 255, 0.58);
  --surface-2: rgba(255, 255, 255, 0.44);
  --surface-3: rgba(255, 255, 255, 0.32);
  --border: rgba(255, 255, 255, 0.74);
  --border-soft: rgba(79, 85, 208, 0.16);
  --text: #151839;
  --text-2: #363b62;
  --text-3: #434872;
  --orange: #f2814e;
  --orange-2: #b84a1a;
  --blue: #7b80e3;
  --blue-2: #4f55d0;
  --violet: #6b4fd8;
  --green: #0b7a53;
  --red: #b8303a;
  --amber: #8a5400;

  --lav-ink: #151839;
  --lav-ink-2: #363b62;
  --lav-indigo: #4f55d0;
  --lav-indigo-deep: #3c41b0;
  --lav-indigo-mid: #7b80e3;
  --lav-coral: #f2814e;
  --lav-card: radial-gradient(120% 70% at 0% 0%, rgba(255,255,255,.58), transparent 55%),
              linear-gradient(145deg, rgba(255,255,255,.68), rgba(255,255,255,.27));
  --lav-shell: linear-gradient(135deg, rgba(255,255,255,.48), rgba(255,255,255,.18));
  --lav-shadow: 0 14px 40px rgba(60,70,180,.18),
                inset 0 1px 0 rgba(255,255,255,.95),
                inset 0 -1px 0 rgba(255,255,255,.30);
  --lav-shadow-lift: 0 22px 50px rgba(60,70,180,.26),
                     inset 0 1px 0 #fff,
                     inset 0 -1px 0 rgba(255,255,255,.35);
}

html,
body {
  color: var(--lav-ink) !important;
  font-family: Archivo, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
  background:
    radial-gradient(900px 600px at 12% 8%, #8fa4ff 0%, transparent 60%),
    radial-gradient(800px 600px at 92% 18%, #ffb48c 0%, transparent 58%),
    radial-gradient(900px 700px at 80% 95%, #b79bff 0%, transparent 60%),
    radial-gradient(700px 600px at 8% 92%, #7fd6f5 0%, transparent 60%),
    linear-gradient(135deg, #c4d0ff, #aebffb 50%, #d2c3ff) fixed !important;
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  pointer-events: none;
  border-radius: 999px;
  filter: blur(42px);
  opacity: .72;
  transform: translateZ(0);
}

body::before {
  width: 460px;
  height: 460px;
  left: 4%;
  top: 6%;
  background: radial-gradient(circle at 35% 35%, #6f7bff, #4f55d0 70%);
  animation: lavenderDrift 22s ease-in-out infinite alternate;
}

body::after {
  width: 390px;
  height: 390px;
  right: 4%;
  bottom: 2%;
  background: radial-gradient(circle at 40% 40%, #ff9ec1, #e8588f 70%);
  animation: lavenderDrift 26s ease-in-out -8s infinite alternate;
}

@keyframes lavenderDrift {
  to { transform: translate(50px, -40px) scale(1.12); }
}

.app {
  background: var(--lav-shell) !important;
  border: 1px solid rgba(255,255,255,.70);
  box-shadow: 0 30px 90px rgba(52,60,160,.28),
              inset 0 1px 0 rgba(255,255,255,.95),
              inset 0 0 0 1px rgba(255,255,255,.12);
  -webkit-backdrop-filter: blur(30px) saturate(1.7);
  backdrop-filter: blur(30px) saturate(1.7);
}

@media (min-width: 761px) {
  body:has(.app) { padding: 22px; }

  .app {
    height: calc(100vh - 44px) !important;
    max-width: 1480px;
    margin: 0 auto;
    border-radius: 32px;
    overflow: hidden;
  }
}

.sidebar {
  background: linear-gradient(180deg, rgba(88,93,220,.88), rgba(60,65,178,.90)) !important;
  border-right: 1px solid rgba(255,255,255,.28) !important;
  color: #fff !important;
  -webkit-backdrop-filter: blur(18px) saturate(1.55);
  backdrop-filter: blur(18px) saturate(1.55);
}

.sidebar::before {
  background:
    radial-gradient(ellipse 220px 190px at 50% -8%, rgba(255,255,255,.24), transparent 70%),
    radial-gradient(ellipse 200px 180px at 20% 18%, rgba(242,129,78,.20), transparent 68%) !important;
}

.sidebar-brand {
  border-bottom-color: rgba(255,255,255,.18) !important;
}

.brand-mark {
  background: #fff !important;
  color: var(--lav-indigo-deep) !important;
  border-radius: 999px !important;
  box-shadow: 0 8px 22px rgba(20,24,100,.28) !important;
}

.brand-name,
.user-name {
  color: #fff !important;
}

.brand-sub,
.user-role,
.nav-section-label {
  color: rgba(255,255,255,.58) !important;
}

.nav-item {
  color: rgba(255,255,255,.78) !important;
  border-color: transparent !important;
  border-radius: 14px !important;
  min-height: 38px;
}

.nav-item:hover {
  background: rgba(255,255,255,.12) !important;
  color: #fff !important;
}

.nav-item.active {
  background: rgba(255,255,255,.18) !important;
  color: #fff !important;
  border-color: rgba(255,255,255,.20) !important;
  box-shadow: inset 3px 0 0 #fff !important;
}

.header,
.cml-status-strip {
  background: rgba(255,255,255,.38) !important;
  border-bottom: 1px solid rgba(255,255,255,.60) !important;
  color: var(--lav-ink) !important;
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
  backdrop-filter: blur(18px) saturate(1.6);
}

.header-title,
.panel-title,
.section-title,
.page-title,
h1,
h2,
h3 {
  color: var(--lav-ink) !important;
  letter-spacing: -0.025em;
}

.header-title {
  font-size: clamp(22px, 2.3vw, 34px) !important;
  font-weight: 650 !important;
}

.header-sub,
.header-date,
.panel-sub,
.kpi-label,
.kpi-note,
.source-note,
.cml-status-copy,
.muted,
.sub,
.src {
  color: var(--lav-ink-2) !important;
}

.content,
.main,
main {
  background: transparent !important;
}

.panel,
.kpi-card,
.card,
.metric-card,
.story-card,
.table-card,
.calendar-event,
.settings-card,
.auth-card,
.contract-card,
.deduction-card,
.site-card {
  background: var(--lav-card) !important;
  border: 1px solid rgba(255,255,255,.78) !important;
  border-radius: 22px !important;
  box-shadow: var(--lav-shadow) !important;
  color: var(--lav-ink) !important;
  -webkit-backdrop-filter: blur(26px) saturate(1.7);
  backdrop-filter: blur(26px) saturate(1.7);
}

.panel:hover,
.kpi-card:hover,
.card:hover,
.metric-card:hover,
.story-card:hover,
.table-card:hover,
.contract-card:hover,
.deduction-card:hover,
.site-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--lav-shadow-lift) !important;
}

.panel-head,
.panel-footer,
.card-head,
.table-head,
.sidebar-footer {
  border-color: rgba(79,85,208,.16) !important;
}

.kpi-value,
.metric-value,
.pie-hole-value,
.hero-stat,
.value,
.num {
  color: var(--lav-ink) !important;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.035em;
}

.kpi-value,
.metric-value,
.value {
  font-weight: 650 !important;
}

.delta-up,
.up,
.positive,
.is-positive {
  color: var(--green) !important;
}

.delta-down,
.down,
.negative,
.is-negative {
  color: var(--red) !important;
}

button,
.btn,
.button,
.period-btn,
.range-btn,
input,
select,
textarea {
  border-radius: 999px !important;
}

button,
.btn,
.button,
.period-btn,
.range-btn {
  min-height: 40px;
  border-color: rgba(255,255,255,.78) !important;
}

.btn-primary,
.button.primary,
.period-btn.active,
.range-btn.active,
button.active {
  background: var(--lav-ink) !important;
  color: #fff !important;
  border-color: var(--lav-ink) !important;
  box-shadow: 0 8px 20px rgba(21,24,57,.26) !important;
}

input,
select,
textarea,
.search,
.filter,
.select,
.input {
  background: rgba(255,255,255,.48) !important;
  border: 1px solid rgba(255,255,255,.78) !important;
  color: var(--lav-ink) !important;
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
}

input::placeholder,
textarea::placeholder {
  color: rgba(67,72,114,.72) !important;
}

table,
.table {
  color: var(--lav-ink) !important;
}

th,
.table th {
  color: var(--lav-ink-2) !important;
  border-color: rgba(79,85,208,.16) !important;
}

td,
.table td,
.legend-row,
.product-row,
.exp-row,
.row {
  border-color: rgba(79,85,208,.13) !important;
}

.badge,
.status,
.chip,
.tag,
.nav-badge {
  border-radius: 999px !important;
}

.source-note,
.empty,
.calendar-empty {
  background: rgba(255,255,255,.34) !important;
  border-color: rgba(79,85,208,.20) !important;
}

.calendar-frame-wrap,
.pie-hole {
  background: rgba(255,255,255,.42) !important;
  border-color: rgba(255,255,255,.76) !important;
}

.calendar-frame {
  border-radius: 18px;
}

a {
  color: var(--lav-indigo-deep);
}

:focus-visible {
  outline: 2px solid var(--lav-indigo) !important;
  outline-offset: 3px !important;
}

@media (max-width: 760px) {
  body:has(.app) { padding: 0; }

  .app {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .sidebar {
    border-right: 0 !important;
    border-bottom: 1px solid rgba(255,255,255,.24) !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after {
    animation: none !important;
  }
}

/* ----------------------------------------------------------------
   Light Green Glass Override
   ----------------------------------------------------------------
   Visual-only override requested 2026-10-10. Keeps the lavender/glass
   layout intact while replacing the blue/orange background wash.
   ---------------------------------------------------------------- */
:root {
  --bg: #dff4e8;
  --surface: rgba(255, 255, 255, 0.58);
  --surface-2: rgba(255, 255, 255, 0.44);
  --surface-3: rgba(255, 255, 255, 0.32);
  --border-soft: rgba(28, 111, 82, 0.16);
  --orange: #65b879;
  --orange-2: #35784e;
  --blue: #7ad3aa;
  --blue-2: #4baf8a;
  --violet: #82cfa5;
  --lav-indigo: #4baf8a;
  --lav-indigo-deep: #1c6f52;
  --lav-indigo-mid: #7ad3aa;
  --lav-coral: #65b879;
  --lav-shadow: 0 14px 40px rgba(28,111,82,.16),
                inset 0 1px 0 rgba(255,255,255,.95),
                inset 0 -1px 0 rgba(255,255,255,.30);
  --lav-shadow-lift: 0 22px 50px rgba(28,111,82,.24),
                     inset 0 1px 0 #fff,
                     inset 0 -1px 0 rgba(255,255,255,.35);
}

html,
body {
  background:
    radial-gradient(900px 600px at 12% 8%, #a9e4c2 0%, transparent 60%),
    radial-gradient(820px 620px at 92% 18%, #d7f4de 0%, transparent 58%),
    radial-gradient(900px 700px at 80% 95%, #bfead7 0%, transparent 60%),
    radial-gradient(720px 620px at 8% 92%, #eef9e8 0%, transparent 60%),
    linear-gradient(135deg, #f7fcf4, #dff4e8 48%, #c7ebd8) fixed !important;
}

body::before {
  background: radial-gradient(circle at 35% 35%, #a9e4c2, #4baf8a 70%) !important;
}

body::after {
  background: radial-gradient(circle at 40% 40%, #e3f7d8, #8dd09e 70%) !important;
}

.sidebar {
  background: linear-gradient(180deg, rgba(53,120,78,.88), rgba(28,111,82,.90)) !important;
}

.sidebar::before {
  background:
    radial-gradient(ellipse 220px 190px at 50% -8%, rgba(255,255,255,.24), transparent 70%),
    radial-gradient(ellipse 200px 180px at 20% 18%, rgba(126,205,167,.22), transparent 68%) !important;
}

/* ----------------------------------------------------------------
   21. CROSS-DOCUMENT VIEW TRANSITIONS
       Same-origin navigations between pages crossfade the content
       instead of cutting to blank. The page header, the classic sidebar
       and the glass shell's top bar and fixed background get their own
       transition groups so they stay put while the page changes. auth-gate.js
       skips the transition if the page is still auth-hidden when it
       first renders, so unsupported or slow cases fall back to today's
       behaviour. Firefox/older browsers ignore all of this.
   ---------------------------------------------------------------- */
@view-transition {
  navigation: auto;
}

.sidebar { view-transition-name: cml-sidebar; }
.header  { view-transition-name: cml-header; }
.cw-bar  { view-transition-name: cml-bar; }
.cw-bg   { view-transition-name: cml-bg; }

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 180ms;
  animation-timing-function: cubic-bezier(.4, 0, .2, 1);
}

/* Pinned shell: no crossfade, no movement. */
::view-transition-old(cml-sidebar),
::view-transition-new(cml-sidebar),
::view-transition-old(cml-header),
::view-transition-new(cml-header),
::view-transition-old(cml-bar),
::view-transition-new(cml-bar),
::view-transition-old(cml-bg),
::view-transition-new(cml-bg) {
  animation: none;
}

/* The content area already fades in via prShellFade; keep a single fade
   when a view transition is driving the page change. */
html:active-view-transition .js-polish .content {
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }
}

/* ================================================================
   END polish.css
   ---------------------------------------------------------------- */
