:root {
  /* Bleu ciel → bleu nuit */
  --sky: #6ec8f5;
  --sky-light: #a8dcfa;
  --sky-soft: #4db8ef;
  --midnight: #0f2340;
  --midnight-deep: #081628;
  --midnight-panel: #152a4a;
  --midnight-card: #1a3358;

  --bg: var(--midnight-deep);
  --bg-end: #0a1a32;
  --panel: var(--midnight-panel);
  --text: #eef6ff;
  --muted: #8eb4d9;
  --primary: var(--sky-soft);
  --primary-hover: var(--sky);
  --danger: #ff6b8a;
  --ok: #3dd68c;
  --warn: #f5b942;
  --border: rgba(110, 200, 245, 0.18);
  --border-strong: rgba(110, 200, 245, 0.32);
  --glow: rgba(77, 184, 239, 0.15);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: linear-gradient(165deg, var(--midnight) 0%, var(--bg) 45%, var(--bg-end) 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

img, video, svg { max-width: 100%; height: auto; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, rgba(15, 35, 64, 0.95), rgba(21, 42, 74, 0.92));
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 24px rgba(8, 22, 40, 0.45);
}

.topbar__right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.topbar__left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(110, 200, 245, 0.08);
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle__bar {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--sky-light);
  border-radius: 2px;
}

.pill__icon { margin-right: 2px; }

.pill__text {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: bottom;
}

.brand {
  color: var(--sky-light);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.pill {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(110, 200, 245, 0.08);
  font-size: 13px;
  text-decoration: none;
  color: var(--text);
}

.pill--muted { color: var(--muted); }

.pill--accent {
  border-color: var(--border-strong);
  background: linear-gradient(135deg, rgba(77, 184, 239, 0.2), rgba(110, 200, 245, 0.1));
  color: var(--sky-light);
}

.link {
  color: var(--sky);
  text-decoration: none;
  font-size: 14px;
}

.link:hover { color: var(--sky-light); text-decoration: underline; }

.nav {
  display: flex;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(21, 42, 74, 0.85), rgba(15, 35, 64, 0.75));
  flex-wrap: wrap;
}

.nav--open {
  display: flex;
}

