/* Charte : violet #4C0297, rouge #D1271C, crème #FFFCF4, charbon #212320
   Titres : Public Sans Black / Bold — Texte : Gowun Batang */
:root {
  --violet: #4C0297;
  --violet-dark: #3a0174;
  --violet-soft: #efe6f9;
  --rouge: #D1271C;
  --rouge-soft: #fbe7e5;
  --creme: #FFFCF4;
  --charbon: #212320;

  --bg: #f6f1e6;
  --surface: var(--creme);
  --text: var(--charbon);
  --muted: #6e6c66;
  --border: #e9e2d2;
  --accent: var(--violet);
  --ok: #2f8f5b;
  --warn: #e0731a;
  --danger: var(--rouge);
  --neutral: #8f8b82;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(33,35,32,.04), 0 6px 24px -8px rgba(76,2,151,.12);
  --shadow-lg: 0 24px 60px -12px rgba(33,35,32,.35);

  --font-title: "Public Sans", system-ui, sans-serif;
  --font-body: "Gowun Batang", Georgia, serif;
  font-family: var(--font-body);
  font-size: 15px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* Connexion membre : les éléments réservés à l'admin (data-admin) sont masqués ; le serveur les refuse aussi */
.role-user [data-admin] { display: none !important; }
body { margin: 0; display: flex; min-height: 100vh; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--violet); }

/* Les éléments d'interface et les données utilisent la police de titre, plus lisible en petit */
button, .btn, input, select, textarea, table, .badge, .stat, .sidebar, .muted, label, legend, .chip, .cal, .leaflet-container {
  font-family: var(--font-title);
}

/* --- Navigation --------------------------------------------------------- */
.sidebar {
  width: 236px; flex-shrink: 0; background: var(--violet); color: var(--creme);
  padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px;
}
.brand {
  display: block; position: relative; padding: 0; margin: 0 4px 22px; border: none; border-radius: 18px;
  background: none; cursor: pointer;
}
.brand:hover { border: none; }
.brand img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 18px; box-shadow: 0 10px 30px -10px rgba(0,0,0,.5); transition: transform .15s; }
.brand:hover img { transform: scale(1.02); }
.brand-switch {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); white-space: nowrap;
  background: rgba(33,35,32,.75); color: var(--creme); font-size: 11.5px; font-weight: 700; padding: 4px 10px;
  border-radius: 999px; opacity: 0; transition: opacity .15s; backdrop-filter: blur(4px);
}
.brand:hover .brand-switch, .brand:focus-visible .brand-switch { opacity: 1; }

/* Choix du groupe */
.group-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.group-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 16px; border-radius: 18px;
  border: 2px solid var(--border); background: #fff; font-family: var(--font-title); font-weight: 700; font-size: 15px;
}
.group-card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 14px; }
.group-card:hover { border-color: var(--violet); color: var(--violet); }
.group-card.actif { border-color: var(--violet); box-shadow: 0 0 0 4px var(--violet-soft); }
.group-card .muted { font-weight: 600; }
.sidebar a {
  display: flex; align-items: center; gap: 12px; color: rgba(255,252,244,.78); text-decoration: none;
  padding: 10px 12px; border-radius: 12px; font-weight: 600; font-size: 14.5px; transition: background .15s, color .15s;
}
.sidebar a svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.sidebar a:hover { background: rgba(255,252,244,.1); color: var(--creme); }
.sidebar a.active { background: var(--creme); color: var(--violet); }
.sidebar a.nav-ext { margin-top: 10px; border: 1.5px dashed rgba(255,252,244,.35); }
.sidebar a.nav-ext:hover { border-color: var(--creme); }
.programme-link {
  display: block; margin: -6px 0 18px; padding: 10px 14px; border-radius: 12px; text-decoration: none;
  background: var(--violet-soft); color: var(--charbon); font-size: 14px; border-left: 4px solid var(--violet);
}
.programme-link strong { font-family: var(--font-title); color: var(--violet); }
.programme-link span { font-family: var(--font-title); font-weight: 700; color: var(--violet); white-space: nowrap; }
.programme-link:hover { background: #e4d6f5; }
.nav-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 2px; padding-top: 16px; }
.nav-bottom button {
  background: none; border: none; color: rgba(255,252,244,.65); text-align: left; padding: 8px 12px;
  border-radius: 10px; font-size: 13px; font-weight: 600;
}
.nav-role { font-family: var(--font-title); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,252,244,.5); padding: 0 12px 4px; }
.nav-bottom button:hover { background: rgba(255,252,244,.1); color: var(--creme); }

