/* Atlas électoral : thème clair, sobre, mobile d'abord. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #d9dee5;
  --text: #1c2430;
  --muted: #5b6676;
  --accent: #1f3a5f;
  --accent-hover: #172c48;
  --accent-soft: #e8eef6;
  --danger: #a3262a;
  --danger-soft: #fbeaea;
  --ok: #1f6b3b;
  --ok-soft: #e6f3ea;
  --radius: 8px;
  --nav-h: 60px;
  --top-h: 52px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
h1 { font-size: 1.25rem; margin: 0 0 .75rem; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: .9rem; }
.hidden { display: none !important; }

/* --- Formulaires --- */
label { display: block; font-weight: 600; font-size: .9rem; margin: 0 0 .25rem; }
input[type=text], input[type=password], input[type=search], select {
  width: 100%; min-height: 44px; padding: .55rem .75rem; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 3px solid #8fb0d8; outline-offset: 1px; }
.field { margin-bottom: 1rem; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 5.5rem; }
.pw-wrap button { position: absolute; right: 4px; top: 4px; min-height: 36px; padding: 0 .75rem; background: transparent; color: var(--accent); border: 0; font-weight: 600; cursor: pointer; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: 0 1.1rem; font: inherit; font-weight: 600;
  color: #fff; background: var(--accent); border: 1px solid var(--accent); border-radius: var(--radius); cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--accent-hover); }
.btn.secondary { color: var(--accent); background: var(--surface); border-color: var(--border); }
.btn.secondary:hover { background: var(--accent-soft); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 .75rem; font-size: .9rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }

.alert { padding: .65rem .85rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .95rem; }
.alert.error { background: var(--danger-soft); color: var(--danger); border: 1px solid #efc3c4; }
.alert.ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #bfe0c8; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }

/* --- Page de connexion --- */
.login-page { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-box { width: 100%; max-width: 380px; }
.login-box .brand { text-align: center; margin-bottom: 1.25rem; }
.brand-name { font-size: 1.5rem; font-weight: 700; color: var(--accent); letter-spacing: .01em; }
.brand-sub { color: var(--muted); font-size: .9rem; }

/* --- Coque de l'application --- */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar { height: var(--top-h); flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 0 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .brand-name { font-size: 1.1rem; white-space: nowrap; }
@media (max-width: 520px) { .userbox .who { display: none; } }
.userbox { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--muted); }
.userbox .who { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { flex: 1 1 auto; min-height: 0; overflow: auto; position: relative; }
.page { padding: 1rem; max-width: 960px; margin: 0 auto; }

/* Navigation : barre du bas sur mobile, barre du haut sur grand écran */
.nav { flex: 0 0 auto; height: var(--nav-h); display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); }
.nav { overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { flex: 1 0 auto; min-width: 72px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .75rem; font-weight: 600; color: var(--muted); text-decoration: none; min-width: 0; padding: 0 2px; }
.nav a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a.active { color: var(--accent); background: var(--accent-soft); }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: var(--top-h) 1fr; }
  .topbar { grid-column: 1 / 3; }
  .nav { grid-column: 1; grid-row: 2; height: auto; flex-direction: column; justify-content: flex-start; border-top: 0; border-right: 1px solid var(--border); padding: .5rem; gap: 2px; }
  .nav { overflow-x: visible; }
  .nav a { min-width: 0; flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: .65rem; height: 44px; padding: 0 .75rem; font-size: .95rem; border-radius: var(--radius); }
  .main { grid-column: 2; grid-row: 2; }
}

/* --- Carte --- */
.map-page { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; }
.map-actions { position: absolute; right: 12px; top: 12px; z-index: 2; display: flex; flex-direction: column; gap: 8px; }
.map-actions .btn { box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.map-note { position: absolute; left: 12px; bottom: 12px; z-index: 2; max-width: calc(100% - 24px); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .5rem .75rem; font-size: .85rem; color: var(--muted); }

/* --- Tableaux et listes --- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfc; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.badge.off { background: #eceff3; color: var(--muted); }
.badge.warn { background: #fff3d6; color: #7a5a00; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row.between { justify-content: space-between; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .25rem .75rem; }
.checks label { font-weight: 400; display: flex; gap: .5rem; align-items: center; min-height: 36px; margin: 0; }
.checks input { width: 20px; height: 20px; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; width: min(560px, calc(100vw - 24px)); max-height: 90vh; overflow: auto; }
dialog::backdrop { background: rgba(20, 28, 40, .45); }

/* --- Panneaux --- */
.pan-wrap { height: 100%; display: flex; flex-direction: column; }
.pan-bar { flex: 0 0 auto; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: .5rem; }
.pan-filters { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.pan-sel span { display: block; font-size: .75rem; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.pan-sel select { min-height: 40px; padding: .35rem .5rem; font-size: .9rem; }
.pan-body { flex: 1 1 auto; min-height: 0; overflow: auto; position: relative; display: flex; flex-direction: column; }
.pan-list { padding: 0 1rem 1rem; display: flex; flex-direction: column; gap: .5rem; max-width: 900px; width: 100%; margin: 0 auto; }
.pan-card { display: flex; flex-direction: column; gap: .3rem; text-align: left; width: 100%; font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; cursor: pointer; }
.pan-card:hover { border-color: var(--accent); }
.pan-mapbox { position: relative; flex: 1 1 auto; min-height: 320px; }
.pan-mapbox .pan-map { position: absolute; inset: 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg button { min-height: 36px; padding: 0 .9rem; font: inherit; font-weight: 600; background: var(--surface); color: var(--accent); border: 0; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: #fff; }
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; color: #fff; }
.thumbs { display: flex; gap: .5rem; flex-wrap: wrap; margin: .5rem 0; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
dialog.sheet { padding: 1rem; }
@media (max-width: 520px) {
  .pan-filters { gap: .35rem; }
  .pan-sel select { font-size: .85rem; padding: .35rem .3rem; }
  dialog.sheet { width: calc(100vw - 12px); max-height: 94vh; margin: auto 6px 6px; }
}

/* --- Code électoral --- */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { display: inline-flex; align-items: center; min-height: 36px; padding: 0 .8rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--accent); font-size: .9rem; font-weight: 600; text-decoration: none; }
.chip:hover { background: var(--accent-soft); }
mark { background: #fff0b3; color: inherit; padding: 0 .1em; border-radius: 3px; }
.art-texte p { margin: 0 0 .75rem; }
.art-texte p:last-child { margin-bottom: 0; }
input[type=search] { -webkit-appearance: none; appearance: none; }

/* --- Résultats --- */
.res-wrap { height: 100%; display: flex; flex-direction: column; }
.res-filters { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.res-body { flex: 1 1 auto; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.res-map { position: relative; flex: 0 0 52vh; min-height: 300px; }
.res-map .res-map-el { position: absolute; inset: 0; }
.res-legend { position: absolute; left: 8px; bottom: 8px; z-index: 2; background: rgba(255,255,255,.94); border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem .55rem; font-size: .72rem; max-width: calc(100% - 16px); }
.res-leg-row { display: flex; flex-wrap: wrap; gap: .15rem .6rem; }
.res-leg-item { display: flex; align-items: center; gap: .25rem; white-space: nowrap; }
.res-leg-sw { display: inline-block; width: 14px; height: 14px; border: 1px solid #9aa3af; border-radius: 3px; }
.res-list { padding: 1rem; max-width: 960px; width: 100%; margin: 0 auto; }
.res-dot { display: inline-block; width: 11px; height: 11px; border-radius: 3px; border: 1px solid #9aa3af; margin-right: .4rem; vertical-align: -1px; }
@media (max-width: 520px) { .res-filters { grid-template-columns: 1fr 1fr; } .res-map { flex-basis: 46vh; } }
@media (min-width: 900px) { .res-body { flex-direction: row; } .res-map { flex: 1 1 55%; min-height: 0; } .res-list { flex: 1 1 45%; max-width: none; overflow: auto; } }

/* --- Feuille de route imprimable (module Terrain) --- */
.print-sheet { display: none; }
@media print {
  body > *:not(.print-sheet) { display: none !important; }
  .print-sheet { display: block !important; padding: 0; color: #000; background: #fff; font-size: 11pt; }
  .print-sheet h1 { font-size: 15pt; margin: 0 0 .3rem; }
  .print-sheet table { width: 100%; border-collapse: collapse; }
  .print-sheet th, .print-sheet td { border: 1px solid #888; padding: 4px 6px; vertical-align: top; }
  .print-sheet tr { page-break-inside: avoid; }
  html, body { background: #fff !important; height: auto !important; }
}
