/* =========================================================================
   CommandX · Dashboard components (analysis screens)
   Blocks: cx-accent-*, cx-page-header, cx-icon-badge, cx-tag, cx-kpi,
           cx-delta, cx-feature, cx-section, cx-filter-bar, cx-select,
           cx-segmented, cx-donut, cx-legend, cx-key, cx-table-wrap,
           cx-matrix, cx-growth, cx-heatmap, cx-scale, cx-toggle,
           cx-progress, cx-fuel-badge, cx-search
   Spacing is rem (root 14px); fonts/icons are px via the type scale.
   ========================================================================= */

/* ---------- Accent palette ----------------------------------------------
   Set on a component (or any ancestor). Components read --cx-accent and
   --cx-accent-soft, so one class recolours bars, icons, tags and borders.
   ------------------------------------------------------------------------ */
.cx-accent-navy { --cx-accent: #1f2a7a; --cx-accent-soft: #eef2ff; --cx-accent-border: #e0e7ff; }
.cx-accent-sky { --cx-accent: #0284c7; --cx-accent-soft: #f0f9ff; --cx-accent-border: #bae6fd; }
.cx-accent-emerald { --cx-accent: #059669; --cx-accent-soft: #ecfdf5; --cx-accent-border: #a7f3d0; }
.cx-accent-slate-blue { --cx-accent: #4d57a8; --cx-accent-soft: #eef2ff; --cx-accent-border: #e0e7ff; }
.cx-accent-crimson { --cx-accent: #e32119; --cx-accent-soft: #fef2f2; --cx-accent-border: #fecaca; }
.cx-accent-violet { --cx-accent: #7c3aed; --cx-accent-soft: #faf5ff; --cx-accent-border: #e9d5ff; }
.cx-accent-amber { --cx-accent: #f59e0b; --cx-accent-soft: #fffbeb; --cx-accent-border: #fde68a; }
.cx-accent-indigo { --cx-accent: #6366f1; --cx-accent-soft: #eef2ff; --cx-accent-border: #c7d2fe; }
.cx-accent-rose { --cx-accent: #f43f5e; --cx-accent-soft: #fff1f2; --cx-accent-border: #fecdd3; }
.cx-accent-blue { --cx-accent: #2563eb; --cx-accent-soft: #eff6ff; --cx-accent-border: #bfdbfe; }
.cx-accent-cyan { --cx-accent: #0891b2; --cx-accent-soft: #ecfeff; --cx-accent-border: #a5f3fc; }
.cx-accent-teal { --cx-accent: #0d9488; --cx-accent-soft: #f0fdfa; --cx-accent-border: #99f6e4; }
.cx-accent-pink { --cx-accent: #db2777; --cx-accent-soft: #fdf2f8; --cx-accent-border: #fbcfe8; }
.cx-accent-orange { --cx-accent: #d97706; --cx-accent-soft: #fffbeb; --cx-accent-border: #fde68a; }
.cx-accent-slate { --cx-accent: #475569; --cx-accent-soft: #f8fafc; --cx-accent-border: #cbd5e1; }

/* ---------- Icon badge (solid accent tile with white icon) ---------- */
.cx-icon-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--cx-radius-lg);
  background-color: var(--cx-accent, var(--cx-navy));
  color: #ffffff;
  box-shadow: var(--cx-shadow-xs);
}

.cx-icon-badge .material-symbols-outlined {
  font-size: 22px;
}

.cx-icon-badge--sm {
  width: 2rem;
  height: 2rem;
  border-radius: var(--cx-radius);
}

.cx-icon-badge--sm .material-symbols-outlined {
  font-size: 18px;
}

/* ---------- Tag (small inline label) ---------- */
.cx-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.125rem 0.5rem;
  border: 1px solid var(--cx-slate-200);
  border-radius: var(--cx-radius-pill);
  background-color: var(--cx-slate-100);
  color: var(--cx-slate-600);
  font-size: var(--cx-fs-2xs);
  font-weight: 700;
  white-space: nowrap;
}

.cx-tag--success {
  border-color: #a7f3d0;
  background-color: #ecfdf5;
  color: #047857;
}

.cx-tag--accent {
  border-color: var(--cx-accent-border, #e0e7ff);
  background-color: var(--cx-accent-soft, #eef2ff);
  color: var(--cx-accent, var(--cx-navy));
}

.cx-tag--warning {
  border-color: rgba(253, 230, 138, 0.7);
  background-color: #fffbeb;
  color: var(--cx-amber-dark);
}

/* Larger, square-cornered variant for header actions */
.cx-tag--lg {
  padding: 0.25rem 0.625rem;
  border-radius: var(--cx-radius-lg);
  font-size: var(--cx-fs-xs);
  font-weight: 600;
}

.cx-tag__icon {
  font-size: 15px;
}

/* ---------- Page header card ---------- */
.cx-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--cx-space-3);
  padding: 0.875rem;
}

.cx-page-header__main {
  display: flex;
  align-items: center;
  gap: var(--cx-space-3);
  min-width: 0;
}

.cx-page-header__title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--cx-space-2);
}

.cx-page-header__title {
  font-size: var(--cx-fs-lg);
  font-weight: 700;
  line-height: 1.25;
  color: var(--cx-text-strong);
}

.cx-page-header__subtitle {
  margin-top: 0.125rem;
  font-size: var(--cx-fs-sm);
  line-height: 1.25;
  color: var(--cx-text-subtle);
}

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

/* ---------- KPI card ---------- */
.cx-kpi {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  padding: 0.875rem;
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s var(--cx-ease);
}

.cx-kpi::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 0.25rem;
  background-color: var(--cx-accent, var(--cx-navy));
}

.cx-kpi__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--cx-space-2);
  margin-bottom: var(--cx-space-2);
}

.cx-kpi__label {
  font-size: var(--cx-fs-xs);
  font-weight: 700;
  letter-spacing: var(--cx-tracking-wide);
  text-transform: uppercase;
  color: var(--cx-text-muted);
  transition: color 0.2s ease;
}

.cx-kpi__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem;
  border-radius: var(--cx-radius);
  background-color: var(--cx-accent-soft, #eef2ff);
  color: var(--cx-accent, var(--cx-navy));
  transition: transform 0.2s ease;
}

.cx-kpi__icon .material-symbols-outlined {
  font-size: 18px;
}

.cx-kpi__value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.025em;
  color: var(--cx-text-strong);
  font-variant-numeric: tabular-nums;
}

@media (min-width: 768px) {
  .cx-kpi__value {
    font-size: var(--cx-fs-3xl);
  }
}

.cx-kpi__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--cx-space-2);
  margin-top: var(--cx-space-2);
}

.cx-kpi__footer--divided {
  padding-top: var(--cx-space-2);
  border-top: 1px solid var(--cx-slate-100);
}

.cx-kpi__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
}

.cx-kpi__note {
  font-size: var(--cx-fs-sm);
  font-weight: 500;
  color: var(--cx-text-subtle);
}

.cx-kpi__cta {
  font-size: var(--cx-fs-xs);
  font-weight: 600;
  color: var(--cx-accent, var(--cx-navy));
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* Clickable card */
.cx-kpi--interactive {
  cursor: pointer;
  user-select: none;
}

.cx-kpi--interactive:hover {
  border-color: color-mix(in srgb, var(--cx-accent, var(--cx-navy)) 50%, transparent);
  box-shadow: var(--cx-shadow-md);
}

.cx-kpi--interactive:hover .cx-kpi__label {
  color: var(--cx-accent, var(--cx-navy));
}

.cx-kpi--interactive:hover .cx-kpi__icon {
  transform: scale(1.1);
}

.cx-kpi--interactive:hover .cx-kpi__cta {
  opacity: 1;
}

/* Selected (filter cards) */
.cx-kpi--selected,
.cx-kpi--selected:hover {
  border-color: var(--cx-accent, var(--cx-navy));
  box-shadow: 0 0 0 1.5px var(--cx-accent, var(--cx-navy)), var(--cx-shadow-md);
}

/* ---------- Delta / trend chip ---------- */
.cx-delta {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  padding: 0.125rem 0.375rem;
  border-radius: var(--cx-radius-sm);
  background-color: var(--cx-slate-100);
  color: var(--cx-slate-600);
  font-size: var(--cx-fs-xs);
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.cx-delta .material-symbols-outlined {
  font-size: 13px;
}

.cx-delta--pill {
  padding: 0.125rem 0.5rem;
  border-radius: var(--cx-radius-pill);
}

.cx-delta--up { background-color: #ecfdf5; color: #047857; }
.cx-delta--down { background-color: #fef2f2; color: var(--cx-crimson); }
.cx-delta--warning { background-color: #fffbeb; color: #b45309; }
.cx-delta--accent { background-color: var(--cx-accent-soft, #eef2ff); color: var(--cx-accent, var(--cx-navy)); }

/* ---------- Feature (drill-down) card ---------- */
.cx-feature {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--cx-space-4);
  height: 100%;
  padding: var(--cx-space-5);
}

.cx-feature__body {
  display: flex;
  flex-direction: column;
  gap: var(--cx-space-2);
}

.cx-feature__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--cx-radius);
  background-color: var(--cx-accent-soft, #eef2ff);
  color: var(--cx-accent, var(--cx-navy));
}

.cx-feature__title {
  font-size: var(--cx-fs-lg);
  font-weight: 700;
  color: var(--cx-text-strong);
}

.cx-feature__text {
  font-size: var(--cx-fs-base);
  line-height: 1.625;
  color: var(--cx-text-muted);
}

.cx-feature__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--cx-space-2);
  border-top: 1px solid var(--cx-slate-100);
}

.cx-feature__meta {
  font-size: var(--cx-fs-xs);
  font-weight: 500;
  color: var(--cx-text-subtle);
}

.cx-feature__link {
  font-size: var(--cx-fs-sm);
  font-weight: 600;
  color: var(--cx-navy);
  text-decoration: none;
}

.cx-feature__link:hover {
  text-decoration: underline;
}

/* ---------- Section card (titled dashboard panel) ---------- */
.cx-section {
  display: flex;
  flex-direction: column;
  gap: var(--cx-space-3);
  height: 100%;
  padding: 0.875rem;
}

.cx-section__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--cx-space-3);
}

.cx-section__header--divided {
  padding-bottom: var(--cx-space-3);
  border-bottom: 1px solid var(--cx-slate-100);
}

.cx-section__heading {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}

.cx-section__title {
  font-size: var(--cx-fs-lg);
  font-weight: 700;
  line-height: 1.25;
  color: var(--cx-text-strong);
}

.cx-section__subtitle {
  margin-top: 0.125rem;
  font-size: var(--cx-fs-sm);
  line-height: 1.3;
  color: var(--cx-text-subtle);
}

.cx-section__trailing-icon {
  font-size: 20px;
  color: var(--cx-text-subtle);
}

.cx-section__empty {
  padding: 1.5rem 0;
  text-align: center;
  font-size: var(--cx-fs-sm);
  color: var(--cx-text-subtle);
}

/* ---------- Filter bar ---------- */
.cx-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--cx-space-3);
  padding: 0.875rem;
}

.cx-filter-bar__title {
  display: flex;
  align-items: center;
  gap: var(--cx-space-2);
  font-size: var(--cx-fs-base);
  font-weight: 700;
  color: var(--cx-slate-800);
}

.cx-filter-bar__title .material-symbols-outlined {
  font-size: 18px;
  color: var(--cx-navy);
}

.cx-filter-bar__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.625rem;
}

.cx-filter-label {
  display: flex;
  align-items: center;
  gap: 0.3125rem;
  margin-bottom: 0.3125rem;
  font-size: var(--cx-fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--cx-slate-600);
}

.cx-filter-label i {
  color: var(--cx-navy);
}

/* Compact select used in filter bars */
select.form-select.cx-select {
  width: auto;
  min-height: 0;
  padding: 0.375rem 2rem 0.375rem 0.75rem;
  border-color: var(--cx-slate-200);
  border-radius: var(--cx-radius);
  font-size: var(--cx-fs-base);
  font-weight: 500;
  color: var(--cx-slate-800);
  box-shadow: var(--cx-shadow-xs);
  cursor: pointer;
}

select.form-select.cx-select:hover {
  border-color: var(--cx-slate-300);
}

/* ---------- Segmented control (period picker) ---------- */
.cx-segmented {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 2.7rem;
  padding: 3px;
  border-radius: var(--cx-radius-lg);
  background-color: #eef2f6;
}

.cx-segmented__item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 0 0.875rem;
  border: 0;
  border-radius: var(--cx-radius);
  background: transparent;
  color: var(--cx-slate-600);
  font-size: var(--cx-fs-sm);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.cx-segmented__item:hover {
  background-color: rgba(255, 255, 255, 0.6);
  color: var(--cx-text-strong);
}

.cx-segmented__item--active,
.cx-segmented__item--active:hover {
  background-color: var(--cx-navy);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(31, 42, 122, 0.3);
}

/* ---------- Search input (table headers) ---------- */
.cx-search {
  width: 15.75rem;
  max-width: 100%;
}

/* ---------- Donut chart ---------- */
.cx-donut {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 11rem;
  margin: var(--cx-space-4) 0;
}

.cx-donut__svg {
  width: 10rem;
  height: 10rem;
  transform: rotate(-90deg);
  transform-origin: center center;
  animation: cx-donut-entry 0.85s var(--cx-ease) forwards;
}

.cx-donut__track {
  stroke: var(--cx-slate-100);
}

.cx-donut__center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  animation: cx-donut-center 0.7s var(--cx-ease) 0.15s both;
}

