/* ═══════════════════════════════════════════════════
   DRMSA · Clean Analytics Dashboard
   Font: Inter · Light default · Flat colours · No neon
   ═══════════════════════════════════════════════════ */

:root,
[data-theme="light"] {
  --bg:        #eceef3;
  --bg2:       #f4f6f9;
  --bg3:       #eaecf2;
  --bg4:       #dde0ea;
  --bg5:       #cdd2df;
  --border:    #dfe3ed;
  --border2:   #c8ceda;
  --text:      #2c3444;
  --text2:     #47526a;
  --text3:     #6b7280;
  --text4:     #9ca3af;

  /* Flat muted accents — no neon */
  --red:       #d63f3f;
  --red-dim:   #fdf1f1;
  --amber:     #c27c1a;
  --amber-dim: #fef6e8;
  --green:     #1a9044;
  --green-dim: #edf7f1;
  --blue:      #2057b8;
  --blue-dim:  #edf1fb;

  /* KPI card backgrounds — flat tinted fills */
  --kpi-red-bg:   #fdf1f1;
  --kpi-amber-bg: #fef6e8;
  --kpi-green-bg: #edf7f1;
  --kpi-blue-bg:  #edf1fb;

  --sidebar-w:     220px;
  --sidebar-w-col: 54px;
  --topbar-h:      52px;

  --r-sm:  5px;
  --r-md:  8px;
  --r-lg:  12px;
  --r-xl:  14px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.05);
  --shadow-md: 0 3px 10px rgba(0,0,0,.07);
  --transition: .14s ease;

  --font-display: 'Inter', system-ui, sans-serif;
  --font-body:    'Inter', system-ui, sans-serif;
  --font-mono:    'Inter', system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg:        #111318;
  --bg2:       #1a1d24;
  --bg3:       #21252d;
  --bg4:       #2a2f3a;
  --bg5:       #343b49;
  --border:    #2a2f3a;
  --border2:   #363d4d;
  --text:      #e8ecf4;
  --text2:     #adb5c7;
  --text3:     #6b7696;
  --text4:     #454e65;
  --red:       #cc4e4e;
  --red-dim:   rgba(204,78,78,.13);
  --amber:     #bd8228;
  --amber-dim: rgba(189,130,40,.13);
  --green:     #2a9e58;
  --green-dim: rgba(42,158,88,.13);
  --blue:      #3e6fcc;
  --blue-dim:  rgba(62,111,204,.13);
  --kpi-red-bg:   rgba(204,78,78,.13);
  --kpi-amber-bg: rgba(189,130,40,.13);
  --kpi-green-bg: rgba(42,158,88,.13);
  --kpi-blue-bg:  rgba(62,111,204,.13);
}

/* ── BASE ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; font-family: inherit; }
select { font-family: inherit; }

/* ═══ SHELL ═══ */
.shell { display: flex; height: 100vh; width: 100vw; overflow: hidden; }

/* ═══ SIDEBAR ═══ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width .22s cubic-bezier(.4,0,.2,1);
  overflow: hidden;          /* always hidden — tooltip rendered via JS portal */
  z-index: 60;
}
.sidebar.collapsed { width: var(--sidebar-w-col); }

.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 13px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}
.sb-logo { width: 24px; height: 24px; flex-shrink: 0; }
.sb-brand-text { overflow: hidden; white-space: nowrap; flex: 1; min-width: 0; }
.sb-brand-name { font-size: 14px; font-weight: 800; color: var(--text); letter-spacing: -.02em; line-height: 1; }
.sb-brand-sub  { font-size: 9px; color: var(--text3); letter-spacing: .06em; text-transform: uppercase; margin-top: 3px; }

.sb-toggle {
  width: 24px; height: 24px; border: none;
  border-radius: var(--r-sm);
  background: var(--bg3); color: var(--text3);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all var(--transition);
}
.sb-toggle:hover { background: var(--bg4); color: var(--text); }
.sb-toggle svg { transition: transform .22s; }
.sidebar.collapsed .sb-toggle svg { transform: scaleX(-1); }

