:root {
  --navy: #16243F;
  --navy-light: #233A63;
  --amber: #E8871E;
  --amber-dark: #C56F12;
  --green: #2F9E44;
  --red: #D64545;
  --bg: #F3F4F7;
  --surface: #FFFFFF;
  --text: #1A1D29;
  --text-muted: #69707D;
  --border: #E2E4E9;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(22, 36, 63, 0.08), 0 1px 2px rgba(22, 36, 63, 0.06);
}

* { box-sizing: border-box; }

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

a { color: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: transform 0.05s ease, opacity 0.15s ease;
}
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--amber);
  color: #fff;
  padding: 12px 20px;
}
.btn-primary:hover { background: var(--amber-dark); }

.btn-secondary {
  background: var(--surface);
  color: var(--navy);
  border: 1px solid var(--border);
  padding: 11px 18px;
}
.btn-secondary:hover { background: #F8F9FB; }

.btn-danger {
  background: #FBEAEA;
  color: var(--red);
  padding: 9px 14px;
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 10px;
}

input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
  border-color: var(--amber);
}
label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
  margin-bottom: 6px;
}
.field { margin-bottom: 16px; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--navy) 0%, #0D1730 100%);
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.login-brand .mark {
  width: 40px; height: 40px;
  background: var(--navy);
  border-radius: 9px;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1rem;
}
.login-brand .name { font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }
.login-brand .sub { font-size: 0.78rem; color: var(--text-muted); margin-top: -2px; }
.login-error {
  background: #FBEAEA;
  color: var(--red);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 16px;
}
.login-card .btn-primary { width: 100%; margin-top: 6px; }

/* ---------- App shell ---------- */
.topbar {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.topbar .brand .mark {
  width: 30px; height: 30px;
  background: var(--amber);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.8rem; color: var(--navy);
}
.topbar .who { display: flex; align-items: center; gap: 14px; font-size: 0.9rem; }
.topbar .who .name { opacity: 0.9; }
.topbar button.logout {
  background: rgba(255,255,255,0.1);
  color: #fff;
  padding: 8px 14px;
  font-size: 0.85rem;
}
.topbar button.logout:hover { background: rgba(255,255,255,0.18); }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  overflow-x: auto;
}
.tab {
  padding: 14px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  cursor: pointer;
}
.tab.active { color: var(--navy); border-bottom-color: var(--amber); }

.container { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-head h1 { font-size: 1.3rem; margin: 0; letter-spacing: -0.01em; }

/* ---------- Cards / grid ---------- */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  border: 1px solid var(--border);
}
.vehicule-card { cursor: pointer; }
.vehicule-card:hover { border-color: var(--amber); }
.vehicule-card .plate {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  margin-bottom: 2px;
}
.vehicule-card .meta { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 12px; }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 100px;
  background: #EEF1F6;
  color: var(--text-muted);
}
.badge.ok { background: #E7F6EA; color: var(--green); }
.badge.soon { background: #FFF1E0; color: var(--amber-dark); }
.badge.urgent { background: #FDEAEA; color: var(--red); }
.badge.overdue { background: var(--red); color: #fff; }

.cat-dot {
  width: 9px; height: 9px; border-radius: 50%; display: inline-block;
}

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
thead th {
  text-align: left;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: #FAFBFC; }
.table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(13, 20, 38, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 16px;
}
.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px;
}
.modal h2 { margin: 0 0 4px; font-size: 1.15rem; }
.modal .modal-sub { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 20px; }
.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: transparent; color: var(--text-muted); font-size: 1.3rem; padding: 4px 8px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.section-block { margin-bottom: 26px; }
.section-block h3 {
  font-size: 0.95rem;
  margin: 0 0 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.hist-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.88rem;
}
.hist-row:last-child { border-bottom: none; }
.hist-row .date { color: var(--text-muted); font-size: 0.8rem; }
.hist-row .cout { font-weight: 700; color: var(--navy); }
.hist-actions { display: flex; gap: 6px; }
.hist-actions button { padding: 5px 8px; font-size: 0.78rem; }

.empty-state {
  text-align: center; padding: 50px 20px; color: var(--text-muted);
}
.empty-state .big { font-size: 2rem; margin-bottom: 8px; }

/* ---------- Driver view ---------- */
.driver-shell { max-width: 560px; margin: 0 auto; padding: 18px 16px 80px; }
.driver-vehicule-banner {
  background: var(--navy);
  color: #fff;
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 18px;
}
.driver-vehicule-banner .label { font-size: 0.78rem; opacity: 0.75; text-transform: uppercase; letter-spacing: 0.05em; }
.driver-vehicule-banner .plate { font-size: 1.6rem; font-weight: 800; margin-top: 2px; }

.driver-cat-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.driver-cat-card .left { display: flex; align-items: center; gap: 12px; }
.driver-cat-card .cat-label { font-weight: 700; font-size: 0.98rem; }
.driver-cat-card .cat-date { font-size: 0.8rem; color: var(--text-muted); }

.fab {
  position: fixed;
  bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--amber);
  color: #fff;
  padding: 16px 26px;
  border-radius: 100px;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(232,135,30,0.45);
  max-width: 520px;
  width: calc(100% - 32px);
}

.req-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 8px;
}
.req-item .top-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.req-item .titre { font-weight: 600; font-size: 0.92rem; }
.req-item .date { font-size: 0.76rem; color: var(--text-muted); margin-top: 2px; }

.status-pill {
  font-size: 0.72rem; font-weight: 700; padding: 3px 9px; border-radius: 100px; white-space: nowrap;
}
.status-pill.en_attente { background: #FFF1E0; color: var(--amber-dark); }
.status-pill.fait { background: #E7F6EA; color: var(--green); }
.status-pill.planifie { background: #EAF0FB; color: #3B5BA9; }

.loading-spin {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--navy); color: #fff;
  padding: 12px 18px; border-radius: 8px; font-size: 0.9rem;
  box-shadow: var(--shadow); z-index: 100;
}
.toast.error { background: var(--red); }

@media (max-width: 640px) {
  .row-2 { grid-template-columns: 1fr; }
  .container { padding: 16px 12px 60px; }
}
