/* ═══════════════════════════════════════════════════════════════
 * fleetInsightsDeviations.css — Fleet Insights page
 * (REDESIGNED 2026-06-11 · lane/dispatch-accounting-improvements)
 *
 * Theme-aware: every color resolves through the canonical --emr-*
 * tokens (styles/emr-design-system.css) so the page follows the
 * light/dark toggle like the rest of the dashboard. The previous
 * version hardcoded a dark ramp that ignored the theme.
 *
 * Namespace: fid- prefix. Self-contained — no override of global
 * dashboard.html selectors. NEVER sets display on .panel (switchTab
 * trap).
 * ═══════════════════════════════════════════════════════════════ */

#panel-fleetinsights {
  background: var(--emr-bg, #FFFFFF);
  color: var(--emr-text, #111827);
  padding: 12px 16px 24px;
  overflow: auto;
  font-family: var(--emr-font-sans, 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif);
  font-size: 13px;
  line-height: 1.4;
}

#fleetinsights-root {
  max-width: 1320px;
  margin: 0 auto;
}

/* ── Header — compact, filters inline (no wasted upper space) ──── */
.fid-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 10px;
  gap: 10px 16px;
}
.fid-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}
.fid-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--emr-text, #111827);
  margin: 0;
  white-space: nowrap;
}
.fid-sub {
  font-size: 11px;
  color: var(--emr-text-subtle, #6B7280);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fid-filters {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.fid-chip-row {
  display: flex;
  gap: 4px;
}
.fid-chip {
  padding: 4px 11px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  color: var(--emr-text-muted, #4B5563);
  background: var(--emr-bg-muted, #F7F8FA);
  border: 1px solid var(--emr-border, #E5E7EB);
  border-radius: var(--emr-radius-pill, 999px);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  transition: color var(--emr-tx, 150ms ease), background var(--emr-tx, 150ms ease);
}
.fid-chip:hover { color: var(--emr-text, #111827); border-color: var(--emr-border-strong, #D1D5DB); }
.fid-chip.active {
  color: var(--emr-text-on-gold, #1A1A1A);
  background: var(--emr-gold, #F5A800);
  border-color: var(--emr-gold, #F5A800);
}
.fid-chip-divider {
  width: 1px;
  height: 18px;
  background: var(--emr-border, #E5E7EB);
}
.fid-chip-refresh { text-transform: none; font-size: 13px; line-height: 1; padding: 4px 9px; }

/* ── KPI strip ─────────────────────────────────────────────────── */
.fid-kpis {
  display: grid;
  /* 8 cells since FLEET-INSIGHTS-PROFIT-RANKINGS (was repeat(6,1fr));
     4-up keeps the strip aligned as two clean rows on wide screens. */
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.fid-kpi {
  background: var(--emr-card-bg, #FFFFFF);
  border: 1px solid var(--emr-card-border, #E5E7EB);
  border-radius: var(--emr-radius, 10px);
  box-shadow: var(--emr-card-shadow, 0 1px 2px rgba(17,24,39,0.04));
  padding: 10px 12px;
  min-width: 0;
}
.fid-kpi-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--emr-text-subtle, #6B7280);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fid-kpi-value {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--emr-text, #111827);
  font-variant-numeric: tabular-nums;
}
.fid-kpi.good .fid-kpi-value { color: var(--emr-status-green, #16A34A); }
.fid-kpi.warn .fid-kpi-value { color: var(--emr-status-yellow, #D97706); }
.fid-kpi.bad  .fid-kpi-value { color: var(--emr-status-red, #DC2626); }
.fid-kpi-sub {
  font-size: 10px;
  color: var(--emr-text-faint, #9CA3AF);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Card grid ─────────────────────────────────────────────────── */
.fid-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
}
.fid-card {
  background: var(--emr-card-bg, #FFFFFF);
  border: 1px solid var(--emr-card-border, #E5E7EB);
  border-radius: var(--emr-radius, 10px);
  box-shadow: var(--emr-card-shadow, 0 1px 2px rgba(17,24,39,0.04));
  padding: 12px 14px;
  min-width: 0;
}
.fid-card-full { grid-column: 1 / -1; }
.fid-card-h3 {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--emr-text-subtle, #6B7280);
  margin: 0 0 8px 0;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.fid-card-footer {
  font-size: 10px;
  color: var(--emr-text-faint, #9CA3AF);
  margin-top: 8px;
}

/* ── Trend chart (inline SVG) ──────────────────────────────────── */
.fid-trend-wrap { width: 100%; }
.fid-trend-svg {
  display: block;
  width: 100%;
  height: 120px;
}
.fid-trend-bar { fill: var(--emr-status-blue, #2563EB); opacity: 0.85; }
.fid-trend-bar:hover { opacity: 1; }

/* ── Tier mix ──────────────────────────────────────────────────── */
.fid-tier-bar {
  display: flex;
  height: 14px;
  border-radius: 7px;
  overflow: hidden;
  margin-bottom: 10px;
  background: var(--emr-bg-subtle, #EEF0F3);
}
.fid-tier-seg { min-width: 3px; }
.fid-tier-legend { display: flex; flex-direction: column; gap: 4px; }
.fid-tier-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--emr-text-muted, #4B5563);
}
.fid-tier-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex: none;
}
.fid-tier-name { flex: 1; }
.fid-tier-n { font-weight: 600; color: var(--emr-text, #111827); font-variant-numeric: tabular-nums; }

.fid-tier-high       { background: var(--emr-status-green, #16A34A); }
.fid-tier-medium     { background: var(--emr-status-blue, #2563EB); }
.fid-tier-low        { background: var(--emr-status-yellow, #D97706); }
.fid-tier-very_low   { background: var(--emr-status-red, #DC2626); }
.fid-tier-new        { background: var(--emr-text-faint, #9CA3AF); }
.fid-tier-broke_down { background: var(--emr-text-muted, #4B5563); }

/* Tier chip (table cell) */
.fid-tier-chip {
  display: inline-block;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  border-radius: var(--emr-radius-pill, 999px);
  color: #fff;
  white-space: nowrap;
}
.fid-tier-chip.fid-tier-new { color: var(--emr-text, #111827); background: var(--emr-bg-subtle, #EEF0F3); }
.fid-tier-chip.fid-tier-broke_down {
  color: var(--emr-text-muted, #4B5563);
  background: transparent;
  border: 1px solid var(--emr-border-strong, #D1D5DB);
}

/* ── Status chips ──────────────────────────────────────────────── */
.fid-status-chip {
  display: inline-block;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  border-radius: var(--emr-radius-pill, 999px);
  white-space: nowrap;
  background: var(--emr-bg-subtle, #EEF0F3);
  color: var(--emr-text-muted, #4B5563);
}
.fid-st-need_a_load { background: var(--emr-status-green-bg, #DCFCE7);  color: var(--emr-status-green, #16A34A); }
.fid-st-in_transit  { background: var(--emr-status-cyan-bg, #CFFAFE);   color: var(--emr-status-cyan, #0891B2); }
.fid-st-loaded      { background: var(--emr-status-gold-bg, #FEF3C7);   color: var(--emr-status-yellow, #D97706); }
.fid-st-assigned    { background: var(--emr-status-purple-bg, #EDE9FE); color: var(--emr-status-purple, #7C3AED); }
.fid-st-broke_down  { background: var(--emr-status-red-bg, #FEE2E2);    color: var(--emr-status-red, #DC2626); }
/* statusChip() lowercases + dashes non-alphanumerics; keep dash twins */
.fid-st-need-a-load { background: var(--emr-status-green-bg, #DCFCE7);  color: var(--emr-status-green, #16A34A); }
.fid-st-in-transit  { background: var(--emr-status-cyan-bg, #CFFAFE);   color: var(--emr-status-cyan, #0891B2); }
.fid-st-broke-down  { background: var(--emr-status-red-bg, #FEE2E2);    color: var(--emr-status-red, #DC2626); }

/* ── Tables ────────────────────────────────────────────────────── */
.fid-table-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.fid-table-toolbar .fid-card-h3 { margin: 0; flex: none; }
.fid-table-count {
  font-size: 10px;
  color: var(--emr-text-faint, #9CA3AF);
}
.fid-search {
  margin-left: auto;
  font-family: inherit;
  font-size: 11px;
  padding: 4px 10px;
  width: 200px;
  color: var(--emr-input-text, #111827);
  background: var(--emr-input-bg, #FFFFFF);
  border: 1px solid var(--emr-input-border, #D1D5DB);
  border-radius: var(--emr-radius-sm, 6px);
  outline: none;
}
.fid-search:focus { box-shadow: 0 0 0 3px var(--emr-input-focus-ring, rgba(245,168,0,0.32)); }

.fid-table-scroll { overflow-x: auto; }
.fid-table {
  width: 100%;
  font-size: 11.5px;
  border-collapse: collapse;
}
.fid-table th {
  text-align: left;
  color: var(--emr-text-subtle, #6B7280);
  font-weight: 600;
  padding: 5px 10px 5px 0;
  border-bottom: 1px solid var(--emr-border, #E5E7EB);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-size: 10px;
  white-space: nowrap;
}
.fid-table th.fid-th-num { text-align: right; }
.fid-table td {
  padding: 5px 10px 5px 0;
  color: var(--emr-text, #111827);
  white-space: nowrap;
}
.fid-table tr + tr td { border-top: 1px solid var(--emr-divider, #F1F3F5); }
.fid-table tbody tr:hover td { background: var(--emr-bg-muted, #F7F8FA); }
.fid-table td.warn,  .fid-table td .warn  { color: var(--emr-status-yellow, #D97706); font-weight: 600; }
.fid-table td.alarm, .fid-table td .alarm { color: var(--emr-status-red, #DC2626);    font-weight: 600; }
.fid-table td.ok,    .fid-table td .ok    { color: var(--emr-status-green, #16A34A);  font-weight: 600; }

/* ── Dispatcher rankings (FLEET-INSIGHTS-PROFIT-RANKINGS) ───────── */
.fid-rank-active { background: var(--emr-bg-subtle, #EEF0F3); }
.fid-rank-medal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: #1A1A1A;
}
.fid-rank-1 { background: var(--emr-gold, #D4AF37); }
.fid-rank-2 { background: var(--emr-border, #C0C4CC); }
.fid-rank-3 { background: #C9885A; }
.fid-row-unassigned td { opacity: 0.65; font-style: italic; }
.fid-row-unassigned td .fid-rank-medal { display: none; }

.fid-cell-truck { font-weight: 700; font-variant-numeric: tabular-nums; }
.fid-cell-num   { text-align: right; font-variant-numeric: tabular-nums; }
.fid-cell-dim   { color: var(--emr-text-faint, #9CA3AF); }

/* Sortable column headers */
.fid-th-sortable {
  cursor: pointer;
  user-select: none;
}
.fid-th-sortable:hover { color: var(--emr-text, #111827); }
.fid-th-sortable.active { color: var(--emr-gold-hover, #DC9700); }

.fid-empty-row {
  text-align: center;
  color: var(--emr-text-faint, #9CA3AF);
  font-style: italic;
  padding: 14px 0 !important;
}

/* ── Sparklines ────────────────────────────────────────────────── */
.fid-spark { display: block; }
.fid-spark-line {
  fill: none;
  stroke: var(--emr-status-cyan, #0891B2);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* ── Breach chips (deviations card) ────────────────────────────── */
.fid-breach-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
}
.fid-breach-chip {
  display: inline-block;
  padding: 2px 9px;
  font-size: 10px;
  font-weight: 600;
  border-radius: var(--emr-radius-pill, 999px);
  background: var(--emr-bg-subtle, #EEF0F3);
  color: var(--emr-text-muted, #4B5563);
  white-space: nowrap;
}
.fid-breach-chip.warn  { background: var(--emr-status-yellow-bg, #FEF3C7); color: var(--emr-status-yellow, #D97706); }
.fid-breach-chip.alarm { background: var(--emr-status-red-bg, #FEE2E2);    color: var(--emr-status-red, #DC2626); }

/* ── Empty / loading / error states ───────────────────────────── */
.fid-card-empty {
  min-height: 110px;
  display: flex;
  flex-direction: column;
}
.fid-empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--emr-text-faint, #9CA3AF);
  font-size: 11px;
  font-style: italic;
  padding: 20px 8px;
}
.fid-loading {
  padding: 40px;
  text-align: center;
  color: var(--emr-text-subtle, #6B7280);
  font-size: 12px;
}
.fid-error {
  padding: 16px;
  background: var(--emr-status-red-bg, #FEE2E2);
  border: 1px solid var(--emr-status-red, #DC2626);
  border-radius: var(--emr-radius-sm, 6px);
  color: var(--emr-status-red, #DC2626);
  font-size: 12px;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .fid-kpis { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  .fid-kpis { grid-template-columns: repeat(2, 1fr); }
  .fid-grid { grid-template-columns: 1fr; }
  .fid-card-full { grid-column: 1; }
  .fid-search { width: 100%; margin-left: 0; }
}

/* ── Fleet Utilization Settings panel (fus- namespace) ───────────
 * Control-panel modal opened from the ⚙ button on Fleet Insights and
 * the Fleet Utilization heat map (js/fleetUtilizationSettingsPanel.js).
 * Lives in this sheet because dashboard.html links it globally and the
 * modal is shared by both pages. Theme-aware via --emr-* tokens. */
.fus-panel {
  min-width: 360px;
  max-width: 560px;
  color: var(--emr-text, #111827);
  font-size: 13px;
  line-height: 1.45;
}
.fus-title { margin: 0 0 2px; font-size: 16px; font-weight: 800; }
.fus-sub   { color: var(--emr-text-dim, #6B7280); margin-bottom: 14px; font-size: 12px; }
.fus-section { margin-bottom: 16px; }
.fus-label {
  display: block;
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--emr-text-dim, #6B7280);
}
.fus-input {
  background: var(--emr-bg, #FFFFFF);
  color: var(--emr-text, #111827);
  border: 1px solid var(--emr-border-strong, #D1D5DB);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  width: 100%;
  box-sizing: border-box;
}
.fus-input-num { width: 92px; }
.fus-hint { color: var(--emr-text-dim, #6B7280); font-size: 11px; margin-top: 5px; }
.fus-bracket-inputs { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.fus-bracket-lbl { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.fus-tier-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: baseline;
}
.fus-tier-high     { background: var(--emr-status-green, #16A34A); }
.fus-tier-medium   { background: var(--emr-status-blue, #2563EB); }
.fus-tier-low      { background: var(--emr-status-yellow, #D97706); }
.fus-tier-very_low { background: var(--emr-status-red, #DC2626); }
.fus-bracket-preview {
  border: 1px solid var(--emr-border, #E5E7EB);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
}
.fus-preview-head, .fus-preview-row {
  display: grid;
  grid-template-columns: 90px 1fr 1fr;
  gap: 8px;
  padding: 2px 0;
}
.fus-preview-head { font-weight: 700; color: var(--emr-text-dim, #6B7280); border-bottom: 1px solid var(--emr-border, #E5E7EB); margin-bottom: 3px; }
.fus-dim { color: var(--emr-text-dim, #6B7280); }
.fus-error {
  color: var(--emr-status-red, #DC2626);
  font-size: 12px;
  margin-top: 8px;
}
.fus-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.fus-btn {
  border: 1px solid var(--emr-border-strong, #D1D5DB);
  background: var(--emr-bg, #FFFFFF);
  color: var(--emr-text, #111827);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.fus-btn:hover { border-color: var(--emr-text-dim, #6B7280); }
.fus-btn-save {
  background: var(--emr-accent, #2563EB);
  border-color: var(--emr-accent, #2563EB);
  color: #FFFFFF;
}
.fus-btn-save[disabled] { opacity: 0.6; cursor: default; }
