:root {
  --brand: #4b96ab;
  --brand-dark: #357a8f;
  --brand-light: #6daabc;
  --brand-muted: #c0dbe7;
  --sidebar: #353638;
  --sidebar-hover: #434548;
  --sidebar-active: #4b96ab;
  --surface: #f8f9fb;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 8px 30px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  background: var(--surface);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--brand-dark); text-decoration: none; }
a:hover { color: var(--brand); }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  background: var(--sidebar);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1000;
  transition: transform .25s ease;
}

.sidebar-brand {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar-brand .logo-mark {
  width: 44px; height: 44px;
  background: #fff;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: .75rem;
  vertical-align: middle;
  padding: 4px;
  overflow: hidden;
}
.sidebar-brand .logo-mark img { max-width: 100%; max-height: 100%; object-fit: contain; }

.sidebar-brand .brand-text { display: inline-block; vertical-align: middle; }
.sidebar-brand .brand-name { color: #fff; font-weight: 700; font-size: 1rem; line-height: 1.2; }
.sidebar-brand .brand-tagline { font-size: .7rem; color: #94a3b8; }

.sidebar-nav { flex: 1; padding: 1rem .75rem; overflow-y: auto; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem 1rem;
  border-radius: 8px;
  color: #94a3b8;
  font-weight: 500;
  font-size: .9rem;
  margin-bottom: 2px;
  transition: all .15s;
}
.sidebar-nav a i { font-size: 1.1rem; width: 1.25rem; text-align: center; }
.sidebar-nav a:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.sidebar-nav a.active { background: rgba(75, 150, 171, 0.2); color: #fff; border-left: 3px solid var(--brand-light); }
.sidebar-nav a.active i { color: var(--brand-light); }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.06);
  font-size: .8rem;
}

.main-area {
  flex: 1;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: .875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-title { font-weight: 600; font-size: 1.05rem; }

.nav-back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  flex-shrink: 0;
  transition: background .15s, border-color .15s, color .15s;
}
.nav-back-btn:hover {
  background: var(--brand-muted);
  border-color: var(--brand-light);
  color: var(--brand-dark);
}
.driver-header .nav-back-btn {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}
.driver-header .nav-back-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.4);
  color: #fff;
}

.topbar-user { display: flex; align-items: center; gap: 1rem; font-size: .875rem; }
.role-badge {
  background: var(--brand-muted);
  color: var(--brand-dark);
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}

.content-area { padding: 1.5rem; flex: 1; }

/* Cards & stats */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
  font-weight: 600;
  font-size: .95rem;
}

.card-body { padding: 1.25rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand), var(--brand-light));
}

.stat-card .stat-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--brand-muted);
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  margin-bottom: .75rem;
}

.stat-label {
  font-size: .75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-header h1 { font-size: 1.5rem; font-weight: 700; margin: 0; }

.report-card {
  transition: box-shadow .15s, border-color .15s;
  border: 1px solid var(--border);
}
.report-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--brand-light);
}
.report-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--brand-muted);
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.finance-tabs {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding-bottom: .75rem;
}

.finance-tab {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .9rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: .875rem;
  border: 1px solid transparent;
}

.finance-tab:hover {
  color: var(--brand-dark);
  background: rgba(232, 93, 4, .06);
}

.finance-tab.active {
  color: var(--brand-dark);
  background: rgba(232, 93, 4, .12);
  border-color: rgba(232, 93, 4, .25);
}

/* Buttons */
.btn-brand {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  border: none;
  color: #fff;
  font-weight: 600;
  border-radius: 8px;
  padding: .5rem 1rem;
}
.btn-brand:hover { color: #fff; opacity: .92; transform: translateY(-1px); }

.btn-outline-brand {
  border: 1.5px solid var(--brand);
  color: var(--brand-dark);
  background: transparent;
  font-weight: 600;
  border-radius: 8px;
}
.btn-outline-brand:hover { background: var(--brand-muted); color: var(--brand-dark); }

/* Tables */
.table { margin-bottom: 0; }
.table thead th {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom-width: 1px;
  background: #f8fafc;
}
.table tbody tr:hover { background: #fafbfc; }

/* Status badges */
.badge { font-weight: 600; font-size: .72rem; padding: .35em .65em; border-radius: 6px; }
.badge.status-draft { background: #e2e8f0; color: #475569; }
.badge.status-quoted, .badge.status-sent { background: #e0f2fe; color: #0369a1; }
.badge.status-confirmed, .badge.status-pending { background: #fef3c7; color: #b45309; }
.badge.status-in_progress, .badge.status-dispatched, .badge.status-in_transit { background: #dbeafe; color: #1d4ed8; }
.badge.status-completed, .badge.status-delivered, .badge.status-paid { background: #dcfce7; color: #15803d; }
.badge.status-cancelled { background: #fee2e2; color: #b91c1c; }
.badge.status-partial, .badge.status-overdue { background: #ffedd5; color: #c2410c; }
.badge.status-available { background: #dcfce7; color: #15803d; }
.badge.status-on_trip { background: #dbeafe; color: #1d4ed8; }
.badge.status-maintenance, .badge.status-out_of_service { background: #fee2e2; color: #b91c1c; }

/* Forms */
.form-control, .form-select {
  border-radius: 8px;
  border-color: var(--border);
  padding: .55rem .875rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(232, 93, 4, .15);
}

/* Map */
#map { height: 480px; border-radius: var(--radius); border: 1px solid var(--border); }

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #353638 0%, #4b96ab 100%);
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.login-header {
  background: #fff;
  color: var(--text);
  padding: 2rem;
  text-align: center;
  border-bottom: 3px solid var(--brand);
}

.login-header .logo-mark {
  width: 80px; height: 80px;
  margin: 0 auto 1rem;
}
.login-header .logo-mark img { max-width: 100%; max-height: 100%; }

.login-body { padding: 2rem; }

/* Driver mobile */
.driver-shell { min-height: 100vh; background: var(--surface); padding-bottom: 80px; }
.driver-header {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  padding: 1.25rem 1rem 1.75rem;
}
.driver-header h1 { font-size: 1.25rem; font-weight: 700; margin: 0; }
.driver-trip-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1rem;
  margin-bottom: .75rem;
  box-shadow: var(--shadow);
}
.driver-trip-card .trip-reg {
  font-weight: 700;
  font-size: 1.1rem;
}
.driver-bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: .75rem;
  z-index: 100;
}
.driver-bottom-nav a {
  text-align: center;
  color: var(--text-muted);
  font-size: .75rem;
  font-weight: 600;
}
.driver-bottom-nav a i { display: block; font-size: 1.35rem; margin-bottom: 2px; }
.driver-bottom-nav a.active { color: var(--brand); }

.signature-pad {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
  touch-action: none;
  width: 100%;
  height: 180px;
  cursor: crosshair;
}

.gps-stat {
  text-align: center;
  padding: 1rem;
  background: #f8fafc;
  border-radius: 8px;
}
.gps-stat .val { font-size: 1.5rem; font-weight: 800; color: var(--brand-dark); }
.gps-stat .lbl { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; }

/* Mobile sidebar toggle */
.sidebar-toggle { display: none; background: none; border: none; font-size: 1.25rem; color: var(--text); }

@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 999;
  }
  .sidebar-overlay.show { display: block; }
}
