/* =====================================================
   Reset & Base
   ===================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, a, [role="button"] { touch-action: manipulation; }

:root {
  --navy:    #1a3a5c;
  --navy-lt: #2C5F8A;
  --gold:    #C9922A;
  --gold-lt: #E8A838;
  --cream:   #F6F3ED;
  --white:   #FFFFFF;
  --gray-1:  #F0EDE8;
  --gray-2:  #DDD9D2;
  --gray-3:  #B0A99F;
  --gray-4:  #6E6860;
  --text:    #2D2926;
  --danger:  #C0392B;
  --success: #27AE60;
  --shadow:  0 2px 12px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.22);
  --radius:  10px;
  --header-h: 46px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--cream);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body.modal-open {
  overflow: hidden;
  /* avoid position:fixed which disrupts tap events on iOS */
}

/* =====================================================
   Header
   ===================================================== */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 18px;
  background: var(--navy);
  color: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  position: relative;
  z-index: 900;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.trip-flag {
  font-size: 1.6rem;
}

#trip-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: white;
}

#trip-travelers {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.65);
  margin-top: 1px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#admin-badge {
  background: var(--gold);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* =====================================================
   Main Layout (split pane)
   ===================================================== */
#main {
  display: flex;
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  overflow: hidden;
}

#itinerary-panel {
  width: 380px;
  min-width: 280px;
  max-width: 50vw;
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-right: 1px solid var(--gray-2);
  overflow: hidden;
}

#itinerary-header {
  border-bottom: 1px solid var(--gray-1);
  flex-shrink: 0;
}

.ih-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
}

.ih-btns { display: flex; gap: 6px; }

.btn-pin {
  background: var(--gold);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-pin:hover { background: var(--gold-lt); }


.section-header {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gray-3);
  padding: 8px 16px 4px;
  background: var(--gray-1);
}

#itinerary-header h2 {
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-4);
}

#itinerary-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}

#map-panel {
  flex: 1;
  position: relative;
}

#map {
  position: absolute;
  inset: 0;
}

/* =====================================================
   Itinerary Items
   ===================================================== */
