:root {
  --bg: #faf7f2; --panel: #ffffff; --ink: #1f2430; --muted: #6b7180; --line: #e6e1d8;
  --accent: #d9534f; --accent-ink: #fff; --accent-soft: #fbe9e7;
  --r1: #2a9d8f; --r2: #4f8fd9; --r3: #8e6bd1; --r4: #e09f3e; --r5: #9aa0a6;
  --star: #f2b705; --good: #2a9d8f; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161b; --panel: #1d2027; --ink: #e9eaee; --muted: #9aa0ad; --line: #2c303a;
    --accent: #ef6b62; --accent-soft: #3a2422; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { background: var(--panel); padding: 32px 28px; border-radius: 16px; box-shadow: var(--shadow);
  width: min(380px, 100%); text-align: center; }
.login-logo { font-size: 48px; }
.login-box h1 { margin: 4px 0 6px; }
.login-box p { color: var(--muted); margin: 0 0 18px; }
.login-box input { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font-size: 16px; }
.login-box button { width: 100%; margin-top: 12px; padding: 12px; border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.err { color: var(--accent) !important; margin-top: 12px !important; }

.top { position: sticky; top: 0; z-index: 1000; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; white-space: nowrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs button { border: 0; background: none; color: var(--muted); padding: 6px 12px; border-radius: 999px; white-space: nowrap; }
.tabs button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tabs .ico, .tabs .court { display: none; }
.tabs .ico + .lib { margin-left: 0; }
.ghost { border: 1px solid var(--line); background: none; color: var(--muted); font-size: 13px; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }

.filters { padding: 12px 16px 0; max-width: 1200px; margin: 0 auto; }
.filters-toggle { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 5px 11px;
  border-radius: 999px; font-size: 13.5px; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.row { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-top: 10px; }
.dist { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.dist b { color: var(--ink); min-width: 9em; }
#q { flex: 1; min-width: 200px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--ink); }
.chk { color: var(--muted); font-size: 13.5px; }
.count { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

main { max-width: 1200px; margin: 0 auto; padding: 12px 16px 48px; }
.ring-head { display: flex; align-items: center; gap: 10px; margin: 22px 0 10px; font-weight: 700; }
.ring-dot { width: 12px; height: 12px; border-radius: 50%; }
.ring-head small { color: var(--muted); font-weight: 400; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px;
  box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: 6px; position: relative; }
.card:hover { border-color: var(--muted); }
.card h3 { margin: 0; font-size: 15.5px; line-height: 1.3; padding-right: 28px; }
.where { color: var(--muted); font-size: 13px; }
.forms { margin: 2px 0 0; padding-left: 18px; font-size: 13.5px; }
.plaire { font-size: 13.5px; background: var(--bg); border-radius: 10px; padding: 8px 10px; margin-top: 2px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; padding-top: 4px; }
.tag { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.tag.prive { color: var(--r4); border-color: var(--r4); }
.tag.money { color: var(--good); border-color: var(--good); font-weight: 600; }
.tag.todo { font-style: italic; }
.star { position: absolute; top: 10px; right: 10px; border: 0; background: none; font-size: 20px; color: var(--line); line-height: 1; }
.star.on { color: var(--star); }
.star.parents { text-shadow: 0 0 0 var(--r2); }

#map { height: calc(100vh - 230px); min-height: 420px; border-radius: 14px; border: 1px solid var(--line); }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(760px, calc(100% - 24px)); max-height: 90vh;
  background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); overflow-y: auto; overscroll-behavior: contain; }
dialog::backdrop { background: rgba(0,0,0,.45); }
#detail-body { padding: 22px 22px 26px; }
.d-head { display: flex; gap: 12px; align-items: flex-start; }
.d-head h2 { margin: 0; flex: 1; font-size: 20px; }
.close { border: 0; background: var(--bg); border-radius: 50%; width: 32px; height: 32px; color: var(--ink); }
.d-sec { margin-top: 18px; }
.d-sec h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.d-sec ul { margin: 0; padding-left: 18px; }
.formation { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-top: 10px; }
.formation h5 { margin: 0 0 6px; font-size: 15px; }
.kv { display: grid; grid-template-columns: 9.5em 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.money-box { background: var(--accent-soft); border-radius: 10px; padding: 8px 12px; margin-top: 8px; font-size: 14px; }
.note { width: 100%; min-height: 60px; margin-top: 6px; padding: 8px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.agenda-item { display: flex; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.agenda-date { min-width: 64px; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.agenda-date b { display: block; font-size: 20px; }
.piste { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; }
.piste h3 { margin: 0 0 6px; }
.piste ul { margin: 0; padding-left: 18px; }

table.costs { width: 100%; border-collapse: collapse; font-size: 13.5px; background: var(--panel); border-radius: 12px; overflow: hidden; }
.costs th, .costs td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.costs th { cursor: pointer; white-space: nowrap; color: var(--muted); font-weight: 600; }
.costs td.n { text-align: right; white-space: nowrap; }
.costs tr:hover td { background: var(--bg); cursor: pointer; }
.table-wrap { overflow-x: auto; }

@media (max-width: 640px) {
  .top { justify-content: space-between; }
  /* Onglets en barre fixe en bas d'écran */
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; background: var(--panel); border-top: 1px solid var(--line);
    justify-content: space-around; gap: 0; padding: 4px 2px calc(4px + env(safe-area-inset-bottom)); overflow: visible; flex: none; }
  .tabs button { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 2px; border-radius: 10px; flex: 1; min-width: 0; }
  .tabs .ico { display: block; font-size: 18px; line-height: 1.2; }
  .tabs .lib { display: none; }
  .tabs .court { display: block; font-size: 10.5px; }
  main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  /* Filtres repliables */
  .filters-toggle { display: flex; width: 100%; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel);
    color: var(--ink); border-radius: 10px; padding: 8px 12px; text-align: left; }
  .filters-toggle #filters-sum { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .filters.collapsed .filters-body { display: none; }
  .filters:not(.collapsed) .caret { transform: rotate(180deg); }
  .filters-body { padding-top: 10px; }
  .dist { width: 100%; flex-wrap: wrap; }
  .dist b { min-width: 0; }
  .dist input { flex: 1; }
  .grid { grid-template-columns: 1fr; }
  /* Coûts : une carte par école */
  table.costs, .costs tbody, .costs tr, .costs td { display: block; }
  .costs thead { display: none; }
  .costs tr { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .costs td { border: 0; padding: 0; text-align: left !important; }
  .costs td.nom { grid-column: 1 / -1; font-weight: 600; margin-bottom: 4px; }
  .costs td.nom .muted { font-weight: 400; }
  .costs td[data-label]::before { content: attr(data-label) " : "; color: var(--muted); font-size: 12px; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 6px; }
  #map { height: calc(100vh - 250px); min-height: 360px; }
  dialog { width: 100%; max-height: 92vh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  #detail-body { padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); }
}
