@font-face {
  font-family: 'Overpass';
  src: url('/fonts/overpass-latin.woff2') format('woff2');
  font-weight: 400 800;
  font-display: swap;
}

/* Couleurs de la signalisation routière américaine : vert des panneaux, jaune d'avertissement. */
:root {
  --bg: #eef2f0;
  --surface: #ffffff;
  --ink: #14201b;
  --muted: #56645e;
  --line: #d3dcd8;
  --sign: #0a6b4b;
  --sign-strong: #075238;
  --on-sign: #ffffff;
  --yellow: #f4c20d;
  --on-yellow: #241d00;
  --red: #b42318;
  --focus: #1d5fd1;
  --shadow: 0 1px 2px rgb(20 32 27 / 0.08);
  --tabbar-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1512;
    --surface: #16211d;
    --ink: #e6ece9;
    --muted: #9aa9a3;
    --line: #2b3a34;
    --sign: #0c7a55;
    --sign-strong: #0f8f64;
    --red: #f97066;
    --focus: #7fb0ff;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Overpass', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 { line-height: 1.15; margin: 0; }
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.boot, .empty-screen { padding: 40vh 16px 0; text-align: center; color: var(--muted); }
.empty-screen .btn { margin-top: 12px; }
.empty { color: var(--muted); margin: 16px 0; }
.hint { display: block; color: var(--muted); font-size: 0.85rem; font-weight: 400; }

/* ---------- Barres ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.1rem;
  text-decoration: none;
  margin-right: auto;
}
.brand img { border-radius: 6px; }

.tabs-top { display: none; }
.tabs-bottom {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tabbar-h);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--muted);
  text-decoration: none;
}
.tab[aria-current='page'] { color: var(--sign-strong); }
.tab[aria-current='page']::before {
  content: '';
  position: absolute;
  inset: 0 22% auto;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--sign);
}
.badge {
  min-width: 20px;
  padding: 1px 6px 0;
  border-radius: 10px;
  background: var(--yellow);
  color: var(--on-yellow);
  font-size: 0.75rem;
  font-weight: 800;
  text-align: center;
}

.offline-banner {
  margin: 0;
  padding: 8px 16px;
  background: var(--yellow);
  color: var(--on-yellow);
  font-weight: 700;
  font-size: 0.9rem;
  text-align: center;
}

.main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 32px);
}

@media (min-width: 760px) {
  .tabs-bottom { display: none; }
  .tabs-top { display: flex; gap: 4px; }
  .tabs-top .tab { min-height: 44px; padding: 0 14px; }
  .tabs-top .tab[aria-current='page']::before { inset: auto 14px 0; border-radius: 3px 3px 0 0; }
  .main { padding: 28px 24px 64px; }
}

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 14px 6px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 700;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--sign); border-color: var(--sign); color: var(--on-sign); }
.btn-primary:hover { background: var(--sign-strong); border-color: var(--sign-strong); }
.btn-quiet { border-color: transparent; background: transparent; }
.btn-quiet[aria-pressed='true'] { background: var(--sign); color: var(--on-sign); }
.btn-small { min-height: 34px; padding: 5px 10px 3px; font-size: 0.85rem; }
.btn-icon { min-width: 34px; padding-inline: 0; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger-quiet { color: var(--red); }
.btn-add {
  width: 100%;
  margin-top: 16px;
  border-style: dashed;
  background: transparent;
  color: var(--sign-strong);
}

/* ---------- Villes et panneau ---------- */
.city-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 -16px 22px;
  padding: 2px 16px;
  scrollbar-width: none;
}
.city-tab {
  flex: none;
  padding: 7px 14px 5px;
  border: 2px solid var(--sign);
  border-radius: 8px;
  background: transparent;
  color: var(--sign-strong);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}
.city-tab[aria-current='page'] { background: var(--sign); color: var(--on-sign); }
.city-add { border-style: dashed; font-weight: 700; }

.sign {
  position: relative;
  padding: 6px;
  border-radius: 14px;
  background: var(--sign);
  color: var(--on-sign);
  box-shadow: var(--shadow);
}
.sign-face {
  padding: 22px 20px 18px;
  border: 3px solid var(--on-sign);
  border-radius: 9px;
}
.sign-city {
  font-size: clamp(2.1rem, 9vw, 3.4rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 0.95;
}
.sign-sub { margin: 10px 0 0; font-weight: 600; font-size: 1rem; }
/* La plaque « sortie » posée sur le bord du panneau porte les dates. */
.sign-range {
  position: absolute;
  top: -15px;
  right: 18px;
  margin: 0;
  padding: 3px 10px 1px;
  border: 3px solid var(--on-sign);
  border-radius: 7px;
  background: var(--sign);
  font-weight: 800;
  font-size: 0.9rem;
  box-shadow: 0 0 0 3px var(--bg);
}
.btn-on-sign {
  margin: 8px 0 0;
  background: transparent;
  border-color: rgb(255 255 255 / 0.6);
  color: var(--on-sign);
}

/* ---------- Jours ---------- */
.day-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 18px -16px 0;
  padding: 2px 16px 4px;
  scrollbar-width: none;
}
.day-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 14px 4px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.day-chip[aria-current='page'] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.day-chip.is-today::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 1.5px var(--on-yellow);
}
.day-add { border-style: dashed; color: var(--sign-strong); }

