/* ── Box-sizing Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

/* ── App Shell ────────────────────────────────────────────────────────────── */
#app-shell {
  display: flex;
  min-height: 70vh;
  background: var(--color-bg-page);
  font-family: 'DM Sans', sans-serif;
  color: var(--color-text-primary);
  min-width: 1080px;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-bg-sidebar);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.2s;
}
.sidebar-eyebrow {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-sidebar-text);
  padding: 0 1.25rem 0.6rem;
  opacity: 0.7;
  overflow: hidden;
  transition: opacity 0.2s, height 0.2s;
}
/* Admin section is pinned to the very bottom of the sidebar. The sidebar is a
   full-height flex column, so margin-top:auto absorbs the free space above. */
.sidebar-admin {
  margin-top: auto;
  padding-top: 0.75rem;
}
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  color: var(--color-sidebar-text);
  font-size: 0.85rem;
  font-weight: 500;
  border-left: 4px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  text-decoration: none;
  overflow: hidden;
  cursor: pointer;
}
.sidebar-nav-item:hover {
  background: rgba(255,255,255,0.07);
  color: #fff;
  text-decoration: none;
}
.sidebar-nav-item.active {
  color: var(--color-sidebar-active);
  border-left-color: var(--color-primary-light);
  background: rgba(26,140,255,0.12);
  font-weight: 600;
}
.sidebar-sub-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 1.25rem 0.4rem 2.75rem;
  color: var(--color-sidebar-text);
  font-size: 0.78rem;
  border-left: 4px solid transparent;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}
.sidebar-sub-item:hover {
  background: rgba(255,255,255,0.05);
  color: #fff;
  text-decoration: none;
}
.sidebar-sub-item.active {
  color: #fff;
  border-left-color: var(--color-primary-light);
}
.sidebar-section-label {
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-sidebar-text);
  padding: 0.75rem 1.25rem 0.25rem;
  opacity: 0.55;
}
.nav-icon { font-size: 1rem; flex-shrink: 0; width: 1.2rem; text-align: center; }
.nav-label { white-space: nowrap; }

/* Collapsed sidebar at <=1280px */
@media (max-width: 1280px) {
  :root { --sidebar-width: 60px; }
  .sidebar-eyebrow { opacity: 0; padding: 0; height: 0; overflow: hidden; }
  .sidebar-nav-item { justify-content: center; padding: 0.75rem; position: relative; }
  .sidebar-nav-item .nav-label { display: none; }
  .sidebar-sub-item { display: none; }
  .sidebar-section-label { display: none; }
  /* Tooltip on hover for collapsed icon-only sidebar */
  .sidebar-nav-item[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--color-bg-sidebar);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 500;
    padding: 0.35rem 0.65rem;
    border-radius: 5px;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
  }
}

/* ── Main Content ─────────────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  padding: 1.5rem 1.75rem 2.5rem;
  overflow-x: hidden;
  min-width: 0;
}

/* ── Dashboard Header Row ─────────────────────────────────────────────────── */
.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.dash-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: 0.02em;
}
.dash-title span {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  display: block;
  margin-bottom: 0.15rem;
}
.period-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--color-text-secondary);
}
.period-control label { font-weight: 500; }
.period-control select,
#period-select,
#inv-period-select {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  background: var(--color-bg-card);
  color: var(--color-text-primary);
  cursor: pointer;
  outline: none;
}
.period-control select:focus,
#period-select:focus,
#inv-period-select:focus { border-color: var(--color-primary); }

/* ── KPI Tiles ────────────────────────────────────────────────────────────── */
.kpi-row,
.kpi-tile-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 16px;
  width: 100%;
  margin-bottom: 20px;
  box-sizing: border-box;
}
.kpi-tile {
  flex: 1 1 0;
  min-width: 140px;
  background: var(--color-bg-card);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  box-shadow: 0 2px 8px var(--color-shadow);
  border-top: 3px solid var(--color-primary);
  box-sizing: border-box;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.kpi-tile.green-top { border-top-color: var(--color-accent-green); }
.kpi-tile.red-top   { border-top-color: var(--color-accent-red);   }
.kpi-tile.amber-top { border-top-color: var(--color-accent-amber); }
.kpi-tile.teal-top  { border-top-color: var(--color-accent-teal);  }
.kpi-tile.blue-top  { border-top-color: var(--color-primary);      }
.kpi-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-secondary);
  margin-bottom: 0.15rem;
}
.kpi-value {
  font-family: 'DM Mono', monospace;
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--color-text-primary);
  line-height: 1.2;
}
.kpi-value.loading { color: var(--color-border); }
.kpi-trend { font-size: 0.7rem; margin-top: 0.15rem; color: var(--color-text-secondary); }
/* Mini gauge container inside KPI tiles */
.kpi-tile [id^="gauge-kpi-"] {
  height: 64px;
  width: 100px;
  margin: 0.15rem auto 0;
}
.kpi-trend.up   { color: var(--color-accent-green); }
.kpi-trend.down { color: var(--color-accent-red);   }
.kpi-trend.warn { color: var(--color-accent-amber); }