.itinerary-item {
  padding: 12px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
  position: relative;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.itinerary-item:hover { background: var(--gray-1); }
.itinerary-item.selected {
  background: #EBF3FA;
  border-left-color: var(--navy-lt);
}

.item-number {
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 50%;
  background: var(--navy);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.item-number.has-coords { background: var(--navy-lt); }
.item-number.pin-cat { background: var(--gold); font-size: 1rem; }

.item-body { flex: 1; min-width: 0; }

.item-date {
  font-size: 0.72rem;
  color: var(--gold);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.item-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-location {
  font-size: 0.78rem;
  color: var(--gray-3);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}


.item-description {
  font-size: 0.8rem;
  color: var(--gray-4);
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-photo-strip {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: nowrap;
  overflow: hidden;
}

.item-photo-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.1s;
}

.item-photo-thumb:hover { transform: scale(1.08); }

.item-photo-more {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  background: var(--gray-2);
  color: var(--gray-4);
  font-size: 0.7rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.item-top-actions {
  position: absolute;
  top: 9px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s;
}

.itinerary-item:hover .item-top-actions { opacity: 1; }

.item-edit-icon {
  background: none;
  border: none;
  color: var(--gray-3);
  font-size: 1rem;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 5px;
  line-height: 1;
  transition: color 0.1s, background 0.1s;
}

.item-edit-icon:hover { color: var(--navy); background: var(--gray-2); }

.drag-handle {
  cursor: grab;
  color: var(--gray-3);
  font-size: 1rem;
  line-height: 1;
  padding: 3px 4px;
  border-radius: 5px;
  user-select: none;
  transition: color 0.1s, background 0.1s;
}

.drag-handle:hover { color: var(--navy); background: var(--gray-2); }
.drag-handle:active { cursor: grabbing; }

.item-edit-btn {
  background: none;
  border: 1px solid var(--gray-2);
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 0.72rem;
  color: var(--gray-4);
  cursor: pointer;
  transition: all 0.1s;
}

.item-edit-btn:hover {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
}

/* Divider between items */
.itinerary-item + .itinerary-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 52px;
  right: 16px;
  height: 1px;
  background: var(--gray-1);
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-3);
}

.empty-state p { margin-top: 10px; line-height: 1.5; font-size: 0.85rem; }

/* =====================================================
   Map Layer Toggle
   ===================================================== */

/* Shared map overlay button */
.map-btn {
  position: absolute;
  z-index: 900;
  width: 34px; height: 34px;
  background: white;
  border: 1px solid var(--gray-2);
  border-radius: 6px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.05rem; line-height: 1;
  color: var(--text);
  padding: 0;
  transition: background 0.13s, border-color 0.13s, color 0.13s;
}
.map-btn:hover { background: var(--gray-1); }
.map-btn.active { background: var(--gold); border-color: var(--gold); color: white; }
.map-btn.satellite { background: var(--navy); border-color: var(--navy); color: white; }

/* Left column */
#map-expand-btn { top: 120px; left: 10px; }

/* Right column -- view controls then action buttons */
#layer-toggle        { top:  10px; right: 10px; }
#photo-marker-toggle { top:  52px; right: 10px; }
#fit-all-btn         { top:  94px; right: 10px; }
#add-post-map-btn    { top: 136px; right: 10px; }
#add-pin-btn         { top: 178px; right: 10px; }
#add-photo-map-btn   { top: 220px; right: 10px; }

#main.map-expanded #itinerary-panel { display: none; }
#main.map-expanded #map-expand-btn  { background: #EBF3FA; border-color: var(--navy-lt); color: var(--navy); }

.icon-toggle {
  width: 30px; height: 30px;
  border-radius: 6px;
  border: 1.5px solid var(--gray-2);
  background: var(--gray-1);
  color: var(--gray-4);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.13s, border-color 0.13s;
  flex-shrink: 0;
}
.icon-toggle.active { background: var(--navy); border-color: var(--navy); }
.icon-toggle:hover { border-color: var(--navy-lt); }
.icon-add {
  position: relative;
  overflow: visible;
}
.icon-add::after {
  content: '+';
  position: absolute;
  top: -5px;
  right: -5px;
  width: 13px;
  height: 13px;
  background: var(--gold);
  color: white;
  border-radius: 50%;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 13px;
  text-align: center;
  pointer-events: none;
  border: 1.5px solid white;
}
.icon-add:hover { border-color: var(--navy-lt); }

.map-btn-add {
  overflow: visible;
}
.map-btn-add::after {
  content: '+';
  position: absolute;
  top: -5px;
  right: -5px;
  width: 13px;
  height: 13px;
  background: var(--gold);
  color: white;
  border-radius: 50%;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 13px;
  text-align: center;
  pointer-events: none;
  border: 1.5px solid white;
}


/* =====================================================
   Map Pins (Leaflet DivIcon)
   ===================================================== */
.map-pin {
  width: 36px;
  height: 36px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--navy);
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}

.map-pin span {
  transform: rotate(45deg);
  color: white;
  font-size: 13px;
  font-weight: 700;
  display: block;
}

.map-pin.selected {
  background: var(--gold);
  transform: rotate(-45deg) scale(1.15);
  z-index: 999;
}

.map-pin.no-coords {
  background: var(--gray-3);
}

/* Leaflet popup customization */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0 !important;
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0 !important;
  width: 220px !important;
}

.popup-inner {
  padding: 12px 14px;
}

.popup-date {
  font-size: 0.7rem;
  color: var(--gold);
  font-weight: 600;
  text-transform: uppercase;
}

.popup-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-top: 2px;
  color: var(--text);
}

