* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --green: #2d5a3d;
  --green-light: #3d7a52;
  --bg: #f4f6f4;
  --track: #d63031;
}
html, body { height: 100%; font-family: system-ui, -apple-system, sans-serif; }
#app { display: flex; height: 100vh; }

#sidebar {
  width: 340px; flex-shrink: 0; background: var(--bg);
  display: flex; flex-direction: column; border-right: 1px solid #ddd;
  position: relative;
}
#sidebar header { padding: 16px; background: var(--green); color: #fff; }
#sidebar h1 { font-size: 1.4rem; margin-bottom: 12px; }

#add-btn {
  display: block; text-align: center; background: #fff; color: var(--green);
  padding: 10px; border-radius: 8px; cursor: pointer; font-weight: 600;
  text-decoration: none; transition: background .15s;
}
#add-btn:hover { background: #e8f0e8; }

#search { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
#s-place {
  width: 100%; padding: 8px 10px; border: none; border-radius: 8px; font-size: .95rem;
}
#search .s-row { display: flex; align-items: center; gap: 8px; font-size: .85rem; }
#search .s-row label { display: flex; align-items: center; gap: 4px; }
#s-radius { width: 56px; padding: 6px; border: none; border-radius: 6px; font-size: .9rem; }
#s-go {
  border: none; background: #fff; color: var(--green); font-weight: 600;
  padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
#s-clear {
  border: none; background: rgba(255,255,255,.2); color: #fff;
  padding: 6px 10px; border-radius: 6px; cursor: pointer;
}
#s-clear.hidden { display: none; }
#s-status { font-size: .82rem; min-height: 1em; color: #d8efe0; }
#s-status.error { color: #ffd0d0; }

