/* ==========================================================
   Car Mileage Tracker — mobile-first stylesheet
   Breakpoints: 480px (phones), 768px (tablet), 1024px (desktop)
   ========================================================== */

:root {
  --bg: #0f1220;
  --bg-alt: #151a2e;
  --surface: #1b2140;
  --surface-alt: #212850;
  --border: #2b3260;
  --text: #eef0fb;
  --text-muted: #9aa1c7;
  --primary: #7c5cff;
  --primary-2: #4dd0e1;
  --accent-grad: linear-gradient(135deg, #7c5cff 0%, #4dd0e1 100%);
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #fb7185;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --topbar-h: 60px;
  --sidebar-w: 240px;
  --footer-h: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background: radial-gradient(1200px 600px at 10% -10%, #23295a 0%, transparent 60%),
              radial-gradient(1000px 500px at 110% 10%, #1a3a4a 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  font-family: 'Poppins', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
img, svg { max-width: 100%; display: block; }

/* ---------------- App shell ---------------- */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: rgba(21, 26, 46, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 1.05rem;
  white-space: nowrap;
}

.brand-mark { font-size: 1.4rem; }

.topbar-vehicle { flex: 1; min-width: 0; text-align: center; }

.vehicle-chip {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.notif-bell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
}

.notif-bell:hover { background: var(--surface); }

.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.hamburger {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 44px;
  height: 44px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.hamburger span {
  display: block;
  height: 2px;
  margin: 0 9px;
  background: var(--text);
  border-radius: 2px;
}

/* Side / top navigation */

.sidenav {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
  position: sticky;
  top: var(--topbar-h);
  z-index: 20;
}

.sidenav-scroll {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.sidenav-scroll::-webkit-scrollbar { height: 4px; }
.sidenav-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  flex: 0 0 auto;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover { background: var(--surface); color: var(--text); }

.nav-link.active {
  background: var(--accent-grad);
  color: #fff;
}

.sidenav-footer {
  display: none;
}

.user-chip {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 8px 14px;
}

/* ---------------- Main content ---------------- */

.main-content {
  flex: 1 1 auto;
  width: 100%;
  padding: 16px 16px calc(16px + var(--footer-h));
  max-width: 1200px;
  margin: 0 auto;
}

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

.page-header h1 {
  font-size: 1.4rem;
  margin: 0;
}

.page-header p.subtitle {
  color: var(--text-muted);
  margin: 4px 0 0;
  font-size: 0.9rem;
}

/* ---------------- Grid / cards ---------------- */

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card h2, .card h3 {
  margin-top: 0;
  font-size: 1rem;
  font-weight: 600;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-card .stat-icon { font-size: 1.6rem; }

.stat-card .stat-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-card .stat-label {
  color: var(--text-muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.chart-card canvas {
  width: 100% !important;
  max-width: 100%;
}

.chart-container {
  position: relative;
  width: 100%;
  height: 240px;
}

@media (min-width: 768px) {
  .chart-container { height: 300px; }
}

/* ---------------- Forms ---------------- */

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

.form-field { display: flex; flex-direction: column; gap: 6px; }

.form-field label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

textarea { min-height: 90px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.25);
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.checkbox-field input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
  text-align: center;
}

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

.btn-primary { background: var(--accent-grad); color: #fff; }
.btn-secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-danger { background: rgba(251, 113, 133, 0.15); color: var(--danger); border-color: rgba(251, 113, 133, 0.4); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 14px; font-size: 0.82rem; }

.btn:hover { opacity: 0.92; }

/* ---------------- Tables ---------------- */

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  text-align: left;
  padding: 12px 14px;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

tbody td {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

.table-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
}

/* Badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}

.badge-ok { background: rgba(52, 211, 153, 0.15); color: var(--ok); }
.badge-warn { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.badge-danger { background: rgba(251, 113, 133, 0.15); color: var(--danger); }
.badge-muted { background: rgba(154, 161, 199, 0.15); color: var(--text-muted); }

/* Alert summary counters */

.alert-counters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.alert-counter {
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  border: 1px solid var(--border);
}

.alert-counter .count { font-size: 1.4rem; font-weight: 700; }
.alert-counter .label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; }

/* ---------------- Flash messages ---------------- */

.flash-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  border: 1px solid transparent;
}

.flash-success { background: rgba(52, 211, 153, 0.12); color: var(--ok); border-color: rgba(52, 211, 153, 0.3); }
.flash-error { background: rgba(251, 113, 133, 0.12); color: var(--danger); border-color: rgba(251, 113, 133, 0.3); }
.flash-info { background: rgba(77, 208, 225, 0.12); color: var(--primary-2); border-color: rgba(77, 208, 225, 0.3); }
.flash-warning { background: rgba(251, 191, 36, 0.12); color: var(--warn); border-color: rgba(251, 191, 36, 0.3); }

.field-error { color: var(--danger); font-size: 0.78rem; margin-top: -2px; }

/* ---------------- Auth pages (login/register) ---------------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 18px;
  font-size: 1.3rem;
  font-weight: 700;
}

.auth-switch {
  text-align: center;
  margin-top: 16px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.auth-switch a { color: var(--primary-2); font-weight: 600; }

/* Vehicle picker */

.vehicle-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.vehicle-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vehicle-card h3 { margin: 0; }
.vehicle-card .meta { color: var(--text-muted); font-size: 0.85rem; }

/* ---------------- Footer ---------------- */

.app-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  text-align: center;
  padding: 0 16px;
  color: var(--text-muted);
  font-size: 0.78rem;
  background: rgba(21, 26, 46, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  z-index: 25;
}

.app-footer p {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Slide-in drawer nav below tablet breakpoint */
.nav-backdrop { display: none; }

@media (max-width: 767.98px) {
  .sidenav {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: var(--footer-h);
    width: min(82vw, 300px);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-bottom: none;
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    z-index: 45;
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.45);
    overflow-y: auto;
  }
  .sidenav.open {
    transform: translateX(0);
  }
  .sidenav-scroll {
    flex-direction: column;
    align-items: stretch;
    overflow-x: visible;
    padding: 12px;
  }
  .sidenav-footer {
    display: block;
    border-top: 1px solid var(--border);
    padding: 10px;
  }
  .nav-backdrop {
    display: block;
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 7, 20, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
    z-index: 40;
  }
  .nav-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }
}

/* ==========================================================
   Breakpoints
   ========================================================== */

/* Small phones */
@media (min-width: 480px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
}

/* Tablet */
@media (min-width: 768px) {
  .main-content { padding: 24px 24px calc(24px + var(--footer-h)); }
  .grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
  .form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
  .form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
  .vehicle-grid { grid-template-columns: repeat(2, 1fr); }
  .hamburger { display: none; }
}

/* Desktop: sidebar layout */
@media (min-width: 1024px) {
  .app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
      "topbar topbar"
      "sidenav main";
    min-height: 100vh;
  }

  .topbar { grid-area: topbar; }
  .sidenav {
    grid-area: sidenav;
    position: sticky;
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h) - var(--footer-h));
    border-bottom: none;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }
  .sidenav-scroll {
    flex-direction: column;
    overflow-x: visible;
    overflow-y: auto;
    padding: 16px 10px;
  }
  .nav-link { padding: 12px 14px; }
  .sidenav-footer { display: block; border-top: 1px solid var(--border); padding: 10px; }
  .main-content { grid-area: main; padding: 32px 32px calc(32px + var(--footer-h)); max-width: 1200px; width: 100%; }

  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
}

/* Utility */
.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hidden { display: none !important; }