/* ── Nav scroll area ── */
.sb-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;   /* never show horizontal scroll */
  padding: 8px 7px 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--blue) transparent;
  min-height: 0;        /* allow flex child to shrink and scroll */
}
.sb-nav::-webkit-scrollbar { width: 3px; }
.sb-nav::-webkit-scrollbar-track { background: transparent; }
.sb-nav::-webkit-scrollbar-thumb { background: var(--blue); border-radius: 3px; }

/* Hide scrollbar in collapsed mode — rail too narrow */
.sidebar.collapsed .sb-nav {
  scrollbar-width: none;
  padding: 8px 0 14px;
}
.sidebar.collapsed .sb-nav::-webkit-scrollbar { display: none; }

/* ── Section labels ── */
.sb-label {
  font-size: 9px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text4); padding: 10px 7px 4px;
  white-space: nowrap; overflow: hidden;
  transition: opacity .18s, max-height .22s, padding .22s;
  max-height: 30px;
}
.sidebar.collapsed .sb-label { opacity: 0; max-height: 0; padding: 0; pointer-events: none; }

/* ── Nav item ── */
.sni {
  position: relative;
  display: flex; align-items: center; gap: 9px;
  padding: 4px 6px;
  border-radius: var(--r-md);
  cursor: pointer; color: var(--text3);
  white-space: nowrap;
  margin-bottom: 1px;
  transition: background var(--transition), color var(--transition);
}
.sni:hover { background: var(--bg3); color: var(--text2); }
.sni.on    { background: var(--blue-dim); color: var(--blue); }

