/* ============================================================================
   PEARL — "CA" Unified Enterprise Design System
   Build: CA1  |  Scope: visual standardisation ONLY.
   No KPI formula, calculation, data point, or business logic is touched by
   this file or by the markup change that loads it (a <link> + a body class).

   HOW THIS WORKS
   - Load this file AFTER any page-specific CSS, so it wins on ties.
   - Add class="ca-enterprise ca-app-<name>" to <body> (appended, not
     replacing existing classes).
   - Every rule below is scoped under body.ca-enterprise so it can never
     leak into, or conflict with, pages that don't opt in.
   - Rules target class names/tags that ALREADY exist across the PEARL
     dashboards (card, kpi-card, metric-card, table th, tab buttons, filter
     bars, buttons, modals, empty/loading/error states) plus a small set of
     new "ds-/ca-" utility classes pages can optionally use later.
   - Sales V2 remains the reference visual language: teal/slate accents,
     clean white surfaces, restrained shadows, confident type hierarchy.
   ============================================================================ */

/* ---------------------------------------------------------------------------
   1. DESIGN TOKENS
   --------------------------------------------------------------------------- */
:root{
  /* Core palette */
  --ca-canvas:        #f5f7fb;
  --ca-surface:        #ffffff;
  --ca-surface-subtle: #f8fafc;
  --ca-surface-muted:  #f1f5f9;
  --ca-border:         #e2e8f0;
  --ca-border-strong:  #cbd5e1;

  /* Ink */
  --ca-ink:            #0f172a;
  --ca-ink-2:          #334155;
  --ca-muted:          #64748b;
  --ca-faint:          #94a3b8;

  /* Brand — deep blue primary, teal accent (Sales V2 language) */
  --ca-brand:          #2563eb;
  --ca-brand-dark:     #1d4ed8;
  --ca-accent:         #0f766e;
  --ca-accent-soft:    #f0fdfa;
  --ca-accent-border:  #99f6e4;

  /* Semantic */
  --ca-good:           #15803d;
  --ca-good-bg:        #dcfce7;
  --ca-warn:           #b45309;
  --ca-warn-bg:        #fef3c7;
  --ca-bad:            #b91c1c;
  --ca-bad-bg:         #fee2e2;
  --ca-info:           #1d4ed8;
  --ca-info-bg:        #dbeafe;

  /* Shape */
  --ca-r-sm:           7px;
  --ca-r-md:           10px;
  --ca-r-lg:           14px;
  --ca-r-pill:         999px;

  /* Elevation */
  --ca-shadow-xs:      0 1px 2px rgba(15,23,42,.04);
  --ca-shadow-sm:      0 1px 2px rgba(15,23,42,.035), 0 6px 18px rgba(15,23,42,.05);
  --ca-shadow-md:      0 4px 14px rgba(15,23,42,.07);
  --ca-shadow-pop:     0 20px 50px rgba(15,23,42,.16);

  /* Type */
  --ca-font:           'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  /* Density */
  --ca-control-h:      36px;
  --ca-control-h-mobile: 42px;
  --ca-page-pad:       16px;
  --ca-gap:            12px;

  /* Chart chrome (not chart data/colors — chrome only) */
  --ca-chart-pad:      14px;
}

/* ---------------------------------------------------------------------------
   2. BASE SURFACE
   --------------------------------------------------------------------------- */
