/* assets/css/style.css - Professional Enterprise Telematics Theme */
:root {
  --bg: #f8fafc;
  --sb: #0f172a;
  --sb-hover: #1e293b;
  --sb-active: #2563eb;
  --card: #ffffff;
  --line: #e2e8f0;
  --line-light: #f1f5f9;
  
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-light: #eff6ff;
  
  --ok: #10b981;
  --ok-bg: #ecfdf5;
  --ok-line: #a7f3d0;
  
  --warn: #f59e0b;
  --warn-bg: #fffbeb;
  --warn-line: #fde68a;
  
  --bad: #ef4444;
  --bad-bg: #fef2f2;
  --bad-line: #fecaca;
  
  --slate: #64748b;
  --slate-bg: #f1f5f9;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--brand);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   1. APP SHELL & SIDEBAR
   ========================================================================== */
.app {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.sidebar {
  width: 270px;
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 600;
  flex-shrink: 0;
  border-right: 1px solid #1e293b;
}

.sb-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sb-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.sb-brand-t {
  display: flex;
  flex-direction: column;
}

.sb-title {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.01em;
}

.sb-sub {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 500;
  margin-top: 1px;
}

.sb-school {
  margin: 12px 14px 4px;
  padding: 8px 12px;
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: #93c5fd;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sb-school.all {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.25);
  color: #6ee7b7;
}

.sb-school-ic {
  display: flex;
  align-items: center;
}

.sb-school-t {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 16px;
}

.sb-sec {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #64748b;
  margin: 18px 10px 6px;
  font-weight: 700;
  text-transform: uppercase;
}

.sb-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: #94a3b8;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  margin: 2px 0;
  transition: all 0.15s ease;
}

.sb-link .ic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  color: #64748b;
  transition: color 0.15s ease;
}

.sb-link:hover {
  background: #1e293b;
  color: #f1f5f9;
  text-decoration: none;
}
.sb-link:hover .ic {
  color: #93c5fd;
}

.sb-link.active {
  background: #2563eb;
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}
.sb-link.active .ic {
  color: #ffffff;
}

.sb-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.2);
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  color: #ffffff;
  flex-shrink: 0;
}

.sb-user-t {
  flex: 1;
  min-width: 0;
}
.sb-user-t b {
  display: block;
  font-size: 13px;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-user-t small {
  color: #94a3b8;
  font-size: 11px;
}

.sb-logout {
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}
.sb-logout:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  text-decoration: none;
}

/* ==========================================================================
   2. TOPBAR & MAIN CONTENT
   ========================================================================== */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar2 {
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 500;
}

.topbar2 h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
  letter-spacing: -0.01em;
}

.tb-title {
  flex: 1;
}

.hamb {
  display: none;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text-main);
}

.tb-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12.5px;
}

.tb-status-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}
.tb-status-badge:hover {
  filter: brightness(0.96);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.tb-status-badge.online {
  background: var(--ok-bg);
  border: 1px solid var(--ok-line);
  color: #065f46;
}
.tb-status-badge.online .live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-dot-green 2s infinite;
}

.tb-status-badge.offline {
  background: var(--bad-bg);
  border: 1px solid var(--bad-line);
  color: #991b1b;
}
.tb-status-badge.offline .live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bad);
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  animation: pulse-dot-red 2s infinite;
}