/* ── KPI Gauge Containers ───────────────────────────────────────────────── */
.kpi-gauge-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
}

/* ── Secondary KPI Row ────────────────────────────────────────────────────── */
.kpi-row-secondary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.9rem;
  margin-top: 1.25rem;
  margin-bottom: 1.25rem;
}

/* ── Sub-Dashboard KPI Row ────────────────────────────────────────────────── */
.sub-kpi-row {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
}

/* ── Dashboard Grid Container ─────────────────────────────────────────────── */
.dashboard-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 20px;
}

/* ── Column Width Utility Classes ─────────────────────────────────────────── */
.col-1 {
  flex: 0 0 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.col-2 {
  flex: 0 0 calc(50% - 10px);
  max-width: calc(50% - 10px);
  box-sizing: border-box;
}
.col-3 {
  flex: 0 0 calc(33.333% - 14px);
  max-width: calc(33.333% - 14px);
  box-sizing: border-box;
}
.col-4 {
  flex: 0 0 calc(25% - 15px);
  max-width: calc(25% - 15px);
  box-sizing: border-box;
}
.col-5 {
  flex: 0 0 calc(20% - 16px);
  max-width: calc(20% - 16px);
  box-sizing: border-box;
}

/* ── Chart Card ───────────────────────────────────────────────────────────── */
.chart-card {
  background: var(--color-bg-card);
  border-radius: 8px;
  box-shadow: 0 2px 8px var(--color-shadow);
  padding: 1.1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  margin-bottom: 1rem;
}
.chart-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}
.chart-card-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1.3;
}
.chart-badge {
  font-size: 0.6rem;
  font-weight: 600;
  background: rgba(255, 122, 0, 0.10);
  color: var(--color-primary);
  padding: 0.15rem 0.45rem;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.chart-badge-alltime {
  font-size: 0.6rem;
  font-weight: 600;
  background: rgba(255, 122, 0, 0.10);
  color: var(--color-primary);
  padding: 0.15rem 0.45rem;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.chart-body {
  flex: 1;
  position: relative;
  min-height: 240px;
}
.chart-body canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }

/* ── Returns & Pricing Card Layout ───────────────────────────────────────── */
.db-pane-inner {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}
.db-card {
  background: var(--color-bg-card);
  border-radius: 8px;
  box-shadow: 0 2px 8px var(--color-shadow);
  padding: 1.1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  min-height: 280px;
}
.db-card-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1.3;
  margin-bottom: 0.75rem;
}

/* ── Generic Card ─────────────────────────────────────────────────────────── */
.card {
  background: var(--color-bg-card, #ffffff);
  border-radius: 8px;
  box-shadow: 0 2px 8px var(--color-shadow, rgba(0,0,0,0.08));
  padding: 1.1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
}

/* Override legacy bottom-margin when chart-card is a grid child */
.dashboard-grid > .chart-card {
  margin-bottom: 0;
}

/* ── Chart Container Height ─────────────────────────────────────────────────
   Chart containers inside panel cards must have an explicit height
   so Chart.js can render properly.
   ─────────────────────────────────────────────────────────────────────────── */
.chart-container {
  position: relative;
  width: 100%;
  height: 320px;
}
.chart-container.chart-tall   { height: 420px; }
.chart-container.chart-short  { height: 220px; }
.chart-container.chart-square { height: 360px; width: 360px; margin: 0 auto; }

/* ── Chart Body Height Utilities ──────────────────────────────────────────── */
.chart-body-h240 { min-height: 240px; }
.chart-body-h260 { min-height: 260px; }
.chart-body-h280 { min-height: 280px; }
.chart-body-h300 { min-height: 300px; }
.chart-body-h320 { min-height: 320px; }
.chart-body-h340 { min-height: 340px; }
.chart-body-h360 { min-height: 360px; }
.chart-body-h380 { min-height: 380px; }
.chart-body-h420 { min-height: 420px; }

/* ── Panel States ─────────────────────────────────────────────────────────── */
.loading-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.9);
  z-index: 5;
  border-radius: 4px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-state {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: rgba(255,255,255,0.95);
  z-index: 5;
  border-radius: 4px;
}
.error-state p {
  font-size: 0.8rem;
  color: var(--color-accent-red);
  text-align: center;
  max-width: 200px;
}
.retry-btn {
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 0.35rem 0.85rem;
  border-radius: 5px;
  cursor: pointer;
}
.retry-btn:hover { background: var(--color-primary-dark); }

