:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2563eb;
  --brand-ink: #1d4ed8;
  --accent: #06b6d4;
  --danger: #ef4444;
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f1f5f9;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; text-decoration: none; font-size: 17px; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(6,182,212,.25); }

.container { max-width: 820px; margin: 0 auto; padding: 18px 16px 120px; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }

/* Buttons */
.btn-primary, .btn-ghost, .btn-danger {
  font: inherit; font-weight: 600; border-radius: 12px; cursor: pointer; border: none; padding: 12px 18px;
  transition: transform .06s ease, opacity .2s ease;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.25); padding: 8px 14px; }
.container .btn-ghost { color: var(--ink); border-color: var(--line); }
.btn-danger { background: transparent; color: var(--danger); padding: 6px 10px; font-size: 13px; }

/* Home */
.page-title { font-size: 26px; margin: 6px 0 2px; }
.page-sub { color: var(--muted); margin: 0 0 20px; }

.create-card {
  background: var(--card); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 26px;
}
.create-card h2 { margin: 0 0 12px; font-size: 17px; }
.form label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 14px; }
.form input[type=text], .form textarea {
  width: 100%; margin-top: 6px; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 12px; font: inherit; color: var(--ink); background: #fff;
}
.form textarea { resize: vertical; }
.form input:focus, .form textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }

/* Entete accueil : titre + bouton Nouveau */
.home-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 16px; }
.home-head .page-title { margin: 0; }
.btn-new {
  font: inherit; font-weight: 700; background: var(--brand); color: #fff; border: none;
  border-radius: 12px; padding: 10px 16px; cursor: pointer; white-space: nowrap;
}
.btn-new:active { transform: scale(.97); }

