:root {
  --bg: #f4f7f6; --surface: #fff; --text: #14201f; --muted: #5d6f6d; --line: #e0e8e6;
  --primary: #0f766e; --primary-soft: #d9f2ee; --accent: #f59e0b; --danger: #dc2626;
  --ok: #16a34a; --radius: 16px; --shadow: 0 1px 2px rgba(16,40,38,.06), 0 6px 18px rgba(16,40,38,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1514; --surface: #15211f; --text: #e8f1ef; --muted: #8fa5a2; --line: #26363a;
    --primary: #2dd4bf; --primary-soft: #12342f; --accent: #fbbf24; --danger: #f87171;
    --ok: #4ade80; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: 12px max(16px, calc((100% - 880px) / 2)); background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 1.25rem; letter-spacing: -.02em; display: flex; align-items: center; gap: 8px; }
.brand-logo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--primary-soft); }
.me {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px 6px 6px;
  display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: .9rem;
}
.me:hover { border-color: var(--primary); }

.container { max-width: 880px; margin: 0 auto; padding: 20px 16px 80px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 8px 0 20px; flex-wrap: wrap; }
.page-head h1 { font-size: clamp(1.6rem, 5vw, 2.1rem); letter-spacing: -.02em; line-height: 1.15; }
.sub { color: var(--muted); margin-top: 4px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; font-size: .9rem; padding: 6px 0; }
.back:hover { color: var(--primary); }

