:root {
  --bg-page: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-subtle: #F1F5F9;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --text-main: #0F172A;
  --text-muted: #475569;
  --navy: #1E3A8A;
  --navy-light: #EFF6FF;
  --emerald: #059669;
  --emerald-subtle: #ECFDF5;

  /* Severity-Prioritized 4-Mode Hierarchy (Matches geo_msi_fpo_interactive_heatmap.html) */
  --mode-rack: #DC2626;   /* Priority #1: Crimson Red (Frame Twist / Pothole) */
  --mode-bias: #EA580C;   /* Priority #2: Deep Safety Orange (Crossfall / Curve Banking) */
  --mode-pitch: #D97706;  /* Priority #3: Amber Gold (Sub-base Pumping / Undulation) */
  --mode-shock: #2563EB;  /* Priority #4: Royal Cobalt Blue (Surface Spillage Sweep) */
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  background: var(--bg-page);
  color: var(--text-main);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
}

/* ==============================================================================
   INDUSTRIAL TASKBAR (LEFT SIDEBAR RAIL) & UNIFIED APPLICATION SHELL
   Standard Mining Dispatch & Geotechnical Engineering Cockpit
   ============================================================================== */

.app-layout {
  display: flex;
  min-height: 100vh;
  background: var(--bg-page);
}

/* 1. Left Sidebar Rail */
.app-sidebar {
  width: 236px;
  min-width: 236px;
  background: #0B132B; /* Deep Industrial Obsidian Navy */
  border-right: 1px solid #1E293B;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1000;
  transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
  overflow-y: auto;
  overflow-x: hidden;
}

/* Sidebar Brand Header */
.sidebar-brand {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: #080D1F;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  min-width: 0;
}

