
:root {
  --bg: #f6f1e8;
  --panel: rgba(255,255,255,.92);
  --text: #1f2933;
  --muted: #687385;
  --line: #e7dccb;
  --brand: #0f766e;
  --brand-dark: #0b5c56;
  --shadow: 0 14px 40px rgba(31,41,51,.14);
}
html, body { height: 100%; margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
.hidden { display: none !important; }
#app { display: grid; grid-template-columns: minmax(320px, 380px) 1fr; height: 100%; }
#panel { padding: 18px; overflow: auto; border-right: 1px solid var(--line); background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(255,250,242,.92)); box-shadow: 6px 0 28px rgba(31,41,51,.08); z-index: 500; }
#map { height: 100%; background: #d9e5d5; }
h1 { font-size: 24px; line-height: 1.1; margin: 0 0 12px; letter-spacing: -.03em; }
label { display: block; margin-top: 14px; font-weight: 750; font-size: 13px; color: #334155; }
select, input, button, textarea { font: inherit; border: 1px solid #d7cbbb; border-radius: 12px; padding: 10px 11px; background: white; color: var(--text); box-sizing: border-box; }
select, input, textarea { width: 100%; box-shadow: inset 0 1px 0 rgba(255,255,255,.6); }
select:focus, input:focus, textarea:focus { outline: 3px solid rgba(15,118,110,.18); border-color: var(--brand); }
button { cursor: pointer; border: 0; background: #ffffff; box-shadow: 0 1px 0 rgba(255,255,255,.8), 0 3px 12px rgba(31,41,51,.08); transition: transform .12s ease, box-shadow .12s ease, background .12s ease; }
button:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(31,41,51,.12); }
button.primary, .card button { background: var(--brand); color: white; font-weight: 750; }
button.primary:hover, .card button:hover { background: var(--brand-dark); }
button.secondary { padding: 8px 10px; border: 1px solid var(--line); color: #475569; }
.topline, .row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.search-row input { min-width: 0; flex: 1; }
.search-row button { width: 44px; flex: 0 0 44px; font-size: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
.chips label { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 8px 10px; border: 1px solid #e2d7c8; border-radius: 999px; background: rgba(255,255,255,.86); font-weight: 650; font-size: 13px; }
.chips input { width: auto; accent-color: var(--brand); }
.muted { color: var(--muted); font-size: 13px; }
.error { color: #b00020; }
.login { height: 100%; display: grid; place-items: center; background: radial-gradient(circle at top, #d7f4ec, #f6f1e8 55%); }
.card { width: min(380px, calc(100% - 32px)); padding: 24px; border: 1px solid rgba(255,255,255,.7); border-radius: 24px; background: rgba(255,255,255,.9); box-shadow: var(--shadow); }
.card input, .card button { width: 100%; margin-top: 10px; }
.popup { max-width: 350px; min-width: 280px; }
.leaflet-popup-content { margin: 14px 16px 16px; }
.leaflet-popup-content-wrapper { border-radius: 20px !important; box-shadow: 0 18px 45px rgba(15,23,42,.22) !important; }
.popup-head { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.popup h2 { font-size: 19px; line-height: 1.15; margin: 0; letter-spacing: -.025em; color: #172033; }
.popup-zone { margin: 2px 0 10px; color: var(--muted); font-size: 13px; font-weight: 650; }
.popup-badge { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px; color: white; font-size: 12px; font-weight: 800; box-shadow: 0 5px 14px rgba(15,23,42,.16); }
.popup .photos { display: flex; gap: 8px; overflow-x: auto; margin: 12px 0; padding-bottom: 3px; }
.popup img { width: 148px; height: 96px; object-fit: cover; border-radius: 14px; background: #eee; box-shadow: 0 4px 14px rgba(15,23,42,.12); }
.photo-empty { margin: 12px 0; padding: 14px; border-radius: 16px; background: #f8fafc; border: 1px dashed #cbd5e1; color: #64748b; font-size: 13px; line-height: 1.35; }
.photo-empty span { color: #8792a3; }
.popup-description { line-height: 1.45; margin: 10px 0; }
.popup-address { color: #475569; margin: 10px 0; font-size: 13px; }
.popup-links { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 14px 0 12px; }
.popup-links:has(.popup-btn:only-child) { grid-template-columns: 1fr; }
.popup a.popup-btn, .popup a.popup-btn:visited { display: inline-flex; justify-content: center; align-items: center; gap: 6px; min-height: 38px; padding: 10px 12px; border-radius: 14px; color: white; text-decoration: none; font-weight: 850; box-shadow: 0 8px 18px rgba(15,23,42,.16); transition: transform .12s ease, box-shadow .12s ease, filter .12s ease; }
.popup a.popup-btn:hover { transform: translateY(-1px); box-shadow: 0 12px 22px rgba(15,23,42,.22); filter: brightness(1.04); }
.popup-btn-site { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.popup-btn-route { background: linear-gradient(135deg, #059669, #047857); }
.popup .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 10px; }
.popup .actions button, .popup .save-note { min-height: 42px; padding: 10px 12px; border-radius: 14px; font-weight: 850; border: 0; }
.toggle-btn { color: #334155; background: #f8fafc; border: 1px solid #e2e8f0 !important; box-shadow: 0 6px 16px rgba(15,23,42,.08); }
.fav-btn.active, .fav-btn:hover { background: linear-gradient(135deg, #f59e0b, #d97706); color: white; border-color: transparent !important; }
.visited-btn.active, .visited-btn:hover { background: linear-gradient(135deg, #10b981, #059669); color: white; border-color: transparent !important; }
.popup textarea { width: 100%; min-height: 70px; margin-top: 10px; border-radius: 14px; border-color: #cbd5e1; padding: 11px 12px; resize: vertical; }
.popup .save-note { margin-top: 8px; background: linear-gradient(135deg, #7c3aed, #6d28d9); color: white; box-shadow: 0 8px 18px rgba(109,40,217,.22); }
.popup .save-note:hover { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.leaflet-control-layers { border-radius: 14px !important; box-shadow: var(--shadow) !important; border: 1px solid var(--line) !important; }
.marker-pin { width: 31px; height: 31px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 3px solid white; box-shadow: 0 3px 9px rgba(0,0,0,.36); display: grid; place-items: center; position: relative; }
.marker-pin span { transform: rotate(45deg); font-size: 16px; line-height: 1; filter: drop-shadow(0 1px 1px rgba(255,255,255,.75)); }
.status-fav { box-shadow: 0 0 0 4px #facc15, 0 3px 9px rgba(0,0,0,.36); }
.status-visited { box-shadow: 0 0 0 4px #22c55e, 0 3px 9px rgba(0,0,0,.36); opacity: .78; }
.status-both { box-shadow: 0 0 0 4px #a855f7, 0 3px 9px rgba(0,0,0,.36); }
.cat-indispensable { background: #dc2626; }
.cat-musee { background: #7c3aed; }
.cat-restaurant { background: #f97316; }
.cat-bar { background: #be123c; }
.cat-cafe { background: #92400e; }
.cat-nature, .cat-parc { background: #16a34a; }
.cat-shopping { background: #0891b2; }
.cat-viewpoint { background: #2563eb; }
.cat-marche { background: #ca8a04; }
.cat-spectacle { background: #db2777; }
.cat-quartier, .cat-village { background: #64748b; }
.cat-dessert { background: #e879f9; }
.cat-hotel { background: #4f46e5; }
.cat-route { background: #0f766e; }
.cat-patrimoine { background: #9333ea; }
.cat-plage { background: #0284c7; }
.cat-spa { background: #14b8a6; }
.cat-transport { background: #475569; }

/* Spider mode for overlapping markers */
.oms-spider-leg {
  stroke: #334155;
  stroke-width: 2px;
  stroke-opacity: .75;
}

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: minmax(250px, 42vh) 1fr; }
  #panel { max-height: 42vh; border-right: 0; border-bottom: 1px solid var(--line); }
  #map { min-height: 58vh; }
  h1 { font-size: 21px; }
}

/* Photo fallback: Google Places / Wikimedia */
.photo-card { margin: 0; flex: 0 0 auto; position: relative; }
.photo-card figcaption {
  max-width: 148px;
  margin-top: 4px;
  font-size: 10px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.photo-loading {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}
.photo-loading small, .photo-empty small { color: #8792a3; }
.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid #cbd5e1;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin .85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Mode galerie photo */
.view-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0 16px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.72);
}
.view-btn {
  min-height: 40px;
  border-radius: 12px;
  background: transparent;
  color: #475569;
  font-weight: 850;
  box-shadow: none;
}
.view-btn.active {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: white;
  box-shadow: 0 8px 18px rgba(15,118,110,.22);
}
#gallery {
  height: 100%;
  overflow: auto;
  padding: 22px;
  background:
    radial-gradient(circle at top left, rgba(15,118,110,.12), transparent 34%),
    linear-gradient(180deg, #fffaf2, #f6f1e8);
}
.gallery-group { margin-bottom: 30px; }
.gallery-group h2 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 22px;
  letter-spacing: -.03em;
}
.gallery-group h2 span {
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(15,118,110,.12);
  color: var(--brand-dark);
  font-size: 13px;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}
.gallery-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(231,220,203,.92);
  border-radius: 24px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 10px 28px rgba(31,41,51,.10);
  cursor: pointer;
  transition: box-shadow .18s ease, border-color .18s ease;
  will-change: box-shadow;
}
.gallery-card:hover {
  border-color: rgba(15,118,110,.28);
  box-shadow: 0 18px 42px rgba(31,41,51,.18);
}
.gallery-image {
  position: relative;
  height: 168px;
  background: #e2e8f0;
  overflow: hidden;
}
.gallery-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: filter .18s ease;
}
.gallery-card:hover .gallery-image img {
  filter: saturate(1.04) contrast(1.015);
}
.gallery-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: white;
  position: relative;
  overflow: hidden;
}
.gallery-placeholder::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 28% 22%, rgba(255,255,255,.38), transparent 27%), linear-gradient(135deg, rgba(255,255,255,.16), rgba(0,0,0,.18));
}
.gallery-placeholder span { position: relative; z-index: 1; font-size: 48px; filter: drop-shadow(0 3px 7px rgba(0,0,0,.28)); }
.gallery-placeholder em { position: relative; z-index: 1; align-self: end; margin-bottom: 18px; padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,.22); color: rgba(255,255,255,.96); font-size: 12px; font-style: normal; font-weight: 850; backdrop-filter: blur(5px); }
.gallery-fav {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: rgba(255,255,255,.92);
  color: #92400e;
  font-size: 21px;
  box-shadow: 0 8px 18px rgba(15,23,42,.18);
  z-index: 2;
}
.gallery-fav.active {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
}
.gallery-fav:hover {
  transform: none;
  box-shadow: 0 8px 18px rgba(15,23,42,.22);
}
.gallery-visited {
  position: absolute;
  top: 12px;
  left: 12px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgba(16,185,129,.95);
  color: white;
  box-shadow: 0 8px 18px rgba(15,23,42,.18);
}
.gallery-info {
  display: grid;
  gap: 8px;
  padding: 13px 14px 15px;
}
.gallery-info strong {
  font-size: 16px;
  line-height: 1.2;
  letter-spacing: -.02em;
}
.gallery-info small { color: var(--muted); font-weight: 650; }

.gallery-open-btn {
  width: 100%;
  margin-top: 4px;
  padding: 11px 12px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, #0f766e, #14b8a6);
  color: white;
  font-weight: 850;
  box-shadow: 0 10px 20px rgba(15,118,110,.18);
  cursor: pointer;
}
.gallery-open-btn:hover {
  filter: brightness(1.03);
  box-shadow: 0 12px 22px rgba(15,118,110,.24);
}
.gallery-open-btn:active, .gallery-card:active .gallery-open-btn {
  filter: brightness(.98);
}
.gallery-card button {
  touch-action: manipulation;
}
.gallery-card:focus-within,
.gallery-card:focus {
  outline: 3px solid rgba(20,184,166,.35);
  outline-offset: 3px;
}
@media (hover: hover) {
  .gallery-card::after {
    content: "Cliquer pour voir la fiche";
    position: absolute;
    left: 14px;
    top: 14px;
    z-index: 2;
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(15,23,42,.74);
    color: white;
    font-size: 12px;
    font-weight: 800;
    opacity: 0;
    transition: opacity .16s ease;
    pointer-events: none;
  }
  .gallery-card:hover::after {
    opacity: 1;

  }
}
.gallery-category {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  color: white;
  font-size: 12px;
  font-weight: 850;
}
.gallery-empty {
  margin: 40px auto;
  max-width: 480px;
  padding: 24px;
  border-radius: 22px;
  background: rgba(255,255,255,.9);
  text-align: center;
  color: var(--muted);
  box-shadow: var(--shadow);
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 18px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15,23,42,.46);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  width: min(430px, calc(100vw - 28px));
  max-height: min(86vh, 760px);
  overflow: auto;
  border-radius: 24px;
  background: white;
  box-shadow: 0 24px 70px rgba(0,0,0,.35);
}
.modal-card .popup { max-width: none; padding: 18px; }
.modal-close {
  position: sticky;
  top: 10px;
  float: right;
  z-index: 4;
  width: 38px;
  height: 38px;
  margin: 10px 10px -48px 0;
  border-radius: 999px;
  background: rgba(15,23,42,.84);
  color: white;
  font-size: 24px;
  line-height: 1;
}
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #gallery { min-height: 58vh; padding: 14px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 12px; }
  .gallery-image { height: 125px; }
  .gallery-info { padding: 11px; }
  .gallery-info strong { font-size: 14px; }
}

@media (min-width: 1100px) {
  #gallery { padding: 32px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(285px, 1fr)); gap: 22px; }
  .gallery-image { height: 215px; }
  .gallery-info { padding: 16px 17px 18px; }
  .gallery-info strong { font-size: 18px; }
}

@media (min-width: 1500px) {
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 24px; }
  .gallery-image { height: 245px; }
}

.popup-fallback-photo {
  height: 132px;
  margin: 12px 0;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: white;
  box-shadow: 0 8px 22px rgba(15,23,42,.14);
  overflow: hidden;
  position: relative;
}
.popup-fallback-photo::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 18%, rgba(255,255,255,.38), transparent 28%), linear-gradient(135deg, rgba(255,255,255,.12), rgba(0,0,0,.22));
}
.popup-fallback-photo span { position: relative; z-index: 1; font-size: 44px; filter: drop-shadow(0 3px 7px rgba(0,0,0,.28)); }
.popup-fallback-photo strong { position: relative; z-index: 1; align-self: end; margin-bottom: 18px; padding: 6px 11px; border-radius: 999px; background: rgba(255,255,255,.22); font-size: 12px; backdrop-filter: blur(5px); }

/* Distance par rapport a Montreal par defaut, ou a la position GPS si activee */
.popup-distance {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 12px;
  padding: 7px 11px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #0f172a;
  font-size: 13px;
  font-weight: 800;
}
.gallery-distance {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-top: 2px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #334155 !important;
  font-size: 12px;
  font-weight: 850 !important;
}


.range-value {
  display: inline-flex;
  margin-left: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(15,118,110,.12);
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 850;
  vertical-align: middle;
}
.distance-filter {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.74);
}
.distance-filter input[type=range] {
  padding: 0;
  border: 0;
  box-shadow: none;
  accent-color: var(--brand);
  cursor: pointer;
}
.distance-filter button {
  min-width: 58px;
  font-weight: 800;
}
.range-help { margin: 6px 0 0; }
@media (max-width: 760px) {
  .distance-filter { grid-template-columns: 1fr; }
  .distance-filter button { width: 100%; }
}
