:root {
  color-scheme: light;
  --ink: #1c1f24;
  --muted: #667085;
  --line: #dfe3e8;
  --line-strong: #b8c0cc;
  --ground: #f6f7f9;
  --card: #fff;
  --accent: #1f5fd1;
  --on-accent: #fff;
  --regular: #1a7f4b;
  --new: #b25e00;
  --paused: #8a5cc7;
  --oneoff: #667085;
  --danger: #b42318;
  --note: #fff7e0;
  --note-line: #ecd28a;
  --shadow: #1c1f2426;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e6e8ec;
  --muted: #98a2b3;
  --line: #2e333b;
  --line-strong: #4a515c;
  --ground: #14161a;
  --card: #1d2026;
  --accent: #6ea0ff;
  --on-accent: #0b1220;
  --regular: #3fb27a;
  --new: #e0943a;
  --paused: #b08ae6;
  --oneoff: #8a93a3;
  --danger: #ff7b6e;
  --note: #33290f;
  --note-line: #6b5518;
  --shadow: #00000080;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--ground); display: flex; flex-direction: column; }
h1, h2 { margin: 0; font-size: 17px; }
h1 span { font-weight: 400; color: var(--muted); }
h1 { display: flex; align-items: center; gap: 8px; }
h1 span { margin-left: -2px; }
/* The icon is pixel art : it must scale without blur. */
.logo { image-rendering: pixelated; border-radius: 6px; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--card); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
button:hover { border-color: var(--line-strong); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.danger { color: var(--danger); margin-right: auto; }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; background: var(--card); width: 100%; min-width: 0; }
input[type=checkbox], input[type=radio], input[type=range] { width: auto; padding: 0; }
input[type=range] { width: 100%; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--danger); }

.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.top h1 { margin-right: auto; }

main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(380px, 46%) 1fr; }
.panel { overflow-y: auto; padding: 12px 16px 40px; }
#map { min-height: 300px; border-left: 1px solid var(--line); }

.filters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 10px; }
.filters label, .filters .field, .grid label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.filters .wide { grid-column: span 2; }
.inline { display: flex; gap: 6px; }
.inline button { white-space: nowrap; }
button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
#map.picking, #map.picking .leaflet-interactive { cursor: crosshair; }
.filters input[type=range] { height: 31px; margin: 0; }
.km { display: flex; align-items: center; gap: 6px; }
.km input { width: 76px; }
.multi { position: relative; color: var(--ink); font-size: 14px; }
.multi summary { border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; background: var(--card); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.multi .options { position: absolute; z-index: 1000; top: calc(100% + 4px); left: 0; width: max-content; min-width: 100%; max-width: 340px; max-height: 320px; overflow-y: auto; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px; box-shadow: 0 6px 20px var(--shadow); }
.multi .options label { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); padding: 2px 4px; }
.multi .options label span { color: var(--muted); margin-left: auto; padding-left: 10px; }
.multi-head { position: sticky; top: -6px; display: flex; gap: 6px; background: var(--card); padding: 6px 0; margin-top: -6px; z-index: 1; }
.multi-head input { font-size: 13px; padding: 3px 8px; }
.multi-head button { font-size: 12px; padding: 1px 8px; white-space: nowrap; }
.multi .options label[hidden] { display: none; }

.searches { display: grid; grid-template-columns: 1fr 1fr auto auto auto; gap: 6px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: 8px; margin: 14px 0 8px; position: sticky; top: -12px; background: var(--ground); padding: 8px 0; z-index: 2; flex-wrap: wrap; }
.bar strong { margin-right: auto; }
.bar select { width: auto; }
.status { margin: 12px 0 0; background: var(--note); border: 1px solid var(--note-line); border-radius: 6px; padding: 8px 10px; }