.brand-ptp-badge {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: linear-gradient(135deg, #1E3A8A 0%, #D97706 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 0.8rem;
  color: #FFFFFF;
  letter-spacing: 0.05em;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
  flex-shrink: 0;
}

.brand-text-block {
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: opacity 0.15s ease;
}

.brand-main-title {
  font-size: 0.86rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #F8FAFC;
  line-height: 1.1;
  white-space: nowrap;
}

.brand-sub-title {
  font-size: 0.65rem;
  font-weight: 700;
  color: #F59E0B; /* Petrosea Gold */
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.btn-sidebar-collapse {
  background: transparent;
  border: none;
  color: #94A3B8;
  cursor: pointer;
  padding: 5px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.btn-sidebar-collapse:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #FFFFFF;
}

/* Sidebar Nav Sections */
.sidebar-nav {
  padding: 12px 8px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-section-header {
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748B;
  padding: 10px 10px 4px 10px;
  white-space: nowrap;
  transition: opacity 0.15s ease;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 6px;
  text-decoration: none;
  color: #94A3B8;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.15s ease;
  white-space: nowrap;
  position: relative;
}

.sidebar-nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #F8FAFC;
}

.sidebar-nav-item.active {
  background: #1E3A8A;
  color: #FFFFFF;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(30, 58, 138, 0.4);
}

.sidebar-nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3.5px;
  background: #F59E0B; /* Petrosea Gold active indicator */
  border-radius: 0 3px 3px 0;
}

.sidebar-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-label {
  transition: opacity 0.15s ease;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar Footer / User Profile */
.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: #080D1F;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-user-block {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.sidebar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #1E293B;
  border: 1.5px solid #3B82F6;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #93C5FD;
  flex-shrink: 0;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: opacity 0.15s ease;
}

.sidebar-user-name {
  font-size: 0.77rem;
  font-weight: 700;
  color: #F8FAFC;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.65rem;
  font-weight: 800;
  color: #38BDF8;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.btn-sidebar-logout {
  background: transparent;
  border: none;
  color: #94A3B8;
  padding: 6px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  text-decoration: none;
}
.btn-sidebar-logout:hover {
  background: rgba(220, 38, 38, 0.15);
  color: #EF4444;
}

/* 2. Main Content Wrapper */
.app-main {
  flex: 1;
  margin-left: 236px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin-left 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 3. Top Context & Operational Bar */
.app-topbar {
  height: 50px;
  background: #FFFFFF;
  border-bottom: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  position: sticky;
  top: 0;
  z-index: 900;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-topbar-menu {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-topbar-menu:hover {
  background: var(--bg-subtle);
  color: var(--navy);
  border-color: var(--border-strong);
}

.site-switcher-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  padding: 4px 10px;
  border-radius: 6px;
}

.site-lbl {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
}

.site-select {
  border: none;
  background: transparent;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  outline: none;
  padding: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 700;
}

.status-live {
  background: #ECFDF5;
  color: #065F46;
  border: 1px solid #A7F3D0;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background: #10B981;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 5px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-topbar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  text-decoration: none;
}

.btn-topbar-primary {
  background: var(--navy);
  color: #FFFFFF;
}
.btn-topbar-primary:hover {
  background: #1D4ED8;
  box-shadow: 0 2px 6px rgba(30, 58, 138, 0.3);
}

.btn-topbar-success {
  background: #059669;
  color: #FFFFFF;
}
.btn-topbar-success:hover {
  background: #047857;
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.3);
}

.btn-filter-reset {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-filter-reset:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
  border-color: var(--navy);
}

.app-content {
  padding: 14px 18px;
  flex: 1;
}

/* 4. Collapsed Sidebar State */
body.sidebar-collapsed .app-sidebar {
  width: 66px;
  min-width: 66px;
}

body.sidebar-collapsed .app-main {
  margin-left: 66px;
}

body.sidebar-collapsed .brand-text-block,
body.sidebar-collapsed .nav-section-header,
body.sidebar-collapsed .sidebar-label,
body.sidebar-collapsed .sidebar-user-info {
  display: none !important;
}

body.sidebar-collapsed .sidebar-nav-item {
  justify-content: center;
  padding: 10px 0;
}

body.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding: 0 8px;
}

body.sidebar-collapsed .btn-sidebar-collapse {
  display: none;
}

body.sidebar-collapsed .sidebar-footer {
  justify-content: center;
  padding: 10px 6px;
}

/* Responsive Handling */
@media (max-width: 992px) {
  .app-sidebar {
    transform: translateX(-100%);
    width: 236px;
  }
  .app-main {
    margin-left: 0 !important;
  }
  body.sidebar-mobile-open .app-sidebar {
    transform: translateX(0);
  }
}

/* Legacy Header Bar (Fallback for isolated containers) */
.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-left: 6px solid var(--navy);
  border-radius: 10px;
  padding: 12px 18px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand-sub {
  font-size: 0.79rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.nav-tabs {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.nav-tab {
  text-decoration: none;
  color: var(--text-main);
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 0.81rem;
  font-weight: 700;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.nav-tab:hover {
  background: #E2E8F0;
  border-color: var(--navy);
}

.nav-tab.active {
  background: var(--navy);
  color: #FFFFFF;
  border-color: var(--navy);
  box-shadow: 0 1px 3px rgba(30, 58, 138, 0.25);
}

/* Badges */
.badge {
  background: var(--navy);
  color: #FFFFFF;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.badge-crit { background: var(--mode-rack); }
.badge-warn { background: var(--mode-bias); }
.badge-ok   { background: var(--emerald); }

/* Control & Filter Bar */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.ctrl-left, .ctrl-right {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.81rem;
}

.ctrl-group label {
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

select, input[type="text"], input[type="number"], input[type="date"], textarea {
  background: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 11px;
  font-size: 0.81rem;
  font-weight: 600;
  outline: none;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--navy);
  background: #FFFFFF;
}

button {
  background: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.81rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

button:hover {
  background: #E2E8F0;
}

button.btn-primary {
  background: var(--navy);
  color: #FFFFFF;
  border-color: var(--navy);
}

button.btn-primary:hover {
  background: #1E40AF;
}

button.btn-success {
  background: var(--emerald);
  color: #FFFFFF;
  border-color: var(--emerald);
}

button.btn-success:hover {
  background: #047857;
}

/* KPI Row */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

@media (max-width: 1200px) {
  .kpi-row { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.kpi-label {
  font-size: 0.71rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 700;
}

.kpi-val-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin: 4px 0 2px 0;
}

.kpi-val {
  font-size: 1.38rem;
  font-weight: 800;
  color: var(--text-main);
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.delta-pill {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 800;
  display: inline-block;
}
.delta-bad { background: #FEE2E2; color: #991B1B; border: 1px solid #FCA5A5; }
.delta-good { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.delta-neutral { background: #F1F5F9; color: #475569; border: 1px solid #CBD5E1; }
.delta-rebound { background: #FFEDD5; color: #9A3412; border: 1px solid #FDBA74; }

/* Main Grid Layout */
.main-grid {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

@media (max-width: 1100px) {
  .main-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.panel-title {
  font-size: 0.92rem;
  font-weight: 800;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  color: var(--text-main);
  flex-wrap: wrap;
  gap: 8px;
}

canvas.network-canvas {
  background: #F8FAFC;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  width: 100%;
  cursor: pointer;
  display: block;
}

canvas.telemetry-canvas {
  background: #FFFFFF;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  width: 100%;
  cursor: crosshair;
  display: block;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  font-size: 0.76rem;
  color: var(--text-main);
  font-weight: 600;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
  vertical-align: middle;
}

/* Inspector Box */
.inspector-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.inspector-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 8px;
}

.inspector-box h3 {
  font-size: 0.95rem;
  color: var(--navy);
  font-weight: 800;
}

.kv-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  font-size: 0.8rem;
  margin-bottom: 10px;
}

.kv-grid div span {
  color: var(--text-muted);
}

.diff-box {
  background: #FFFFFF;
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--navy);
  border-radius: 6px;
  padding: 8px 11px;
  margin-bottom: 10px;
  font-size: 0.78rem;
}

.action-card {
  background: #ECFDF5;
  border-left: 4px solid var(--emerald);
  padding: 9px 12px;
  border-radius: 4px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: #064E3B;
}

/* 4-Wheel Strut Footprint */
.strut-4wheel-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.strut-cell {
  background: #FFFFFF;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 8px;
  text-align: center;
}

.strut-cell .wheel-lbl {
  font-size: 0.67rem;
  color: var(--text-muted);
  font-weight: 700;
}

.strut-cell .wheel-val {
  font-size: 0.88rem;
  font-weight: 800;
  margin-top: 2px;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.77rem;
  margin-top: 6px;
}

th, td {
  padding: 8px 9px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.69rem;
}

tbody tr:hover {
  background: #EFF6FF;
  cursor: pointer;
}

tbody tr.selected-row {
  background: #DBEAFE;
  border-left: 4px solid var(--navy);
}

.pill {
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 800;
  font-size: 0.69rem;
  color: #FFFFFF;
  display: inline-block;
}
.pill-RACK  { background: var(--mode-rack); }
.pill-BIAS  { background: var(--mode-bias); }
.pill-PITCH { background: var(--mode-pitch); }
.pill-SHOCK { background: var(--mode-shock); }

/* Filter Tabs for Queue */
.queue-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.q-tab {
  padding: 4px 9px;
  font-size: 0.72rem;
  border-radius: 5px;
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: pointer;
  font-weight: 700;
}
.q-tab.active {
  background: var(--navy);
  color: #FFFFFF;
  border-color: var(--navy);
}

/* Modals */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(3px);
  z-index: 999;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: #FFFFFF;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  width: 100%;
  max-width: 680px;
  padding: 20px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  margin-bottom: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--text-muted);
}
