:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1c2433;
  --muted: #6b7689;
  --line: #e4e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
}

:root[data-theme="dark"] {
  --bg: #0f1521;
  --card: #18202f;
  --ink: #e6eaf2;
  --muted: #93a0b5;
  --line: #2a3447;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --green: #34d399; --green-bg: #0c3a2c;
  --amber: #fbbf24; --amber-bg: #3a2e0c;
  --red: #f87171; --red-bg: #3a1414;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
}
:root[data-theme="dark"] .google-btn,
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] .btn { background: #1f2a3d; color: var(--ink); }
:root[data-theme="dark"] .btn.primary { background: var(--primary); }
:root[data-theme="dark"] th { background: #141b28; }
:root[data-theme="dark"] tbody tr:hover { background: #1d2738; }

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); padding: 0 24px; height: 60px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
/* ---------- Menu utilisateur ---------- */
.user-menu { display: flex; align-items: center; gap: 10px; }
.user-menu img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.user-menu .uname { font-weight: 600; font-size: 13px; }
.user-menu .uname small { display: block; color: var(--muted); font-weight: 500; }

/* ---------- Page de connexion ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 10px 40px rgba(16,24,40,.12); padding: 40px 36px; width: 100%;
  max-width: 380px; text-align: center; margin: 20px;
}
.login-logo { font-size: 46px; }
.login-card h1 { font-size: 22px; margin: 8px 0 6px; }
.login-sub { color: var(--muted); margin: 0 0 24px; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 11px 16px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font-weight: 600; text-decoration: none; cursor: pointer;
}
.google-btn:hover { background: var(--bg); box-shadow: var(--shadow); }
.login-note { margin-top: 20px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.login-note a { color: var(--primary); font-weight: 600; }
.login-form { display: grid; gap: 14px; text-align: left; }
.login-form .field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.login-form input { width: 100%; }
.btn.block { width: 100%; justify-content: center; }
.login-sep { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 18px 0; font-size: 13px; }
.login-sep::before, .login-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.login-foot { margin-top: 18px; font-size: 13px; }
.login-foot a { color: var(--primary); font-weight: 600; text-decoration: none; }
.login-ok { background: var(--green-bg); color: var(--green); padding: 12px 14px; border-radius: 9px; font-weight: 600; margin-bottom: 16px; }

/* ---------- Entités ---------- */
.entities-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 700px) { .entities-grid { grid-template-columns: 1fr; } }
.entity-col { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
.entity-col h3 { margin: 0 0 14px; font-size: 16px; }
.entity-add { display: flex; gap: 8px; margin-bottom: 14px; }
.entity-add input { flex: 1; }
.entity-list { list-style: none; margin: 0; padding: 0; }
.entity-list li { display: flex; align-items: center; justify-content: space-between; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.entity-list li:last-child { border-bottom: none; }
.entity-list .ecount { color: var(--muted); font-size: 12px; margin-left: 8px; }

/* ---------- Paramètres compte ---------- */
.modal.modal-lg { max-width: 560px; }
.modal.modal-xl { max-width: 820px; }

/* ---------- Indicateurs de politique de mot de passe ---------- */
.pw-policy { list-style: none; margin: 8px 0 0; padding: 0; font-size: 12.5px; }
.pw-policy li { padding: 2px 0; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.pw-policy li::before { content: "○"; color: var(--muted); font-weight: 700; }
.pw-policy li.ok { color: var(--green); }
.pw-policy li.ok::before { content: "✓"; color: var(--green); }
.switch-row { display: flex; align-items: center; justify-content: space-between; }
.switch { position: relative; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch .slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.settings-body { padding: 20px 22px; display: grid; gap: 22px; max-height: 75vh; overflow-y: auto; }
.settings-section { border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.settings-section h4 { margin: 0 0 12px; font-size: 14px; }
.settings-section .field { margin-bottom: 10px; }
.settings-section .field label { font-size: 12.5px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
.settings-section input { width: 100%; }
.pk-list { list-style: none; margin: 10px 0 0; padding: 0; }
.pk-list li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.qr-box { text-align: center; }
.qr-box svg { width: 180px; height: 180px; }
.qr-secret { font-family: ui-monospace, Menlo, monospace; background: var(--bg); padding: 6px 10px; border-radius: 6px; display: inline-block; word-break: break-all; font-size: 12px; }
.badge.on { background: var(--green-bg); color: var(--green); }
.badge.off { background: var(--line); color: var(--muted); }

.brand { font-size: 19px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand span { letter-spacing: -.3px; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: none; background: transparent; padding: 8px 16px; border-radius: 8px;
  font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tab:hover { background: var(--bg); }
.tab.active { background: var(--primary); color: #fff; }
.tab-badge {
  display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 4px;
  background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700;
}
.tab.active .tab-badge { background: #fff; color: var(--primary); }

/* ---------- Stats ---------- */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px; padding: 20px 24px 4px;
}
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat.green .value { color: var(--green); }
.stat.amber .value { color: var(--amber); }
.stat.red .value { color: var(--red); }
.stat.blue .value { color: var(--primary); }

/* ---------- Main / toolbar ---------- */
main { padding: 16px 24px 48px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; font-size: 18px; }
.toolbar input[type="search"] { flex: 1; min-width: 220px; }

input, select {
  font: inherit; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; color: var(--ink); outline: none;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

.btn {
  font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 9px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--red); border-color: var(--red-bg); }
.btn.danger:hover { background: var(--red-bg); }
.btn.sm { padding: 5px 10px; font-size: 13px; }

/* ---------- Table ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fafbfd;
}
td { padding: 11px 16px; border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbff; }
td.plate { font-weight: 700; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.en_service { background: var(--green-bg); color: var(--green); }
.badge.maintenance { background: var(--amber-bg); color: var(--amber); }
.badge.hors_service { background: var(--red-bg); color: var(--red); }
.badge.expiree { background: var(--red-bg); color: var(--red); }
.badge.bientot { background: var(--amber-bg); color: var(--amber); }
.muted { color: var(--muted); }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 6px; align-items: center; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.pagination button { min-width: 36px; }
.pagination .info { color: var(--muted); margin: 0 10px; }

/* ---------- Modale ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16,24,40,.45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 480px;
  box-shadow: 0 20px 50px rgba(16,24,40,.25); animation: pop .14s ease;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close { border: none; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
#modal-form { padding: 20px 22px; display: grid; gap: 14px; max-height: 78vh; overflow-y: auto; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 13px; border-bottom: 1px solid var(--line); }
.kv span { color: var(--muted); }
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.det-h { margin: 18px 0 8px; font-size: 14px; display: flex; align-items: center; gap: 10px; }
#modal-form textarea { font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; resize: vertical; width: 100%; }
#modal-form textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); outline: none; }
.field-group { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px 4px; display: grid; gap: 10px; }
.field-group legend { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; padding: 0 6px; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); }
.chk input { width: auto; }
input[type="file"] { font: inherit; }
.field { display: grid; gap: 5px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field .row { display: flex; gap: 10px; }
.field .row > * { flex: 1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line); }
.modal-error { margin: 0 22px; padding: 10px 14px; background: var(--red-bg); color: var(--red); border-radius: 9px; font-weight: 600; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 60; font-weight: 600;
}
.toast.err { background: var(--red); }

/* ---------- Historique entretien dans la modale ---------- */
.maint-history { max-height: 200px; overflow-y: auto; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini-table th { padding: 6px 8px; font-size: 11px; }
.mini-table td { padding: 6px 8px; }
.sep { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

.hidden { display: none !important; }
