:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --line: #e3e3e0;
  --accent: #2c5fd4;
  --accent-soft: #e6edfb;
  --video: #c2410c;
  --stop: #6b7280;
  --track-done: #2c5fd4;
  --track-todo: #9db4ea;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416;
    --panel: #1c1c1f;
    --text: #ececef;
    --muted: #9a9aa2;
    --line: #2e2e33;
    --accent: #7aa2ff;
    --accent-soft: #23304d;
    --video: #fb923c;
    --stop: #9ca3af;
    --track-done: #7aa2ff;
    --track-todo: #3c4f7a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
h1 { font-size: 17px; margin: 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 12.5px; margin: 2px 0 0; }

main { flex: 1; display: flex; min-height: 0; }
#map-wrap { flex: 1; min-width: 0; position: relative; }
#map { position: absolute; inset: 0; }
#map.picking { cursor: crosshair; }
.map-btn {
  position: absolute; z-index: 1000; left: 54px; top: 10px; padding: 7px 12px; font-weight: 600;
  background: var(--panel); box-shadow: 0 1px 5px #0004;
}
.map-btn.second { left: 160px; }
.pass-marker {
  width: 14px; height: 14px; background: #f59e0b; border: 2px solid #fff; border-radius: 3px;
  box-shadow: 0 1px 3px #0008; cursor: grab;
}
.map-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.map-hint {
  position: absolute; z-index: 1000; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 7px 12px; border-radius: 8px; font-size: 13px;
}
#editor form { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
#editor label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); flex: 1; }
#editor input, #editor textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
}
#editor .row { display: flex; gap: 10px; }
#editor .buttons { flex-wrap: wrap; }
#editor .buttons button { padding: 7px 10px; }
button.primary.wide { width: auto; height: auto; }
button.danger { color: #b91c1c; border-color: color-mix(in srgb, #b91c1c 40%, transparent); }
.note-marker {
  width: 28px; height: 28px; border-radius: 6px; transform: rotate(45deg); border: 2px solid #fff;
  box-shadow: 0 1px 4px #0007; display: grid; place-items: center;
}
.note-marker span { transform: rotate(-45deg); font-size: 14px; line-height: 1; }
.note-marker.sel { outline: 3px solid var(--accent); }
#timeline li.note { padding-left: 18px; }
.nbadge { display: inline-block; width: 18px; height: 18px; border-radius: 4px; margin-right: 6px; vertical-align: -3px; }
aside {
  width: 390px;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 14px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

button {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 38px; height: 34px; }
button.icon { border: 0; background: none; font-size: 16px; padding: 2px 6px; }
select { font: inherit; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 5px; }

.clock-row { display: flex; align-items: center; gap: 10px; }
#now { font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 600; flex: 1; }
#slider { width: 100%; margin: 10px 0 2px; accent-color: var(--accent); }
.ticks { position: relative; height: 18px; }
.ticks span {
  position: absolute; top: 0; transform: translateX(-50%);
  font-size: 10px; font-weight: 700; color: #fff; background: var(--video);
  border-radius: 8px; padding: 0 4px; line-height: 14px; cursor: pointer;
}

#player video { width: 100%; max-height: 52vh; background: #000; border-radius: 8px; display: block; margin-top: 6px; }
.player-head { display: flex; justify-content: space-between; align-items: center; }

#timeline { list-style: none; margin: 0; padding: 0; }
#timeline li {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
  padding: 8px 6px;
  border-radius: 8px;
  cursor: pointer;
}
#timeline li:hover { background: var(--accent-soft); }
#timeline li.current { background: var(--accent-soft); outline: 1px solid var(--accent); }
#timeline .when { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12.5px; }
#timeline .what { min-width: 0; }
#timeline li.stop .what strong { color: var(--text); }
#timeline li.video { padding-left: 18px; }
.badge {
  display: inline-block; min-width: 20px; height: 20px; line-height: 20px; text-align: center;
  border-radius: 10px; background: var(--video); color: #fff; font-weight: 700; font-size: 11.5px;
  margin-right: 6px;
}
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; margin-left: 4px; }

.vid-marker {
  width: 26px; height: 26px; border-radius: 13px; background: var(--video); color: #fff;
  font: 700 12px/22px system-ui, sans-serif; text-align: center; border: 2px solid #fff;
  box-shadow: 0 1px 4px #0007;
}
.vid-marker.active { transform: scale(1.25); }
.me-marker {
  width: 18px; height: 18px; border-radius: 9px; background: var(--accent);
  border: 3px solid #fff; box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 30%, transparent);
}