.cx-donut__value {
  font-size: var(--cx-fs-lg);
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--cx-text-strong);
  font-variant-numeric: tabular-nums;
}

.cx-donut__unit {
  font-size: var(--cx-fs-2xs);
  font-weight: 700;
  letter-spacing: var(--cx-tracking-wide);
  text-transform: uppercase;
  color: var(--cx-text-subtle);
}

@keyframes cx-donut-entry {
  0% { transform: rotate(-135deg) scale(0.92); opacity: 0.25; }
  100% { transform: rotate(-90deg) scale(1); opacity: 1; }
}

@keyframes cx-donut-center {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes cx-legend-in {
  0% { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ---------- Chart legend ---------- */
.cx-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--cx-space-2) var(--cx-space-4);
  padding-top: var(--cx-space-2);
  border-top: 1px solid var(--cx-slate-50);
  font-size: var(--cx-fs-sm);
  color: var(--cx-slate-600);
  animation: cx-legend-in 0.6s var(--cx-ease) 0.25s both;
}

.cx-legend--grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--cx-space-2) var(--cx-space-3);
}

.cx-legend--spread {
  justify-content: space-around;
}

.cx-legend--center {
  justify-content: center;
}

.cx-legend__item {
  display: flex;
  align-items: center;
  gap: var(--cx-space-2);
  min-width: 0;
}

