/* DealerMap Admin Console — desk-density chrome on the shared tokens
   Design law: docs/extracted-design-tokens.md · docs/extracted-interaction-patterns.md */

/* [hidden] must always win, even over class display rules */
[hidden] { display: none !important; }

/* ============================================================
   THEME — light / dark / system. Dark is the base (styles.css :root).
   These overrides live in console.css so ONLY the console themes;
   the marketing landing page (styles.css alone) stays dark.
   The six status colors + accent are locked — identical in both themes.
   ============================================================ */
:root[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f0f0f3;
  --surface-3: #e4e4ea;
  --separator: rgba(0, 0, 0, 0.13);
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #a1a1a6;
  --accent: #007aff;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface-2: #f0f0f3;
    --surface-3: #e4e4ea;
    --separator: rgba(0, 0, 0, 0.13);
    --text: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-tertiary: #a1a1a6;
    --accent: #007aff;
  }
}

/* Theme toggle (sidebar footer) */
.theme-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  margin-bottom: 10px;
}
.theme-toggle button {
  all: unset;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1;
  color: var(--text-secondary);
  padding: 5px 9px;
  border-radius: 999px;
  display: grid;
  place-items: center;
}
.theme-toggle button:hover { color: var(--text); }
.theme-toggle button.active { background: var(--surface-3); color: var(--text); }

/* ---------- Accounts ▸ Map (Leaflet) ---------- */
.cmap {
  height: min(640px, calc(100vh - 230px));
  min-height: 420px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--separator);
  overflow: hidden;
  background: var(--surface);
}
.map-loading {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
  padding: 24px;
}
.map-legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 12px;
}
.legend-chip {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: 999px;
  padding: 5px 12px;
}
.legend-chip:hover { background: var(--surface-2); color: var(--text); }
.legend-chip b { color: var(--text); font-variant-numeric: tabular-nums; }
.legend-chip.off { opacity: 0.4; text-decoration: line-through; }
.legend-chip .dot { width: 10px; height: 10px; border-radius: 50%; }

/* Leaflet chrome tuned to the console's surfaces (theme-aware) */
.leaflet-container { background: var(--surface-2); font-family: var(--font); }
.leaflet-bar a, .leaflet-control-zoom a {
  background: var(--surface-2); color: var(--text); border-color: var(--separator);
}
.leaflet-bar a:hover { background: var(--surface-3); }
.leaflet-control-attribution {
  background: rgba(0,0,0,0.6) !important; color: var(--text-tertiary) !important;
}
.leaflet-control-attribution a { color: var(--text-secondary) !important; }
.leaflet-tooltip {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--separator); border-radius: 8px;
  font-size: 12.5px; font-weight: 600; box-shadow: 0 6px 18px rgba(0,0,0,0.5);
}
.leaflet-tooltip-top::before { border-top-color: var(--surface-2); }
.map-basemap-note {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 500; background: rgba(0,0,0,0.7); color: var(--text-secondary);
  border: 1px solid var(--separator); border-radius: 999px;
  padding: 6px 14px; font-size: 12.5px; pointer-events: none;
}

/* ---------- Sign-in ---------- */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  padding: 36px 32px;
  text-align: center;
}

.auth-sub {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 26px;
}

.auth-card form { text-align: left; display: grid; gap: 8px; }
.auth-card label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.auth-card input {
  background: var(--surface-2);
  border: 1px solid var(--separator);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  padding: 11px 14px;
  margin-bottom: 8px;
  outline: none;
}
.auth-card input:focus { border-color: var(--accent); }
.auth-card .btn { width: 100%; margin-top: 8px; padding: 12px; font-size: 16px; }

.auth-error {
  color: var(--status-dead);
  font-size: 14px;
  margin-top: 12px;
  text-align: center;
}

.sample-link {
  all: unset;
  cursor: pointer;
  display: block;
  margin: 20px auto 0;
  color: var(--accent);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
}
.sample-link:hover { opacity: 0.85; }

.auth-foot {
  color: var(--text-tertiary);
  font-size: 12.5px;
  margin-top: 24px;
  line-height: 1.5;
}