main { flex: 1; padding: 32px 36px 48px; min-width: 0; }
h1 {
  font-family: var(--font-title); font-weight: 900; font-size: 34px; letter-spacing: -.025em;
  text-transform: uppercase; margin: 0 0 22px; line-height: 1;
}
h1::after { content: ""; display: block; width: 44px; height: 5px; background: var(--rouge); margin-top: 12px; border-radius: 3px; }
h2 { font-family: var(--font-title); font-weight: 700; font-size: 17px; margin: 0 0 14px; letter-spacing: -.01em; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 20px; }
.toolbar .spacer { flex: 1; }

/* --- Cartes et grilles ------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .v { font-size: 34px; font-weight: 900; letter-spacing: -.03em; color: var(--violet); font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 13px; font-weight: 600; margin-top: 2px; }
.stat:first-child { background: var(--violet); border-color: var(--violet); }
.stat:first-child .v, .stat:first-child .l { color: var(--creme); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 11px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }
.list li:last-child { border-bottom: none; }
.list .grow { flex: 1; min-width: 0; }
.list a, .list strong { font-family: var(--font-title); font-weight: 700; text-decoration: none; }
.list a:hover { text-decoration: underline; }
.empty { color: var(--muted); font-style: italic; padding: 8px 0; }
.muted { color: var(--muted); font-size: 13px; }
.card p { line-height: 1.5; }
.link-more { font-family: var(--font-title); font-weight: 700; font-size: 14px; text-decoration: none; }

/* --- Tableaux ---------------------------------------------------------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; transition: background .1s; }
tr.clickable:hover td { background: var(--violet-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- Badges ------------------------------------------------------------ */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; color: #fff; background: var(--neutral); letter-spacing: .01em; }
.badge.outline { background: transparent; color: var(--violet); border: 1px solid #d6c4ec; font-weight: 600; }

/* --- Boutons et formulaires --------------------------------------------- */
button, .btn {
  font-size: 14px; font-weight: 600; border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 16px; border-radius: 999px; cursor: pointer; text-decoration: none; display: inline-block; transition: all .15s;
}
button:hover, .btn:hover { border-color: var(--violet); color: var(--violet); }
button.primary { background: var(--rouge); border-color: var(--rouge); color: var(--creme); font-weight: 700; }
button.primary:hover { background: #b51f15; border-color: #b51f15; color: var(--creme); }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); color: var(--danger); }
button.small { padding: 4px 11px; font-size: 12.5px; }
button.icon { padding: 6px 12px; font-size: 16px; line-height: 1; }
button.active-mode { background: var(--violet-soft); border-color: var(--violet); color: var(--violet); }

input, select, textarea {
  font-size: 14px; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; color: var(--text); width: 100%; transition: border-color .15s, box-shadow .15s;
}
input:disabled, select:disabled, textarea:disabled { background: #f1ece1; color: var(--muted); cursor: not-allowed; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px var(--violet-soft); }
textarea { min-height: 76px; resize: vertical; font-family: var(--font-body); font-size: 15px; }
.toolbar select, .toolbar input { width: auto; border-radius: 999px; padding: 8px 14px; }
form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 14px; }
form label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); }
form label > input, form label > select, form label > textarea { margin-top: 5px; }
fieldset { border: 1.5px solid var(--border); border-radius: var(--radius-sm); margin: 0 0 14px; padding: 10px 14px 14px; }
legend { font-size: 12.5px; font-weight: 700; color: var(--violet); padding: 0 6px; text-transform: uppercase; letter-spacing: .05em; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; max-height: 170px; overflow-y: auto; }
.checks label { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 14px; font-weight: 400; }
.checks input { width: auto; margin: 0; accent-color: var(--violet); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.form-actions .left { margin-right: auto; }

dialog {
  border: none; border-radius: 20px; padding: 0; width: min(700px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  box-shadow: var(--shadow-lg); background: var(--creme); color: var(--text);
}
dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
dialog::backdrop { background: rgba(33,35,32,.5); backdrop-filter: blur(3px); }
#modal-body { padding: 26px 28px; }
#modal-body h2 { font-size: 22px; font-weight: 900; text-transform: uppercase; letter-spacing: -.01em; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--charbon); color: var(--creme);
  padding: 12px 22px; border-radius: 999px; z-index: 2000; font-family: var(--font-title); font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow-lg);
}