/* Étoiles */
.stars-ro { color: #f1c40f; letter-spacing: 1px; }
.stars-edit { font-size: 1.6rem; line-height: 1; user-select: none; }
.stars-edit .star { cursor: pointer; color: #bbb; padding: 0 1px; }
.stars-edit .star.on { color: #f1c40f; }
#detail-rating { margin: 4px 0; font-size: 1.1rem; }
.comment {
  background: #f0f4f0; border-left: 3px solid var(--green); padding: 8px 10px;
  border-radius: 4px; margin: 10px 0; font-size: .9rem; color: #444; white-space: pre-wrap;
}

#filter-bar { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px; background: #ebeeeb; }
.chip {
  border: 1px solid #cdd6cd; background: #fff; border-radius: 999px;
  padding: 3px 10px; font-size: .8rem; cursor: pointer; color: #555;
}
.chip.on { background: var(--green); color: #fff; border-color: var(--green); }

.hike-item .row { display: flex; align-items: center; gap: 8px; }
.hike-item .ico { font-size: 1.1rem; }
.hike-item .name { font-weight: 600; color: #222; flex: 1; }
.hike-item .edit, .hike-item .del {
  border: none; background: none; cursor: pointer; opacity: 0; font-size: .95rem;
  transition: opacity .12s;
}
.hike-item:hover .edit, .hike-item:hover .del { opacity: .6; }
.hike-item .edit:hover, .hike-item .del:hover { opacity: 1; }

#detail-name { display: flex; align-items: center; gap: 10px; }
#detail-type {
  border: 1px solid #ccc; border-radius: 6px; padding: 4px 6px; font-size: .9rem; cursor: pointer;
}
#upload-status { font-size: .85rem; margin-top: 8px; min-height: 1em; }
#upload-status.error { color: #ffd0d0; }

#summary { padding: 12px 16px; font-size: .85rem; color: #555; border-bottom: 1px solid #ddd; }

#hike-list { list-style: none; overflow-y: auto; flex: 1; }
.hike-item {
  padding: 12px 16px; border-bottom: 1px solid #e2e6e2; cursor: pointer;
  transition: background .12s;
}
.hike-item:hover { background: #e8f0e8; }
.hike-item.active { background: #dcebe0; border-left: 4px solid var(--green); }
.hike-item .name { font-weight: 600; color: #222; }
.hike-item .meta { font-size: .8rem; color: #666; margin-top: 4px; display: flex; gap: 12px; flex-wrap: wrap; }

/* Mode édition : overlay qui occupe toute la sidebar (partie gauche) */
#edit-panel {
  position: absolute; inset: 0; z-index: 1100; background: var(--bg);
  display: flex; flex-direction: column;
}
#edit-panel.hidden { display: none; }
#edit-panel > header { padding: 16px; background: var(--green); color: #fff; }
#edit-panel > header h2 { font-size: 1.2rem; margin-top: 8px; }
#edit-back {
  border: none; background: rgba(255,255,255,.2); color: #fff; padding: 6px 12px;
  border-radius: 6px; cursor: pointer; font-size: .9rem;
}
.edit-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; flex: 1; }
.fld { display: flex; flex-direction: column; gap: 6px; font-size: .8rem; color: #666; font-weight: 600; text-transform: uppercase; }
.fld input, .fld select, .fld textarea {
  font-size: 1rem; padding: 10px; border: 1px solid #ccc; border-radius: 8px;
  background: #fff; color: #222; font-weight: 400; text-transform: none;
  font-family: inherit; resize: vertical;
}
.fld .hint { font-weight: 400; text-transform: none; color: #999; font-size: .75rem; }
#edit-meta { font-size: .85rem; color: #666; }
.edit-actions { padding: 16px; display: flex; gap: 12px; border-top: 1px solid #ddd; }
#edit-save {
  flex: 1; background: var(--green); color: #fff; border: none; border-radius: 8px;
  padding: 12px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
#edit-save:hover { background: var(--green-light); }
#edit-cancel {
  background: #fff; border: 1px solid #ccc; border-radius: 8px; padding: 12px 18px;
  cursor: pointer; color: #555;
}

main { flex: 1; position: relative; }
#map { position: absolute; inset: 0; }

#detail {
  position: absolute; bottom: 0; left: 0; right: 0; background: #fff;
  border-top: 2px solid var(--green); padding: 16px; box-shadow: 0 -4px 12px rgba(0,0,0,.15);
  z-index: 1000; max-height: 60vh; overflow-y: auto;
}
#detail.hidden { display: none; }
#detail h2 { color: var(--green); margin-right: 32px; }
#detail-close {
  position: absolute; top: 8px; right: 12px; border: none; background: none;
  font-size: 1.8rem; cursor: pointer; color: #888; line-height: 1;
}
#detail-stats { display: flex; gap: 20px; flex-wrap: wrap; margin: 12px 0; }
.stat { text-align: center; }
.stat .val { font-size: 1.3rem; font-weight: 700; color: var(--green); }
.stat .lbl { font-size: .72rem; color: #888; text-transform: uppercase; }
#profile { width: 100%; max-width: 100%; }

#detail-actions { display: flex; gap: 12px; margin-top: 8px; }
#detail-actions a, #detail-actions button {
  text-decoration: none; padding: 6px 12px; border-radius: 6px; border: 1px solid #ccc;
  background: #fff; cursor: pointer; font-size: .9rem; color: #333;
}
#detail-delete { color: var(--track); border-color: #f0b0b0; }

@media (max-width: 700px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; height: 40vh; }
  main { height: 60vh; }
}

/* ---- Page séparée d'ajout d'une randonnée ---- */
body.page-add { background: var(--bg); min-height: 100vh; }
#add-card {
  max-width: 560px; margin: 0 auto; background: #fff; min-height: 100vh;
  box-shadow: 0 0 20px rgba(0,0,0,.08); display: flex; flex-direction: column;
}
#add-card > header { padding: 20px; background: var(--green); color: #fff; }
#add-card > header h1 { font-size: 1.4rem; margin-top: 10px; }
#back-link {
  color: #fff; text-decoration: none; background: rgba(255,255,255,.2);
  padding: 6px 12px; border-radius: 6px; font-size: .9rem;
}
#add-form { padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.add-actions { display: flex; gap: 12px; align-items: center; margin-top: 6px; }
#f-submit {
  background: var(--green); color: #fff; border: none; border-radius: 8px;
  padding: 12px 24px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
#f-submit:hover { background: var(--green-light); }
#f-submit:disabled { opacity: .6; cursor: default; }
.add-actions .cancel { color: #777; text-decoration: none; }
#f-status { font-size: .9rem; min-height: 1em; }
#f-status.error { color: var(--track); }
#f-status.ok { color: var(--green); }

/* ---- Pages connexion / inscription ---- */
body.page-auth {
  background: linear-gradient(135deg, #2d5a3d, #1d3a28);
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px;
}
.auth-card {
  background: #fff; border-radius: 14px; padding: 32px; width: 100%; max-width: 360px;
  box-shadow: 0 12px 40px rgba(0,0,0,.3); display: flex; flex-direction: column; gap: 14px;
}
.auth-card h1 { text-align: center; color: var(--green); }
.auth-card .sub { text-align: center; color: #888; margin-top: -8px; font-size: .95rem; }
.auth-card button {
  background: var(--green); color: #fff; border: none; border-radius: 8px;
  padding: 12px; font-size: 1rem; font-weight: 600; cursor: pointer; margin-top: 4px;
}
.auth-card button:hover { background: var(--green-light); }
.auth-card button:disabled { opacity: .6; cursor: default; }
.auth-card .alt { text-align: center; font-size: .88rem; color: #666; }
.auth-card .alt a { color: var(--green); font-weight: 600; }
.auth-card #status { font-size: .88rem; min-height: 1em; text-align: center; }
.auth-card #status.error { color: var(--track); }

/* Barre utilisateur dans l'appli */
#userbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: .82rem; }
#who { opacity: .9; color: #fff; text-decoration: none; }
#who:hover { text-decoration: underline; }
#logout {
  border: 1px solid rgba(255,255,255,.4); background: transparent; color: #fff;
  border-radius: 6px; padding: 3px 10px; cursor: pointer; font-size: .8rem;
}
#logout:hover { background: rgba(255,255,255,.15); }

/* ---- Page profil ---- */
#add-card > header #who-big { margin-top: 6px; font-size: .9rem; opacity: .85; }
#profile-form, #password-form {
  padding: 24px; display: flex; flex-direction: column; gap: 16px;
}
#password-form { border-top: 1px solid #e2e6e2; }
.section { color: var(--green); font-size: 1.1rem; margin-bottom: -4px; }
#p-status, #pw-status { font-size: .9rem; min-height: 1em; }
#p-status.error, #pw-status.error { color: var(--track); }
#p-status.ok, #pw-status.ok { color: var(--green); }
#profile-form .add-actions #p-save,
#password-form .add-actions #pw-save {
  background: var(--green); color: #fff; border: none; border-radius: 8px;
  padding: 12px 20px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
#profile-form .add-actions #p-save:disabled,
#password-form .add-actions #pw-save:disabled { opacity: .6; cursor: default; }

/* ---- Bouton import dossier ---- */
#import-btn {
  display: block; width: 100%; margin-top: 8px; background: transparent;
  border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: 8px;
  padding: 8px; cursor: pointer; font-size: .85rem;
}
#import-btn:hover { background: rgba(255,255,255,.12); }
#import-btn:disabled { opacity: .6; cursor: default; }
#import-status { font-size: .8rem; min-height: 1em; margin-top: 6px; color: #d8efe0; }
#import-status.error { color: #ffd0d0; }

/* ---- Galerie photos (détail) ---- */
#detail-photos { margin-top: 14px; border-top: 1px solid #e2e6e2; padding-top: 10px; }
.photos-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--green); }
.photo-add {
  font-weight: 600; color: #fff; cursor: pointer; font-size: .85rem;
  border: none; border-radius: 6px; padding: 6px 12px; background: var(--green);
}
.photo-add:hover { background: var(--green-light); }
#photo-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.no-photo { font-size: .85rem; color: #999; }
.photo-cell { position: relative; width: 92px; height: 92px; }
.photo-cell img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 6px; cursor: pointer;
  border: 1px solid #ddd;
}
.photo-del {
  position: absolute; top: 2px; right: 2px; border: none; background: rgba(0,0,0,.55);
  color: #fff; width: 20px; height: 20px; border-radius: 50%; cursor: pointer;
  line-height: 1; font-size: 1rem; opacity: 0; transition: opacity .12s;
}
.photo-cell:hover .photo-del { opacity: 1; }

/* ---- Marqueur photo sur la carte ---- */
.photo-marker { font-size: 20px; text-align: center; line-height: 26px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); cursor: pointer; }

/* ---- Lightbox ---- */
#lightbox {
  position: absolute; inset: 0; z-index: 2000; background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
}
#lightbox.hidden { display: none; }
#lightbox img { max-width: 92%; max-height: 92%; border-radius: 6px; box-shadow: 0 6px 30px rgba(0,0,0,.6); }
#lightbox-close {
  position: absolute; top: 16px; right: 24px; border: none; background: none;
  color: #fff; font-size: 2.5rem; cursor: pointer; line-height: 1;
}
