/* TravelMap — warm, photo-forward, mobile-first. */
:root {
  --accent: #D85A30;
  --accent-dark: #B8461F;
  --ink: #2B2622;
  --ink-soft: #6B6259;
  --surface: #FAF6F1;
  --surface-2: #F1E9E0;
  --card: #FFFFFF;
  --line: #E7DCD0;
  --shadow: 0 2px 10px rgba(60, 40, 20, 0.08);
  --shadow-lg: 0 8px 30px rgba(60, 40, 20, 0.16);
  --radius: 14px;
  --radius-sm: 9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---- Manual photo placement (search + tap + map center) — FIX B ---- */
.media-thumb.selected { outline: 3px solid var(--accent); outline-offset: 1px; }
.place-panel { margin-top: .8rem; }
.place-hint { font-size: .85rem; color: var(--ink-soft); margin-bottom: .5rem; line-height: 1.35; }
.place-hint.error { color: var(--accent-dark); }
.place-search { display: flex; gap: .5rem; }
.place-input {
  flex: 1 1 auto; min-width: 0;
  padding: .6em .8em; font: inherit; font-size: 16px; /* 16px avoids iOS zoom-on-focus */
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card); color: var(--ink);
}
.place-search-btn { flex: 0 0 auto; }
.place-results { margin-top: .5rem; display: flex; flex-direction: column; gap: .4rem; }
.place-result {
  display: block; width: 100%; text-align: left;
  padding: .55em .7em; font: inherit; font-size: .85rem; line-height: 1.3;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer;
}
.place-result:hover { border-color: var(--accent); }
.place-empty { font-size: .85rem; color: var(--ink-soft); padding: .2rem 0; }
.place-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.place-actions .btn { flex: 1 1 auto; justify-content: center; }
@media (max-width: 560px) {
  .place-search { flex-wrap: wrap; }
  .place-search-btn { width: 100%; justify-content: center; }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--surface);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-dark); }
img { max-width: 100%; display: block; }
.muted { color: var(--ink-soft); }
.hidden { display: none !important; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: .5em;
  font: inherit; font-weight: 600;
  padding: .6em 1.1em; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  cursor: pointer; text-decoration: none; transition: .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: #B3261E; border-color: #E8C4C0; }
.btn-danger:hover { background: #FBEDEC; }
.btn-sm { padding: .35em .7em; font-size: .85rem; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Forms ---- */
label { display: block; font-weight: 600; font-size: .9rem; margin: .8em 0 .3em; }
input[type=text], input[type=password], input[type=date], input[type=url], textarea, select {
  width: 100%; font: inherit; color: var(--ink);
  padding: .6em .7em; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

.alert { background: #FBEDEC; border: 1px solid #E8C4C0; color: #8A2018; padding: .7em 1em; border-radius: var(--radius-sm); margin: .6em 0; }
.notice { background: #FFF6EE; border: 1px solid #F0D8C2; color: #7A4A22; padding: .7em 1em; border-radius: var(--radius-sm); }

/* ---- Header ---- */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .8rem 1.2rem; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.brand-pin { color: var(--accent); font-size: 1.1rem; }
/* Logo badge: square, rounded, never stretched (cover-cropped). */
.brand-logo {
  width: 36px; height: 36px; flex: none; border-radius: 10px;
  object-fit: cover; display: block; box-shadow: 0 1px 3px rgba(0,0,0,.18);
}
.topbar h1, .brand h1 { font-size: 1.25rem; margin: 0; letter-spacing: -.01em; white-space: nowrap; }
.topbar .spacer { flex: 1; }
/* Narrow phones: keep badge + wordmark, let the text shrink rather than wrap. */
@media (max-width: 480px) {
  .brand-logo { width: 32px; height: 32px; }
  .topbar h1, .brand h1 { font-size: 1.05rem; }
}

/* ---- Login ---- */
.login-page { display: grid; place-items: center; min-height: 100vh; background: var(--surface-2); }
.login-card {
  background: var(--card); padding: 2rem; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); width: min(360px, 92vw); text-align: center;
}
.login-card .brand { justify-content: center; margin-bottom: .2rem; }
.login-card form { text-align: left; margin-top: 1rem; }
/* Full logo, large + centred, on the sign-in screen. */
.login-logo {
  display: block; width: 100%; max-width: 280px; height: auto; margin: 0 auto .6rem;
  border-radius: 18px; box-shadow: var(--shadow-lg);
}

/* ---- Layout ---- */
.wrap { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.2rem 4rem; }
.page-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 1.6rem; }

/* ---- Trip library grid ---- */
.trip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.3rem; }
.trip-card {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); text-decoration: none; color: inherit;
  display: flex; flex-direction: column; transition: .18s; border: 1px solid var(--line);
}
.trip-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.trip-cover { aspect-ratio: 3/2; background: var(--surface-2) center/cover no-repeat; position: relative; }
.trip-cover .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-soft); font-size: 2rem; }
.trip-card .body { padding: .9rem 1rem 1.1rem; }
.trip-card h3 { margin: 0 0 .2rem; font-size: 1.1rem; }
.trip-card .meta { font-size: .85rem; color: var(--ink-soft); }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .15em .55em; border-radius: 999px; background: var(--accent); color: #fff; }
.empty-state { text-align: center; padding: 4rem 1rem; color: var(--ink-soft); }

