:root {
  --bg-main: #070b14;
  --bg-panel: #0f1626;
  --bg-card: #151f34;
  --bg-card-hover: #1c2944;
  --bg-glass: rgba(15, 22, 38, 0.86);
  --border-subtle: rgba(148, 163, 184, 0.14);
  --border-highlight: rgba(56, 189, 248, 0.45);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-cyan: #06b6d4;
  --accent-blue: #3b82f6;
  --accent-indigo: #6366f1;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-purple: #8b5cf6;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --shadow-lg: 0 18px 40px -12px rgba(0, 0, 0, 0.65);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

code, pre, .mono {
  font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
}

/* TOP COMMAND HEADER */
.top-header {
  height: 64px;
  background: rgba(10, 15, 28, 0.95);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(12px);
}

.brand-box {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-indigo));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.5px;
  color: #fff;
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.4);
}

.brand-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* PORTAL MODE SWITCHER */
.mode-switcher {
  display: flex;
  background: #090e1a;
  padding: 4px;
  border-radius: 11px;
  border: 1px solid var(--border-subtle);
  gap: 4px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 15px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.mode-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.mode-btn.active-admin {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.mode-btn.active-client {
  background: linear-gradient(135deg, #0ea5e9, #10b981);
  color: #fff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}

.mode-btn.active-mobile {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.live-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #34d399;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

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

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.tenant-selector-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  padding: 5px 10px;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
}

.tenant-selector-wrap label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-weight: 700;
}

.select-input, .text-input {
  background: #0b1120;
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 7px 11px;
  font-size: 13px;
  outline: none;
}

.select-input:focus, .text-input:focus {
  border-color: var(--accent-cyan);
}

/* SUB-NAVIGATION TABS */
.sub-nav {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 50px;
}

.sub-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.sub-tab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 13px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: all 0.15s;
}

.sub-tab:hover {
  color: var(--text-primary);
}

.sub-tab.active {
  color: var(--accent-cyan);
  border-bottom-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.06);
}

/* MAIN WORKSPACE */
.main-content {
  flex: 1;
  padding: 20px 24px;
  max-width: 1720px;
  width: 100%;
  margin: 0 auto;
}

/* KPI GRID */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-indigo));
}

.kpi-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.kpi-value {
  font-size: 28px;
  font-weight: 800;
  margin: 8px 0 4px;
  letter-spacing: -0.6px;
}

.kpi-foot {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* SECTION PANELS & TABLES */
.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-title {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 9px;
}

.panel-subtitle {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.btn {
  border: 1px solid var(--border-subtle);
  background: #1e293b;
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all 0.15s ease;
}

.btn:hover {
  background: #334155;
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  border-color: transparent;
  color: #fff;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-emerald {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.45);
  color: #34d399;
}

.btn-danger {
  background: rgba(244, 63, 94, 0.16);
  border-color: rgba(244, 63, 94, 0.45);
  color: #fb7185;
}

.btn-amber {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.45);
  color: #fbbf24;
}

.data-table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 11px 12px;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.55);
}

.data-table td {
  padding: 13px 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.row-physical-unit td {
  background: rgba(6, 182, 212, 0.07) !important;
}

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.badge-emerald {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-cyan {
  background: rgba(6, 182, 212, 0.15);
  color: #22d3ee;
  border: 1px solid rgba(6, 182, 212, 0.4);
}

.badge-amber {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.badge-rose {
  background: rgba(244, 63, 94, 0.15);
  color: #fb7185;
  border: 1px solid rgba(244, 63, 94, 0.35);
}

.badge-purple {
  background: rgba(139, 92, 246, 0.16);
  color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, 0.35);
}

/* SERVICE PILL TOGGLES */
.service-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.srv-pill {
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.6);
  color: var(--text-muted);
  transition: all 0.15s;
  user-select: none;
}

.srv-pill.on {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.45);
  color: #34d399;
}

/* FLEET COCKPIT LAYOUT (MAP + SIDEBARS) */
.cockpit-grid {
  display: grid;
  grid-template-columns: 330px 1fr 390px;
  gap: 16px;
  height: calc(100vh - 155px);
  min-height: 620px;
}

@media (max-width: 1360px) {
  .cockpit-grid {
    grid-template-columns: 300px 1fr;
    height: auto;
  }
}

.cockpit-col {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cockpit-col-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(10, 15, 28, 0.5);
}

.cockpit-col-body {
  padding: 12px;
  overflow-y: auto;
  flex: 1;
}

.map-container {
  width: 100%;
  height: 100%;
  min-height: 540px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border-subtle);
}

#liveMap, #playbackMap, #geoMap {
  width: 100%;
  height: 100%;
  min-height: 540px;
  background: #0b1120;
}

.map-overlay-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 500;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.map-overlay-card {
  pointer-events: auto;
  background: rgba(10, 15, 28, 0.88);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 8px 13px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-lg);
}

/* VEHICLE LIST CARDS */
.veh-item {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.55);
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.veh-item:hover {
  border-color: rgba(56, 189, 248, 0.35);
  background: var(--bg-card-hover);
}

.veh-item.selected {
  border-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.11);
  box-shadow: 0 0 0 1px var(--accent-cyan);
}

.veh-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.veh-plate {
  font-weight: 800;
  font-size: 13.5px;
  letter-spacing: 0.3px;
}

/* TELEMETRY GAUGES GRID */
.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
  margin-bottom: 14px;
}

.tele-box {
  background: rgba(10, 15, 28, 0.65);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  padding: 10px 11px;
}

.tele-label {
  font-size: 10.5px;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-weight: 600;
}

.tele-val {
  font-size: 16px;
  font-weight: 800;
  margin-top: 3px;
}

/* DOUT HARDWARE CONTROL BUTTONS */
.dout-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.dout-btn {
  width: 100%;
  padding: 11px 13px;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.8);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  transition: all 0.15s;
}

.dout-btn:hover {
  border-color: var(--accent-cyan);
}

.dout-btn.active-cut {
  background: rgba(244, 63, 94, 0.2);
  border-color: #f43f5e;
  color: #fda4af;
}

/* MOBILE PHONE SIMULATOR */
.mobile-sim-layout {
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 1050px) {
  .mobile-sim-layout {
    grid-template-columns: 1fr;
  }
}

.phone-frame {
  width: 375px;
  height: 740px;
  background: #050811;
  border: 10px solid #1e293b;
  border-radius: 44px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  margin: 0 auto;
}

.phone-notch {
  width: 130px;
  height: 22px;
  background: #1e293b;
  border-radius: 0 0 14px 14px;
  margin: 0 auto;
}

.phone-body {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.78);
  backdrop-filter: blur(6px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-highlight);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}

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

.form-group.full {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}

/* HEX DUMP BOX */
.hex-box {
  background: #050811;
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: 9px;
  padding: 12px;
  font-size: 11.5px;
  color: #38bdf8;
  word-break: break-all;
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
}

/* TOAST NOTIFICATION */
.toast-container {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: rgba(15, 23, 42, 0.96);
  border-left: 4px solid var(--accent-cyan);
  border-top: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 13px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  min-width: 310px;
  max-width: 420px;
  font-size: 13px;
}