.day { margin-top: 22px; }
.day-head { margin-bottom: 14px; }
.day-head h2 { font-size: 1.4rem; font-weight: 800; }
.day-title { margin: 4px 0 0; color: var(--muted); font-weight: 600; }
.day-head .btn { margin-top: 10px; }
.today-tag {
  display: inline-block;
  vertical-align: 3px;
  padding: 2px 8px 0;
  border-radius: 6px;
  background: var(--yellow);
  color: var(--on-yellow);
  font-size: 0.75rem;
  font-weight: 800;
}

/* ---------- Étapes (ligne de route) ---------- */
.stops { list-style: none; margin: 0; padding: 0; }
.stop {
  display: grid;
  grid-template-columns: 4.6rem 1fr;
  gap: 0 14px;
}
.stop-time {
  padding-top: 14px;
  text-align: right;
  font-weight: 800;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.stop-body {
  position: relative;
  padding: 12px 0 18px 18px;
  border-left: 3px solid var(--line);
  min-width: 0;
}
.stop:last-child .stop-body { border-left-color: transparent; }
.stop-body::before {
  content: '';
  position: absolute;
  top: 16px;
  left: -9.5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--sign);
}
.stop.is-next .stop-body::before { background: var(--yellow); border-color: var(--on-yellow); }
.stop.is-next .stop-time { color: var(--sign-strong); }
.next-tag {
  display: inline-block;
  margin: 0 0 4px;
  padding: 2px 8px 0;
  border-radius: 6px;
  background: var(--yellow);
  color: var(--on-yellow);
  font-size: 0.75rem;
  font-weight: 800;
}
.stop-title { font-size: 1.08rem; font-weight: 700; }
.stop-address {
  display: inline-block;
  margin-top: 3px;
  color: var(--sign-strong);
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.stop .prose { margin-top: 4px; color: var(--muted); font-size: 0.95rem; }
.edit-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- Texte libre ---------- */
.prose p { margin: 0.35em 0; }
.prose ul { margin: 0.35em 0; padding-left: 1.15rem; }
.prose li { margin: 0.15em 0; }
.prose h4 { margin: 1em 0 0.3em; font-size: 1rem; }
.prose blockquote { margin: 0.5em 0; padding-left: 12px; border-left: 3px solid var(--line); }
.prose code { font-size: 0.9em; }
.prose a { color: var(--sign-strong); }
.table-wrap { overflow-x: auto; margin: 0.5em 0; }
.prose table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
.prose th, .prose td { text-align: left; padding: 7px 10px 5px; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose th { font-weight: 800; }

/* ---------- Billets ---------- */
.page-title { font-size: 1.9rem; font-weight: 800; margin-bottom: 12px; }
.ticket-counts { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 8px; }
.count { padding: 3px 10px 1px; border-radius: 6px; font-weight: 800; font-size: 0.85rem; }
.count.status-reserve { background: var(--sign); color: var(--on-sign); }
.count.status-a_reserver { background: var(--yellow); color: var(--on-yellow); }
.count.status-optionnel { border: 1.5px solid var(--line); }

.ticket-group { margin-top: 22px; }
.ticket-group h2 { font-size: 1.15rem; font-weight: 800; margin-bottom: 10px; color: var(--muted); }

.ticket {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 44px;
  margin-bottom: 14px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  scroll-margin: 90px;
}
.ticket-main { padding: 16px 16px 14px; min-width: 0; }
.ticket h3 { font-size: 1.08rem; font-weight: 800; }
.ticket-when { margin: 4px 0 0; font-weight: 700; color: var(--sign-strong); }
.ticket .prose { color: var(--muted); font-size: 0.93rem; }
.ticket-meta { margin: 6px 0 0; color: var(--muted); font-size: 0.85rem; }
.ticket-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Talon détachable : pointillés et encoches. */
.ticket-stub {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 2px dashed var(--line);
  border-radius: 0 11px 11px 0;
  font-weight: 800;
  font-size: 0.85rem;
}
.ticket-stub span { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; }
.ticket-stub::before, .ticket-stub::after {
  content: '';
  position: absolute;
  left: -9px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line);
}
.ticket-stub::before { top: -9px; }
.ticket-stub::after { bottom: -9px; }
.status-reserve .ticket-stub { background: var(--sign); color: var(--on-sign); }
.status-a_reserver .ticket-stub { background: var(--yellow); color: var(--on-yellow); }
.status-optionnel .ticket-stub { color: var(--muted); }
.ticket.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 4px var(--yellow); } to { box-shadow: 0 0 0 4px transparent; } }