.popup-location {
  font-size: 0.75rem;
  color: var(--gray-3);
  margin-top: 2px;
}

.popup-desc {
  font-size: 0.78rem;
  color: var(--gray-4);
  margin-top: 6px;
  line-height: 1.4;
}

.popup-sv-link {
  display: inline-block;
  margin-top: 7px;
  font-size: 0.75rem;
  color: var(--navy-lt);
  text-decoration: none;
  font-weight: 600;
}
.popup-sv-link:hover { color: var(--gold); }

.popup-photo {
  width: 100%;
  height: 110px;
  object-fit: cover;
  display: block;
}

/* =====================================================
   Buttons
   ===================================================== */
.btn-primary {
  background: var(--navy);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--navy-lt); }

.btn-secondary {
  background: var(--gray-1);
  color: var(--text);
  border: 1px solid var(--gray-2);
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:hover { background: var(--gray-2); }

.btn-ghost {
  background: rgba(255,255,255,0.12);
  color: white;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-ghost:hover { background: rgba(255,255,255,0.22); }

.admin-dog-btn {
  padding: 2px 4px;
  line-height: 1;
  border-radius: 8px;
  transition: transform 0.15s;
}
.admin-dog-btn img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: block;
}
.admin-dog-btn.admin-active {
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.5);
}
.admin-dog-btn:hover { transform: scale(1.15); background: rgba(255,255,255,0.22); }

.btn-danger {
  background: none;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-danger:hover { background: var(--danger); color: white; }

/* =====================================================
   Modals
   ===================================================== */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: none;
  pointer-events: none; /* let touches pass through to the modal above */
}

#overlay.active {
  display: block;
}

.modal {
  position: fixed;
  inset: 0;
  margin: auto;
  background: white;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 1100;
  width: 400px;
  max-width: 92vw;
  max-height: 90dvh;
  height: fit-content;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-large { width: 580px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-1);
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
}

.close-x {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--gray-3);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.1s;
}

.close-x:hover { background: var(--gray-1); color: var(--text); }

.modal-sub {
  font-size: 0.83rem;
  color: var(--gray-4);
  margin-bottom: 14px;
  line-height: 1.4;
}

#admin-login-view, #admin-setup-view {
  padding: 20px;
  overflow-y: auto;
}

#edit-form {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

/* =====================================================
   Form Elements
   ===================================================== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-full { grid-column: 1 / -1; }

label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gray-4);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.required { color: var(--danger); }
.hint { font-size: 0.72rem; color: var(--gray-3); text-transform: none; font-weight: 400; letter-spacing: 0; }

.input-field {
  border: 1px solid var(--gray-2);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 16px; /* must be >=16px to prevent iOS Safari auto-zoom on focus */
  color: var(--text);
  background: white;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
  font-family: inherit;
  resize: vertical;
  -webkit-appearance: none; /* removes iOS default styling on selects/inputs */
}

.input-field:focus { border-color: var(--navy-lt); box-shadow: 0 0 0 3px rgba(44,95,138,0.1); }

.input-group {
  display: flex;
  gap: 8px;
}

.input-group .input-field { flex: 1; }
.input-group .btn-secondary { white-space: nowrap; flex-shrink: 0; }

.form-hint { font-size: 0.75rem; color: var(--gray-4); margin-top: 3px; }
.form-hint.success { color: var(--success); }
.form-hint.error { color: var(--danger); }

.gps-offer {
  margin-top: 8px;
  padding: 8px 12px;
  background: #EBF5FB;
  border: 1px solid #AED6F1;
  border-radius: 7px;
  font-size: 0.78rem;
  color: #1A5276;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.gps-offer button {
  background: var(--navy);
  color: white;
  border: none;
  border-radius: 5px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.gps-offer button:hover { background: var(--navy-lt); }
.form-error { font-size: 0.8rem; color: var(--danger); margin: 6px 0; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--gray-1);
  margin-top: 16px;
  flex-shrink: 0;
}