/* --- Cartes géographiques ------------------------------------------------ */
.map { height: 580px; border-radius: var(--radius); border: 1px solid var(--border); z-index: 0; box-shadow: var(--shadow); }
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 18px; align-items: start; }
.map-layout .side { max-height: 580px; overflow-y: auto; }
.leaflet-tile-pane { filter: saturate(.45) sepia(.12) brightness(1.04) contrast(.92); }
.leaflet-control-layers input { width: auto; padding: 0; accent-color: var(--violet); }
.leaflet-container button { line-height: 1.3; }
.leaflet-popup-content-wrapper { border-radius: 14px; background: var(--creme); }
.leaflet-popup-tip { background: var(--creme); }
.leaflet-control-layers, .leaflet-bar { border-radius: 12px !important; border: none !important; box-shadow: var(--shadow) !important; }

.score-bar { height: 7px; border-radius: 4px; background: var(--border); overflow: hidden; margin: 7px 0 5px; }
.score-bar > div { height: 100%; border-radius: 4px; }
.criteres { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 13px; color: var(--muted); margin-top: 10px; font-family: var(--font-title); }
.legend { background: var(--creme); padding: 10px 12px; border-radius: 12px; font-size: 12px; line-height: 1.8; box-shadow: var(--shadow); font-weight: 600; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 7px; vertical-align: -1px; }
.popup-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }

/* --- Calendrier --------------------------------------------------------- */
.cal-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.cal-title { font-family: var(--font-title); font-weight: 900; font-size: 24px; text-transform: capitalize; letter-spacing: -.02em; min-width: 200px; }
.segmented { display: inline-flex; background: var(--surface); border: 1.5px solid var(--border); border-radius: 999px; padding: 3px; }
.segmented button { border: none; padding: 5px 14px; background: transparent; }
.segmented button.on { background: var(--violet); color: var(--creme); }

