@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&family=Syne:wght@700;800&display=swap');

:root {
  --navy: #0f1729;
  --navy-mid: #1a2744;
  --navy-light: #243358;
  --red: #e63946;
  --red-dark: #c1121f;
  --red-glow: rgba(230,57,70,0.15);
  --gold: #f4a261;
  --green: #2a9d8f;
  --green-light: #52b788;
  --white: #f8f9fc;
  --grey: #8892a4;
  --grey-light: #c5cdd9;
  --card: rgba(26,39,68,0.85);
  --border: rgba(255,255,255,0.07);
  --shadow: 0 8px 32px rgba(0,0,0,0.35);
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: 'Syne', sans-serif;
  --font-body: 'DM Sans', sans-serif;
  --sidebar-w: 240px;
}

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

html, body {
  height: 100%;
  font-family: var(--font-body);
  background: var(--navy);
  color: var(--white);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ─── Layout ──────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: linear-gradient(180deg, #111d3a 0%, #0d1524 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
  transition: transform 0.25s ease;
}

.sidebar-logo {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo .logo-icon {
  width: 36px; height: 36px;
  background: var(--red);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  margin-bottom: 10px;
}

.sidebar-logo h1 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 800;
  color: var(--white);
  letter-spacing: 0.3px;
  line-height: 1.2;
}

.sidebar-logo p {
  font-size: 10px;
  color: var(--grey);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 2px;
}

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

.nav-section-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--grey);
  padding: 12px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--grey-light);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.18s ease;
  text-decoration: none;
  margin-bottom: 2px;
}

.nav-item:hover { background: rgba(255,255,255,0.06); color: var(--white); }
.nav-item.active { background: var(--red-glow); color: var(--red); border-left: 2px solid var(--red); padding-left: 10px; }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }
.nav-item .badge { margin-left: auto; background: var(--red); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 10px; }

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}
.user-info:hover { background: rgba(255,255,255,0.05); }
.user-avatar { width: 30px; height: 30px; background: var(--navy-light); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--grey-light); }
.user-name { font-size: 12px; font-weight: 600; }
.user-role { font-size: 10px; color: var(--grey); }

/* ─── Main content ────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: radial-gradient(ellipse at 70% 0%, rgba(230,57,70,0.04) 0%, transparent 50%), var(--navy);
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(15,23,41,0.6);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
  gap: 12px;
}

.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-title { font-family: var(--font-display); font-size: 18px; font-weight: 800; white-space: nowrap; }
.topbar-sub { font-size: 11px; color: var(--grey); margin-top: 1px; white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* Hamburger (mobile only) */
.btn-hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--white);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9;
  backdrop-filter: blur(2px);
}

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  scroll-behavior: smooth;
}

/* ─── Cards & panels ─────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  padding: 20px;
}

.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-family: var(--font-display); font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 8px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}

.stat-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; }
.stat-card.red::before { background: var(--red); }
.stat-card.green::before { background: var(--green); }
.stat-card.gold::before { background: var(--gold); }
.stat-card.blue::before { background: #4cc9f0; }

.stat-icon { font-size: 20px; margin-bottom: 6px; }
.stat-value { font-family: var(--font-display); font-size: 26px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 10px; color: var(--grey); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ─── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

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

thead th {
  background: rgba(255,255,255,0.04);
  padding: 10px 12px;
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--grey);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid rgba(255,255,255,0.03); transition: background 0.12s; }
tbody tr:hover { background: rgba(255,255,255,0.03); }
tbody td { padding: 10px 12px; vertical-align: middle; color: var(--grey-light); }
tbody td:first-child { color: var(--white); font-weight: 500; }

/* ─── Status badges ───────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.out { background: rgba(230,57,70,0.15); color: var(--red); }
.badge.returned { background: rgba(42,157,143,0.15); color: var(--green-light); }
.badge.alert { background: rgba(244,162,97,0.15); color: var(--gold); }

/* ─── Vehicle cards ───────────────────────────────────────── */
.vehicle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }

.vehicle-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.vehicle-card:hover { border-color: rgba(255,255,255,0.15); transform: translateY(-2px); box-shadow: var(--shadow); }
.vehicle-card.out { border-color: rgba(230,57,70,0.35); background: rgba(230,57,70,0.05); }
.vehicle-card.available { border-color: rgba(42,157,143,0.25); }