.modal-actions-spread {
  justify-content: space-between;
}

/* =====================================================
   File Upload
   ===================================================== */
.file-upload-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--gray-1);
  border: 1px dashed var(--gray-2);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gray-4);
  cursor: pointer;
  transition: background 0.15s;
  text-transform: none;
  letter-spacing: 0;
}

.file-upload-label:hover { background: var(--gray-2); }

/* Per-photo edit rows */
.edit-photo-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--gray-1);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
}

.edit-photo-item.removed { opacity: 0.3; pointer-events: none; }

.edit-photo-thumb {
  position: relative;
  flex-shrink: 0;
  width: 72px;
  height: 72px;
}

.edit-photo-thumb img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.edit-photo-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.photo-remove-btn {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  font-size: 0.65rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  line-height: 1;
}

/* Photos open button in itinerary */
.photos-open-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  background: var(--navy);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.photos-open-btn:hover { background: var(--navy-lt); }

/* =====================================================
   Item Viewer Modal
   ===================================================== */
.modal-viewer {
  width: min(90vw, 780px);
  max-height: 92vh;
  background: rgba(18,18,18,0.97);
  border-radius: 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: visible;
  transition: width 0.3s ease;
}

.modal-viewer.photo-mode {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  border-radius: 0;
  transform: none;
  justify-content: center;
}

.viewer-panel {
  width: 100%;
  border-radius: 14px;
  overflow: hidden;
}

/* Summary panel */
#viewer-hero {
  width: 100%;
  height: 260px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-lt) 100%);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}

.viewer-summary-body {
  padding: 24px 30px 20px;
  max-height: calc(92vh - 260px);
  overflow-y: auto;
}

.viewer-meta-date {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--gold-lt);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

#viewer-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
  margin-bottom: 8px;
  line-height: 1.3;
}

.viewer-meta-loc {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.55);
  margin-bottom: 12px;
}

.viewer-desc {
  font-size: 0.92rem;
  color: rgba(255,255,255,0.82);
  line-height: 1.65;
  margin-bottom: 16px;
  white-space: pre-wrap;
}

.viewer-notes {
  background: rgba(255,255,255,0.07);
  border-left: 3px solid var(--gold);
  border-radius: 0 6px 6px 0;
  padding: 10px 14px;
  margin-bottom: 14px;
}

.viewer-notes-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold-lt);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 5px;
}

.viewer-notes p, #viewer-notes {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.75);
  line-height: 1.55;
  white-space: pre-wrap;
}

.viewer-photo-hint {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.4);
  text-align: center;
  padding-bottom: 4px;
}

/* Photo panel */
#viewer-photo-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 1;
  min-height: 0;
}

#photo-viewer-img {
  width: calc(100vw - 140px);
  height: calc(100vh - 110px);
  height: calc(100dvh - 110px);
  object-fit: contain;
  display: block;
  border-radius: 4px;
  margin: 0 auto;
}

#photo-info {
  width: 100%;
  padding: 0 20px 10px;
  text-align: center;
}

#photo-title-display {
  font-size: 1rem;
  font-weight: 700;
  color: white;
  margin-bottom: 4px;
}

#photo-caption-display {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.65);
  line-height: 1.5;
  white-space: pre-wrap;
}

.photo-close {
  position: absolute;
  top: -14px;
  right: -14px;
  background: white;
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  z-index: 10;
}

.photo-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.18);
  color: white;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.25rem;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-nav-btn:hover { background: rgba(255,255,255,0.32); }

#photo-prev { left: -60px; }
#photo-next { right: -60px; }

.modal-viewer.photo-mode #photo-prev { left: 18px; }
.modal-viewer.photo-mode #photo-next { right: 18px; }
.modal-viewer.photo-mode .photo-close { top: 18px; right: 18px; }