.nav__item {
  color: var(--text);
  text-decoration: none;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.nav__item:hover {
  border-color: var(--border-strong);
  background: var(--glow);
  color: var(--sky-light);
}

.container { max-width: 1180px; margin: 22px auto; padding: 0 18px 60px; width: 100%; }

.card {
  background: linear-gradient(145deg, rgba(26, 51, 88, 0.92), rgba(21, 42, 74, 0.88));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 8px 32px rgba(8, 22, 40, 0.35);
  max-width: 100%;
}

.card--narrow-sm { max-width: 480px; margin-left: auto; margin-right: auto; }
.card--narrow-md { max-width: 640px; margin-left: auto; margin-right: auto; }
.card--narrow-lg { max-width: 720px; margin-left: auto; margin-right: auto; }
.card--narrow-xl { max-width: 800px; margin-left: auto; margin-right: auto; }

.form-limit { max-width: 640px; }
.form-limit--sm { max-width: 480px; }
.form-limit--lg { max-width: 720px; }

.btn-row {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.dashboard-search {
  margin-top: 12px;
}

.stack-top { margin-top: 14px; }
.stack-top-lg { margin-top: 16px; }

.grid { display: grid; gap: 14px; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 980px) {
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .grid--2, .grid--3, .grid--4 { grid-template-columns: minmax(0, 1fr); }
}

.h1 { font-size: 22px; margin: 0 0 12px; color: var(--sky-light); }
.muted { color: var(--muted); }
.commentaire-dge { color: var(--danger); }
.commentaire-dge .muted { color: var(--danger); opacity: 0.85; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row > .h1 { flex: 1 1 auto; min-width: 0; }

form label {
  display: block;
  margin-top: 10px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
input[type="tel"],
input[type="url"],
select,
textarea {
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(8, 22, 40, 0.55);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-size: 16px;
}

select option {
  background: var(--midnight-panel);
  color: var(--text);
}

textarea { min-height: 90px; resize: vertical; }

input:focus,
select:focus,
textarea:focus {
  border-color: var(--sky-soft);
  box-shadow: 0 0 0 3px var(--glow);
}

input.input--locked,
select.input--locked:disabled,
textarea.input--locked {
  background: rgba(8, 22, 40, 0.28);
  color: var(--muted);
  border-color: rgba(255, 255, 255, 0.06);
  cursor: not-allowed;
  opacity: 0.8;
}

input.input--locked:focus,
select.input--locked:disabled:focus,
textarea.input--locked:focus {
  border-color: var(--border);
  box-shadow: none;
}

.btn {
  border: 1px solid var(--border);
  background: rgba(110, 200, 245, 0.08);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  min-height: 44px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:hover {
  border-color: var(--border-strong);
  background: var(--glow);
  color: var(--sky-light);
}

.btn--primary {
  border-color: rgba(77, 184, 239, 0.55);
  background: linear-gradient(135deg, rgba(77, 184, 239, 0.35), rgba(110, 200, 245, 0.22));
  color: #fff;
  font-weight: 600;
}

.btn--primary:hover {
  background: linear-gradient(135deg, rgba(110, 200, 245, 0.45), rgba(77, 184, 239, 0.32));
  border-color: var(--sky);
}

.btn--danger {
  border-color: rgba(255, 107, 138, 0.45);
  background: rgba(255, 107, 138, 0.12);
  color: #ffc8d4;
}

.table {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  display: block;
  -webkit-overflow-scrolling: touch;
}

.table table {
  min-width: 640px;
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 14px;
  vertical-align: top;
  word-break: break-word;
}

.table th {
  color: var(--sky-light);
  font-weight: 600;
  background: rgba(110, 200, 245, 0.06);
}

.table tbody tr:hover {
  background: rgba(110, 200, 245, 0.05);
}

.table-scroll {
  max-height: min(420px, 55vh);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  -webkit-overflow-scrolling: touch;
}

.table-scroll .table {
  overflow: visible;
  display: block;
}

.table-scroll .table th {
  position: sticky;
  top: 0;
  z-index: 1;
  box-shadow: 0 1px 0 var(--border);
}

.flash {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 12px 0;
}

.flash--info {
  border-color: rgba(77, 184, 239, 0.45);
  background: rgba(77, 184, 239, 0.12);
  color: var(--sky-light);
}

.flash--success {
  border-color: rgba(61, 214, 140, 0.4);
  background: rgba(61, 214, 140, 0.1);
  color: #a8f0ce;
}

.flash--danger {
  border-color: rgba(255, 107, 138, 0.4);
  background: rgba(255, 107, 138, 0.1);
  color: #ffc8d4;
}

.footer {
  margin-top: 40px;
  padding: 20px 18px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  text-align: center;
  background: rgba(8, 22, 40, 0.4);
}

.kpi-card {
  background: linear-gradient(160deg, rgba(26, 51, 88, 0.95), rgba(15, 35, 64, 0.9));
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 4px 20px rgba(8, 22, 40, 0.3);
}

.kpi-card__label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-card__val {
  font-size: 32px;
  font-weight: 700;
  color: var(--sky);
  text-shadow: 0 0 24px rgba(110, 200, 245, 0.25);
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge--ok { background: rgba(61, 214, 140, 0.15); color: var(--ok); }
.badge--danger { background: rgba(255, 107, 138, 0.15); color: var(--danger); }
.badge--primary { background: rgba(77, 184, 239, 0.2); color: var(--sky-light); }
.badge--warn { background: rgba(245, 185, 66, 0.15); color: var(--warn); }
.badge--muted { background: rgba(110, 200, 245, 0.08); color: var(--muted); }

.commune-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
}

.commune-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  background: rgba(8, 22, 40, 0.45);
  text-decoration: none;
  color: var(--text);
  display: block;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.commune-card:hover {
  border-color: var(--sky-soft);
  background: var(--glow);
  box-shadow: 0 4px 20px rgba(77, 184, 239, 0.15);
}

code {
  background: rgba(110, 200, 245, 0.12);
  color: var(--sky-light);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.9em;
  overflow-wrap: anywhere;
}

/* --- Administration --- */
.admin-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 20px;
  border-radius: 16px;
  border: 1px solid var(--border-strong);
  background: linear-gradient(135deg, rgba(26, 51, 88, 0.95), rgba(15, 35, 64, 0.92));
  box-shadow: 0 10px 40px rgba(8, 22, 40, 0.35);
}

.admin-hero__eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sky);
}

.admin-hero__title {
  margin: 0 0 8px;
  font-size: clamp(22px, 4vw, 28px);
  color: var(--sky-light);
}

.admin-hero__subtitle {
  margin: 0;
  max-width: 640px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

.admin-hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.admin-hero__chip {
  min-width: 120px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(8, 22, 40, 0.45);
}

.admin-hero__chip-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}

.admin-hero__chip strong {
  font-size: 22px;
  color: var(--sky-light);
}

.admin-hero__chip--status strong {
  font-size: 14px;
}

.admin-tiles {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
}

.admin-tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(8, 22, 40, 0.4);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
  min-height: 120px;
}

.admin-tile:hover {
  border-color: var(--sky-soft);
  background: var(--glow);
  transform: translateY(-2px);
}

.admin-tile__icon {
  font-size: 22px;
  line-height: 1;
}

.admin-tile__title {
  font-weight: 600;
  color: var(--sky-light);
  font-size: 15px;
}

.admin-tile__desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.admin-feed {
  list-style: none;
  margin: 0;
  padding: 0;
}

.admin-feed__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.admin-feed__item:last-child {
  border-bottom: none;
}

.admin-feed__action {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

.admin-feed__meta {
  font-size: 12px;
  color: var(--muted);
}

.kpi-card__suffix {
  font-size: 18px;
  color: var(--muted);
  font-weight: 500;
}

.kpi-card__hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.hint {
  font-size: 12px;
  margin-top: 4px;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin: 0;
}

fieldset legend {
  font-weight: 600;
  padding: 0 6px;
}

.inline-option {
  display: block;
  margin-top: 8px;
  cursor: pointer;
}

.inline-option:first-of-type {
  margin-top: 0;
}

.inline-option input {
  margin-right: 8px;
}

.graphes-filters {
  margin-top: 16px;
}

.graphes-charts .card {
  min-height: 360px;
}

.chart-wrap {
  position: relative;
  height: 280px;
  margin-top: 12px;
}

.chart-wrap--wide {
  height: 340px;
}

.section-title {
  font-size: 18px;
  margin-top: 24px;
}

.message-body {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}

/* Tablette */
@media (max-width: 980px) {
  .container { margin: 18px auto; padding: 0 16px 48px; }
  .kpi-card__val { font-size: 28px; }
  .pill__text { max-width: 140px; }
}

/* Tablette : menu repliable */
@media (max-width: 1024px) {
  .nav-toggle { display: inline-flex; }

  .nav {
    display: none;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px 14px;
  }

  .nav.nav--open {
    display: flex;
  }

  .nav__item {
    width: 100%;
    text-align: left;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

@media (min-width: 1025px) {
  .nav-toggle { display: none !important; }
}

/* Tablette / mobile : tableaux en cartes */
@media (max-width: 900px) {
  .table {
    overflow: visible;
  }

  .table table {
    min-width: 0;
    display: block;
  }

  .table thead {
    display: none;
  }

  .table tbody {
    display: block;
  }

  .table tr {
    display: block;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px 12px 8px;
    background: rgba(8, 22, 40, 0.35);
  }

  .table td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    border-bottom: 1px solid var(--border);
    padding: 10px 0;
    min-width: 0;
  }

  .table td:last-child {
    border-bottom: none;
  }

  .table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--sky-light);
    flex: 0 0 42%;
    max-width: 42%;
  }

  .table td[colspan] {
    display: block;
    text-align: center;
    padding: 14px 0;
  }

  .table td[colspan]::before {
    display: none;
  }

  .row .btn,
  .row .btn--primary {
    width: 100%;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .brand {
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100vw - 120px);
  }

  .topbar__right {
    gap: 6px;
  }

  .pill--role,
  .pill--user {
    display: none;
  }

  .pill--commune .pill__text {
    max-width: 110px;
  }

  .kpi-card__val { font-size: 24px; }
}

@media (max-width: 520px) {
  .container { margin: 12px auto; padding: 0 12px 36px; }
  .card { padding: 14px; }
  .h1 { font-size: 20px; }
  .topbar__right .link { font-size: 13px; padding: 8px 10px; min-height: 36px; }
  .btn-row .btn { flex: 1 1 100%; }
}

@media (min-width: 901px) and (max-width: 1024px) {
  .table table { min-width: 720px; }
}

/* Lignes cliquables — bureaux de vote */
.bureau-row--clickable {
  cursor: pointer;
}

.bureau-row--clickable:focus {
  outline: 2px solid var(--sky-soft);
  outline-offset: -2px;
}

.bureau-row--clickable:hover td {
  background: rgba(110, 200, 245, 0.12);
}

/* Modale */
body.modal-open {
  overflow: hidden;
}

.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 22, 40, 0.72);
  backdrop-filter: blur(4px);
}

.modal__dialog {
  position: relative;
  width: min(920px, 100%);
  max-height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--midnight-panel), var(--midnight-card));
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(8, 22, 40, 0.55);
  overflow: hidden;
}

.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.modal__title {
  margin: 0;
  font-size: 18px;
}

.modal__subtitle {
  margin: 4px 0 0;
  font-size: 13px;
}

.modal__close {
  border: 1px solid var(--border);
  background: rgba(110, 200, 245, 0.08);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.modal__close:hover {
  background: rgba(110, 200, 245, 0.18);
}

.modal__loading {
  padding: 12px 18px 0;
}

.modal__body {
  padding: 12px 18px 18px;
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.modal-table-scroll {
  max-height: calc(88vh - 140px);
}

.detail-section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.detail-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: 0;
}
.detail-section__title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 20px;
  margin: 0;
}
.detail-row {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}
.detail-row dt {
  margin: 0;
  flex: 0 0 auto;
  max-width: 46%;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.detail-row dt::after {
  content: ' :';
}
.detail-row dd {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}
@media (max-width: 720px) {
  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