/* ---- Wizard ---- */
.steps { display: flex; gap: .5rem; margin-bottom: 1.5rem; }
.steps .step { flex: 1; text-align: center; padding: .6rem; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink-soft); font-weight: 600; font-size: .9rem; }
.steps .step.active { background: var(--accent); color: #fff; }
.steps .step.done { background: #E9DfD3; color: var(--ink); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow); }
.wizard-actions { display: flex; justify-content: space-between; margin-top: 1.4rem; gap: 1rem; }

/* ---- Upload pipeline ---- */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 2.2rem 1rem;
  text-align: center; color: var(--ink-soft); cursor: pointer; background: var(--surface);
}
.dropzone.drag { border-color: var(--accent); background: #FFF6EE; }
.upload-list { margin-top: 1rem; display: grid; gap: .5rem; }
.upload-row { display: grid; grid-template-columns: 52px 1fr auto; gap: .7rem; align-items: center; font-size: .85rem; }
.upload-row .thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.progress { height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.upload-row .state { font-size: .75rem; color: var(--ink-soft); white-space: nowrap; }
.upload-row .state.gps { color: #2E7D32; }
.upload-row .state.nogps { color: #B5641E; }

/* Editor "+ Add photos" progress overlay (mobile-first centred card). */
.upload-overlay {
  position: fixed; inset: 0; z-index: 1000; display: none;
  align-items: flex-start; justify-content: center;
  padding: 1rem; background: rgba(43, 38, 34, .45); overflow-y: auto;
}
.upload-overlay.show { display: flex; }
.upload-overlay-card {
  width: 100%; max-width: 520px; margin-top: 8vh;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.2rem; box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
.upload-overlay-card h4 { margin: 0 0 .4rem; }
.upload-overlay-card .upload-list { max-height: 60vh; overflow-y: auto; }

/* ---- Editor ---- */
.editor-grid { display: grid; grid-template-columns: 1fr 380px; gap: 1.2rem; align-items: start; }
.editor-map { height: 70vh; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); position: sticky; top: 80px; }
.stop-list { display: flex; flex-direction: column; gap: .8rem; }
.stop-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; box-shadow: var(--shadow); }
.stop-item.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(216,90,48,.25); }
.stop-item h4 { margin: 0 0 .3rem; font-size: 1rem; }
.stop-head { display: flex; align-items: center; gap: .4rem; }
.stop-head .drag { cursor: grab; color: var(--ink-soft); }
.stop-head .spacer { flex: 1; }
.thumb-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.media-thumb { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-thumb.video { display: grid; place-items: center; color: var(--accent-dark); font-size: 1.4rem; }
.media-thumb.cover-sel { outline: 3px solid var(--accent); }
.tray { background: var(--surface-2); border: 1px dashed var(--line); border-radius: var(--radius); padding: .9rem; }
.tray h4 { margin: 0 0 .5rem; }
.field-row { display: flex; gap: .6rem; }
.field-row > * { flex: 1; }

/* leaflet markers */
.pin-num {
  background: var(--accent); color: #fff; border-radius: 50%;
  width: 26px; height: 26px; display: grid; place-items: center;
  font-weight: 700; font-size: .8rem; border: 2px solid #fff; box-shadow: var(--shadow);
}
.pin-num.visited { background: var(--ink-soft); }
.pin-num.active { transform: scale(1.25); }

/* ---- Story viewer ---- */
.viewer { display: grid; grid-template-columns: 45% 55%; gap: 0; min-height: 100vh; }
.viewer-map { position: sticky; top: 0; height: 100vh; }
.viewer-scroll { padding: 0 0 40vh; }
.viewer-intro { padding: 18vh 2.2rem 8vh; }
.viewer-intro h1 { font-size: 2.4rem; margin: 0 0 .3rem; letter-spacing: -.02em; }
.viewer-intro .place { color: var(--accent-dark); font-weight: 600; }
.viewer-intro .desc { margin-top: 1rem; color: var(--ink-soft); max-width: 40ch; }

/* Owner-only Share / Unshare control in the header (trip_view.php): a trigger
   button anchoring a popover. .share-control is a direct child of .topbar after
   #topnav, so it stays in the always-visible header row (never the ☰ panel). */
.share-control { position: relative; flex: none; display: inline-flex; }
.share-panel { margin-top: 1.6rem; display: flex; flex-direction: column; gap: .6rem; align-items: flex-start; max-width: 40ch; }
/* Repositioned as a dropdown popover anchored to the trigger's right edge. */
.share-popover {
  position: absolute; top: calc(100% + .5rem); right: 0; margin-top: 0;
  width: min(22rem, 90vw); max-width: none; z-index: 60;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: .9rem 1rem;
}
.share-popover[hidden] { display: none; }
.share-link-row { display: flex; gap: .5rem; width: 100%; flex-wrap: wrap; }
.share-link {
  flex: 1 1 14rem; min-width: 0; font: inherit; font-size: .85rem;
  padding: .45em .7em; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card); color: var(--ink);
}
.share-hint { font-size: .8rem; }
.story-stop { padding: 8vh 2.2rem; min-height: 60vh; }
.story-stop h2 { font-size: 1.7rem; margin: .2rem 0 .2rem; }
.story-stop .stop-meta { color: var(--ink-soft); font-size: .9rem; margin-bottom: 1rem; }
.story-stop .stop-desc { margin-top: 1rem; max-width: 46ch; }

.gallery { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; box-shadow: var(--shadow-lg); }
.gallery .slide { display: none; }
.gallery .slide.active { display: block; }
.gallery img { width: 100%; max-height: 70vh; object-fit: contain; background: #000; }
.gallery .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.45); color: #fff; border: none; width: 42px; height: 42px; border-radius: 50%; font-size: 1.4rem; cursor: pointer; display: grid; place-items: center; }
.gallery .nav:hover { background: rgba(0,0,0,.7); }
.gallery .prev { left: 10px; } .gallery .next { right: 10px; }
.gallery .counter { position: absolute; bottom: 10px; right: 12px; background: rgba(0,0,0,.55); color: #fff; font-size: .8rem; padding: .2em .6em; border-radius: 999px; }
.gallery .caption { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(transparent, rgba(0,0,0,.7)); color: #fff; padding: 2rem 1rem .8rem; font-size: .9rem; }
.gallery .slide img { cursor: zoom-in; }

/* ---- Lightbox (fullscreen photo viewer; one reusable overlay) ---- */
.lightbox { position: fixed; inset: 0; z-index: 2000; display: none; background: rgba(0,0,0,.9); }
.lightbox.show { display: block; }
.lb-img {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  max-width: 94vw; max-height: 86vh; object-fit: contain; background: #000;
}
.lb-top { position: absolute; top: 0; right: 0; display: flex; gap: .4rem; padding: .6rem; z-index: 2; }
.lb-btn, .lb-nav {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: none; border-radius: 50%; background: rgba(255,255,255,.14);
  color: #fff; cursor: pointer; text-decoration: none; line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.lb-btn { font-size: 1.3rem; }
.lb-btn:hover, .lb-nav:hover { background: rgba(255,255,255,.28); }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 1.9rem; z-index: 2; }
.lb-prev { left: .6rem; }
.lb-next { right: .6rem; }
.lb-caption {
  position: absolute; bottom: 3.1rem; left: 50%; transform: translateX(-50%);
  max-width: 90vw; text-align: center; color: #fff; font-size: .9rem; padding: 0 1rem;
}
.lb-counter {
  position: absolute; bottom: .8rem; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: .82rem; background: rgba(255,255,255,.14);
  padding: .25em .8em; border-radius: 999px; z-index: 2;
}
.lightbox.single .lb-nav { display: none; }

/* video embeds */
.video-embed { position: relative; aspect-ratio: 16/9; background: #000 center/cover no-repeat; border-radius: var(--radius); overflow: hidden; cursor: pointer; box-shadow: var(--shadow-lg); }
.video-embed .play { position: absolute; inset: 0; display: grid; place-items: center; }
.video-embed .play span { width: 64px; height: 64px; border-radius: 50%; background: rgba(216,90,48,.92); color: #fff; display: grid; place-items: center; font-size: 1.6rem; }
.video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-btn { display: inline-flex; }

/* no-download deterrent on shared view */
.no-select img { -webkit-user-select: none; user-select: none; -webkit-user-drag: none; pointer-events: auto; }

/* ---- Top nav (owner pages) ---- */
.brand { text-decoration: none; color: inherit; }
.topnav { display: flex; gap: .35rem; align-items: center; flex: 1 1 auto; min-width: 0; }
.nav-spacer { flex: 1 1 auto; } /* pushes contextual buttons + Log out to the right */
.navlink {
  text-decoration: none; font-weight: 600; font-size: .95rem; color: var(--ink-soft);
  padding: .45em .85em; border-radius: var(--radius-sm); white-space: nowrap;
}
.navlink:hover { background: var(--surface-2); color: var(--ink); }
.navlink.active { background: var(--accent); color: #fff; }

/* Hamburger: hidden on desktop, shown when the nav collapses (≤700px). */
.nav-toggle {
  display: none; flex: none; margin-left: auto;
  width: 44px; height: 44px; padding: 0; line-height: 1;
  background: transparent; border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--ink); font-size: 1.3rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-toggle:hover { background: var(--surface-2); }

@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; gap: .6rem; position: relative; }
  .nav-toggle { display: grid; place-items: center; }
  /* Collapsed dropdown panel: full-width, stacked, below the brand row. */
  .topnav {
    display: none; flex: 1 1 100%; order: 3; flex-direction: column;
    align-items: stretch; gap: .25rem; width: 100%;
    border-top: 1px solid var(--line); margin-top: .6rem; padding-top: .6rem;
  }
  .topbar.nav-open .topnav { display: flex; }
  .nav-spacer { display: none; }
  .topnav .navlink,
  .topnav .btn {
    width: 100%; box-sizing: border-box;
    display: flex; align-items: center; min-height: 44px;
    font-size: 1rem;
  }
  .topnav .navlink { justify-content: flex-start; }
  .topnav #saveState { padding: .2rem .2rem; }
}

/* ---- Explore mode (lifetime clustered globe) ---- */
.explore { display: flex; position: relative; height: 80vh; overflow: hidden; }
.explore-map { flex: 1 1 auto; height: 100%; }
.explore-panel {
  flex: 0 0 260px; width: 260px; height: 100%; background: var(--card);
  border-left: 1px solid var(--line); box-shadow: -4px 0 16px rgba(60,40,20,.06);
  overflow-y: auto; transition: width .2s ease, flex-basis .2s ease;
}
.explore.collapsed .explore-panel { flex-basis: 0; width: 0; border-left: 0; }
.panel-body { padding: 1.1rem; }
.panel-empty { text-align: center; color: var(--ink-soft); padding: 1.5rem .5rem; }
.panel-empty h3 { margin: .5rem 0 .3rem; color: var(--ink); }
.panel-thumb {
  width: 100%; aspect-ratio: 4/3; border-radius: var(--radius-sm);
  background: var(--surface-2) center/cover no-repeat; margin-bottom: .8rem;
}
.panel-thumb.placeholder { display: grid; place-items: center; font-size: 2rem; color: var(--ink-soft); }
.panel-detail h3 { margin: 0 0 .15rem; font-size: 1.15rem; }
.panel-trip { color: var(--accent-dark); font-weight: 600; font-size: .92rem; }
.panel-meta { font-size: .85rem; margin: .15rem 0 1rem; }

/* Collapse toggle: a small tab on the panel edge. */
.panel-toggle {
  position: absolute; top: 50%; right: 260px; transform: translateY(-50%);
  z-index: 500; width: 26px; height: 52px; border: 1px solid var(--line);
  border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: var(--card); color: var(--ink); cursor: pointer; font-size: 1.1rem;
  box-shadow: -2px 0 8px rgba(60,40,20,.08); transition: right .2s ease;
}
.panel-toggle:hover { background: var(--surface-2); }
.explore.collapsed .panel-toggle { right: 0; }

/* Single pins + terracotta cluster bubbles. */
.pin-dot {
  width: 18px; height: 18px; border-radius: 50%; background: var(--accent);
  border: 3px solid #fff; box-shadow: var(--shadow);
}
.tm-cluster-wrap { background: transparent; }
.tm-cluster {
  display: grid; place-items: center; border-radius: 50%; color: #fff;
  font-weight: 700; border: 3px solid #fff; box-shadow: var(--shadow);
  background: var(--accent);
}
.tm-cluster span { line-height: 1; }
.tm-cluster.tm-sm { width: 34px; height: 34px; font-size: .8rem; }
.tm-cluster.tm-md { width: 42px; height: 42px; font-size: .9rem; background: var(--accent-dark); }
.tm-cluster.tm-lg { width: 52px; height: 52px; font-size: 1rem; background: var(--accent-dark); }

.explore-empty {
  position: absolute; inset: 0; z-index: 600; display: grid; place-items: center;
  padding: 1rem; pointer-events: none;
}
.explore-empty .empty-state { pointer-events: auto; }

/* ---- Responsive ---- */
@media (max-width: 860px) {
  .editor-grid { grid-template-columns: 1fr; }
  .editor-map { position: relative; top: 0; height: 50vh; }

  .viewer { display: block; }
  .viewer-map {
    position: sticky; top: 0; height: 40vh; z-index: 10;
    box-shadow: 0 4px 14px rgba(0,0,0,.18);
  }
  /* Story column is natural document scroll on mobile (the base rules already
     use document scroll, not an inner scroller — these are an explicit guard). */
  .viewer-scroll { padding-bottom: 30vh; height: auto; overflow: visible; }
  .viewer-intro { padding: 2rem 1.2rem; }
  .viewer-intro h1 { font-size: 1.8rem; }
  .story-stop { padding: 2.2rem 1.2rem; min-height: auto; }
  .gallery img { max-height: 55vh; }

  /* Explore: map fills the viewport; panel becomes a bottom sheet. */
  .explore-map { width: 100%; }
  .explore-panel {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto;
    flex-basis: auto; height: auto; max-height: 55%; border-left: 0;
    border-top: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -6px 20px rgba(60,40,20,.16); transform: translateY(100%);
    transition: transform .22s ease;
  }
  .explore:not(.collapsed) .explore-panel { transform: translateY(0); }
  .explore.collapsed .explore-panel { width: auto; }
  .panel-toggle {
    top: auto; bottom: 0; right: 12px; transform: none; width: 46px; height: 26px;
    border: 1px solid var(--line); border-bottom: 0;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  }
  .explore:not(.collapsed) .panel-toggle { bottom: 55%; }
  .panel-toggle::before { content: ''; }
}