.empty-state {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  font-style: italic;
}

/* ── Snapshot Badge (replaces period selector for static dashboards) ────── */
.snapshot-badge {
  display: inline-block;
  background: rgba(255, 122, 0, 0.10);
  color: var(--color-primary);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.35rem 0.9rem;
  border-radius: 20px;
}

/* ── Reference Line Label ─────────────────────────────────────────────────── */
.ref-line-label {
  font-size: 0.65rem;
  color: var(--color-text-secondary);
  text-align: right;
  margin-top: 0.2rem;
}

/* ── UI Controls ──────────────────────────────────────────────────────────── */
.chart-toggle-btn {
  font-size: 0.7rem;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  background: rgba(255, 122, 0, 0.10);
  color: var(--color-primary);
  border: 1px solid rgba(255, 122, 0, 0.45);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  white-space: nowrap;
}
.chart-toggle-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.inner-tab-nav {
  display: flex;
  gap: 0.25rem;
  margin: 1rem 0 0.75rem;
  border-bottom: 2px solid var(--color-border);
  flex-wrap: wrap;
}
.inner-tab-btn {
  padding: 0.5rem 1rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.inner-tab-btn:hover { color: var(--color-primary); }
.inner-tab-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}
.inner-tab-pane { display: none; }
.inner-tab-pane.active { display: block; }