footer { margin-top: auto; }

#sheet-handle { display: none; }
@media (max-width: 760px) {
  main { flex-direction: column; }
  #map-wrap { flex: none; height: 45vh; }
  aside { width: auto; border-left: 0; border-top: 1px solid var(--line); }
  /* Poignee du panneau du bas : toucher ou glisser pour le replier */
  #sheet-handle {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    margin: -10px -16px -10px; padding: 4px 0 2px; width: calc(100% + 32px);
    background: none; border: 0; border-radius: 0; color: var(--muted); font-size: 12px;
    touch-action: none; cursor: pointer;
  }
  #sheet-handle::before { content: ""; width: 38px; height: 4px; border-radius: 2px; background: var(--muted); opacity: .5; }
  /* Replie : la carte prend la place, le panneau ne garde que la barre de lecture */
  body.sheet-down #map-wrap { flex: 1; height: auto; }
  body.sheet-down aside { overflow: hidden; flex: none; }
  body.sheet-down aside > :not(#sheet-handle):not(.clock) { display: none !important; }
}

.arrow-badge {
  width: 30px; height: 30px; border-radius: 15px; border: 2px solid #fff; color: #fff;
  display: grid; place-items: center; font-size: 16px; line-height: 1; box-shadow: 0 1px 5px #0008; cursor: pointer;
}
.fat-arrow { cursor: pointer; }
.arrow-badge.sel { outline: 3px solid var(--accent); }
.handle { width: 16px; height: 16px; border-radius: 8px; border: 3px solid var(--accent); background: #fff; box-shadow: 0 1px 3px #0008; cursor: grab; }
.handle.end { background: var(--accent); }
.leaflet-tooltip.bubble {
  width: 250px; white-space: normal; font: 12.5px/1.35 system-ui, sans-serif;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 9px; box-shadow: 0 2px 8px #0003; cursor: pointer;
}
.leaflet-tooltip.bubble.leaflet-tooltip-top::before { border-top-color: var(--panel); }
.leaflet-tooltip.bubble.leaflet-tooltip-bottom::before { border-bottom-color: var(--panel); }
.leaflet-tooltip.bubble .more { color: var(--accent); font-weight: 600; white-space: nowrap; }
.leaflet-tooltip.bubble.open { max-height: 60vh; overflow-y: auto; z-index: 5; } /* devant les autres bulles */
.leaflet-tooltip.bubble .bubble-actions { display: flex; justify-content: space-between; margin-top: 6px; }
.leaflet-tooltip.bubble .edit { color: var(--muted); text-decoration: none; }

/* Bulles placees (commentaires et videos) */
.callout-host { overflow: visible; }
.callout-host .leader { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.callout-host .leader line { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 3 3; }
.callout {
  position: absolute; width: 250px; box-sizing: border-box; pointer-events: auto; cursor: pointer;
  font: 12.5px/1.35 system-ui, sans-serif; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; box-shadow: 0 2px 8px #0003;
}
.callout.open { z-index: 5; cursor: default; }
.callout.note.open { max-height: 60vh; overflow-y: auto; }
.callout .more { color: var(--accent); font-weight: 600; white-space: nowrap; cursor: pointer; }
.callout .bubble-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.callout .edit, .callout .close { color: var(--muted); text-decoration: none; }
.callout.video { width: 168px; padding: 6px; }
.callout.video.open { width: 260px; }
.callout .vrow { display: flex; gap: 8px; align-items: center; }
.callout .vthumb { position: relative; flex: none; width: 45px; height: 80px; border-radius: 6px; overflow: hidden; background: #000; }
.callout .vthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.callout .vthumb .play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 20px; text-shadow: 0 1px 4px #000; }
.callout .vhead .badge { margin-right: 4px; }
.callout video { width: 100%; max-height: 52vh; display: block; margin-top: 6px; border-radius: 6px; background: #000; }
.callout .vhead { line-height: 1.5; }
.callout .vhead .muted { font-size: 12px; margin: 0; }
.callout.video.open .vhead { cursor: pointer; }

/* Lecture seule (derriere edge, hors groupe humane-admin) : pas d'outils d'edition */
.read-only #add-note, .read-only #add-pass, .read-only #editor { display: none !important; }
#login { margin-left: auto; font-size: 13px; white-space: nowrap; }