body.ca-enterprise{
  background:var(--ca-canvas) !important;
  color:var(--ca-ink) !important;
  font-family:var(--ca-font);
  line-height:1.45;
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
  font-variant-numeric:tabular-nums;
}
body.ca-enterprise *{ scrollbar-width:thin; scrollbar-color:#cbd5e1 transparent; }
body.ca-enterprise *::-webkit-scrollbar{ width:8px; height:8px; }
body.ca-enterprise *::-webkit-scrollbar-thumb{ background:#cbd5e1; border-radius:999px; border:2px solid transparent; background-clip:padding-box; }
body.ca-enterprise ::selection{ background:#dbeafe; color:#1e3a8a; }
body.ca-enterprise :focus-visible{ outline:3px solid rgba(37,99,235,.22) !important; outline-offset:2px !important; }

body.ca-enterprise h1,body.ca-enterprise h2,body.ca-enterprise h3,body.ca-enterprise h4{
  color:var(--ca-ink); letter-spacing:-.012em;
}
body.ca-enterprise h1{ font-weight:800; }
body.ca-enterprise h2{ font-weight:800; }
body.ca-enterprise h3{ font-weight:700; }

body.ca-enterprise button{ font-family:var(--ca-font); }
body.ca-enterprise table{ font-variant-numeric:tabular-nums; }
body.ca-enterprise table th{ letter-spacing:.02em; }
body.ca-enterprise table tbody tr{ transition:background .12s ease; }

body.ca-enterprise input:not([type=checkbox]):not([type=radio]),
body.ca-enterprise select,
body.ca-enterprise textarea{
  border-color:var(--ca-border-strong) !important;
  border-radius:8px !important;
  box-shadow:0 1px 2px rgba(15,23,42,.02) !important;
  font-family:var(--ca-font);
  min-height:var(--ca-control-h);
}
body.ca-enterprise input:not([type=checkbox]):not([type=radio]):focus,
body.ca-enterprise select:focus,
body.ca-enterprise textarea:focus{
  border-color:#60a5fa !important;
  box-shadow:0 0 0 3px rgba(37,99,235,.10) !important;
}

/* ---------------------------------------------------------------------------
   3. HEADERS / APP SHELLS
   Common header/nav wrapper class names across the suite.
   --------------------------------------------------------------------------- */
body.ca-enterprise .master-nav,
body.ca-enterprise .dashboard-header,
body.ca-enterprise .app-header,
body.ca-enterprise header.top-bar{
  background:linear-gradient(135deg,#10233f 0%,#173b66 58%,#1f4f7a 100%) !important;
  box-shadow:0 3px 14px rgba(15,35,63,.16) !important;
  color:#fff !important;
}
body.ca-enterprise .master-nav *, body.ca-enterprise .dashboard-header *{ color:inherit; }

/* ---------------------------------------------------------------------------
   4. CARDS / PANELS / WIDGETS
   Matches whatever card class each dashboard already uses.
   --------------------------------------------------------------------------- */
body.ca-enterprise .card,
body.ca-enterprise .widget,
body.ca-enterprise .panel,
body.ca-enterprise .section-card,
body.ca-enterprise .content-card,
body.ca-enterprise .metric-card,
body.ca-enterprise .kpi-card,
body.ca-enterprise .jcsu-card,
body.ca-enterprise .flash-pro-card,
body.ca-enterprise .ds-widget{
  background:var(--ca-surface) !important;
  border:1px solid var(--ca-border) !important;
  border-radius:var(--ca-r-md) !important;
  box-shadow:var(--ca-shadow-sm) !important;
}
/* YCS gradients carried white text; the CA surface turns them white. */
body.ca-app-ycs .metric-card.text-white{color:var(--ca-ink)!important}
body.ca-enterprise .kpi-card,
body.ca-enterprise .metric-card{
  transition:box-shadow .15s ease, transform .15s ease;
}
body.ca-enterprise .kpi-card:hover,
body.ca-enterprise .metric-card:hover{
  box-shadow:var(--ca-shadow-md) !important;
}

/* KPI label/value/meta hierarchy (utility classes for future/optional use) */
body.ca-enterprise .ds-kpi-label,
body.ca-enterprise .kpi-label{
  font-size:11px; text-transform:uppercase; color:var(--ca-muted);
  font-weight:700; letter-spacing:.04em;
}
body.ca-enterprise .ds-kpi-value,
body.ca-enterprise .kpi-value{
  font-size:26px; font-weight:800; color:var(--ca-ink); line-height:1.1; margin-top:4px;
}
body.ca-enterprise .ds-kpi-meta,
body.ca-enterprise .kpi-meta{
  font-size:11px; color:var(--ca-muted); margin-top:4px;
}

/* ---------------------------------------------------------------------------
   5. CHART CHROME (containers only — never chart data/colors/series logic)
   --------------------------------------------------------------------------- */
body.ca-enterprise .chart-card,
body.ca-enterprise .chart-container,
body.ca-enterprise .chart-panel,
body.ca-enterprise [class*="chart-wrap"]{
  background:var(--ca-surface) !important;
  border:1px solid var(--ca-border) !important;
  border-radius:var(--ca-r-md) !important;
  box-shadow:var(--ca-shadow-sm) !important;
  padding:var(--ca-chart-pad) !important;
}
body.ca-enterprise .chart-title,
body.ca-enterprise .chart-card h3,
body.ca-enterprise .chart-card h4{
  font-size:13px; font-weight:700; color:var(--ca-ink-2); letter-spacing:-.01em;
}
body.ca-enterprise canvas{ border-radius:6px; }

/* ---------------------------------------------------------------------------
   6. TABS
   --------------------------------------------------------------------------- */
body.ca-enterprise .tab-navigation,
body.ca-enterprise .tab-nav,
body.ca-enterprise .cg-tab-strip,
body.ca-enterprise [role="tablist"]{
  background:var(--ca-surface) !important;
  border:1px solid var(--ca-border) !important;
  border-radius:var(--ca-r-md) !important;
  box-shadow:var(--ca-shadow-xs) !important;
  padding:4px !important;
  display:flex; gap:4px; flex-wrap:wrap;
}
body.ca-enterprise .tab-navigation button,
body.ca-enterprise .tab-nav button,
body.ca-enterprise .nav-button,
body.ca-enterprise .tab-button,
body.ca-enterprise [role="tab"]{
  border-radius:8px !important;
  font-weight:700 !important;
  letter-spacing:0 !important;
  font-family:var(--ca-font);
  transition:background .12s ease,color .12s ease,border-color .12s ease !important;
}
body.ca-enterprise .tab-navigation button:hover,
body.ca-enterprise .tab-nav button:hover,
body.ca-enterprise [role="tab"]:hover{
  background:#f1f5f9 !important; color:#0f172a !important;
}
body.ca-enterprise .tab-navigation button.active,
body.ca-enterprise .tab-nav button.active,
body.ca-enterprise [role="tab"][aria-selected="true"],
body.ca-enterprise [role="tab"].is-active{
  background:var(--ca-accent-soft) !important;
  color:var(--ca-accent) !important;
  box-shadow:inset 0 0 0 1px var(--ca-accent-border) !important;
}

/* ---------------------------------------------------------------------------
   7. FILTER BARS / TOOLBARS
   --------------------------------------------------------------------------- */
body.ca-enterprise .filter-bar,
body.ca-enterprise .main-filter-bar,
body.ca-enterprise .master-filters,
body.ca-enterprise .work-filter-bar,
body.ca-enterprise .flash-pro-filterbar,
body.ca-enterprise .cg-filter-surface{
  background:var(--ca-surface) !important;
  border:1px solid var(--ca-border) !important;
  border-radius:var(--ca-r-md) !important;
  box-shadow:var(--ca-shadow-xs) !important;
  padding:10px 12px !important;
}
body.ca-enterprise .filter-bar label,
body.ca-enterprise .main-filter-bar label,
body.ca-enterprise .master-filters label{
  color:var(--ca-muted) !important; font-size:10.5px !important;
  font-weight:700 !important; letter-spacing:.03em; text-transform:uppercase;
}

/* ---------------------------------------------------------------------------
   8. TABLES
   --------------------------------------------------------------------------- */
body.ca-enterprise table thead th,
body.ca-enterprise .ds-thead th,
body.ca-enterprise .data-table thead th{
  background:#f8fafc !important;
  color:#475569 !important;
  font-size:10.5px !important;
  font-weight:800 !important;
  letter-spacing:.03em;
  text-transform:uppercase;
  border-bottom:1px solid var(--ca-border) !important;
  position:sticky; top:0; z-index:1;
}
body.ca-enterprise table tbody td{ border-bottom:1px solid #edf2f7 !important; }
body.ca-enterprise:not(.vx-ops,.vxs-salesv2,.vxs-salesmini,.vxs-salesstd,.ca-app-pearlfin,.ca-app-accounts) table tbody td,
body.ca-enterprise table tbody td:not([class*="text-"]):not([style*="color"]){ color:#334155; }
/* Rollout sidebar hosts own a guarded hover in their family sheet (semantic fills never washed). */
body.ca-enterprise:not(.vx-ops,.vxs-salesv2,.vxs-salesmini,.vxs-salesstd,.ca-app-pearlfin,.ca-app-accounts) table tbody tr:hover td{
  background-color:rgba(239,246,255,.55) !important;
}
body.ca-enterprise table tbody tr:last-child td{ border-bottom:0 !important; }
body.ca-enterprise .ds-num{ text-align:right; font-variant-numeric:tabular-nums; }

/* ---------------------------------------------------------------------------
   9. BUTTONS
   --------------------------------------------------------------------------- */
body.ca-enterprise .btn,
body.ca-enterprise .cg-btn,
body.ca-enterprise button.primary,
body.ca-enterprise .btn-primary,
body.ca-enterprise .btn-secondary,
body.ca-enterprise .btn-danger{
  min-height:34px;
  border-radius:8px !important;
  font-size:11.5px !important;
  font-weight:750 !important;
  letter-spacing:0 !important;
  padding-left:12px !important; padding-right:12px !important;
  box-shadow:none !important;
  transition:background .12s ease,border-color .12s ease,transform .08s ease !important;
}
body.ca-enterprise .btn:active,
body.ca-enterprise .cg-btn:active{ transform:translateY(1px); }
body.ca-enterprise .btn-primary,
body.ca-enterprise button.primary{
  background:var(--ca-brand) !important; color:#fff !important; border-color:var(--ca-brand) !important;
}
body.ca-enterprise .btn-primary:hover,
body.ca-enterprise button.primary:hover{
  background:var(--ca-brand-dark) !important; border-color:var(--ca-brand-dark) !important;
}
body.ca-enterprise .btn-secondary{
  background:#fff !important; color:#334155 !important; border:1px solid var(--ca-border-strong) !important;
}
body.ca-enterprise .btn-secondary:hover{ background:#f8fafc !important; border-color:#94a3b8 !important; }
body.ca-enterprise .btn-danger{
  background:#fff !important; color:var(--ca-bad) !important; border:1px solid #fecaca !important;
}
body.ca-enterprise .btn-danger:hover{ background:#fef2f2 !important; }

/* ---------------------------------------------------------------------------
   10. STATUS CHIPS / BADGES
   --------------------------------------------------------------------------- */
body.ca-enterprise .ds-chip,
body.ca-enterprise .status-chip,
body.ca-enterprise .cg-status-chip{
  display:inline-flex; align-items:center; gap:4px;
  border-radius:var(--ca-r-pill); padding:3px 8px;
  font-size:10.5px; font-weight:800; line-height:1.2; white-space:nowrap;
}
body.ca-enterprise .ds-chip--good, body.ca-enterprise .status-good, body.ca-enterprise .cg-status-good{ background:var(--ca-good-bg) !important; color:var(--ca-good) !important; }
body.ca-enterprise .ds-chip--warn, body.ca-enterprise .status-warn, body.ca-enterprise .cg-status-warn{ background:var(--ca-warn-bg) !important; color:var(--ca-warn) !important; }
body.ca-enterprise .ds-chip--bad,  body.ca-enterprise .status-bad,  body.ca-enterprise .cg-status-bad { background:var(--ca-bad-bg)  !important; color:var(--ca-bad)  !important; }
body.ca-enterprise .ds-chip--info, body.ca-enterprise .status-info, body.ca-enterprise .cg-status-info{ background:var(--ca-info-bg) !important; color:var(--ca-info) !important; }
body.ca-enterprise .ds-chip--gray{ background:#e5e7eb !important; color:#4b5563 !important; }

/* ---------------------------------------------------------------------------
   11. EMPTY / LOADING / ERROR STATES
   --------------------------------------------------------------------------- */
body.ca-enterprise .state-empty,
body.ca-enterprise .state-loading,
body.ca-enterprise .empty-state,
body.ca-enterprise .loading-state,
body.ca-enterprise .cg-state-empty,
body.ca-enterprise .cg-state-loading{
  border-radius:var(--ca-r-md) !important;
  border:1px dashed var(--ca-border-strong) !important;
  padding:20px !important; text-align:center !important;
  background:#fbfcfe !important; color:var(--ca-muted) !important;
}
body.ca-enterprise .state-error,
body.ca-enterprise .error-state,
body.ca-enterprise .cg-state-error{
  border-radius:var(--ca-r-md) !important;
  padding:20px !important; text-align:center !important;
  background:#fff7f7 !important; border:1px solid #fecaca !important; color:#991b1b !important;
}

/* ---------------------------------------------------------------------------
   12. MODALS / DIALOGS
   --------------------------------------------------------------------------- */
body.ca-enterprise .modal-surface,
body.ca-enterprise [role="dialog"],
body.ca-enterprise dialog{
  border-radius:var(--ca-r-lg) !important;
  border-color:var(--ca-border) !important;
  box-shadow:var(--ca-shadow-pop) !important;
}

/* ---------------------------------------------------------------------------
   13. BUILD BADGE (small, unobtrusive, bottom-right — matches prior pattern)
   --------------------------------------------------------------------------- */
body.ca-enterprise .ca-build-badge{
  position:fixed; right:10px; bottom:10px; z-index:2147483000;
  display:inline-flex; align-items:center; gap:6px;
  padding:5px 9px; border:1px solid #bfdbfe; background:rgba(239,246,255,.94);
  color:#1e40af; border-radius:999px; box-shadow:0 4px 14px rgba(30,64,175,.12);
  font:700 10px/1.2 var(--ca-font); letter-spacing:.07em; text-transform:uppercase;
  backdrop-filter:blur(8px); pointer-events:none;
}
body.ca-enterprise .ca-build-badge:before{
  content:""; width:6px; height:6px; border-radius:50%;
  background:#2563eb; box-shadow:0 0 0 3px rgba(37,99,235,.12);
}
@media print{ .ca-build-badge{ display:none !important; } }

/* ---------------------------------------------------------------------------
   14. APP-FAMILY ACCENTS
   Same chrome language, small per-app accent so each tool still feels like
   itself inside a common shell (mirrors the Sales V2 teal accent already
   used app-wide).
   --------------------------------------------------------------------------- */
body.ca-app-sales .tab-navigation button.active,
body.ca-app-sales [role="tab"][aria-selected="true"]{
  color:#0f766e !important;
}
body.ca-app-workshop .tab-navigation button.active,
body.ca-app-livews .tab-navigation button.active{
  color:#1d4ed8 !important;
}

/* ---------------------------------------------------------------------------
   15. MOBILE / FLOOR APPS — denser targets, same visual language
   --------------------------------------------------------------------------- */
body.ca-app-sup9, body.ca-app-supx{
  --ca-control-h:var(--ca-control-h-mobile);
}
body.ca-app-sup9 .btn, body.ca-app-supx .btn,
body.ca-app-sup9 .cg-btn, body.ca-app-supx .cg-btn{
  min-height:40px; font-size:12px !important;
}
body.ca-app-sup9 .filter-bar, body.ca-app-supx .filter-bar,
body.ca-app-sup9 .cg-filter-surface, body.ca-app-supx .cg-filter-surface{
  padding:8px !important; border-radius:9px !important;
}
body.ca-app-sup9 .ca-build-badge, body.ca-app-supx .ca-build-badge{ opacity:.6; }

/* ---------------------------------------------------------------------------
   16. RESPONSIVE
   --------------------------------------------------------------------------- */
@media (max-width:800px){
  body.ca-enterprise .filter-bar,
  body.ca-enterprise .main-filter-bar,
  body.ca-enterprise .master-filters{ padding:8px !important; }
  body.ca-enterprise table thead th{ font-size:9.5px !important; }
}

/* ---------------------------------------------------------------------------
   17. PRINT
   --------------------------------------------------------------------------- */
@media print{
  body.ca-enterprise{ background:#fff !important; }
  body.ca-enterprise .filter-bar,
  body.ca-enterprise .cg-filter-surface,
  body.ca-enterprise .kpi-card,
  body.ca-enterprise .chart-card{ box-shadow:none !important; }
}

/* ---------------------------------------------------------------------------
   18. ACCESSIBILITY — reduced motion
   --------------------------------------------------------------------------- */
@media (prefers-reduced-motion:reduce){
  body.ca-enterprise *, body.ca-enterprise *:before, body.ca-enterprise *:after{
    animation-duration:.001ms !important; animation-iteration-count:1 !important;
    scroll-behavior:auto !important; transition-duration:.001ms !important;
  }
}