#photo-caption {
  color: rgba(255,255,255,0.5);
  font-size: 0.75rem;
  margin: 6px 0 4px;
  text-align: center;
}

.photo-sv-link {
  display: block;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  margin: 2px 0 4px;
}
.photo-sv-link:hover { color: var(--gold); }

#photo-dots {
  display: flex;
  gap: 7px;
  margin-bottom: 14px;
  align-items: center;
}

.photo-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.photo-dot.active {
  background: white;
  transform: scale(1.3);
}

.photo-dot.dot-summary {
  border-radius: 3px;
  width: 10px;
}

/* =====================================================
   Toast
   ===================================================== */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 999;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.3s;
}

#toast.success { background: var(--success); }
#toast.error { background: var(--danger); }

/* =====================================================
   Sortable ghost
   ===================================================== */
.sortable-ghost { opacity: 0.4; background: var(--gray-1) !important; }
.sortable-chosen { background: var(--gray-1) !important; }

/* =====================================================
   Utility
   ===================================================== */
.hidden { display: none !important; }
.admin-only { /* shown/hidden via JS */ }

/* =====================================================
   Links editor
   ===================================================== */
.link-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.link-row .link-url { flex: 2; min-width: 140px; }
.link-row .link-name { flex: 1.5; min-width: 100px; }
.link-row .link-desc { flex: 2; min-width: 120px; }
.link-remove-btn {
  background: none; border: 1px solid var(--gray-2); border-radius: 50%;
  width: 22px; height: 22px; flex-shrink: 0;
  font-size: 0.65rem; cursor: pointer; color: var(--danger);
  display: flex; align-items: center; justify-content: center;
}
.btn-ghost-sm {
  background: none; border: 1px dashed var(--gray-2); border-radius: 6px;
  padding: 5px 12px; font-size: 0.78rem; color: var(--gray-4);
  cursor: pointer; margin-top: 4px;
}
.btn-ghost-sm:hover { background: var(--gray-1); border-color: var(--gray-3); }

/* =====================================================
   Viewer links
   ===================================================== */
.viewer-links { margin-bottom: 14px; }
.viewer-links-label {
  font-size: 0.7rem; font-weight: 700; color: var(--gold-lt);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px;
}
.viewer-link-item {
  display: flex; flex-direction: column;
  padding: 7px 10px; margin-bottom: 4px;
  background: rgba(255,255,255,0.07); border-radius: 6px;
  text-decoration: none; transition: background 0.12s;
}
.viewer-link-item:hover { background: rgba(255,255,255,0.13); }
.viewer-link-name { font-size: 0.85rem; font-weight: 600; color: #7EC8E3; }
.viewer-link-desc { font-size: 0.75rem; color: rgba(255,255,255,0.5); margin-top: 1px; }

/* =====================================================
   Nearby panel
   ===================================================== */

/* =====================================================
   Add Pin map button
   ===================================================== */

/* =====================================================
   Custom map pins
   ===================================================== */
.custom-map-pin {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--gold); border: 2.5px solid white;
  box-shadow: 0 3px 10px rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; cursor: pointer;
}

/* =====================================================
   Pin timestamps
   ===================================================== */
.pin-timestamps {
  font-size: 0.75rem; color: var(--gray-3);
  padding: 0 20px 12px; border-bottom: 1px solid var(--gray-1);
  margin-bottom: 4px;
}

/* =====================================================
   Pin form scrollable body
   ===================================================== */
#pin-form {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

/* =====================================================
   Item badges (photo count + post count)
   ===================================================== */
