:root {
  --bg: #0e1116;
  --surface: #171c24;
  --surface2: #202733;
  --text: #e8ecf1;
  --muted: #8b95a5;
  --accent: #5aa9ff;
  --line: #2a3240;
  --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; min-height: 100vh; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* Connexion */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login img { margin: 0 auto; border-radius: 18px; }
.login h1 { margin: 0; font-size: 26px; font-weight: 600; }
.login p { margin: 0; }
.login label { text-align: left; font-size: 14px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.login input { font-size: 17px; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.login input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.err { color: #ff8a8a; min-height: 1.4em; font-size: 14px; }
.btn { border: 0; border-radius: 12px; padding: 13px 16px; font-weight: 600; background: var(--surface2); cursor: pointer; }
.btn.primary { background: var(--accent); color: #06121f; }
.btn:disabled { opacity: .6; }

/* En-tête et filtres */
.top { position: sticky; top: 0; z-index: 20; background: rgba(14, 17, 22, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 14px) 8px calc(var(--safe-l) + 14px); border-bottom: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: 10px; }
.bar h1 { flex: 1; margin: 0; font-size: 21px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--surface); display: grid; place-items: center; cursor: pointer; font-size: 18px; flex: none; }
.icon:active { background: var(--surface2); }
.search { width: 100%; margin-top: 10px; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 16px; }
.search:focus { outline: 2px solid var(--accent); border-color: transparent; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 7px 14px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
.chip small { opacity: .7; margin-left: 4px; }
.seg { display: inline-flex; background: var(--surface); border-radius: 12px; padding: 3px; margin-top: 10px; }
.seg button { border: 0; background: transparent; padding: 7px 16px; border-radius: 9px; font-size: 14px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--surface2); color: var(--text); font-weight: 600; }

/* Contenu */
main.content { padding: 14px calc(var(--safe-r) + 14px) calc(var(--safe-b) + 40px) calc(var(--safe-l) + 14px); }
.section-title { margin: 18px 0 10px; font-size: 14px; color: var(--muted); font-weight: 500; }
.events { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.ev { background: var(--surface); border-radius: var(--radius); overflow: hidden; cursor: pointer; border: 0; text-align: left; padding: 0; display: block; width: 100%; }
.ev:active { transform: scale(.985); }
.ev .cover { aspect-ratio: 4 / 3; background: var(--surface2); width: 100%; display: block; object-fit: cover; }
.ev .meta { padding: 9px 11px 11px; }
.ev .name { font-weight: 600; font-size: 15px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ev .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 3px; }
.tile { aspect-ratio: 1; background: var(--surface); border: 0; padding: 0; cursor: pointer; overflow: hidden; display: block; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s; }
.tile img.ok { opacity: 1; }
.tile.bad { background: var(--surface2); position: relative; }
.tile.bad::after { content: "Aperçu indisponible"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; color: var(--muted); text-align: center; padding: 6px; }
.back { display: flex; align-items: center; gap: 8px; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.sentinel { height: 40px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 0 0; }

/* Indexation */
.index-box { max-width: 420px; margin: 12vh auto 0; text-align: center; padding: 0 20px; }
.index-box h2 { margin: 0 0 8px; font-size: 22px; }
.progress { height: 8px; background: var(--surface); border-radius: 99px; overflow: hidden; margin: 18px 0 8px; }
.progress i { display: block; height: 100%; width: 8%; background: var(--accent); transition: width .4s; }

/* Visionneuse */
.viewer { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; flex-direction: column; touch-action: pan-y pinch-zoom; }
.viewer .vtop, .viewer .vbot { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: 10px calc(var(--safe-r) + 12px) 10px calc(var(--safe-l) + 12px); background: linear-gradient(rgba(0, 0, 0, .65), transparent); z-index: 3; transition: opacity .2s; }
.viewer .vtop { top: 0; padding-top: calc(var(--safe-t) + 10px); }
.viewer .vbot { bottom: 0; background: linear-gradient(transparent, rgba(0, 0, 0, .65)); padding-bottom: calc(var(--safe-b) + 12px); }
.viewer.hide .vtop, .viewer.hide .vbot { opacity: 0; pointer-events: none; }
.viewer .cap { flex: 1; min-width: 0; font-size: 14px; }
.viewer .cap b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer .cap span { color: #b9c2cf; font-size: 12px; }
.viewer .stage { flex: 1; display: grid; place-items: center; overflow: hidden; }
.viewer .stage img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.viewer a.btn, .viewer .vbtn { background: rgba(255, 255, 255, .16); color: #fff; border: 0; border-radius: 12px; padding: 10px 14px; font-size: 14px; text-decoration: none; cursor: pointer; }
.viewer .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 46px; height: 64px; background: rgba(255, 255, 255, .12); color: #fff; border: 0; border-radius: 12px; font-size: 26px; z-index: 2; cursor: pointer; display: none; }
.viewer .nav.l { left: 10px; }
.viewer .nav.r { right: 10px; }
@media (hover: hover) and (min-width: 700px) { .viewer .nav { display: block; } }

/* Vidéos */
.tile { position: relative; }
.tile.vid::before { content: ""; position: absolute; left: 8px; bottom: 8px; width: 26px; height: 26px; border-radius: 50%; background: rgba(0, 0, 0, .6) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M9 6.5v11l9-5.5z'/%3E%3C/svg%3E") center / 20px no-repeat; z-index: 2; }
.tile.bad.vid::after { content: "Vidéo"; }
.viewer .stage video { max-width: 100%; max-height: 100%; background: #000; }
.viewer .vmsg { position: absolute; left: 20px; right: 20px; bottom: calc(var(--safe-b) + 90px); text-align: center; color: #d6dde8; font-size: 15px; background: rgba(0, 0, 0, .6); padding: 12px 14px; border-radius: 12px; }
.viewer #vo2 { display: none; }
.viewer.isvid #vo2 { display: inline-block; }
.viewer.isvid .vbot { display: none; }

/* Filtres personne / lieu */
.frow { padding-top: 8px; }
.chip.clear { background: transparent; color: var(--muted); }
.chip.danger { color: #ff8a8a; }
.small { font-size: 13px; }
.evhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.evhead .chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; }
.evhead .chip svg { width: 16px; height: 16px; }

/* Fenêtres (filtres, partage) */
.sheet-bg { position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 86vh; background: var(--surface); border-radius: 20px 20px 0 0; display: flex; flex-direction: column; padding-bottom: var(--safe-b); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.sh-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.sh-head b { font-size: 18px; }
.sh-head .icon { background: var(--surface2); width: 36px; height: 36px; }
.sh-body { overflow-y: auto; padding: 0 16px 20px; -webkit-overflow-scrolling: touch; }
.row { display: flex; width: 100%; justify-content: space-between; align-items: center; text-align: left; border: 0; background: transparent; padding: 12px 6px; border-bottom: 1px solid var(--line); font-size: 16px; cursor: pointer; }
.row small { color: var(--muted); }
.row.on { color: var(--accent); font-weight: 600; }
.row.sub { padding-left: 22px; }
.grp { margin: 16px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.fld { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); margin: 14px 0; }
.fld select, .linkbox { font-size: 16px; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); width: 100%; }
.chk { display: flex; gap: 10px; align-items: center; margin: 12px 0 16px; font-size: 15px; }
.chk input { width: 20px; height: 20px; }
.btn.wide { width: 100%; }
.btnrow { display: flex; gap: 10px; margin-top: 10px; }
.btnrow .btn { flex: 1; }
#shres { margin-top: 14px; }
.shrow { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.shi { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.shi b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 30px); transform: translateX(-50%); background: #fff; color: #111; padding: 10px 16px; border-radius: 99px; font-size: 14px; z-index: 300; box-shadow: 0 4px 20px rgba(0, 0, 0, .4); max-width: 90vw; }

/* Carte */
.map { height: 56vh; min-height: 320px; border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.mappanel { margin-top: 6px; }
.pin span { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg); background: var(--accent); color: #06121f; font-weight: 700; font-size: 13px; border: 2px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .5); }
.pin span::first-line { line-height: 1; }
.leaflet-container { font: inherit; }

/* Boutons de la visionneuse */
.viewer .vbtn.ic { padding: 8px; display: grid; place-items: center; width: 40px; height: 40px; flex: none; }

/* Page de partage */
.sharepage .top .bar h1 { font-size: 19px; }
.sharepage .sub { color: var(--muted); font-size: 13px; padding: 2px 0 0; }
.sharepage .dlbtn { display: none; }
.sharepage.canDl .dlbtn { display: grid; }
.sharepage .badge { text-align: center; color: var(--muted); font-size: 12px; padding: 18px 0 0; }