/* ── Chart Grid Layouts ───────────────────────────────────────────────────── */
.chart-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}
.chart-grid-3 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}
.chart-grid-3 > .chart-card:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}
.chart-grid-split {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
/* Grid items default to min-width:auto, letting wide intrinsic content (e.g.
   the CRO at-risk TABLE) steal width from the 2fr map column. Force the fr
   ratio to win; inner tables scroll within their own wrappers instead. */
.chart-grid-split > .chart-card { min-width: 0; }
.chart-grid-split-rev {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

/* ── Drill-down Modal (class-based canonical system) ─────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.45);
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-dialog {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  width: min(90vw, 900px);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e0e0e0;
}
.modal-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--primaforja-slate, #5A6A7A);
}
.modal-close {
  border: none;
  background: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: #888;
  padding: 0 0.25rem;
  line-height: 1;
}
.modal-close:hover { color: #333; }
.modal-body {
  max-height: 60vh;
  overflow-y: auto;
  padding: 1rem 1.25rem;
}
.modal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.modal-table th {
  background: #f5f7f9;
  text-align: left;
  padding: 0.5rem 0.6rem;
  font-weight: 600;
  color: var(--primaforja-slate, #5A6A7A);
  border-bottom: 2px solid #e0e0e0;
  white-space: nowrap;
}
.modal-table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid #f0f0f0;
  color: #333;
}
.modal-table tr:hover td { background: #f9fafb; }

/* ── DC Filter Dropdown ───────────────────────────────────────────────────── */
.dc-filter-dropdown { position: relative; flex-shrink: 0; }
.dc-filter-btn {
  background: #f5f8fa;
  border: 1px solid #d0dae2;
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 0.72rem;
  font-family: 'DM Sans', sans-serif;
  color: var(--color-text-primary);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.dc-filter-btn:hover { background: #e4ecf2; border-color: #8aa3b1; }
.dc-filter-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid #d0dae2;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
  min-width: 210px;
  max-height: 260px;
  overflow-y: auto;
  z-index: 300;
  padding: 5px 0;
}
.dc-filter-menu.open { display: block; }
.dc-filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--color-text-primary);
  user-select: none;
}
.dc-filter-item:hover { background: #f0f5f9; }
.dc-filter-item input[type="checkbox"],
.dc-filter-item input[type="radio"] { cursor: pointer; accent-color: var(--color-primary); }
.dc-filter-divider { border: none; border-top: 1px solid #e5eaee; margin: 4px 0; }

/* ── Placeholder Pages ────────────────────────────────────────────────────── */
.placeholder-page {
  text-align: center;
  padding: 4rem 2rem;
  max-width: 520px;
  margin: 0 auto;
}
.placeholder-icon { font-size: 3rem; margin-bottom: 1rem; }
.placeholder-page h2 { font-size: 1.4rem; font-weight: 700; margin-bottom: 0.75rem; }
.placeholder-page p { color: var(--color-text-secondary); font-size: 0.88rem; margin-bottom: 0.75rem; }
.placeholder-page ul { list-style: none; text-align: left; margin: 0 auto 1rem; display: inline-block; }
.placeholder-page ul li { font-size: 0.85rem; padding: 0.25rem 0; }
.placeholder-page ul li::before { content: '\2192  '; color: var(--color-primary); }
.coming-soon-label {
  display: inline-block;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.35rem 0.9rem;
  border-radius: 20px;
}

/* ── Skeleton Loader ──────────────────────────────────────────────────────── */
.chart-skeleton {
  width: 100%;
  height: 100%;
  min-height: 200px;
  background: linear-gradient(90deg,
    var(--color-bg-page) 25%,
    var(--color-border) 50%,
    var(--color-bg-page) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s infinite;
  border-radius: 4px;
}

@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Chart Empty State ────────────────────────────────────────────────────── */
.chart-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  gap: 8px;
  color: var(--color-text-secondary);
}
.chart-empty-icon { font-size: 2rem; }
.chart-empty-message { font-size: 0.875rem; }

/* ── Responsive Overrides ─────────────────────────────────────────────────── */
/* Tablet: 768-1199px -- force 1 column for all panels */
@media (max-width: 1199px) {
  .col-2, .col-3, .col-4, .col-5 {
    flex: 0 0 100%;
    max-width: 100%;
  }
  .kpi-row,
  .kpi-tile-row {
    flex-wrap: wrap;
  }
  .kpi-tile {
    flex: 0 0 calc(50% - 8px);
  }
}

/* Mobile: < 768px -- single column everything */
@media (max-width: 600px) {
  .col-1, .col-2, .col-3, .col-4, .col-5 {
    flex: 0 0 100%;
    max-width: 100%;
  }
  .kpi-tile {
    flex: 0 0 100%;
  }
  .chart-container {
    height: 260px;
  }
}

/* ── Legacy Aliases (backwards compatibility) ─────────────────────────────── */
.loading-shimmer {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px; min-height: 120px; width: 100%;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.panel-error-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; min-height: 120px;
  color: #B71C1C; font-size: 14px; gap: 10px;
}
.btn-retry {
  padding: 4px 14px; border: 1px solid #B71C1C;
  background: white; color: #B71C1C; border-radius: 4px;
  cursor: pointer; font-size: 13px;
}
.empty-icon { font-size: 28px; }

/* ── Executive Dashboard Overrides ────────────────────────────────────────── */

/* US Map */
#us-map-svg path {
  stroke: #fff;
  stroke-width: 0.5;
  cursor: pointer;
  transition: opacity 0.15s;
}
#us-map-svg path:hover { opacity: 0.75; }
#map-tooltip {
  position: fixed;
  background: rgba(10,37,64,0.92);
  color: #fff;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.75rem;
  line-height: 1.5;
  pointer-events: none;
  z-index: 9999;
  display: none;
}

/* Map Card Layout */
.map-card-inner {
  display: flex;
  flex: 1;
  gap: 0.75rem;
  min-height: 480px;
  overflow: hidden;
}
.map-svg-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
}
.map-region-col {
  width: 180px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--color-border);
  padding-left: 0.75rem;
  overflow: hidden;
}
.map-region-col-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-secondary);
  padding: 0.3rem 0 0.5rem;
  flex-shrink: 0;
}