/* Swatch colour comes from the data: style="--cx-swatch: #hex" */
.cx-legend__swatch {
  flex-shrink: 0;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  background-color: var(--cx-swatch, var(--cx-slate-400));
}

.cx-legend__text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cx-legend__value {
  font-weight: 700;
  color: var(--cx-slate-800);
}

/* ---------- Table key (header legend for PY / CY columns) ---------- */
.cx-key {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--cx-space-3);
  font-size: var(--cx-fs-xs);
  font-weight: 500;
  color: var(--cx-text-muted);
}

.cx-key__item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.cx-key__swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: var(--cx-radius-sm);
}

.cx-key__swatch--py {
  border: 1px solid #bfdbfe;
  background-color: #dce9ff;
}

.cx-key__swatch--cy {
  border: 1px solid var(--cx-slate-300);
  background-color: #ffffff;
}

/* ---------- Table wrapper ---------- */
.cx-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--cx-slate-200);
  border-radius: var(--cx-radius-lg);
  box-shadow: var(--cx-shadow-xs);
}

.cx-table-wrap--scroll {
  max-height: 27rem;
  overflow-y: auto;
}

/* ---------- Matrix table (quarterly / overall performance) ---------- */
.cx-matrix {
  width: 100%;
  border-collapse: collapse;
  background-color: #ffffff;
  font-size: var(--cx-fs-xs);
  text-align: left;
}