.avatar {
  --h: 170; display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: hsl(var(--h) 55% 40%); color: #fff; font-weight: 700; font-size: .8rem;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface); border-radius: 12px; padding: 10px 16px; font-weight: 600; min-height: 44px;
  transition: transform .08s, border-color .15s, background .15s;
}
.btn:hover { border-color: var(--primary); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #062320; } }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 6px 12px; min-height: 36px; font-size: .9rem; border-radius: 10px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--line); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 36px; height: 36px; padding: 0; min-height: 0; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px;
}
a.card { display: block; transition: transform .15s, border-color .15s; }
a.card:hover { transform: translateY(-2px); border-color: var(--primary); }
.card h3 { font-size: 1.1rem; }
.chips { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.chip { font-size: .8rem; font-weight: 600; background: var(--primary-soft); color: var(--primary); padding: 3px 10px; border-radius: 999px; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .big { font-size: 3rem; }
.empty h2 { color: var(--text); margin: 8px 0 4px; }
.empty .btn { margin-top: 16px; }

.tabs { display: flex; gap: 4px; background: var(--line); padding: 4px; border-radius: 14px; margin-bottom: 18px; }
.tab { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 10px; font-weight: 700; color: var(--muted); min-height: 44px; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.section-head h2 { font-size: 1.05rem; }

/* Sondage */
.options { display: grid; gap: 10px; }
.option {
  position: relative; overflow: hidden; display: block; width: 100%; text-align: left; background: var(--surface);
  border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px; transition: border-color .15s;
}
.option .bar { position: absolute; inset: 0 auto 0 0; background: var(--primary-soft); transition: width .4s ease; z-index: 0; }
.option > * { position: relative; z-index: 1; }
.option.mine { border-color: var(--primary); }
.option.top .count::after { content: " 👑"; }
.option-row { display: flex; align-items: center; gap: 12px; }
.check {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center;
  font-size: .8rem; color: transparent; background: var(--surface);
}
.option.mine .check { background: var(--primary); border-color: var(--primary); color: #fff; }
.option-label { flex: 1; font-weight: 650; word-break: break-word; }
.count { font-weight: 800; font-variant-numeric: tabular-nums; }
.voters { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; padding-left: 36px; }
.voters .avatar { width: 24px; height: 24px; font-size: .7rem; }
.option-tools { display: flex; gap: 2px; margin-left: 4px; }
.option-wrap { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px; }

/* Voitures */
.cars { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.car-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.car-title { display: flex; align-items: center; gap: 10px; }
.car-title .emoji { font-size: 1.6rem; }
.car-title small { display: block; color: var(--muted); font-weight: 500; }
.seats { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.seat {
  display: flex; align-items: center; gap: 8px; width: calc(50% - 4px); min-height: 44px; padding: 6px 10px;
  border-radius: 12px; border: 1.5px dashed var(--line); color: var(--muted); font-size: .9rem; min-width: 0;
}
.seat.taken { border-style: solid; background: var(--bg); color: var(--text); font-weight: 600; }
.seat.driver { border-color: var(--accent); }
.seat span.n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.seat .x { border: 0; background: none; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.seat .x:hover { color: var(--danger); }
.car-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.free { font-size: .85rem; font-weight: 700; color: var(--ok); }
.free.full { color: var(--danger); }
.unplaced { margin-top: 18px; }
.unplaced p { color: var(--muted); font-size: .9rem; margin-bottom: 8px; }

/* Dialog */
dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(440px, calc(100% - 32px)); background: var(--surface);
  color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(8,20,18,.55); backdrop-filter: blur(3px); }
dialog form { padding: 22px; display: grid; gap: 14px; }
dialog h2 { font-size: 1.25rem; }
label { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
label small { font-weight: 400; color: var(--muted); }
input {
  width: 100%; border: 1.5px solid var(--line); background: var(--bg); border-radius: 12px; padding: 11px 14px; min-height: 46px;
}
input:focus-visible, .btn:focus-visible, .tab:focus-visible, .option:focus-visible, .me:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 1px; border-color: var(--primary);
}
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper input { text-align: center; font-weight: 800; font-size: 1.1rem; }
.stepper .btn { width: 46px; padding: 0; flex: none; font-size: 1.2rem; }
.presets { display: flex; gap: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; transition: .25s;
  max-width: calc(100% - 32px); z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #fff; }

/* Multi-sondages, votes pour autrui, surcharge de voiture */
.polls { display: grid; gap: 16px; }
.poll .section-head { align-items: flex-start; }
.option { padding: 0; }
.option-btn { display: flex; width: 100%; border: 0; background: none; text-align: left; padding: 14px 16px; border-radius: 12px; }
.option .voters { padding: 0 16px 12px 52px; margin-top: 0; }
.chip.voter { display: inline-flex; align-items: center; gap: 4px; background: var(--bg); color: var(--text); }
.chip.voter button { border: 0; background: none; color: var(--muted); padding: 0 2px; font-size: .75rem; }
.chip.voter button:hover { color: var(--danger); }
.chip.add-voter { border: 1px dashed var(--line); background: transparent; color: var(--muted); cursor: pointer; }
.chip.add-voter:hover { border-color: var(--primary); color: var(--primary); }
.seat.over { border-color: var(--danger); }
.over-msg { color: var(--danger); font-weight: 700; font-size: .88rem; margin: -6px 0 12px; }
.car-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.seat { background: transparent; font: inherit; text-align: left; cursor: default; }
button.seat { cursor: pointer; }
button.seat:hover { border-color: var(--primary); color: var(--primary); }
.seat.taken { background: var(--bg); }

.people { margin-bottom: 20px; }
.people-list { display: flex; flex-wrap: wrap; gap: 8px; }
.person {
  display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--bg); font-weight: 600; font-size: .9rem;
}
.person small { color: var(--muted); font-weight: 500; }
button.person { cursor: pointer; }
.person.waiting { border-color: var(--accent); }
.person.waiting small { color: var(--accent); font-weight: 700; }
button.person:hover { background: var(--primary-soft); }
dialog form > .btn { width: 100%; justify-content: flex-start; }

@media (max-width: 480px) {
  .seat { width: 100%; }
  .page-head .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Liste des personnes : puces avec action principale + suppression */
.person .p-main { display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; padding: 0; font: inherit; font-weight: 600; color: inherit; }
.person .p-main small { font-size: .75rem; }
.person .x { border: 0; background: none; color: var(--muted); padding: 2px 6px; border-radius: 6px; cursor: pointer; margin-left: -2px; }
.person .x:hover { color: var(--danger); }
.person.waiting:hover { background: var(--primary-soft); }
button.person.waiting:hover { background: var(--bg); }
.pick-list { display: flex; flex-wrap: wrap; gap: 8px; max-height: 220px; overflow-y: auto; }
.pick-list .person { cursor: pointer; color: inherit; font: inherit; font-weight: 600; font-size: .9rem; }
.pick-list .person:hover { border-color: var(--primary); background: var(--primary-soft); }

/* Filtres de la liste des personnes */
.people-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.fchips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1 1 auto; }
.fchip {
  border: 1.5px solid var(--line); background: transparent; border-radius: 999px; padding: 5px 12px; font-size: .85rem;
  font-weight: 600; color: var(--muted); min-height: 34px; cursor: pointer;
}
.fchip b { color: var(--text); margin-left: 2px; font-variant-numeric: tabular-nums; }
.fchip:hover { border-color: var(--primary); }
.fchip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.fchip[aria-pressed="true"] b { color: inherit; }
@media (prefers-color-scheme: dark) { .fchip[aria-pressed="true"], .fchip[aria-pressed="true"] b { color: #062320; } }
.psearch { flex: 0 1 180px; min-height: 36px; padding: 6px 12px; border-radius: 999px; font-size: .9rem; }
.person[hidden] { display: none; }
@media (max-width: 480px) { .psearch { flex: 1 1 100%; } }

/* Bouton supprimer dans les fenêtres de modification */
.dlg-actions .del-btn { order: -1; margin-right: auto; }
dialog form > .btn.danger { justify-content: center; }

/* ---- Interaction : on touche l'élément lui-même, un seul menu ⋯ par bloc ---- */
.kebab { font-size: 1.4rem; font-weight: 800; line-height: 1; color: var(--muted); }
.option-wrap { grid-template-columns: 1fr; }
button.person, button.chip.voter, button.seat { font: inherit; color: inherit; cursor: pointer; }
button.person { text-align: left; }
button.person:hover, button.chip.voter:hover, button.seat.taken:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--text); }
button.person.waiting:hover { background: var(--primary-soft); }
button.chip.voter { border: 1px solid transparent; }
.option.editing { border-style: dashed; border-color: var(--primary); }
.option.editing .voters { display: none; }
.edit-banner { background: var(--primary-soft); color: var(--primary); font-weight: 600; font-size: .9rem; padding: 8px 12px; border-radius: 10px; margin-bottom: 10px; }
.poll-foot { display: flex; gap: 8px; justify-content: space-between; align-items: center; margin-top: 12px; flex-wrap: wrap; }

/* Feuille d'actions : en bas sur mobile, centrée sur grand écran */
dialog.sheet { width: min(420px, calc(100% - 24px)); }
dialog.sheet form { padding: 8px 8px 12px; gap: 6px; }
.sheet-head { padding: 12px 12px 8px; }
.sheet-head h2 { font-size: 1.15rem; }
.sheet-person { display: flex; align-items: center; gap: 12px; }
.sheet-person .avatar { width: 44px; height: 44px; font-size: 1.1rem; }
.sheet-list { display: grid; }
.sheet-item {
  display: flex; align-items: center; gap: 14px; width: 100%; border: 0; background: none; text-align: left;
  padding: 14px 12px; border-radius: 12px; font-weight: 600; min-height: 52px;
}
.sheet-item:hover, .sheet-item:focus-visible { background: var(--bg); }
.sheet-item.danger { color: var(--danger); }
.sheet-item .si { width: 28px; text-align: center; font-size: 1.15rem; }
.sheet-close { width: 100%; justify-content: center !important; margin-top: 4px; }
@media (max-width: 600px) {
  dialog.sheet { margin: auto auto 0; width: 100%; max-width: 100%; border-radius: 22px 22px 0 0; animation: sheet-up .2s ease-out; }
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