.vehicle-icon { font-size: 26px; margin-bottom: 8px; }
.vehicle-name { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.vehicle-plate { font-size: 11px; color: var(--grey); font-family: monospace; letter-spacing: 1px; }
.vehicle-km { font-size: 11px; color: var(--grey); margin-top: 4px; }
.progress-bar { height: 4px; background: rgba(255,255,255,0.08); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 2px; transition: width 0.3s; }

/* ─── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm); border: none;
  cursor: pointer; font-family: var(--font-body); font-size: 13px; font-weight: 600;
  transition: all 0.15s; text-decoration: none; white-space: nowrap;
}

.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); transform: translateY(-1px); }
.btn-secondary { background: rgba(255,255,255,0.08); color: var(--white); border: 1px solid var(--border); }
.btn-secondary:hover { background: rgba(255,255,255,0.13); }
.btn-success { background: rgba(42,157,143,0.2); color: var(--green-light); border: 1px solid rgba(42,157,143,0.3); }
.btn-success:hover { background: rgba(42,157,143,0.3); }
.btn-danger { background: rgba(230,57,70,0.15); color: var(--red); border: 1px solid rgba(230,57,70,0.25); }
.btn-danger:hover { background: rgba(230,57,70,0.25); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); background: rgba(255,255,255,0.06); border: 1px solid var(--border); color: var(--grey-light); cursor: pointer; transition: all 0.15s; font-size: 14px; }
.btn-icon:hover { background: rgba(255,255,255,0.12); color: var(--white); }
.btn-full { width: 100%; justify-content: center; }

/* ─── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

label { display: block; font-size: 11px; font-weight: 600; color: var(--grey); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 6px; }

input[type="text"], input[type="number"], input[type="date"], input[type="time"],
input[type="email"], input[type="password"], select, textarea {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 9px 12px;
  transition: all 0.15s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

/* Bigger touch targets on mobile */
@media (max-width: 768px) {
  input[type="text"], input[type="number"], input[type="date"], input[type="time"],
  input[type="email"], input[type="password"], select, textarea {
    font-size: 16px; /* prevents iOS zoom */
    padding: 12px 14px;
  }
  .btn { padding: 11px 18px; font-size: 14px; }
  .btn-sm { padding: 8px 12px; font-size: 13px; }
}

input:focus, select:focus, textarea:focus {
  border-color: var(--red);
  background: rgba(255,255,255,0.08);
  box-shadow: 0 0 0 3px var(--red-glow);
}

select option { background: var(--navy-mid); }
textarea { resize: vertical; min-height: 70px; }

.form-check { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: rgba(255,255,255,0.04); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
.form-check input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--red); cursor: pointer; flex-shrink: 0; }
.form-check label { margin: 0; text-transform: none; font-size: 13px; color: var(--white); cursor: pointer; letter-spacing: 0; font-weight: 500; }

/* ─── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
  padding: 16px;
}

.modal-overlay.show { opacity: 1; pointer-events: all; }

.modal {
  background: var(--navy-mid);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px) scale(0.97);
  transition: transform 0.2s;
  -webkit-overflow-scrolling: touch;
}

.modal-overlay.show .modal { transform: none; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-title { font-family: var(--font-display); font-size: 17px; font-weight: 800; }
.modal-close { background: none; border: none; color: var(--grey); cursor: pointer; font-size: 20px; line-height: 1; transition: color 0.15s; padding: 4px; }
.modal-close:hover { color: var(--white); }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ─── OCR Camera widget ───────────────────────────────────── */
.ocr-zone {
  border: 2px dashed rgba(230,57,70,0.4);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  background: rgba(230,57,70,0.04);
  margin-bottom: 12px;
}

.ocr-preview {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  display: none;
}

.ocr-result-box {
  display: none;
  align-items: center;
  gap: 10px;
  background: rgba(42,157,143,0.12);
  border: 1px solid rgba(42,157,143,0.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-top: 10px;
}

.ocr-result-box .ocr-km { font-family: var(--font-display); font-size: 22px; font-weight: 800; color: var(--green-light); }
.ocr-spinner { display: none; text-align: center; padding: 12px; color: var(--grey); font-size: 13px; }

/* ─── Alert banner ────────────────────────────────────────── */
.alert-banner { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 13px; }
.alert-banner.warning { background: rgba(244,162,97,0.12); border: 1px solid rgba(244,162,97,0.25); color: var(--gold); }
.alert-banner.error { background: rgba(230,57,70,0.1); border: 1px solid rgba(230,57,70,0.25); color: var(--red); }
.alert-banner.success { background: rgba(42,157,143,0.12); border: 1px solid rgba(42,157,143,0.25); color: var(--green-light); }

/* ─── Toast ───────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }

.toast {
  background: var(--navy-mid); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 16px; font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 320px;
  animation: slideIn 0.2s ease; box-shadow: var(--shadow);
}
.toast.success { border-color: rgba(42,157,143,0.4); }
.toast.error { border-color: rgba(230,57,70,0.4); }
.toast.info { border-color: rgba(76,201,240,0.3); }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Login page ──────────────────────────────────────────── */
#login-page {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 30% 50%, rgba(230,57,70,0.08) 0%, transparent 50%), var(--navy);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}

.login-box { width: 100%; max-width: 380px; padding: 32px; }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo .logo-icon { width: 56px; height: 56px; background: var(--red); border-radius: 16px; display: flex; align-items: center; justify-content: center; font-size: 26px; margin: 0 auto 14px; }
.login-logo h1 { font-family: var(--font-display); font-size: 22px; font-weight: 800; }
.login-logo p { color: var(--grey); font-size: 12px; margin-top: 4px; }

/* ─── Tabs ────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; margin-bottom: 16px; border-bottom: 1px solid var(--border); padding-bottom: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab-btn { padding: 8px 14px; background: none; border: none; border-bottom: 2px solid transparent; color: var(--grey); cursor: pointer; font-family: var(--font-body); font-size: 13px; font-weight: 600; margin-bottom: -1px; transition: all 0.15s; white-space: nowrap; }
.tab-btn:hover { color: var(--white); }
.tab-btn.active { color: var(--red); border-bottom-color: var(--red); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── Mobile bottom nav ───────────────────────────────────── */
#mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #0d1524;
  border-top: 1px solid var(--border);
  z-index: 50;
  padding: 6px 0 env(safe-area-inset-bottom, 6px);
}