/* Region Summary Pills */
#region-summary,
.region-summary {
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
  flex: 1;
  padding: 2px 0;
}
.region-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg-page);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.74rem;
  color: var(--color-text-primary);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.region-pill:hover { background: var(--color-bg-hover, #e4ecf2); border-color: var(--color-primary); }
.region-pill.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
/* Dark mode: primary is amber — white text washes out on it; use coal ink. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .region-pill.active { color: #0B1220; }
}
:root[data-theme="dark"] .region-pill.active { color: #0B1220; }
.region-pill-rev { font-weight: 600; font-size: 0.7rem; opacity: 0.85; }

/* ── Hamburger Toggle (hidden above 768px) ───────────────────────────────── */
.sidebar-hamburger-toggle {
  display: none;
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 1100;
  background: var(--color-bg-sidebar, #0B1220);
  color: #fff;
  border: none;
  border-radius: 6px;
  width: 38px;
  height: 38px;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

/* ── 1024px Breakpoint: secondary KPI 2-per-row, chart grids single col ── */
@media (max-width: 1024px) {
  .kpi-row-secondary {
    grid-template-columns: repeat(2, 1fr);
  }
  .chart-grid-2,
  .chart-grid-split,
  .chart-grid-split-rev {
    grid-template-columns: 1fr;
  }
}

/* ── 768px Breakpoint: hide sidebar, show hamburger, single-column KPI ─── */
@media (max-width: 949px) {
  #app-shell {
    min-width: 0;
  }
  #sidebar {
    display: none;
  }
  body.sidebar-open #sidebar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1050;
    width: 240px;
    height: 100vh;
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
  }
  body.sidebar-open .sidebar-eyebrow { opacity: 0.7; padding: 0 1.25rem 0.6rem; height: auto; }
  body.sidebar-open .sidebar-nav-item { justify-content: flex-start; padding: 0.6rem 1.25rem; }
  body.sidebar-open .sidebar-nav-item .nav-label { display: inline; }
  body.sidebar-open .sidebar-sub-item { display: flex; }
  body.sidebar-open .sidebar-section-label { display: block; }
  .sidebar-hamburger-toggle {
    display: flex;
  }
  #main-content {
    padding: 1rem;
  }
  .kpi-row,
  .kpi-tile-row {
    flex-wrap: wrap;
  }
  .kpi-tile {
    flex: 0 0 100%;
  }
  .kpi-row-secondary {
    grid-template-columns: 1fr;
  }
  .chart-grid-2,
  .chart-grid-3,
  .chart-grid-split,
  .chart-grid-split-rev {
    grid-template-columns: 1fr;
  }
}

/* ── KPI Sparklines ──────────────────────────────────────────────────────── */
.kpi-sparkline-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}
.kpi-sparkline {
  display: block;
  overflow: visible;
}
.kpi-anomaly-badge {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--color-accent-amber);
  background: rgba(255,193,7,0.12);
  border-radius: 3px;
  padding: 1px 4px;
  line-height: 1.4;
  white-space: nowrap;
}

/* ── Dark Mode Toggle Button ─────────────────────────────────────────────── */
.dark-mode-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--color-text-secondary);
  font-size: 1.1rem;
  line-height: 1;
}
.dark-mode-toggle:hover {
  background: rgba(0,0,0,0.06);
}
.dark-mode-toggle .icon-sun  { display: none; }
.dark-mode-toggle .icon-moon { display: inline; }
[data-theme="dark"] .dark-mode-toggle .icon-moon { display: none; }
[data-theme="dark"] .dark-mode-toggle .icon-sun  { display: inline; }

/* ---------------------------------------------------------------------------
   Formula tooltips (core/formula-tooltips.js + core/formulas.js)
   An ⓘ affordance next to KPI labels / chart titles that reveals the metric's
   formula and data source on hover / focus / tap.
   --------------------------------------------------------------------------- */
.formula-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05em;
  height: 1.05em;
  margin-left: 0.35em;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 0.9em;
  line-height: 1;
  cursor: help;
  vertical-align: baseline;
  opacity: 0.55;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.formula-info:hover,
.formula-info:focus-visible {
  opacity: 1;
  color: var(--color-primary);
  outline: none;
}
.formula-info:focus-visible {
  box-shadow: 0 0 0 2px var(--color-primary);
}