.item-badges {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: 6px; flex-shrink: 0;
}
.item-badge {
  display: inline-flex; align-items: center; gap: 2px;
  font-size: 0.7rem; font-weight: 600; padding: 1px 5px;
  border-radius: 10px; cursor: default; white-space: nowrap;
  transition: opacity 0.15s;
}
.photo-badge {
  background: #EBF5FB; color: #1A5276; border: 1px solid #AED6F1;
  cursor: pointer;
}
.photo-badge:hover { background: #D6EAF8; }
.post-badge {
  background: #FDEBD0; color: #784212; border: 1px solid #F5CBA7;
  cursor: pointer;
}
.post-badge:hover { background: #FAD7A0; }
.badge-zero {
  opacity: 0.45;
}

/* =====================================================
   Photo map marker
   ===================================================== */
.map-photo-pin {
  width: 28px; height: 28px; border-radius: 50%;
  background: white; border: 2px solid var(--gold);
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; cursor: pointer;
  transition: transform 0.1s;
}
.map-photo-pin:hover { transform: scale(1.15); }

/* =====================================================
   Photo marker map toggle button
   ===================================================== */

/* =====================================================
   Per-photo GPS tag in edit forms
   ===================================================== */
.photo-gps-tag {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 4px; font-size: 0.72rem; color: #1A5276;
  background: #EBF5FB; border: 1px solid #AED6F1;
  border-radius: 5px; padding: 2px 8px;
}
.photo-gps-clear {
  background: none; border: none; color: #1A5276; cursor: pointer;
  font-size: 0.72rem; padding: 0 2px; line-height: 1;
  opacity: 0.6;
}
.photo-gps-clear:hover { opacity: 1; }

/* =====================================================
   Responsive - mobile stacks vertically
   ===================================================== */
@media (max-width: 640px) {
  #main { flex-direction: column; }

  #header {
    height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: max(18px, env(safe-area-inset-left, 0px));
    padding-right: max(18px, env(safe-area-inset-right, 0px));
  }

  #main {
    height: calc(100dvh - var(--header-h) - env(safe-area-inset-top, 0px));
  }

  #itinerary-panel {
    width: 100%; max-width: 100%;
    height: 42dvh;
    border-right: none;
    border-bottom: 1px solid var(--gray-2);
  }

  #map-panel {
    height: 58dvh;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  #photo-prev { left: -10px; }
  #photo-next { right: -10px; }

  .form-grid { grid-template-columns: 1fr; }

  /* Strip form padding so the mobile bottom-sheet controls it */
  .modal-large #edit-form,
  .modal-large #pin-form {
    padding: 0;
  }
  .modal-large .pin-timestamps {
    padding: 0 16px 12px;
  }

  /* Large modals (edit stop / edit pin) become full bottom sheets on mobile */
  .modal-large {
    width: 100%;
    max-width: 100%;
    height: calc(96dvh - env(safe-area-inset-top, 0px));
    max-height: calc(96dvh - env(safe-area-inset-top, 0px));
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    border-radius: 18px 18px 0 0;
  }

  /* Make the form scroll, pin the action bar at the bottom */
  .modal-large form {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .modal-large .form-grid {
    flex: 1;
    padding: 16px;
  }

  .modal-large .modal-actions {
    flex-shrink: 0;
    border-top: 1px solid var(--gray-1);
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    background: white;
  }

  /* Enlarge tap targets on small screens */
  .item-edit-icon, .drag-handle { padding: 8px; }
  .close-x { width: 44px; height: 44px; }
  .view-btn { padding: 7px 0; font-size: 0.78rem; }
}

/* =====================================================
   Stop expand button (in itinerary list items)
   ===================================================== */
.item-expand-btn {
  float: right;
  background: none;
  border: none;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--navy-lt);
  cursor: pointer;
  padding: 0 0 4px 8px;
  line-height: 1.4;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-radius: 3px;
  transition: color 0.12s;
}
.item-expand-btn:hover { color: var(--navy); }

/* =====================================================
   Stop detail view (inline in itinerary panel)
   ===================================================== */
