/* ============================================================
   FleetPro — Global Stylesheet
   Modern admin dashboard: dark sidebar, cards, badges, modals
   ============================================================ */

:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0ea5e9;
  --brand-dark: #0284c7;
  --navy: #0b1220;
  --navy-2: #101d3a;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --violet: #8b5cf6;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 18px 40px -12px rgba(15, 23, 42, .18);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.main {
  flex: 1;
  margin-left: 264px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.content {
  padding: 26px;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 264px;
  position: fixed;
  inset: 0 auto 0 0;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: transform .25s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px;
  color: #fff;
  border-bottom: 1px solid rgba(148, 163, 184, .12);
}

.brand:hover { color: #fff; }

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 19px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--violet));
  box-shadow: 0 6px 16px -4px rgba(14, 165, 233, .55);
  flex-shrink: 0;
}

.brand strong { display: block; font-size: 17px; letter-spacing: .2px; }
.brand small { font-size: 11px; color: #64748b; letter-spacing: .6px; text-transform: uppercase; }

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

.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  margin-bottom: 3px;
  border-radius: 10px;
  color: #94a3b8;
  font-weight: 500;
  font-size: 14px;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
}

.nav a i { width: 20px; text-align: center; font-size: 15px; }

.nav a:hover { background: rgba(148, 163, 184, .08); color: #e2e8f0; }

.nav a.active {
  background: linear-gradient(90deg, rgba(14, 165, 233, .18), rgba(14, 165, 233, .04));
  color: #fff;
  border-left-color: var(--brand);
}

.sidebar-foot {
  padding: 16px 14px;
  border-top: 1px solid rgba(148, 163, 184, .12);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
}

.user-chip strong { display: block; color: #e2e8f0; font-size: 13px; }
.user-chip small { color: #64748b; font-size: 12px; }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--violet));
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin-top: 6px;
  border-radius: 10px;
  color: #fca5a5;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s;
}

.logout-btn:hover { background: rgba(239, 68, 68, .12); color: #fecaca; }

/* ---------- Topbar ---------- */
.topbar {
  height: 64px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 26px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 19px;
  color: var(--ink);
  cursor: pointer;
  padding: 6px;
}

.page-title { font-size: 20px; font-weight: 800; letter-spacing: -.2px; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }

.today { color: var(--muted); font-size: 13px; font-weight: 500; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-head {
  padding: 16px 20px;
  border-bottom: 1px solid #eef2f7;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-head h2 { font-size: 15px; font-weight: 700; }
.card-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.card-body { padding: 20px; }

/* ---------- KPI cards ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.kpi {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform .18s ease, box-shadow .18s ease;
}

.kpi:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.kpi .icon {
  width: 48px;
  height: 48px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-size: 19px;
  color: #fff;
  flex-shrink: 0;
}

.kpi .icon.blue   { background: linear-gradient(135deg, #0ea5e9, #2563eb); }
.kpi .icon.green  { background: linear-gradient(135deg, #10b981, #059669); }
.kpi .icon.amber  { background: linear-gradient(135deg, #f59e0b, #d97706); }
.kpi .icon.red    { background: linear-gradient(135deg, #ef4444, #dc2626); }
.kpi .icon.violet { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.kpi .icon.teal   { background: linear-gradient(135deg, #14b8a6, #0d9488); }

.kpi .val { font-size: 23px; font-weight: 800; line-height: 1.15; letter-spacing: -.3px; }
.kpi .lbl { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .lbl i { margin-right: 4px; font-size: 11px; }

/* ---------- Grid rows ---------- */
.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 18px; margin-bottom: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; margin-bottom: 24px; }

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

/* ---------- Staff photo cards ---------- */
.staff-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
  gap: 18px;
  padding: 18px;
}

.staff-card {
  background: var(--card);
  border: 1px solid #eef2f7;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform .18s ease, box-shadow .18s ease;
}

.staff-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.staff-card .staff-photo {
  height: 150px;
  background: linear-gradient(135deg, var(--surface2), #eef2f7);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.staff-card .staff-photo img {
  width: 100%;
  height: calc(100% - 8px);
  object-fit: cover;
  display: block;
}

.staff-card .staff-photo .avatar {
  width: 84px;
  height: 84px;
  font-size: 30px;
}

.staff-card .staff-status {
  position: absolute;
  top: 10px;
  right: 10px;
}

.staff-card .staff-body {
  padding: 14px 16px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.staff-card .staff-name { font-weight: 700; font-size: 15px; }
.staff-card .staff-code { color: var(--muted); font-size: 12px; margin-top: 2px; }

.staff-card .staff-meta {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--muted);
  display: grid;
  gap: 6px;
}

.staff-card .staff-meta i { width: 16px; margin-right: 6px; color: #94a3b8; }

.staff-card .staff-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #f1f5f9;
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: #f8fafc;
}

td {
  padding: 12px 18px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13.5px;
  vertical-align: middle;
}

tbody tr { transition: background .12s; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }

td .main { font-weight: 600; }
td .sub { color: var(--muted); font-size: 12px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge-green  { background: #d1fae5; color: #047857; }
.badge-amber  { background: #fef3c7; color: #b45309; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-gray   { background: #e2e8f0; color: #475569; }
.badge-violet { background: #ede9fe; color: #6d28d9; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  transition: transform .12s, box-shadow .12s, background .15s;
  white-space: nowrap;
}

.btn:active { transform: scale(.97); }

.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 6px 14px -6px rgba(14, 165, 233, .6); }
.btn-primary:hover { background: var(--brand-dark); }

.btn-secondary { background: #f1f5f9; color: #334155; }
.btn-secondary:hover { background: #e2e8f0; }

.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }

.btn-ghost { background: none; color: var(--muted); }
.btn-ghost:hover { background: #f1f5f9; color: var(--ink); }

.btn-success { background: var(--green); color: #fff; box-shadow: 0 6px 14px -6px rgba(16, 185, 129, .55); }
.btn-success:hover { background: #059669; }

.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  padding: 7px 9px;
  border-radius: 8px;
  transition: background .12s, color .12s;
}

.icon-btn:hover { background: #f1f5f9; color: var(--ink); }
.icon-btn.danger:hover { background: #fee2e2; color: #b91c1c; }

/* ---------- Alerts / flash ---------- */
.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-weight: 500;
  font-size: 13.5px;
  border: 1px solid transparent;
}

.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-danger  { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-info    { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 6px;
}

.field label .req { color: var(--red); }

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, .15);
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }

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

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: none;
  place-items: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.open { display: grid; animation: fadeIn .15s ease; }

.modal {
  background: #fff;
  border-radius: 16px;
  width: min(620px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp .22s ease;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: #fff;
}

.modal-head h3 { font-size: 16px; font-weight: 700; }

.modal-body { padding: 20px 22px; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--line);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ---------- Filter row ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar .search {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}

.toolbar .search i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 13px;
}

.toolbar .search input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-family: inherit;
  font-size: 13.5px;
  transition: border-color .15s, box-shadow .15s;
}

.toolbar .search input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, .15);
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 42px 20px;
  color: var(--muted);
}

.empty i { font-size: 34px; color: #cbd5e1; margin-bottom: 10px; display: block; }
.empty p { font-weight: 500; }

/* ---------- Misc utilities ---------- */
.text-muted { color: var(--muted); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.fw-700 { font-weight: 700; }
.flex { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-16 { margin-top: 16px; }
.mb-24 { margin-bottom: 24px; }
.nowrap { white-space: nowrap; }

.summary-chips { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Login page ---------- */
.login-body {
  box-sizing: border-box;
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(14, 165, 233, .25), transparent 60%),
    radial-gradient(800px 500px at -10% 110%, rgba(139, 92, 246, .22), transparent 60%),
    var(--navy);
  padding: 20px;
  overflow: hidden;
}

.login-card {
  box-sizing: border-box;
  width: min(400px, 100%);
  height: 400px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 34px 32px;
}

.login-card .brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.login-card h1 { font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.login-card .tag { color: var(--muted); font-size: 13px; margin-bottom: 24px; }

.login-card .brand-icon { width: 46px; height: 46px; font-size: 21px; }

.login-card .field input { padding: 12px 14px; }

.login-msg { min-height: 44px; display: flex; align-items: flex-start; }
.login-msg .alert { margin: 0 0 10px; }

.login-hint {
  margin-top: 18px;
  padding: 11px 13px;
  background: #eff6ff;
  border: 1px dashed #bfdbfe;
  border-radius: 10px;
  color: #1e40af;
  font-size: 12.5px;
}

/* ---------- Bus links & detail page ---------- */
.bus-link { color: var(--brand-dark); font-weight: 600; }
.bus-link:hover { text-decoration: underline; }

.view-link {
  color: var(--brand-dark);
  font-weight: 600;
  font-size: 12.5px;
  white-space: nowrap;
  text-decoration: none;
}
.view-link:hover { text-decoration: underline; }

.bus-item .view-link { margin-left: 8px; color: var(--muted); font-size: 14px; }
.bus-item .view-link:hover { color: var(--brand-dark); }

.detail-cell .dl-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.detail-cell .dl-value { font-size: 13.5px; font-weight: 600; margin-top: 2px; }
.detail-cell .dl-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* ---------- Map page ---------- */
.map-grid {
  display: grid;
  grid-template-columns: 1fr 330px;
  gap: 18px;
  height: calc(100vh - 190px);
  min-height: 480px;
}

@media (max-width: 1000px) {
  .map-grid { grid-template-columns: 1fr; height: auto; }
  .map-card { height: 460px; }
}

#map { height: 100%; width: 100%; border-radius: var(--radius); z-index: 1; }

.map-card { position: relative; box-shadow: var(--shadow); border-radius: var(--radius); overflow: hidden; }

.map-legend {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 500;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 10px 14px;
  display: flex;
  gap: 14px;
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

.map-legend .item { display: flex; align-items: center; gap: 6px; }

.map-status-dot { width: 10px; height: 10px; border-radius: 50%; }
.map-status-dot.active { background: var(--green); box-shadow: 0 0 0 3px rgba(16, 185, 129, .25); }
.map-status-dot.maintenance { background: var(--amber); box-shadow: 0 0 0 3px rgba(245, 158, 11, .25); }
.map-status-dot.out_of_service { background: var(--red); box-shadow: 0 0 0 3px rgba(239, 68, 68, .25); }

.bus-panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.bus-panel .panel-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.bus-panel .panel-head h3 { font-size: 15px; font-weight: 700; }

.bus-list { flex: 1; overflow-y: auto; padding: 10px; }

.bus-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 11px;
  cursor: pointer;
  transition: background .12s;
  border: 1px solid transparent;
}

.bus-item:hover { background: #f1f5f9; }

.bus-item .plate {
  font-weight: 700;
  font-size: 13.5px;
  display: block;
}

.bus-item .meta { color: var(--muted); font-size: 12px; }

.bus-item .speed {
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand-dark);
  white-space: nowrap;
}

/* Leaflet popup tweaks */
.leaflet-popup-content { font-family: var(--font); font-size: 13px; line-height: 1.5; }
.leaflet-popup-content .p-plate { font-weight: 800; font-size: 14px; }
.leaflet-popup-content .p-row { display: flex; gap: 6px; align-items: center; color: #475569; margin-top: 2px; }
.leaflet-popup-content .p-row i { width: 14px; color: var(--brand); }

.bus-marker {
  width: 34px;
  height: 34px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 15px;
  border: 3px solid #fff;
  box-shadow: 0 4px 10px rgba(15, 23, 42, .35);
}

.bus-marker i { transform: rotate(45deg); }

.bus-marker.m-active { background: var(--green); }
.bus-marker.m-maintenance { background: var(--amber); }
.bus-marker.m-out_of_service { background: var(--red); }

/* ---------- Responsive ---------- */
@media (max-width: 992px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .hamburger { display: block; }
  .content { padding: 18px; }
  .topbar { padding: 0 18px; }
  .today { display: none; }
}