.mobile-nav-items { display: flex; }

.mobile-nav-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 6px 4px;
  cursor: pointer;
  color: var(--grey);
  font-size: 10px; font-weight: 600;
  gap: 3px;
  transition: color 0.15s;
  background: none; border: none; font-family: var(--font-body);
  text-transform: uppercase; letter-spacing: 0.5px;
}

.mobile-nav-item .m-icon { font-size: 20px; line-height: 1; }
.mobile-nav-item.active { color: var(--red); }

/* ─── Mobile FAB (floating action button) ─────────────────── */
.mobile-fab {
  display: none;
  position: fixed;
  bottom: 80px; right: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  border: none;
  font-size: 26px;
  cursor: pointer;
  z-index: 49;
  box-shadow: 0 4px 20px rgba(230,57,70,0.4);
  align-items: center; justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
}
.mobile-fab:active { transform: scale(0.93); }

/* ─── Misc ────────────────────────────────────────────────── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.section-title { font-family: var(--font-display); font-size: 15px; font-weight: 800; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.text-muted { color: var(--grey); }
.text-red { color: var(--red); }
.text-green { color: var(--green-light); }
.text-gold { color: var(--gold); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--grey); }
.empty-state .icon { font-size: 36px; margin-bottom: 10px; opacity: 0.4; }
.empty-state p { font-size: 14px; }
.km-alert-pill { display: inline-flex; align-items: center; gap: 5px; background: rgba(244,162,97,0.15); color: var(--gold); border-radius: 20px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.mt-4 { margin-top: 16px; }

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE MOBILE  (≤ 768px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  html, body { overflow: hidden; }

  /* Hide desktop sidebar, show hamburger */
  #sidebar { position: fixed; top: 0; left: 0; height: 100vh; z-index: 20; transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); box-shadow: 4px 0 30px rgba(0,0,0,0.5); }
  .sidebar-overlay.open { display: block; }
  .btn-hamburger { display: flex !important; align-items: center; }

  /* Main takes full width */
  #main { width: 100%; }

  /* Topbar compact */
  .topbar { padding: 10px 14px; }
  .topbar-title { font-size: 15px; }
  .topbar-sub { display: none; }
  .topbar-actions { display: none; } /* hidden on mobile — use FAB instead */

  /* Page content with bottom nav space */
  .page-content { padding: 14px 14px 90px; }

  /* Show mobile nav */
  #mobile-bottom-nav { display: block; }
  .mobile-fab { display: flex; }

  /* Stat grid 2 cols on mobile */
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-value { font-size: 22px; }
  .stat-icon { font-size: 16px; margin-bottom: 4px; }

  /* Vehicle grid single col */
  .vehicle-grid { grid-template-columns: 1fr; }

  /* Forms single col */
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .form-row-3 { grid-template-columns: 1fr; gap: 0; }

  /* Modal full screen on mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: 20px 20px 0 0; max-height: 95vh; padding: 20px 18px; }
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; justify-content: center; }

  /* Grid 2 single col */
  .grid-2 { grid-template-columns: 1fr; }

  /* Hide toast on very small screens if needed */
  #toast-container { bottom: 90px; right: 12px; left: 12px; }
  .toast { min-width: unset; max-width: 100%; }

  /* Table horizontal scroll hint */
  .table-wrap::after {
    content: '';
    display: block;
    height: 1px;
  }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .vehicle-card { padding: 14px; }
}