.cal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-dow { padding: 10px 12px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); border-bottom: 1px solid var(--border); }
.cal-day { min-height: 118px; padding: 8px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-day:nth-child(7n) { border-right: none; }
.cal-day:hover { background: #fbf6ea; }
.cal-day.other { background: #f8f3e8; }
.cal-day.other .cal-num { color: #b9b3a6; }
.cal-day.weekend { background: #fcf8ee; }
.cal-num { font-weight: 700; font-size: 13px; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.today .cal-num { background: var(--rouge); color: var(--creme); }
.chip {
  display: block; font-size: 12px; font-weight: 600; padding: 3px 7px; border-radius: 6px; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; border-left: 3px solid rgba(0,0,0,.18);
}
.chip:hover { filter: brightness(1.12); }
.chip .t { opacity: .85; font-weight: 400; margin-right: 4px; }
.chip.annulee { opacity: .45; text-decoration: line-through; }
.chip.prevue { box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.35); }
.more { font-size: 12px; font-weight: 700; color: var(--violet); background: none; border: none; padding: 2px 4px; text-align: left; }
.more:hover { text-decoration: underline; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 14px; font-size: 13px; font-family: var(--font-title); font-weight: 600; color: var(--muted); }
.cal-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }

.agenda-day { display: grid; grid-template-columns: 74px 1fr; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.agenda-day:last-child { border-bottom: none; }
.agenda-date { font-family: var(--font-title); text-align: center; }
.agenda-date .d { font-size: 28px; font-weight: 900; line-height: 1; color: var(--violet); }
.agenda-date .w { font-size: 11.5px; text-transform: uppercase; font-weight: 700; color: var(--muted); letter-spacing: .06em; }
.agenda-day.today .agenda-date .d { color: var(--rouge); }
.agenda-item { display: flex; gap: 12px; align-items: center; padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.agenda-item:hover { background: var(--violet-soft); }
.agenda-item .bar { width: 4px; align-self: stretch; border-radius: 2px; }
.agenda-item .grow { flex: 1; min-width: 0; }
.agenda-item strong { font-family: var(--font-title); }

/* --- Lien Action Populaire ------------------------------------------------ */
.ap-icon { width: 20px; height: 20px; border-radius: 5px; vertical-align: -5px; display: inline-block; }
.ap-link { display: inline-block; margin-left: 4px; line-height: 0; border-radius: 6px; transition: transform .12s, box-shadow .12s; }
.ap-link:hover { transform: scale(1.15); box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.ap-link.off { opacity: .35; }
.ap-link.off:hover { transform: none; box-shadow: none; }
.ap-button { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.ap-button .ap-icon { vertical-align: 0; }
form .link-row { grid-template-columns: 1fr auto; align-items: end; }

/* --- Secteurs PAP : liste par commune ----------------------------------- */
.commune-group { border-bottom: 1px solid var(--border); }
.commune-group:last-child { border-bottom: none; }
.commune-group summary {
  display: flex; align-items: center; gap: 10px; padding: 12px 4px; cursor: pointer; list-style: none;
  font-family: var(--font-title); border-radius: 10px;
}
.commune-group summary::-webkit-details-marker { display: none; }
.commune-group summary::after { content: "›"; font-size: 20px; color: var(--muted); transition: transform .15s; }
.commune-group[open] summary::after { transform: rotate(90deg); }
.commune-group summary:hover { background: #fbf6ea; }
.commune-group .swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.commune-group .grow { flex: 1; min-width: 0; }
.commune-totals { display: flex; flex-direction: column; align-items: flex-end; font-size: 11.5px; font-weight: 700; color: var(--violet); white-space: nowrap; }
.commune-group .list { padding: 0 4px 8px 26px; }
.sector-counts { display: grid; grid-template-columns: auto auto; gap: 2px 12px; margin: 8px 0 4px; font-size: 12.5px; }
.sector-counts span { color: var(--muted); }
.sector-history { display: flex; flex-direction: column; gap: 3px; margin: 6px 0 2px; padding-top: 6px; border-top: 1px solid var(--border); font-size: 12.5px; }
.sector-history a { text-decoration: none; color: var(--text); }
.sector-history a:hover { color: var(--violet); }

/* --- Tournée de collage ------------------------------------------------ */
.tour-num {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  background: var(--violet); color: var(--creme); font-family: var(--font-title); font-weight: 900; font-size: 12px;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.tour-num.done { background: #2f8f5b; }
.tour-links { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 12px; }
.tour-links .btn { text-align: center; }
.tour-steps li { align-items: flex-start; cursor: pointer; }
.tour-steps li.tour-done { opacity: .55; }
.tour-steps li.tour-done .tour-num { background: #2f8f5b; }
.tour-sectors { margin: 0 0 14px; }
.tour-sectors summary { cursor: pointer; padding: 4px 0; }
.tour-sectors .checks { margin-top: 8px; }

/* --- Tractage : semaine type ---------------------------------------------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.week-day { background: #fbf6ea; border-radius: 12px; padding: 10px; min-height: 90px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.week-day.today { background: var(--violet-soft); box-shadow: inset 0 0 0 2px var(--violet); }
.week-name { font-family: var(--font-title); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.week-day.today .week-name { color: var(--violet); }
.week-item {
  display: block; text-align: left; width: 100%; border-radius: 8px; border: none; border-left: 4px solid; padding: 6px 8px;
  background: var(--creme); font-size: 12.5px; box-shadow: 0 1px 2px rgba(33,35,32,.08);
}
.week-item:hover { color: var(--text); box-shadow: 0 2px 8px rgba(76,2,151,.18); }
.week-item strong, .week-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.week-item strong { white-space: normal; line-height: 1.25; }
.week-item span { color: var(--muted); font-weight: 400; font-size: 11.5px; }

/* --- Responsive --------------------------------------------------------- */
@media (max-width: 900px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 1000; flex-direction: row; overflow-x: auto; padding: 8px; gap: 4px; }
  .brand { width: 40px; flex-shrink: 0; margin: 0 6px 0 0; border-radius: 10px; }
  .brand img { border-radius: 10px; box-shadow: none; }
  .brand-switch { display: none; }
  .sidebar a { white-space: nowrap; padding: 8px 12px; font-size: 13.5px; }
  .sidebar a svg { display: none; }
  .nav-bottom { flex-direction: row; margin-top: 0; padding-top: 0; }
  .nav-bottom button { white-space: nowrap; }
  main { padding: 20px 16px 40px; }
  h1 { font-size: 26px; }
  .map-layout { grid-template-columns: 1fr; }
  .map { height: 420px; }
  .cal-day { min-height: 74px; padding: 4px; }
  .chip { font-size: 0; padding: 0; height: 6px; border: none; border-radius: 3px; }
  .cal-dow { padding: 8px 4px; text-align: center; font-size: 10px; }
  .week { grid-template-columns: 1fr; }
  .week-day { min-height: 0; }
}