@keyframes pulse-dot-green {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
  70% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes pulse-dot-red {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  70% { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.tb-divider {
  width: 1px;
  height: 18px;
  background: var(--line);
}

.content {
  padding: 24px;
  width: 100%;
  max-width: 1650px;
  box-sizing: border-box;
}

.foot {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 16px;
  border-top: 1px solid var(--line);
  margin-top: auto;
  background: #ffffff;
}

.foot-sep {
  margin: 0 8px;
  opacity: 0.4;
}

.sb-overlay {
  display: none;
}

/* ==========================================================================
   3. STATS & KPI CARDS
   ========================================================================== */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat:hover {
  box-shadow: var(--shadow);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat.brand .stat-icon {
  background: var(--brand-light);
  color: var(--brand);
}
.stat.ok .stat-icon {
  background: var(--ok-bg);
  color: var(--ok);
}
.stat.warn .stat-icon {
  background: var(--warn-bg);
  color: var(--warn);
}
.stat.slate .stat-icon {
  background: var(--slate-bg);
  color: var(--slate);
}

.stat-data b {
  font-size: 24px;
  font-weight: 700;
  display: block;
  line-height: 1.1;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.stat-data small {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

/* ==========================================================================
   4. PANELS, FORMS & TABLES
   ========================================================================== */
.panel {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.panel h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.panel-h h3 {
  margin: 0;
}

.search-input {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text-main);
  background: #ffffff;
  outline: none;
  transition: border-color 0.15s ease;
}
.search-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.btn {
  background: var(--brand);
  color: #ffffff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}
.btn:hover {
  background: var(--brand-dark);
  text-decoration: none;
}

.btn.small {
  padding: 6px 12px;
  font-size: 12.5px;
}

.btn.ghost {
  background: #f8fafc;
  color: var(--text-main);
  border: 1px solid var(--line);
}
.btn.ghost:hover {
  background: #f1f5f9;
}

.btn.danger {
  background: var(--bad);
}
.btn.danger:hover {
  background: #dc2626;
}

.pill {
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.pill.ok {
  background: var(--ok-bg);
  color: #065f46;
  border: 1px solid var(--ok-line);
}
.pill.warn {
  background: var(--warn-bg);
  color: #92400e;
  border: 1px solid var(--warn-line);
}
.pill.off {
  background: var(--bad-bg);
  color: #991b1b;
  border: 1px solid var(--bad-line);
}
.pill.slate {
  background: var(--slate-bg);
  color: #475569;
  border: 1px solid var(--line);
}

.form label {
  display: block;
  margin: 12px 0;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-main);
}
.form input, .form select, .form textarea,
.inline input, .inline select {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-top: 4px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text-main);
  background: #ffffff;
  outline: none;
}
.form input:focus, .form select:focus, .form textarea:focus,
.inline input:focus, .inline select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.form input, .form select, .form textarea {
  width: 100%;
}

.inline {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.inline input, .inline select {
  flex: 1;
  min-width: 140px;
}

.tbl-wrap {
  overflow-x: auto;
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 640px;
}
.tbl th, .tbl td {
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
}
.tbl th {
  background: #f8fafc;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}
.tbl tr:hover td {
  background: #f8fafc;
}

.ok {
  background: var(--ok-bg);
  border: 1px solid var(--ok-line);
  color: #065f46;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin: 12px 0;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.bad {
  background: var(--bad-bg);
  border: 1px solid var(--bad-line);
  color: #991b1b;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin: 12px 0;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.muted {
  color: var(--text-muted);
  font-size: 13px;
}
.hidden {
  display: none !important;
}

/* ==========================================================================
   5. LIVE TRACKING GRID & VEHICLE CARDS
   ========================================================================== */
.grid-live {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
}

.buslist {
  max-height: calc(100vh - 170px);
  overflow-y: auto;
  padding: 16px;
}

.filter-tabs {
  display: flex;
  gap: 6px;
  margin: 10px 0;
  overflow-x: auto;
}

.filter-tab {
  padding: 5px 10px;
  border-radius: 16px;
  font-size: 11.5px;
  font-weight: 600;
  color: #64748b;
  background: #f1f5f9;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.filter-tab.active {
  background: #0f172a;
  color: #ffffff;
}

.busrow {
  display: flex;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin: 8px 0;
  cursor: pointer;
  background: #ffffff;
  transition: all 0.15s ease;
}
.busrow:hover {
  border-color: #93c5fd;
  box-shadow: var(--shadow-sm);
}
.busrow.active {
  border-color: var(--brand);
  background: var(--brand-light);
  box-shadow: 0 0 0 1px var(--brand);
}

.bus-status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.bus-status-indicator.moving {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}
.bus-status-indicator.idle {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}
.bus-status-indicator.parked {
  background: var(--slate);
}
.bus-status-indicator.offline {
  background: #cbd5e1;
}

.bus-meta {
  flex: 1;
  min-width: 0;
}

.bus-plate-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.bus-plate {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.bus-school-lbl {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 2px 0 4px;
}

.bus-telemetry-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
}

.bus-spd {
  font-weight: 600;
  color: var(--brand);
  font-size: 13px;
}

.mapwrap {
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.mapbar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 6px 6px 12px;
  flex-wrap: wrap;
}

#map {
  height: 72vh;
  border-radius: var(--radius);
  z-index: 1;
  border: 1px solid var(--line);
}

/* ==========================================================================
   6. PROFESSIONAL MAP MARKERS & POPUPS
   ========================================================================== */
.vehicle-marker-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.vehicle-marker-pin {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  border: 2px solid #ffffff;
  position: relative;
  transition: transform 0.3s ease;
}

.vehicle-marker-pin.moving {
  background: linear-gradient(135deg, #10b981, #059669);
}
.vehicle-marker-pin.idle {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}
.vehicle-marker-pin.parked {
  background: linear-gradient(135deg, #64748b, #475569);
}
.vehicle-marker-pin.offline {
  background: #94a3b8;
}

.vehicle-heading-arrow {
  position: absolute;
  top: -8px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 7px solid #1e293b;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0 !important;
}
.leaflet-popup-content {
  margin: 0 !important;
  line-height: 1.4 !important;
}

.telematics-popup {
  padding: 14px 16px;
  min-width: 220px;
  font-family: inherit;
}
.tp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  margin-bottom: 10px;
}
.tp-plate {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}
.tp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  font-size: 12px;
}
.tp-item {
  display: flex;
  flex-direction: column;
}
.tp-item small {
  color: var(--text-muted);
  font-size: 10.5px;
}
.tp-item b {
  color: var(--text-main);
  font-weight: 600;
}
.tp-footer {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* ==========================================================================
   7. AUTHENTICATION & LOGIN CARD
   ========================================================================== */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.25), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
}

.auth-header {
  text-align: center;
  margin-bottom: 24px;
}

.auth-logo {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
}

.auth-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
}

.auth-header p {
  font-size: 13px;
  color: var(--text-muted);
  margin: 6px 0 0;
}

.auth-footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ==========================================================================
   8. RESPONSIVE DESIGN
   ========================================================================== */
@media (max-width: 960px) {
  .grid-live {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.4);
  }
  .sidebar.open {
    transform: none;
  }
  .sb-overlay.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 550;
  }
  .hamb {
    display: flex;
  }
  .hide-m {
    display: none !important;
  }
  .content {
    padding: 14px;
  }
}