@media (min-width: 576px) {
  .cx-matrix {
    font-size: var(--cx-fs-sm);
  }
}

.cx-matrix th,
.cx-matrix td {
  padding: 0.375rem 0.625rem;
  border-right: 1px solid var(--cx-slate-100);
  white-space: nowrap;
}

.cx-matrix thead th {
  border-right-color: var(--cx-slate-200);
  border-bottom: 1px solid var(--cx-slate-200);
  background-color: var(--cx-slate-50);
  color: var(--cx-slate-600);
  font-size: var(--cx-fs-2xs);
  font-weight: 700;
  text-align: right;
}

.cx-matrix tbody tr {
  border-top: 1px solid var(--cx-slate-100);
  transition: background-color 0.15s ease;
}

.cx-matrix tbody tr:hover {
  background-color: rgba(248, 250, 252, 0.8);
}

/* Header rows */
.cx-matrix .cx-matrix__group {
  padding: 0.5rem 0.75rem;
  background-color: var(--cx-slate-100);
  color: var(--cx-slate-800);
  font-size: var(--cx-fs-xs);
  font-weight: 800;
  letter-spacing: var(--cx-tracking-wide);
  text-align: center;
  text-transform: uppercase;
}

.cx-matrix .cx-matrix__group--total {
  background-color: #eef2ff;
  color: var(--cx-navy);
  font-weight: 900;
}

.cx-matrix .cx-matrix__label-head {
  min-width: 10.75rem;
  text-align: left;
}