#stop-detail {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.stop-detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--gray-1);
  flex-shrink: 0;
}
.stop-detail-back {
  background: none;
  border: 1px solid var(--gray-2);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--navy);
  transition: background 0.12s;
}
.stop-detail-back:hover { background: var(--gray-1); }
.stop-detail-num {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--navy-lt);
  color: white;
  font-size: 0.75rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stop-detail-body {
  overflow-y: auto;
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.detail-date { font-size: 0.78rem; color: var(--gray-4); font-weight: 600; }
.detail-title { font-size: 1.1rem; font-weight: 700; color: var(--text); line-height: 1.3; }
.detail-location { font-size: 0.82rem; color: var(--gray-4); }
.detail-desc { font-size: 0.88rem; line-height: 1.55; color: var(--text); white-space: pre-wrap; }
.detail-notes {
  background: #FEF9EC; border: 1px solid #F5CBA7;
  border-radius: 8px; padding: 10px 12px;
  font-size: 0.84rem; color: #7D6608;
}
.detail-notes-label { font-weight: 700; font-size: 0.75rem; margin-bottom: 4px; }
.detail-notes p { white-space: pre-wrap; }
.detail-links { display: flex; flex-direction: column; gap: 6px; }
.detail-link {
  font-size: 0.82rem; color: var(--navy-lt);
  text-decoration: none; border-bottom: 1px solid var(--gray-2);
  padding-bottom: 4px;
}
.detail-link:hover { color: var(--gold); }
.detail-photos {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.detail-photo-thumb {
  width: 80px; height: 80px; object-fit: cover;
  border-radius: 6px; cursor: pointer;
  border: 2px solid var(--gray-2);
  transition: border-color 0.12s;
}
.detail-photo-thumb:hover { border-color: var(--navy); }

/* =====================================================
   Post Modal
   ===================================================== */
.modal-post {
  width: 480px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
}

#post-modal-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.new-post-form {
  padding: 14px 16px;
  border-bottom: 1px solid var(--gray-1);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.post-textarea {
  resize: none;
  font-size: 16px;
  line-height: 1.5;
  min-height: 90px;
}

.post-link-input-row {
  display: flex;
  gap: 6px;
}

.post-link-input-row .input-field:first-child { flex: 1; }
.post-link-input-row .input-field:last-child  { flex: 2; }

.post-form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.post-list-inner {
  overflow-y: auto;
  flex: 1;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.no-posts-msg {
  font-size: 0.83rem;
  color: var(--gray-3);
  text-align: center;
  padding: 20px 0;
}

.post-card {
  background: var(--gray-1);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.post-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.post-date {
  font-size: 0.72rem;
  color: var(--gray-4);
  font-weight: 600;
}

.post-delete-btn {
  background: none;
  border: none;
  color: var(--gray-3);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.post-delete-btn:hover { background: #fde; color: var(--danger); }

.post-text {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
}

.post-links {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 2px;
}

.post-link {
  font-size: 0.78rem;
  color: var(--navy-lt);
  text-decoration: none;
}
.post-link:hover { text-decoration: underline; }

/* Posts feed in itinerary list */
.post-list-card {
  padding: 10px 16px;
  border-bottom: 1px solid var(--gray-1);
  cursor: pointer;
  transition: background 0.12s;
}
.post-list-card:hover { background: var(--gray-1); }

.post-list-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.post-list-source {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.post-list-date {
  font-size: 0.72rem;
  color: var(--gray-3);
}

.post-list-text {
  font-size: 0.84rem;
  color: var(--text);
  line-height: 1.45;
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Mobile: post modal full bottom sheet */
@media (max-width: 640px) {
  .modal-post {
    width: 100%;
    max-width: 100%;
    height: calc(92dvh - env(safe-area-inset-top, 0px));
    max-height: calc(92dvh - env(safe-area-inset-top, 0px));
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    border-radius: 18px 18px 0 0;
  }
  .new-post-form {
    padding-bottom: 10px;
  }
  .post-list-inner {
    padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  }
}