.row { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; margin-bottom: 7px; }
.row.flash { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.row > input { margin-top: 3px; align-self: start; }
.row .body { min-width: 0; }
.row .name { font-weight: 600; }
.row .line { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.row .next { color: var(--ink); }
.row .next.probable { font-style: italic; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 0 7px; border-radius: 999px; margin-left: 6px; color: var(--on-accent); vertical-align: 1px; }
.tag.regular { background: var(--regular); }
.tag.new { background: var(--new); }
.tag.paused { background: var(--paused); }
.tag.oneoff { background: var(--oneoff); }
.row details { font-size: 13px; margin-top: 3px; }
.row summary { cursor: pointer; color: var(--muted); }
.row ul { margin: 4px 0 0; padding-left: 18px; }
.row li { margin-bottom: 2px; }
.row li button { padding: 0 6px; font-size: 12px; margin-left: 4px; }
.flag { font-size: 11px; color: var(--new); margin-left: 4px; }
#unlocated { margin-top: 14px; }
#unlocated > summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }

dialog { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 18px; width: min(720px, 94vw); }
dialog::backdrop { background: #1c1f2466; }
dialog form { display: flex; flex-direction: column; gap: 10px; }
.formats { display: flex; gap: 14px; flex-wrap: wrap; }
.check { display: flex; gap: 6px; align-items: center; }
#export-hint { margin: 0; }
textarea { font-family: ui-monospace, Menlo, monospace; font-size: 12px; resize: vertical; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.grid .wide { grid-column: span 2; }
.grid textarea { font: inherit; }
.actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }

/* Last column of the filters : its list opens leftwards, inside the panel. */
#regions .options { left: auto; right: 0; }

/* The map tiles are light : in the dark theme they are inverted, hue kept. */
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(1.05) contrast(0.85) saturate(0.6); }
:root[data-theme="dark"] .leaflet-container { background: #14161a; }
:root[data-theme="dark"] .leaflet-bar a, :root[data-theme="dark"] .leaflet-control-attribution { background: var(--card); color: var(--ink); border-color: var(--line); }
:root[data-theme="dark"] .leaflet-control-attribution a { color: var(--accent); }

/* The access page of the hosted site. */
body.admin { display: block; }
.admin-body { max-width: 900px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card p { margin: 0; }
.card table { border-collapse: collapse; width: 100%; }
.card th, .card td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.card td:nth-child(3) { width: 100%; }
.card td input { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.card td .danger { margin-right: 0; }

/* Contact icons on a row, and the small menu under mail and phone. */
.row .contact { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 3px 0 1px; }
.contact-text { min-width: 0; line-height: 26px; }
.icons { display: inline-flex; align-items: center; gap: 4px; }
.icon svg { display: block; }
.icon { display: inline-flex; }
.icon-button { display: inline-flex; align-items: center; gap: 1px; height: 26px; padding: 0 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--ink); cursor: pointer; list-style: none; }
.icon-button::-webkit-details-marker { display: none; }
.icon-button:hover, .pop[open] > .icon-button { border-color: var(--accent); color: var(--accent); }
.pop { position: relative; display: block; font-size: 13px; }
/* `.row details` gives the editions list a top margin ; on a contact menu it
   would push the icon a pixel and a half below the ones beside it. */
.row details.pop { margin: 0; }
.pop > summary { display: flex; }
.pop-panel { position: absolute; z-index: 1000; top: calc(100% + 4px); left: 0; width: max-content; max-width: 300px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px; box-shadow: 0 6px 20px var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.pop-panel .value { color: var(--ink); font-weight: 600; user-select: all; overflow-wrap: anywhere; }
.pop-actions { display: flex; gap: 6px; }
a.button { display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 6px; padding: 5px 10px; text-decoration: none; }
a.button:hover { border-color: var(--line-strong); }

/* "Copié" : the button itself confirms, in place of a toast. */
button.copied { background: var(--regular); border-color: var(--regular); color: var(--on-accent); display: inline-flex; align-items: center; justify-content: center; gap: 5px; animation: copied 0.35s ease-out; }
button.primary.copied { background: var(--regular); border-color: var(--regular); }
@keyframes copied { 0% { transform: scale(0.92); } 55% { transform: scale(1.08); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { button.copied { animation: none; } }

.credits { margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

/* Header : the theme button is an icon. */
.top .icon-button { height: 32px; width: 34px; justify-content: center; padding: 0; }
#filters-toggle, .views, #map-card { display: none; }

/* ─── Small screens ───────────────────────────────────────────────────
   One column. The list and the map are two views, switched from the
   header ; the place and the filters fold behind one button ; menus open
   as sheets at the bottom of the screen instead of beside their button ;
   touching a point of the map shows its event in a card over the map. */
@media (max-width: 860px) {
  body { height: 100dvh; }
  button, select, input, textarea { font-size: 16px; }
  button, select, input:not([type=checkbox]):not([type=radio]):not([type=range]) { min-height: 40px; }

  .top { padding: 8px 12px; gap: 8px; }
  .top h1 { font-size: 16px; }
  .top h1 span, #fetched, .long { display: none; }
  .top > button { font-size: 14px; padding: 4px 10px; min-height: 36px; white-space: nowrap; }
  .top .icon-button { flex: none; height: 36px; width: 40px; }

  /* Top to bottom : the place and filters, the list / map switch, then
     whichever of the two is chosen. The filters apply to both. */
  main { display: flex; flex-direction: column; position: relative; min-height: 0; }
  .panel { display: contents; }
  .panel-head { flex: none; max-height: 64dvh; overflow-y: auto; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .panel-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 24px; }
  #map { flex: 1; min-height: 0; border: 0; }
  body:not([data-view="map"]) #map { display: none; }
  body[data-view="map"] .panel-list { display: none; }
  .views { display: grid; grid-template-columns: 1fr 1fr; margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
  .views button { border: 0; border-radius: 0; min-height: 40px; font-weight: 600; }

  #filters-toggle { display: block; width: 100%; text-align: left; font-weight: 600; }
  #filters-toggle::after { content: '▸'; float: right; }
  #filters-toggle[aria-expanded="true"]::after { content: '▾'; }
  #filters-box { display: none; margin-top: 10px; }
  .filters-open #filters-box { display: block; }
  .filters, .searches { grid-template-columns: 1fr 1fr; }
  .filters .wide { grid-column: 1 / -1; }
  .km input { width: 96px; }

  .bar { top: 0; margin-top: 0; padding-top: 10px; }
  .bar strong { flex-basis: 100%; }
  .bar select { flex: 1; }
  #check-all, #check-none { display: none; }

  .row { padding: 11px 12px; gap: 2px 12px; }
  .row > input { width: 22px; height: 22px; }
  .row .line { font-size: 14px; }
  .icon-button { height: 38px; min-width: 42px; justify-content: center; }
  .contact-text { line-height: 1.5; flex-basis: 100%; }
  .row li button { min-height: 32px; padding: 2px 10px; }

  /* Sheets : full width at the bottom of the screen, whatever opened them. */
  .multi .options, #regions .options, .pop-panel { position: fixed; left: 12px; right: 12px; top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); width: auto; min-width: 0; max-width: none; max-height: 62dvh; box-shadow: 0 0 0 100vmax #1c1f2466, 0 6px 20px var(--shadow); }
  .multi .options label { padding: 9px 4px; font-size: 15px; }
  .multi .options input[type=checkbox] { width: 20px; height: 20px; }
  .pop-panel { padding: 14px; gap: 12px; }
  .pop-panel .value { font-size: 16px; }
  .pop-actions > * { flex: 1; text-align: center; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }

  /* The event touched on the map. */
  body[data-view="map"] #map-card:not([hidden]) { display: flex; flex-direction: column; gap: 8px; position: absolute; z-index: 1100; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); max-height: 58%; overflow-y: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; box-shadow: 0 8px 28px var(--shadow); }
  #map-card .row { border: 0; padding: 2px; margin: 0; background: none; }
  #map-card .actions button { flex: 1; }

  dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; margin: auto 0 0; border-radius: 14px 14px 0 0; padding: 16px 14px calc(16px + env(safe-area-inset-bottom)); }
  .grid { grid-template-columns: 1fr; }
  .grid .wide { grid-column: auto; }
  .formats { flex-direction: column; gap: 4px; }
  .formats label, .check { min-height: 36px; align-items: center; display: flex; gap: 8px; }
  textarea#export-text { max-height: 34dvh; }
  .actions { flex-wrap: wrap; }
  .actions button { flex: 1; }

  /* Picking the place : the instruction floats over the map. */
  #map.picking::after { content: 'Touche un point de la carte pour en faire le lieu'; position: absolute; z-index: 1000; left: 12px; right: 12px; top: 12px; padding: 10px 12px; border-radius: 8px; background: var(--accent); color: var(--on-accent); font-weight: 600; text-align: center; pointer-events: none; }

  .admin-body { padding: 12px; }
  .card table, .card tbody, .card tr, .card td { display: block; white-space: normal; }
  .card thead { display: none; }
  .card tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .card td { border: 0; padding: 3px 0; }
  .inline { flex-wrap: wrap; }
  .inline input { flex: 1 1 100%; }
  .inline button { flex: 1; }
}

/* Version in the footer, and the release notes it opens. */
button.link { border: 0; background: none; padding: 0; min-height: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }
#releases { max-height: 60dvh; overflow-y: auto; }
#releases h3 { margin: 10px 0 4px; font-size: 15px; }
#releases ul { margin: 0; padding-left: 20px; }
#releases li { margin-bottom: 3px; }