/* Column roles */
.cx-matrix .cx-matrix__num {
  min-width: 4.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cx-matrix .cx-matrix__center {
  text-align: center;
}

.cx-matrix .cx-matrix__py { background-color: #f8fbff; color: var(--cx-slate-700); }
.cx-matrix thead .cx-matrix__py { background-color: #eef4ff; color: var(--cx-navy); }
.cx-matrix .cx-matrix__cy { font-weight: 600; color: var(--cx-text-strong); }
.cx-matrix thead .cx-matrix__cy { background-color: #ffffff; color: var(--cx-slate-800); }
.cx-matrix .cx-matrix__qtr { background-color: rgba(248, 250, 252, 0.5); color: var(--cx-slate-800); font-weight: 700; text-align: center; }

.cx-matrix .cx-matrix__total-py { background-color: #f0f5ff; color: var(--cx-navy); font-weight: 700; }
.cx-matrix thead .cx-matrix__total-py { background-color: #e0ebff; }
.cx-matrix .cx-matrix__total-cy { background-color: rgba(238, 242, 255, 0.5); color: var(--cx-text-strong); font-weight: 700; }
.cx-matrix thead .cx-matrix__total-cy { color: var(--cx-navy); }
.cx-matrix .cx-matrix__total-growth { background-color: rgba(238, 242, 255, 0.6); font-weight: 700; }
.cx-matrix thead .cx-matrix__total-growth { background-color: #e0e7ff; color: var(--cx-navy); font-weight: 800; }

/* Separators between column groups */
.cx-matrix .cx-matrix__sep { border-right: 2px solid var(--cx-slate-300); }

/* Sticky first column */
.cx-matrix .cx-matrix__sticky {
  position: sticky;
  left: 0;
  z-index: 10;
  background-color: #ffffff;
  border-right-color: var(--cx-slate-200);
  box-shadow: 1px 0 0 0 var(--cx-slate-200);
  color: var(--cx-slate-800);
  font-weight: 700;
  text-align: left;
}

.cx-matrix thead .cx-matrix__sticky {
  z-index: 20;
  background-color: var(--cx-slate-100);
}

/* Zone banner row */
.cx-matrix .cx-matrix__zone td {
  padding: 0.25rem 0.75rem;
  border-top: 1px solid #fcd34d;
  border-bottom: 1px solid #fcd34d;
  background-color: #fef08a;
  color: var(--cx-text-strong);
  font-size: var(--cx-fs-xs);
  font-weight: 900;
  letter-spacing: var(--cx-tracking-wide);
  text-transform: uppercase;
}

/* Totals row */
.cx-matrix .cx-matrix__totals td,
.cx-matrix tfoot td {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  border-top: 2px solid var(--cx-slate-400);
  border-right-color: var(--cx-slate-300);
  background-color: var(--cx-slate-100);
  color: var(--cx-text-strong);
  font-weight: 800;
}

.cx-matrix tfoot .cx-matrix__sticky,
.cx-matrix .cx-matrix__totals .cx-matrix__qtr {
  background-color: var(--cx-slate-200);
  letter-spacing: var(--cx-tracking-wide);
  text-transform: uppercase;
}

.cx-matrix tfoot .cx-matrix__py,
.cx-matrix .cx-matrix__totals .cx-matrix__py { background-color: #e2ecff; color: var(--cx-navy); }
.cx-matrix tfoot .cx-matrix__total-py,
.cx-matrix .cx-matrix__totals .cx-matrix__total-py { background-color: #d4e4ff; }
.cx-matrix tfoot .cx-matrix__total-cy,
.cx-matrix .cx-matrix__totals .cx-matrix__total-cy { background-color: #e0e7ff; color: var(--cx-navy); }
.cx-matrix tfoot .cx-matrix__total-growth,
.cx-matrix .cx-matrix__totals .cx-matrix__total-growth { background-color: #e0e7ff; color: var(--cx-navy); font-weight: 900; }

/* ---------- Growth value colouring ---------- */
.cx-growth--positive { color: var(--cx-text-strong); font-weight: 600; }
.cx-growth--zero { color: var(--cx-text-subtle); }
.cx-growth--negative { color: var(--cx-crimson) !important; font-weight: 700; }

/* ---------- Billing heatmap ---------- */
.cx-heatmap {
  overflow-x: auto;
  padding-bottom: var(--cx-space-1);
}

.cx-heatmap__grid {
  display: flex;
  flex-direction: column;
  gap: var(--cx-space-1);
  min-width: 82rem;
}

.cx-heatmap__row {
  display: flex;
  align-items: center;
  padding: 0.125rem var(--cx-space-1);
  border-radius: var(--cx-radius-sm);
  transition: background-color 0.15s ease;
}

.cx-heatmap__row:hover {
  background-color: rgba(248, 250, 252, 0.8);
}

.cx-heatmap__row--axis:hover {
  background-color: transparent;
}

.cx-heatmap__label {
  flex-shrink: 0;
  width: 6rem;
  padding-right: var(--cx-space-3);
  text-align: right;
  font-size: var(--cx-fs-sm);
  font-weight: 700;
  color: var(--cx-slate-700);
  white-space: nowrap;
  user-select: none;
}

.cx-heatmap__axis-title {
  font-size: var(--cx-fs-xs);
  letter-spacing: var(--cx-tracking-wide);
  text-transform: uppercase;
  color: var(--cx-text-subtle);
}

.cx-heatmap__days {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(31, minmax(28px, 1fr));
  gap: 3px;
}

.cx-heatmap__day {
  padding: 0.125rem 0;
  text-align: center;
  font-size: var(--cx-fs-2xs);
  font-weight: 700;
  color: var(--cx-text-subtle);
  user-select: none;
}

/* Cell colour comes from the data: style="--cx-cell-bg: #hex" */
.cx-heatmap__cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  background-color: var(--cx-cell-bg, #e5eeff);
  box-shadow: var(--cx-shadow-xs);
  font-size: var(--cx-fs-2xs);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease;
}

.cx-heatmap__cell:hover {
  position: relative;
  z-index: 20;
  transform: scale(1.2);
}

.cx-heatmap__cell--empty { border: 1px solid rgba(191, 219, 254, 0.5); color: var(--cx-text-muted); font-weight: 500; }
.cx-heatmap__cell--light { color: var(--cx-slate-800); }
.cx-heatmap__cell--medium { color: var(--cx-text-strong); }
.cx-heatmap__cell--dark { color: #ffffff; }

.cx-heatmap__cell--na {
  border: 1px dashed rgba(226, 232, 240, 0.6);
  background-color: rgba(248, 250, 252, 0.6);
  box-shadow: none;
  cursor: default;
}

.cx-heatmap__cell--na:hover {
  transform: none;
}

.cx-heatmap__total {
  flex-shrink: 0;
  width: 5rem;
  padding-left: var(--cx-space-2);
  text-align: right;
  font-size: var(--cx-fs-xs);
  font-weight: 700;
  color: var(--cx-slate-800);
  font-variant-numeric: tabular-nums;
}

/* ---------- Colour scale legend (Less → More) ---------- */
.cx-scale {
  display: flex;
  align-items: center;
  gap: var(--cx-space-2);
  font-size: var(--cx-fs-xs);
  font-weight: 500;
  color: var(--cx-text-muted);
}

.cx-scale__steps {
  display: flex;
  align-items: center;
  gap: var(--cx-space-1);
}

.cx-scale__step {
  width: 0.875rem;
  height: 0.875rem;
  border-radius: var(--cx-radius-sm);
}

.cx-scale__step--1 { border: 1px solid rgba(226, 232, 240, 0.5); background-color: #e5eeff; }
.cx-scale__step--2 { background-color: #cbdbf5; }
.cx-scale__step--3 { background-color: #8b95eb; }
.cx-scale__step--4 { background-color: #1f2a7a; }
.cx-scale__step--5 { background-color: #030f66; }

/* ---------- Toggle group (Top 10 / Gainers / Decliners) ---------- */
.cx-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--cx-space-1);
  padding: 0.125rem;
  border-radius: var(--cx-radius);
  background-color: var(--cx-slate-100);
}

.cx-toggle__item {
  padding: var(--cx-space-1) 0.625rem;
  border: 0;
  border-radius: var(--cx-radius-sm);
  background: transparent;
  color: var(--cx-slate-600);
  font-size: var(--cx-fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.cx-toggle__item:hover {
  color: var(--cx-text-strong);
}

.cx-toggle__item--active,
.cx-toggle__item--active:hover {
  background-color: var(--cx-accent, var(--cx-navy));
  color: #ffffff;
  font-weight: 700;
  box-shadow: var(--cx-shadow-xs);
}

/* ---------- Progress bar ---------- */
.cx-progress {
  width: 100%;
  height: 0.5rem;
  overflow: hidden;
  border-radius: var(--cx-radius-pill);
  background-color: var(--cx-slate-100);
}

.cx-progress--thin {
  height: 0.375rem;
}

/* Width comes from the data: style="width: 42%" */
.cx-progress__bar {
  height: 100%;
  border-radius: var(--cx-radius-pill);
  background-color: var(--cx-accent, var(--cx-navy));
}

/* ---------- Fuel badge ---------- */
.cx-fuel-badge {
  display: inline-block;
  white-space: nowrap;
  padding: 0.125rem 0.5rem;
  border-radius: var(--cx-radius-sm);
  background-color: var(--cx-slate-100);
  color: var(--cx-slate-700);
  font-size: var(--cx-fs-2xs);
  font-weight: 700;
}

.cx-fuel-badge--diesel { background-color: #eef2ff; color: var(--cx-navy); }
.cx-fuel-badge--ev { background-color: #ecfdf5; color: #047857; }
.cx-fuel-badge--gas { background-color: #faf5ff; color: #7e22ce; }

/* ---------- Data table extras (Bootstrap .table) ---------- */
.cx-data-table > thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.cx-data-table .cx-sort {
  display: inline-flex;
  align-items: center;
  gap: var(--cx-space-1);
  cursor: pointer;
  user-select: none;
}

.cx-data-table .cx-sort .material-symbols-outlined {
  font-size: 14px;
}

.cx-data-table__primary {
  font-weight: 700;
  color: var(--cx-text-strong);
}

.cx-data-table__secondary {
  font-size: var(--cx-fs-xs);
  color: var(--cx-text-subtle);
}

.cx-data-table__rank {
  width: 2rem;
  font-weight: 700;
  color: var(--cx-text-subtle);
}

/* ---------- KPI card: compact variant (operational telemetry grid) ---------- */
.cx-kpi--compact {
  padding: 0.75rem;
  background-color: rgba(248, 250, 252, 0.7);
}

.cx-kpi--compact:hover {
  background-color: #ffffff;
}

.cx-kpi--compact .cx-kpi__header {
  margin-bottom: 0.375rem;
}

.cx-kpi--compact .cx-kpi__label {
  letter-spacing: normal;
  text-transform: none;
  color: var(--cx-slate-700);
}

.cx-kpi__metric {
  font-size: var(--cx-fs-xs);
  font-weight: 500;
  color: var(--cx-text-subtle);
}

.cx-kpi__value--sm {
  margin: 0.125rem 0;
  font-size: var(--cx-fs-2xl) !important;
}

.cx-kpi__trend {
  display: flex;
  align-items: center;
  gap: var(--cx-space-1);
  margin-top: var(--cx-space-1);
  font-size: var(--cx-fs-xs);
  font-weight: 600;
}

.cx-kpi__trend-note {
  font-weight: 400;
  color: var(--cx-text-subtle);
}

/* Trend text tones */
.cx-trend--up { color: #047857; }
.cx-trend--down { color: #e11d48; }
.cx-trend--warning { color: #b45309; }
.cx-trend--neutral { color: var(--cx-slate-600); }

/* Status dot with halo */
.cx-dot--ring.cx-dot--success { box-shadow: 0 0 0 2px #d1fae5; }
.cx-dot--ring.cx-dot--warning { box-shadow: 0 0 0 2px #fef3c7; }
.cx-dot--ring.cx-dot--danger { box-shadow: 0 0 0 2px #ffe4e6; }

/* Telemetry panel header */
.cx-panel-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--cx-space-2);
}

.cx-panel-title .material-symbols-outlined {
  font-size: 20px;
  color: var(--cx-navy);
}

.cx-panel-title__text {
  font-size: var(--cx-fs-md);
  font-weight: 700;
  color: var(--cx-text-strong);
}

.cx-panel-title__meta {
  font-size: var(--cx-fs-sm);
  color: var(--cx-text-subtle);
}

/* =========================================================================
   MD Dashboard (Pages/Dashboard.razor, Components/Dashboard/MetricCard.razor)
   ========================================================================= */

/* ---------- Header row: title left, date + Sync right ---------- */
.cx-dashboard-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--cx-space-3);
}

.cx-dashboard-header__title {
  font-size: var(--cx-fs-2xl);
  font-weight: 700;
  letter-spacing: var(--cx-tracking-tight);
  color: var(--cx-text-strong);
}

.cx-dashboard-header__subtitle {
  margin-top: 0.125rem;
  font-size: var(--cx-fs-sm);
  color: var(--cx-text-muted);
}

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

.cx-dashboard-header__date {
  width: 11rem;
}

/* ---------- Metric card ---------- */
.cx-metric-card {
  height: 100%;
  margin-bottom: 0;
  border: 1px solid var(--cx-slate-200);
  border-top: 4px solid var(--cx-accent, var(--cx-navy));
  border-radius: var(--cx-radius-lg);
  box-shadow: var(--cx-shadow-sm);
}

.cx-metric-card > .card-body {
  display: flex;
  flex-direction: column;
  padding: var(--cx-space-4);
}

.cx-metric-card__title {
  margin-bottom: var(--cx-space-3);
  font-size: var(--cx-fs-lg);
  font-weight: 700;
  color: var(--cx-accent, var(--cx-navy));
}

.cx-metric-card__rows {
  margin: 0;
}

.cx-metric-card__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--cx-space-3);
  padding: 0.4375rem 0;
  border-bottom: 1px solid var(--cx-slate-100);
}

.cx-metric-card__label {
  margin: 0;
  font-size: var(--cx-fs-base);
  font-weight: 400;
  color: var(--cx-text-muted);
}

.cx-metric-card__value {
  margin: 0;
  font-size: var(--cx-fs-md);
  font-weight: 700;
  color: var(--cx-text-strong);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.cx-metric-card__value--warning {
  color: var(--cx-amber-dark);
}

.cx-metric-card__progress {
  height: 0.375rem;
  margin-top: var(--cx-space-3);
  background-color: var(--cx-slate-100);
}

.cx-metric-card__note {
  margin-top: var(--cx-space-3);
  font-size: var(--cx-fs-xs);
  color: var(--cx-text-muted);
}

/* Footer sits at the bottom so cards in a row line up */
/* Details link on the left, Export Excel (when shown) on the right. */
.cx-metric-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--cx-space-2);
  margin-top: auto;
  padding-top: var(--cx-space-3);
}

.cx-metric-card__link {
  font-size: var(--cx-fs-sm);
  font-weight: 500;
  color: var(--cx-accent, var(--cx-navy));
  text-decoration: none;
}

.cx-metric-card__link:hover {
  text-decoration: underline;
}

.cx-metric-card__link--disabled,
.cx-metric-card__link--disabled:hover {
  cursor: default;
  text-decoration: none;
}

/* ---------- Stacked bar chart (Components/Dashboard/StackedBarChart.razor) ----------
   Pure SVG; each bar segment / legend swatch carries a cx-accent-* class. */
.cx-bar-chart__svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.cx-bar-chart__grid {
  stroke: var(--cx-slate-200);
  stroke-width: 1;
}

.cx-bar-chart__axis-label {
  fill: var(--cx-text-muted);
  font-family: var(--cx-font-sans);
  font-size: 12px;
}

.cx-bar-chart__bar {
  fill: var(--cx-accent);
  transform-box: fill-box;
  transform-origin: bottom;
  animation: cx-bar-grow 0.6s var(--cx-ease) both;
}

.cx-bar-chart__bar:hover {
  opacity: 0.85;
}

@keyframes cx-bar-grow {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

.cx-bar-chart__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--cx-space-4);
  margin-top: var(--cx-space-2);
  font-size: var(--cx-fs-sm);
  color: var(--cx-text-muted);
}

.cx-bar-chart__legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.cx-bar-chart__swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: var(--cx-radius-sm);
  background-color: var(--cx-accent);
}

/* ---------- MD Dashboard: clickable cards + details popup ---------- */
.cx-metric-card--clickable {
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.cx-metric-card--clickable:hover,
.cx-metric-card--clickable:focus-visible {
  box-shadow: var(--cx-shadow-md);
  transform: translateY(-1px);
}

/* Card details popup: the table is the only scroll area. The modal body stops
   scrolling and the table shrinks to the height left under the chart, so the
   sticky total row is never clipped by a second (outer) scroll. */
.cx-dialog__body-scroll:has(> .cx-card-details) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cx-card-details {
  min-height: 0;
}

.cx-card-details > * {
  flex-shrink: 0;
}

.cx-card-details > .cx-card-details__table {
  flex-shrink: 1;
  min-height: 6rem;
  max-height: 18rem;
}

/* Table-only tab (no chart above): use the whole popup height. */
.cx-card-details > .cx-card-details__table--full {
  max-height: none;
}

/* Month-to-date total: same padding as the body cells, stays visible at the
   bottom while the rows scroll. */
.cx-card-details__total > tr > td {
  position: sticky;
  bottom: 0;
  padding: 0.6875rem 1rem;
  border-top: 2px solid var(--cx-slate-300);
  border-bottom: 0;
  background-color: var(--cx-surface-muted);
  color: var(--cx-text-strong);
  font-weight: 700;
}