.formula-tip {
  position: fixed;
  z-index: 9999;
  max-width: 340px;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg-card);
  color: var(--color-text-primary);
  box-shadow: 0 6px 24px var(--color-shadow, rgba(0, 0, 0, 0.18));
  font-size: 0.72rem;
  line-height: 1.4;
  pointer-events: none;
}
.formula-tip[hidden] { display: none; }
.formula-tip-f {
  font-weight: 600;
  font-family: 'DM Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
}
.formula-tip-src {
  margin-top: 0.35rem;
  color: var(--color-text-secondary);
  font-size: 0.68rem;
}
.formula-tip-note {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px dashed var(--color-border);
  color: var(--color-text-secondary);
  font-size: 0.68rem;
}

/* ---------------------------------------------------------------------------
   Chart accessibility — "view as table" toggle + data table (core/chart-a11y.js)
   --------------------------------------------------------------------------- */
.chart-tools {
  flex-shrink: 0;
  display: inline-flex;
  gap: 0.3rem;
  margin-left: 0.4rem;
}
.chart-tool-btn {
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.chart-tool-btn:hover,
.chart-table-toggle[aria-pressed="true"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.chart-tool-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-primary);
}

.chart-table-wrap {
  position: absolute;
  inset: 0;
  overflow: auto;
  background: var(--color-bg-card);
  border-radius: 6px;
  z-index: 3;
}
.chart-table-wrap[hidden] { display: none; }

.chart-data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
}
.chart-data-table caption {
  text-align: left;
  font-weight: 700;
  color: var(--color-text-secondary);
  padding: 0.25rem 0.1rem 0.5rem;
}
.chart-data-table th,
.chart-data-table td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
  text-align: right;
  white-space: nowrap;
}
.chart-data-table thead th {
  position: sticky;
  top: 0;
  background: var(--color-bg-card);
  color: var(--color-text-primary);
  border-bottom: 2px solid var(--color-border);
}
.chart-data-table th[scope="row"],
.chart-data-table thead th:first-child {
  text-align: left;
  color: var(--color-text-primary);
  font-weight: 600;
}
.chart-data-table tbody tr:hover td,
.chart-data-table tbody tr:hover th { background: rgba(0, 102, 204, 0.06); }
.chart-table-empty {
  padding: 1rem;
  color: var(--color-text-secondary);
  font-size: 0.78rem;
  font-style: italic;
}

/* ---------------------------------------------------------------------------
   Print / Save-as-PDF button + print stylesheet
   --------------------------------------------------------------------------- */
.print-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--color-text-secondary);
  font-size: 1.15rem;
  line-height: 1;
}
.print-btn:hover { background: rgba(0, 0, 0, 0.06); }

@media print {
  /* Hide chrome: navigation, filters, interactive affordances. */
  #sidebar,
  .clevel-filter-bar,
  .period-control,
  .dark-mode-toggle,
  .print-btn,
  .chart-tools,
  .clevel-toggle-group,
  .inner-tab-btn,
  .kpi-deeplink,
  .retry-btn,
  .loading-state,
  .error-state,
  .demo-watermark,
  .contact-fab,
  .modal-overlay {
    display: none !important;
  }
  #main-content { margin: 0 !important; padding: 0.4rem !important; width: 100% !important; }
  html, body, #app-shell, #main-content { background: #fff !important; }
  /* Keep each KPI tile / chart card intact across page breaks. */
  .kpi-tile, .chart-card {
    break-inside: avoid;
    page-break-inside: avoid;
    box-shadow: none !important;
    border: 1px solid #d0d7e2 !important;
  }
  .dashboard-grid { gap: 10px !important; }
  .dash-title, .chart-card-title, .kpi-value, .kpi-label { color: #000 !important; }
  /* Don't expand link URLs after anchors when printing. */
  a[href]::after { content: "" !important; }
  @page { margin: 12mm; }
}


/* ── Phone landscape / small tablets: three-across compact KPI tiles ────── */
@media (min-width: 601px) and (max-width: 949px) {
  .kpi-tile { flex: 0 0 calc(33.333% - 11px); }
}
/* Float the dashboard-menu button clear of the site header on small screens */
@media (max-width: 949px) {
  .sidebar-hamburger-toggle {
    top: auto;
    bottom: 1rem;
    left: 1rem;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  }
}

/* 1024px-wide tablets (iPad Mini landscape, 13" iPad Pro portrait): the
   1080px app-shell floor forces a shrink-to-fit; the flex layout handles
   these widths fine, so drop the floor below 1080. */
@media (max-width: 1079px) {
  #app-shell { min-width: 0; }
}