/* ---------- Console shell ---------- */
.console {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--separator);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.side-nav { display: grid; gap: 2px; }
.side-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 9px 12px;
  border-radius: 9px;
}
.side-nav a svg {
  width: 17px; height: 17px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.side-nav a:hover { background: var(--surface); color: var(--text); opacity: 1; }
.side-nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.side-foot { margin-top: auto; padding: 12px 8px 4px; border-top: 1px solid var(--separator); }
.app-version { font-size: 11px; color: var(--text-tertiary); margin-top: 10px; }
.user-email { font-size: 12.5px; color: var(--text-tertiary); word-break: break-all; margin-bottom: 8px; }
.signout {
  all: unset;
  cursor: pointer;
  font-family: var(--font);
  color: var(--status-dead);
  font-size: 14px;
  font-weight: 600;
}

.main { padding: 26px 40px 60px; max-width: 1280px; }
#view-title-row { margin: 8px 0 22px; display: flex; align-items: center; gap: 14px; }
#view-title { font-size: 32px; font-weight: 800; letter-spacing: -0.015em; }

.sample-banner {
  background: rgba(255, 149, 0, 0.12);           /* Follow-up orange — attention, not error */
  border: 1px solid rgba(255, 149, 0, 0.35);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.sample-banner strong { color: var(--status-followup); }
.sample-banner button {
  all: unset; cursor: pointer; margin-left: auto;
  font-family: var(--font); font-size: 13px; font-weight: 600; color: var(--accent);
}

/* ---------- View building blocks ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  padding: 22px 24px;
  margin-bottom: 18px;
}
.panel h3 { font-size: 16px; margin-bottom: 4px; }
.panel .sub { color: var(--text-secondary); font-size: 13.5px; margin-bottom: 14px; }

.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-secondary);
}
.empty-state .big { font-size: 40px; margin-bottom: 12px; }
.empty-state h3 { color: var(--text); }
.empty-state p { max-width: 520px; margin: 6px auto 0; font-size: 14.5px; }
.empty-state .btn { margin-top: 18px; }

.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
}
.kpi strong { display: block; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--text-secondary); font-size: 13px; }

/* Exception cards — lead with what's wrong; calm when healthy */
.exception-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.exception {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  font-family: var(--font);
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  padding: 15px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.exception:hover { background: var(--surface-2); }
.exception strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.exception span { color: var(--text-secondary); font-size: 13px; line-height: 1.3; }
.exception .dot { width: 10px; height: 10px; }
.exception.calm { cursor: default; }
.exception.calm strong { color: var(--status-new); }

/* ---------- Filter bar ---------- */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filter-bar input[type="search"], .filter-bar select, .filter-bar input[type="date"] {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: 9px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 8px 12px;
  outline: none;
}
.filter-bar input[type="search"] { min-width: 220px; }
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--accent); }
.filter-bar .spacer { flex: 1; }
.count-label { color: var(--text-secondary); font-size: 13px; font-variant-numeric: tabular-nums; }

.btn-sm {
  padding: 8px 16px;
  font-size: 13.5px;
  border-radius: 999px;
}
.btn-danger { background: rgba(255, 59, 48, 0.14); color: var(--status-dead); }
.btn-danger:hover { background: rgba(255, 59, 48, 0.22); }

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  overflow: auto;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data th {
  text-align: left;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--separator);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data th .arrow { font-size: 10px; }
table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--separator);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr.selected { background: rgba(10, 132, 255, 0.10); }
table.data tr.deactivated td { opacity: 0.5; }
table.data td.num, table.data th.num { text-align: right; }
table.data input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

.member-cell { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--surface-3);
  font-size: 11px; font-weight: 700; color: var(--text);
}
.member-cell .who { line-height: 1.25; }
.member-cell .who small { display: block; color: var(--text-tertiary); font-size: 11.5px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-secondary);
}
.chip .dot { width: 8px; height: 8px; }
.chip.role-admin { color: var(--status-followup); }
.chip.role-rep { color: var(--accent); }
.chip.st-active { color: var(--status-new); }
.chip.st-deactivated { color: var(--status-dead); }
.trend-up { color: var(--status-new); }
.trend-down { color: var(--status-dead); }
.trend-flat { color: var(--text-tertiary); }

/* ---------- Bulk bar (selection is a first-class state) ---------- */
.bulk-bar {
  position: sticky;
  bottom: 16px;
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--separator);
  border-radius: 999px;
  padding: 10px 18px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.bulk-bar strong { font-size: 14px; }
.bulk-bar select {
  background: var(--surface-3);
  border: 1px solid var(--separator);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 6px 10px;
}
.bulk-bar .spacer { flex: 1; }
.bulk-bar .clear { all: unset; cursor: pointer; color: var(--text-secondary); font-size: 13px; font-family: var(--font); }

/* ---------- Drawer (record detail) ----------
   z-index must sit ABOVE map engine chrome (Leaflet panes/controls reach ~1000; Apple MapKit
   similar) so the record drawer never renders under the map. */