.trip-grid { display: grid; gap: 14px; }
.trip-card {
  background: var(--card); border-radius: 18px; overflow: hidden;
  box-shadow: var(--shadow); border: 1px solid transparent; transition: border-color .2s;
}
.trip-card-main { display: block; padding: 18px; text-decoration: none; color: inherit; }
.trip-card-main:active { background: #f8fafc; }
.card-actions { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); background: #fbfdff; }
.card-btn {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; font-weight: 600;
  background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer;
}
.card-btn svg { width: 15px; height: 15px; }
.card-btn:active { transform: scale(.96); }
.card-share { color: var(--brand-ink); border-color: #bfdbfe; background: #eff6ff; }
.trip-card h3 { margin: 0 0 4px; font-size: 18px; }
.trip-card p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.trip-meta { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.badge { background: #eff6ff; color: var(--brand-ink); padding: 3px 10px; border-radius: 999px; font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* Trip detail */
.trip-header { margin-bottom: 16px; }
.trip-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.trip-title-row .page-title { margin: 0; }
.btn-edit-trip {
  font: inherit; font-size: 13px; font-weight: 600; background: #eff6ff; color: var(--brand-ink);
  border: 1px solid #bfdbfe; border-radius: 10px; padding: 8px 14px; cursor: pointer; white-space: nowrap;
}
.btn-edit-trip:active { transform: scale(.96); }
.back { color: var(--muted); text-decoration: none; font-size: 14px; display: inline-block; margin-bottom: 10px; }

/* Gros bouton "Ajouter une etape" (inline, au-dessus de la liste) */
.big-add {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  margin: 4px 0 20px; padding: 20px; font: inherit; font-size: 18px; font-weight: 800; letter-spacing: .2px;
  background: var(--brand); color: #fff; border: none; border-radius: 16px; cursor: pointer;
  box-shadow: 0 12px 28px rgba(37,99,235,.4);
}
.big-add:active { transform: scale(.98); }
.big-add:disabled { opacity: .85; cursor: default; }
.big-add svg { width: 24px; height: 24px; }

#map { height: 240px; border-radius: 18px; margin-bottom: 20px; box-shadow: var(--shadow); z-index: 1; }
.map-empty {
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 20px; color: var(--muted); font-size: 14px; background: #eef2f7;
  border: 1px dashed var(--line); box-shadow: none;
}
/* Pin numerote par etape */
.step-pin span {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--brand); color: #fff; font-weight: 800; font-size: 14px;
  border: 3px solid #fff; box-shadow: 0 2px 6px rgba(2,6,23,.45);
}

.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.step {
  position: relative; background: var(--card); border-radius: 16px; padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.step::before {
  content: ""; position: absolute; left: -26px; top: 20px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--brand); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--brand);
}
.step-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.step h3 { margin: 0 0 2px; font-size: 17px; }
.step h3.untitled { color: var(--muted); font-weight: 600; font-style: italic; }
.step .place { color: var(--brand-ink); font-size: 13px; font-weight: 600; }
.step .place.muted { color: var(--muted); font-weight: 500; }
.step .when { color: var(--muted); font-size: 12px; margin-top: 2px; }
.step .desc { margin: 10px 0 0; white-space: pre-wrap; line-height: 1.5; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 12px; }
.media-item { position: relative; }
.media-grid img, .media-grid video { width: 100%; height: 110px; object-fit: cover; border-radius: 10px; background: #000; cursor: pointer; display: block; }
.media-del {
  position: absolute; top: 5px; right: 5px; width: 26px; height: 26px; border-radius: 50%;
  border: none; background: rgba(2,6,23,.65); color: #fff; font-size: 17px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.media-del:active { background: var(--danger); }

.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; }
.preview-grid img, .preview-grid video { width: 100%; height: 80px; object-fit: cover; border-radius: 8px; background: #000; }

/* Gros bouton "Ajouter une etape" (barre pleine largeur en bas) */
.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 400; width: min(92%, 620px);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--brand); color: #fff; border: none; border-radius: 16px;
  padding: 20px 22px; font-size: 18px; font-weight: 800; letter-spacing: .2px;
  box-shadow: 0 14px 34px rgba(37,99,235,.5); cursor: pointer;
}
.fab:active { transform: translateX(-50%) scale(.98); }
.fab:disabled { opacity: .85; cursor: default; }
.fab svg { width: 26px; height: 26px; }
.spin {
  width: 20px; height: 20px; border: 3px solid rgba(255,255,255,.4);
  border-top-color: #fff; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Bouton "Ajouter photo/video/texte" sur une etape */
.btn-add {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  margin-top: 12px; padding: 12px; font: inherit; font-weight: 700;
  background: #eff6ff; color: var(--brand-ink); border: 1px dashed #bfdbfe; border-radius: 12px; cursor: pointer;
}
.btn-add:active { transform: scale(.99); }
.btn-add svg { width: 18px; height: 18px; }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 900; background: rgba(2,6,23,.55);
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
/* IMPORTANT : sans cette regle, display:flex ecrase l'attribut hidden et la modale reste affichee */
.modal[hidden] { display: none; }
.modal-card {
  background: #fff; width: 100%; max-width: 560px; border-radius: 22px 22px 0 0;
  max-height: 92vh; overflow-y: auto; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-close { background: none; border: none; font-size: 28px; line-height: 1; color: var(--muted); cursor: pointer; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.modal-actions .btn-ghost { color: var(--ink); border: 1px solid var(--line); }

.geo-status { background: #f0fdfa; color: #0f766e; border: 1px solid #99f6e4; padding: 10px 12px; border-radius: 12px; font-size: 13px; margin-bottom: 14px; }
.geo-status.err { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.geo-status.ok { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }

.media-label { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.media-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.pick-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 2px dashed var(--line); border-radius: 14px; padding: 16px 10px; color: var(--brand-ink);
  font-weight: 700; font-size: 14px; cursor: pointer; background: #f8fafc; text-align: center;
}
.pick-btn:active { transform: scale(.98); background: #eff6ff; }
.pick-btn svg { width: 26px; height: 26px; }
.pick-btn input { display: none; }

/* Bandeau vue partagee (lecture seule) */
.shared-banner {
  background: #ecfeff; color: #0e7490; border: 1px solid #a5f3fc; border-radius: 12px;
  padding: 10px 14px; font-size: 13px; font-weight: 600; margin-bottom: 12px; text-align: center;
}

/* Camera live */
.camera-modal { align-items: center; z-index: 1000; background: rgba(2,6,23,.8); }
.camera-card { max-width: 640px; width: 100%; border-radius: 22px; }
.camera-view { position: relative; background: #000; border-radius: 14px; overflow: hidden; margin-bottom: 14px; }
.camera-view video { width: 100%; max-height: 60vh; display: block; object-fit: contain; background: #000; }
.cam-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; color: #fff; font-size: 14px; }
.camera-controls { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.cam-shutter {
  width: 66px; height: 66px; border-radius: 50%; background: #fff; border: 4px solid var(--brand); cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.3); flex-shrink: 0;
}
.cam-shutter:active { transform: scale(.94); }
.cam-btn {
  font: inherit; font-weight: 700; font-size: 14px; background: #f1f5f9; color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 16px; cursor: pointer;
}
.cam-btn:active { transform: scale(.97); }
.cam-btn.recording { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

/* Lightbox */
.lightbox { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; padding: 16px; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 92vh; border-radius: 8px; }
.lightbox-close { position: absolute; top: 16px; right: 20px; color: #fff; font-size: 34px; cursor: pointer; background: none; border: none; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 1100;
  box-shadow: var(--shadow); font-size: 14px; opacity: 0; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
.toast.err { background: var(--danger); }