/* ── Icon box ── */
.sni-icon {
  width: 30px; height: 30px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sni.on .sni-icon { background: var(--blue); }
.sni.on .sni-icon svg { stroke: #fff !important; }

/* ── Label ── */
.sni-label {
  font-size: 12.5px; font-weight: 500; line-height: 1;
  overflow: hidden;
  transition: opacity .15s, max-width .22s;
  max-width: 160px;
}

/* ── Collapsed nav item — icon perfectly centred ── */
.sidebar.collapsed .sni {
  /* Make item span full rail width, centre icon */
  width: calc(var(--sidebar-w-col) - 2px); /* minus border */
  justify-content: center;
  padding: 7px 0;
  margin-bottom: 2px;
  border-radius: var(--r-md);
}
.sidebar.collapsed .sni-label { opacity: 0; max-width: 0; pointer-events: none; }

/* ── JS-portal tooltip (appended to body) ── */
.sb-tip {
  position: fixed;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  padding: 5px 11px;
  font-size: 12px; font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  z-index: 9999;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transition: opacity .1s;
}
.sb-tip.visible { opacity: 1; }
.sb-tip::before {
  content: '';
  position: absolute;
  right: 100%; top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-right-color: var(--border2);
}
.sb-tip::after {
  content: '';
  position: absolute;
  right: calc(100% - 1px); top: 50%;
  transform: translateY(-50%);
  border: 4px solid transparent;
  border-right-color: var(--bg2);
}

/* ── Footer ── */
.sb-foot { border-top: 1px solid var(--border); padding: 8px 7px; flex-shrink: 0; }
.sidebar.collapsed .sb-foot { padding: 8px 0; }
.sidebar.collapsed .sb-foot .sni {
  width: calc(var(--sidebar-w-col) - 2px);
  justify-content: center;
  padding: 7px 0;
}
.sidebar.collapsed .sb-foot-text { opacity: 0; max-width: 0; overflow: hidden; pointer-events: none; }

/* ── Expand button ── */
.sb-expand-btn {
  display: none;
  width: 100%; height: var(--topbar-h);
  align-items: center; justify-content: center;
  border: none; background: none;
  border-bottom: 1px solid var(--border);
  color: var(--text3); cursor: pointer; flex-shrink: 0;
  transition: color var(--transition), background var(--transition);
}
.sb-expand-btn:hover { background: var(--bg3); color: var(--text); }
.sidebar.collapsed .sb-brand      { display: none; }
.sidebar.collapsed .sb-expand-btn { display: flex; }

/* ═══ MAIN AREA ═══ */
.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* TOPBAR */
.topbar {
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  padding: 0 18px; flex-shrink: 0; z-index: 50;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-page-title { font-size: 14px; font-weight: 700; color: var(--text); letter-spacing: -.01em; line-height: 1; }
.topbar-crumb { font-size: 10px; color: var(--text3); margin-top: 3px; display: flex; align-items: center; gap: 4px; }

.tb-chip {
  display: flex; align-items: center; gap: 5px;
  background: var(--bg3); border-radius: 20px; padding: 5px 11px;
  font-size: 11px; font-weight: 500; color: var(--text2);
}
.tb-sel {
  font-size: 11px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 5px 9px; color: var(--text); outline: none;
  font-weight: 500; max-width: 148px; cursor: pointer;
}
.tb-btn-primary {
  display: flex; align-items: center; gap: 4px;
  background: var(--blue); border: none; border-radius: var(--r-md);
  padding: 7px 13px; color: #fff;
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background var(--transition); white-space: nowrap;
}
.tb-btn-primary:hover { background: #1845a0; }
.tb-btn-ghost {
  display: flex; align-items: center; gap: 4px;
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 6px 10px;
  color: var(--text3); font-size: 11px; font-weight: 500; cursor: pointer;
  transition: all var(--transition);
}
.tb-btn-ghost:hover { background: var(--bg3); color: var(--text); }
.user-av-btn {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--blue); display: flex; align-items: center;
  justify-content: center; font-size: 11px; font-weight: 700;
  color: #fff; cursor: pointer; flex-shrink: 0; border: none;
  transition: opacity var(--transition);
}
.user-av-btn:hover { opacity: .82; }

.theme-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 9px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: transparent;
  color: var(--text3); font-size: 11px; cursor: pointer; font-family: inherit;
  font-weight: 500; transition: all var(--transition);
}
.theme-btn:hover { background: var(--bg3); color: var(--text); }

/* ═══ PAGES ═══ */
.content-area { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.pages-wrap   { flex: 1; overflow-y: auto; overflow-x: hidden; }
.pages-wrap::-webkit-scrollbar { width: 4px; }
.pages-wrap::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

.page { display: none; flex: 1; flex-direction: column; min-height: 0; }
.page.visible { display: flex; }
#app-screen.visible { display: flex !important; }

/* ═══ DASHBOARD ═══ */
.dash-layout {
  padding: 16px 20px 24px;
  display: flex; flex-direction: column; gap: 14px;
}

/* KPI CARDS — no border, no neon, flat tinted bg */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 12px;
}
.kpi-card {
  border-radius: var(--r-xl);
  padding: 18px 20px;
  border: 1px solid var(--border2);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.kpi-card.red   { background: var(--kpi-red-bg); }
.kpi-card.amber { background: var(--kpi-amber-bg); }
.kpi-card.green { background: var(--kpi-green-bg); }
.kpi-card.blue  { background: var(--kpi-blue-bg); }

.kpi-icon {
  width: 30px; height: 30px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center; margin-bottom: 11px;
}
.kpi-card.red   .kpi-icon { background: rgba(214,63,63,.14); }
.kpi-card.amber .kpi-icon { background: rgba(194,124,26,.14); }
.kpi-card.green .kpi-icon { background: rgba(26,144,68,.14); }
.kpi-card.blue  .kpi-icon { background: rgba(32,87,184,.14); }

.kpi-label {
  font-size: 9.5px; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 5px;
}
.kpi-value {
  font-size: 30px; font-weight: 800;
  letter-spacing: -.03em; line-height: 1;
}
.kpi-card.red   .kpi-value { color: var(--red); }
.kpi-card.amber .kpi-value { color: var(--amber); }
.kpi-card.green .kpi-value { color: var(--green); }
.kpi-card.blue  .kpi-value { color: var(--blue); }

.kpi-foot { font-size: 11px; color: var(--text3); margin-top: 5px; display: flex; align-items: center; gap: 5px; }
.kpi-delta { font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 4px; }
.kpi-delta.up  { background: rgba(214,63,63,.1);  color: var(--red); }
.kpi-delta.dn  { background: rgba(26,144,68,.1);  color: var(--green); }
.kpi-delta.neu { background: var(--bg4); color: var(--text3); }

/* Charts row */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Panel */
.ds-panel {
  background: var(--bg2);
  border-radius: var(--r-xl);
  border: 1px solid var(--border2);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.ds-ph {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.ds-ph-title { font-size: 12.5px; font-weight: 700; color: var(--text); }
.ds-ph-sub   { font-size: 10px; color: var(--text3); margin-top: 2px; }
.ds-pb { padding: 13px 15px; }

.ds-sel {
  font-size: 11px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 4px 8px; color: var(--text); outline: none; cursor: pointer; font-weight: 500;
}

/* Hazard table */
.hz-table { width: 100%; border-collapse: collapse; }
.hz-table tr { border-bottom: 1px solid var(--border); }
.hz-table tr:last-child { border-bottom: none; }
.hz-table tr:hover td { background: var(--bg3); }
.hz-table td { padding: 7px 0; vertical-align: middle; }
.hz-rank  { width: 22px; font-size: 10px; font-weight: 600; color: var(--text4); padding-right: 6px; text-align: center; }
.hz-name  { font-size: 12px; font-weight: 500; color: var(--text); min-width: 80px; padding-right: 10px; }
.hz-score { font-size: 12px; font-weight: 700; color: var(--text2); width: 32px; text-align: right; padding-right: 8px; }
.hz-bar-w { width: 70px; padding-right: 10px; }
.hz-bar-bg { height: 3px; background: var(--bg4); border-radius: 2px; overflow: hidden; }
.hz-bar-fg { height: 3px; border-radius: 2px; }

/* Chips */
.chip { display: inline-flex; align-items: center; font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 4px; letter-spacing: .02em; white-space: nowrap; }
.chip-red   { background: rgba(214,63,63,.1);  color: var(--red);   }
.chip-amber { background: rgba(194,124,26,.1); color: var(--amber); }
.chip-green { background: rgba(26,144,68,.1);  color: var(--green); }
.chip-blue  { background: rgba(32,87,184,.1);  color: var(--blue);  }
.chip-muted { background: var(--bg3); color: var(--text3); }

/* IDP rows */
.idp-row { display: flex; align-items: center; gap: 10px; padding: 8px 15px; border-bottom: 1px solid var(--border); }
.idp-row:last-of-type { border-bottom: none; }
.idp-dot  { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.idp-name { font-size: 12px; color: var(--text2); flex: 1; }
.idp-bar-bg { width: 70px; height: 3px; background: var(--bg4); border-radius: 2px; }
.idp-bar-fg { height: 3px; border-radius: 2px; }
.idp-count  { font-size: 12px; font-weight: 700; color: var(--text); width: 18px; text-align: right; }

/* ══ MAP CARD — full width, centred ══
   #map-canvas-wrap and #maplibre-map are UNTOUCHED.
   Only the outer card styling changed.          */
.map-card {
  background: var(--bg2);
  border-radius: var(--r-xl);
  border: 1px solid var(--border2);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.map-card-head {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.map-card-title { font-size: 12.5px; font-weight: 700; color: var(--text); }
.map-card-sub   { font-size: 10px; color: var(--text3); margin-top: 2px; }
.map-controls   { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }

/* — map canvas heights — do NOT touch init code — */
#map-canvas-wrap,
#maplibre-map {
  height: 440px !important;
  min-height: 440px !important;
  width: 100% !important;
  display: block !important;
}

.map-legend-strip {
  padding: 9px 15px;
  border-top: 1px solid var(--border);
  background: var(--bg3);
  display: flex; align-items: center;
  justify-content: space-between; flex-wrap: wrap; gap: 8px;
}
.leg-items { display: flex; gap: 12px; flex-wrap: wrap; }
.leg-item  { display: flex; align-items: center; gap: 4px; font-size: 10px; color: var(--text3); }
.leg-dot   { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

.lyr {
  font-size: 10px; font-weight: 600; letter-spacing: .02em;
  padding: 4px 9px; border-radius: 4px; border: 1px solid var(--border);
  background: var(--bg3); color: var(--text3); cursor: pointer;
  text-transform: uppercase; transition: all var(--transition);
}
.lyr.on { background: var(--blue-dim); color: var(--blue); border-color: transparent; }

.map-search-input {
  font-size: 11px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 5px 9px; color: var(--text); outline: none;
  width: 108px; font-family: inherit;
  transition: border-color var(--transition);
}
.map-search-input:focus { border-color: var(--blue); }

/* SAWS alert */
.saws-bar {
  display: flex; align-items: center; gap: 12px;
  background: var(--amber-dim);
  border: 1px solid rgba(194,124,26,.22);
  border-radius: var(--r-lg); padding: 9px 14px; flex-shrink: 0;
}
.saws-bar-title { font-size: 12px; font-weight: 700; color: var(--amber); }
.saws-bar-desc  { font-size: 11px; color: var(--text2); }
.saws-dismiss   { font-size: 11px; color: var(--text3); cursor: pointer; margin-left: auto; }
.saws-dismiss:hover { color: var(--text); }

/* Generic btn */
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 10px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--bg2);
  color: var(--text2); font-size: 11px; font-weight: 500;
  cursor: pointer; transition: all var(--transition); font-family: inherit;
}
.btn:hover   { background: var(--bg3); border-color: var(--border2); color: var(--text); }
.btn-sm      { padding: 4px 8px; font-size: 10px; }
.btn-red     { background: var(--red);  border-color: var(--red);  color: #fff; }
.btn-red:hover  { background: #b83434; }
.btn-blue    { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-blue:hover { background: #1845a0; }

/* no-muni banner */
#no-muni-banner {
  background: var(--amber-dim); border-bottom: 1px solid rgba(194,124,26,.28);
  padding: 8px 18px; font-size: 12px; color: var(--amber);
  display: flex; align-items: center; gap: 12px; flex-shrink: 0; font-weight: 600;
}

/* Legacy compat */
.tni {
  display: flex; align-items: center; gap: 6px; padding: 0 10px;
  height: 52px; font-size: 12px; font-weight: 600; color: var(--text3);
  cursor: pointer; border-bottom: 2px solid transparent;
  white-space: nowrap; transition: all .14s; flex-shrink: 0;
}
.tni:hover { color: var(--text); background: var(--bg3); }
.tni.on    { color: var(--text); border-bottom-color: var(--blue); }
.tni svg   { width: 14px; height: 14px; flex-shrink: 0; opacity: .7; }
.tni.on svg { opacity: 1; }
.ni { display: none; }
.hidden { display: none !important; }

/* Trend rows */
.trend-row { display: grid; grid-template-columns: 52px 1fr 68px; align-items: center; gap: 8px; margin-bottom: 7px; }
.trend-lbl { font-size: 10px; font-weight: 600; color: var(--text3); text-align: right; }
.trend-bar-bg { height: 16px; background: var(--bg3); border-radius: 4px; position: relative; overflow: hidden; }
.trend-bar-fill { height: 100%; border-radius: 4px; transition: width .4s cubic-bezier(.4,0,.2,1); }
.trend-score { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font-size: 10px; font-weight: 700; }

/* Responsive */
@media (max-width: 900px) { .charts-row { grid-template-columns: 1fr; } }
@media (max-width: 768px) {
  .sidebar { display: none; }
  .kpi-row { grid-template-columns: repeat(2,1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .dash-layout { padding: 12px; gap: 12px; }
}
@media (max-width: 480px) {
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 24px; }
}