.drawer-overlay, .modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1990;
}
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--separator);
  z-index: 2000;
  overflow-y: auto;
  padding: 26px 26px 40px;
}
.drawer .close-x {
  all: unset; cursor: pointer; float: right;
  color: var(--text-secondary); font-size: 20px; line-height: 1; padding: 4px 8px;
}
.drawer h2 { font-size: 21px; font-weight: 800; margin-bottom: 2px; }
.drawer .muted { color: var(--text-secondary); font-size: 13.5px; }
.drawer section { margin-top: 22px; padding: 0; }
.drawer section h4 {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-secondary); margin-bottom: 10px;
}
.drawer .stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.drawer .stat-grid div {
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px;
}
.drawer .stat-grid strong { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.drawer .stat-grid span { font-size: 11.5px; color: var(--text-secondary); }
.field-row {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 9px 0; border-bottom: 1px solid var(--separator); font-size: 14px;
}
.field-row span { color: var(--text-secondary); }
.field-row select {
  background: var(--surface-2); border: 1px solid var(--separator); border-radius: 8px;
  color: var(--text); font-family: var(--font); font-size: 13.5px; padding: 6px 10px;
}
.drawer .history li {
  list-style: none; font-size: 13px; color: var(--text-secondary);
  padding: 7px 0; border-bottom: 1px solid var(--separator);
}
.drawer .history li code { color: var(--text); font-size: 12.5px; }
.drawer .btn { width: 100%; margin-top: 10px; }

/* ---------- Modal (confirmations / bulk preview) ---------- */
.modal-overlay { display: grid; place-items: center; z-index: 2100; }
.modal {
  width: min(460px, 92vw);
  background: var(--surface-2);
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  padding: 26px 28px;
}
.modal h3 { font-size: 17px; margin-bottom: 8px; }
.modal p { color: var(--text-secondary); font-size: 14px; line-height: 1.55; }
.modal .blast {
  background: var(--surface); border: 1px solid var(--separator); border-radius: 10px;
  padding: 12px 14px; margin: 14px 0; font-size: 13.5px; max-height: 180px; overflow-y: auto;
}
.modal .blast li { list-style: none; padding: 3px 0; color: var(--text-secondary); }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--separator);
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 14px;
  z-index: 2200;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

/* ---------- Skeletons (never spinners on white) ---------- */
@keyframes shimmer { 0% { opacity: 0.5; } 50% { opacity: 1; } 100% { opacity: 0.5; } }
.skeleton-row {
  height: 40px; border-radius: 8px; margin: 8px 0;
  background: var(--surface-2); animation: shimmer 1.4s infinite;
}

/* ---------- Hierarchy tree ---------- */
.tree { list-style: none; }
.tree li { padding: 8px 0 8px 0; border-bottom: 1px solid var(--separator); font-size: 14px; }
.tree li .kind {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-tertiary); margin-left: 8px;
}
.tree li small { color: var(--text-secondary); float: right; font-variant-numeric: tabular-nums; }
.tree .indent { padding-left: 22px; }

/* ---------- Data dictionary ---------- */
.dict h3 { margin-top: 26px; font-size: 15px; }
.dict table.data { font-size: 13.5px; }
.dict table.data td { white-space: normal; }
.dict .version { color: var(--text-tertiary); font-size: 12.5px; }

/* ---------- Export rows ---------- */
.export-row {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 0; border-bottom: 1px solid var(--separator);
}
.export-row:last-child { border-bottom: none; }
.export-row .ico {
  width: 36px; height: 36px; border-radius: 9px; flex: none;
  background: var(--surface-2); display: grid; place-items: center; font-size: 16px;
}
.export-row .what { flex: 1; min-width: 0; }
.export-row .what strong { display: block; font-size: 14.5px; }
.export-row .what small { color: var(--text-secondary); font-size: 12.5px; }
.export-row .btn { flex: none; }
.export-row.disabled { opacity: 0.55; }

.seg {
  display: inline-flex; background: var(--surface); border: 1px solid var(--separator);
  border-radius: 999px; padding: 3px; gap: 2px;
}
.seg button {
  all: unset; cursor: pointer; font-family: var(--font); font-size: 13.5px; font-weight: 600;
  color: var(--text-secondary); padding: 6px 16px; border-radius: 999px;
}
.seg button.active { background: var(--surface-3); color: var(--text); }

/* ---------- Responsive (laptop → not phone; the phone story is the app) ---------- */
@media (max-width: 900px) {
  .console { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 10px; overflow-x: auto; }
  .side-nav { display: flex; }
  .side-nav a { white-space: nowrap; }
  .side-foot { margin: 0 0 0 auto; border: none; padding: 0; display: flex; gap: 12px; align-items: center; }
  .main { padding: 24px 18px; }
  .kpi-row, .exception-row { grid-template-columns: repeat(2, 1fr); }
}