.stop-ticket {
  margin-top: 10px;
  padding: 10px 12px 12px;
  border: 1.5px solid var(--line);
  border-left: 6px solid var(--sign);
  border-radius: 8px;
  background: var(--surface);
}
.stop-ticket.status-a_reserver { border-left-color: var(--yellow); }
.stop-ticket.status-optionnel { border-left-color: var(--line); }
.stop-ticket-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.stop-ticket-status {
  padding: 2px 8px 0;
  border-radius: 6px;
  background: var(--sign);
  color: var(--on-sign);
  font-size: 0.78rem;
  font-weight: 800;
}
.status-a_reserver .stop-ticket-status { background: var(--yellow); color: var(--on-yellow); }
.status-optionnel .stop-ticket-status { background: var(--line); color: var(--ink); }
.stop-ticket-when { font-weight: 700; font-size: 0.92rem; }
.stop .stop-ticket .prose { margin-top: 4px; font-size: 0.9rem; }
.stop-ticket .ticket-actions { margin-top: 8px; }
.stop-ticket-preview { margin-top: 10px; border-radius: 6px; overflow: hidden; background: #525659; }
.stop-ticket-preview img { display: block; width: 100%; height: auto; background: #fff; }
.stop-ticket-preview iframe { display: block; width: 100%; height: min(75vh, 720px); border: 0; background: #fff; }
/* Pages d'un PDF converties en images, collées bord à bord : un billet imprimé à cheval
   sur deux pages (impression de page web) se lit d'un seul tenant. */
.doc-pages { max-width: 900px; margin: 0 auto; background: #fff; }
.doc-pages img { display: block; width: 100%; height: auto; }

.loose-tickets { margin-top: 24px; }
.loose-tickets h3 { font-size: 1.05rem; font-weight: 800; color: var(--muted); }
.loose-title { margin: 14px 0 0; font-weight: 700; }
.loose-tickets .stop-ticket { margin-top: 6px; }

/* ---------- Infos ---------- */
.note {
  padding: 18px 18px 14px;
  margin-bottom: 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.note h2 { font-size: 1.15rem; font-weight: 800; margin-bottom: 6px; }

/* ---------- Compte ---------- */
.panel {
  padding: 18px;
  margin-bottom: 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.panel h2 { font-size: 1.1rem; font-weight: 800; margin-bottom: 8px; }
.panel p { margin: 0 0 8px; }
.who { display: block; }
.who span { color: var(--muted); }

/* ---------- Formulaires ---------- */
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 5px; font-weight: 700; font-size: 0.92rem; }
.form input, .form textarea, .form select {
  width: 100%;
  padding: 10px 12px 8px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* évite le zoom automatique sur iPhone */
  font-weight: 400;
}
.form textarea { resize: vertical; line-height: 1.45; }
.form input:focus, .form textarea:focus, .form select:focus { outline: none; border-color: var(--sign); box-shadow: 0 0 0 3px rgb(10 107 75 / 0.25); }
.form-error { margin: 0; color: var(--red); font-weight: 700; }

.login {
  max-width: 440px;
  margin: 0 auto;
  padding: calc(48px + env(safe-area-inset-top)) 16px 48px;
}
.sign-login .sign-face { padding: 26px 22px 24px; }
.sign-kicker { margin: 0 0 12px; font-weight: 700; }
.login-form { margin-top: 28px; }

/* ---------- Fenêtres ---------- */
dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: none;
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: rgb(8 14 12 / 0.55); }
.dialog-form { padding: 20px; }
.dialog-form h2 { font-size: 1.25rem; font-weight: 800; }
.dialog-form p { margin: 0; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
.spacer { flex: 1; }

dialog.viewer {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  border-radius: 0;
}
dialog.viewer[open] { display: flex; flex-direction: column; }
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid var(--line);
}
.viewer-title { flex: 1; margin: 0; font-weight: 800; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-body { flex: 1; min-height: 0; overflow: auto; background: #525659; padding-bottom: env(safe-area-inset-bottom); }
.viewer-body iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-body img { display: block; max-width: 100%; margin: 0 auto; background: #fff; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 16px 8px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 700;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.is-error { background: var(--red); color: #fff; }
@media (min-width: 760px) { #toast { bottom: 24px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Membres (admin) ---------- */
.members { list-style: none; margin: 0; padding: 0; }
.members li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.members li:first-child { padding-top: 0; }
.members p { margin: 0; }
.members span { color: var(--muted); font-size: 0.92rem; }
.members .role {
  padding: 2px 7px 0;
  border-radius: 6px;
  background: var(--sign);
  color: var(--on-sign);
  font-size: 0.75rem;
  font-weight: 800;
}
.form label.check { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.form label.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--sign); }
.secret {
  padding: 12px;
  border: 1.5px dashed var(--sign);
  border-radius: 8px;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: center;
  user-select: all;
  overflow-wrap: anywhere;
}
