:root {
  /* "Straßenatlas" — warm paper, inked pine routes, rust waypoints */
  --color-bg: #e8e1cc;
  --color-surface: #ded5b7;
  --color-border: #c7bc9c;
  --color-text: #2e2b22;
  --color-text-muted: #6f6853;
  --color-primary: #3e5c46;
  --color-primary-hover: #33493a;
  --color-danger: #a8542f;
  --color-visited: #5c8567;
  --color-favorite: #93701f;
  --sidebar-width: 380px;
  --radius: 8px;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Atlas by lantern light */
    --color-bg: #201d16;
    --color-surface: #29251b;
    --color-border: #3d3822;
    --color-text: #ece5d2;
    --color-text-muted: #a89e83;
    --color-primary: #7fa88c;
    --color-primary-hover: #93bb9f;
    --color-danger: #cf8a63;
    --color-visited: #7fa88c;
    --color-favorite: #d1ad5c;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  overflow: hidden;
  /* Stops the native "pull down at the top -> reload the whole page" gesture
     (iOS Safari / Chrome), which feels like a crash in an installed PWA —
     scrolling inside .sidebar/#map still works normally. */
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* Reminder that this session has delete rights — a thin frame around the
   whole window, click-through so it never gets in the way of using the app. */
.owner-border {
  position: fixed;
  inset: 0;
  border: 2px solid var(--color-danger);
  z-index: 500;
  pointer-events: none;
}

/* Header */
.app-header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 900; font-size: 19px; letter-spacing: -0.01em; }

.visited-flags-row {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 16px;
  overflow-x: auto;
  max-width: 200px;
  flex-shrink: 1;
  scrollbar-width: none;
}
.visited-flags-row::-webkit-scrollbar { display: none; }
.visited-flag { flex-shrink: 0; cursor: default; }
.tour-card-flags { font-size: 12px; letter-spacing: 1px; }

.collaborators-row { display: flex; align-items: center; margin-right: 4px; }
.collaborator-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  font-family: var(--font-display);
  margin-left: -8px;
  border: 2px solid var(--color-surface);
  overflow: hidden;
  flex-shrink: 0;
}
.collaborator-avatar:first-child { margin-left: 0; }
.collaborator-avatar img { width: 100%; height: 100%; object-fit: cover; }
.brand-icon { font-size: 22px; }

/* Buttons */
.btn {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--color-bg); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:disabled { background: var(--color-primary); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--color-bg); }
.btn-danger-ghost { background: transparent; border-color: var(--color-danger); color: var(--color-danger); }
.btn-danger-ghost:hover { background: color-mix(in srgb, var(--color-danger) 10%, transparent); }
.btn-icon { padding: 6px 8px; position: relative; }
.btn-back {
  margin-bottom: 12px;
  padding: 7px 14px 7px 10px;
  border-radius: 999px;
  background: var(--color-surface);
  font-weight: 600;
  font-size: 13px;
}
.btn-back:hover { background: var(--color-bg); border-color: var(--color-border); }

/* Layout */
.app-body { display: flex; height: calc(100vh - 56px); }
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-bg);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  overscroll-behavior-y: contain;
}
.map-wrap { flex: 1; position: relative; }
#map { position: absolute; inset: 0; overscroll-behavior: contain; }

/* Custom pull-to-refresh (replaces the native browser gesture, which we
   suppress via overscroll-behavior above — a hard page reload feels like a
   crash in an installed PWA). Grows from 0 height as the user pulls down at
   the very top of the list, pushing the content down like a native app. */
.pull-refresh-indicator {
  height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: height 0.25s ease;
}
.pull-refresh-indicator.dragging { transition: none; }
.pull-refresh-spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--color-primary) 25%, transparent);
  border-top-color: var(--color-primary);
  opacity: 0;
  transition: opacity 0.15s;
}
.pull-refresh-indicator.armed .pull-refresh-spinner,
.pull-refresh-indicator.loading .pull-refresh-spinner { opacity: 1; }
.pull-refresh-indicator.loading .pull-refresh-spinner { animation: upload-spin 0.7s linear infinite; }

.panel { padding: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 19px; font-family: var(--font-display); font-weight: 900; }
.panel h3 { margin: 0; font-size: 14px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.03em; }

.list-header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.list-header h2 { margin: 0; }
.total-km-badge {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  color: var(--color-primary);
  white-space: nowrap;
}
.tour-list-filter-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--color-bg);
  color: var(--color-text);
  margin: 10px 0 12px;
}
.tour-list-filter-input:focus { outline: none; border-color: var(--color-primary); }

.empty-hint { color: var(--color-text-muted); font-size: 13px; line-height: 1.5; }
.hint { color: var(--color-text-muted); font-size: 12px; margin: 6px 0 0; }

/* Tour list */
.tour-list { display: flex; flex-direction: column; gap: 8px; }
.tour-year-heading {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 13px;
  color: var(--color-text-muted);
  padding-bottom: 4px;
  margin: 18px 0 2px;
  border-bottom: 1px solid var(--color-border);
}
.tour-year-heading:first-child { margin-top: 0; }
.tour-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
}
.tour-card:hover { border-color: var(--color-primary); }
.tour-card-main { flex: 1; }
.tour-card-name { font-family: var(--font-display); font-weight: 900; font-size: 15px; }
.tour-card-meta { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }

/* Tour name input */
.tour-name-input {
  width: 100%;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 900;
  border: none;
  border-bottom: 2px solid var(--color-border);
  padding: 4px 2px 8px;
  margin-bottom: 14px;
  background: transparent;
  color: var(--color-text);
}
.tour-name-input:focus { outline: none; border-color: var(--color-primary); }

/* Search */
.search-box { position: relative; margin-bottom: 4px; }
.search-box input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--color-bg);
  color: var(--color-text);
}
.search-box input:focus { outline: none; border-color: var(--color-primary); }
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}
.search-result-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--color-border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--color-bg); }
.search-result-name { flex: 1; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Map-click-to-add-stop toggle */
.btn-toggle-edit {
  width: 100%;
  margin-top: 10px;
  text-align: left;
  font-weight: 600;
}
.btn-toggle-edit.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* Section eyebrow labels — shared look for "NOTIZEN & PACKLISTE"/"FAVORITEN" */
.notes-header h3, .favorites-header h3 {
  margin: 0;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Home address */
.home-section {
  margin-top: 12px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--color-surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.home-row { display: flex; align-items: center; gap: 8px; }
.home-icon { font-size: 17px; }
.home-name { flex: 1; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.home-quick-actions { display: flex; gap: 8px; margin-top: 10px; }
.home-quick-actions .btn { flex: 1; font-size: 12px; padding: 7px 8px; border-radius: 999px; }
.home-current {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}
.btn-small { padding: 5px 9px; font-size: 12px; }

/* Notes & checklist */
.notes-section { margin-top: 16px; }
.notes-header { margin-bottom: 8px; }
.tour-notes-textarea {
  width: 100%;
  min-height: 60px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  font-size: 13px;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  resize: vertical;
  margin-bottom: 8px;
}
.tour-notes-textarea:focus { outline: none; border-color: var(--color-primary); }
.checklist-add-row { display: flex; gap: 6px; margin-bottom: 8px; }
.checklist-add-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-size: 13px;
  background: var(--color-surface);
  color: var(--color-text);
}
.checklist-add-row input:focus { outline: none; border-color: var(--color-primary); }
#btn-add-checklist-item, .favorite-edit-btn, .favorite-add-btn, .favorite-delete-btn, .checklist-delete-btn, #btn-edit-home {
  border-radius: 50%;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#btn-add-checklist-item:hover, .favorite-edit-btn:hover, .favorite-add-btn:hover, .favorite-delete-btn:hover, .checklist-delete-btn:hover, #btn-edit-home:hover {
  background: color-mix(in srgb, var(--color-primary) 14%, transparent);
}
.checklist-list { display: flex; flex-direction: column; gap: 4px; }
.checklist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 10px;
  transition: background 0.15s;
}
.checklist-item:hover { background: color-mix(in srgb, var(--color-text) 5%, transparent); }
.checklist-item-label { display: flex; align-items: center; gap: 8px; flex: 1; cursor: pointer; }
.checklist-item-done { text-decoration: line-through; color: var(--color-text-muted); }

/* Favorites */
.favorites-section { margin-top: 16px; }
.favorites-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.favorites-list { display: flex; flex-direction: column; gap: 6px; }
.favorite-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 13px;
  background: var(--color-surface);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.favorite-item:hover { border-color: color-mix(in srgb, var(--color-primary) 35%, var(--color-border)); box-shadow: 0 2px 6px rgba(0,0,0,0.07); }
.favorite-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.favorite-star-btn { color: var(--color-favorite); }

/* Stops */
.stops-header { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 8px; }
.stop-count { font-size: 12px; color: var(--color-text-muted); }
.stop-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }

/* Each stop is a gutter (drag handle + badge + connecting line, sitting
   directly on the page background) beside a card (the actual content) —
   keeping the line outside the card means it reads as one continuous route
   thread instead of being interrupted by card edges. */
.stop-item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 7px 4px;
  cursor: grab;
}
.stop-item.dragging { opacity: 0.4; }

.stop-timeline-track {
  position: absolute;
  left: 21px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-border);
}
.stop-item.is-first .stop-timeline-track { top: 24px; }
.stop-item.is-last .stop-timeline-track { bottom: calc(100% - 24px); }

.stop-gutter {
  width: 34px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-top: 10px;
  position: relative; /* sits above the track */
  z-index: 1;
}
.stop-drag-handle { color: var(--color-text-muted); font-size: 14px; cursor: grab; }
.stop-move-buttons { display: none; flex-direction: column; gap: 0; }
.stop-move-buttons .btn { padding: 2px; line-height: 1; font-size: 10px; }
.stop-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  color: var(--color-text-muted);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.stop-badge-start { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.stop-badge-end { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }

.stop-card {
  position: relative; /* anchors the poi-results dropdown to the card, not the whole gutter+card row */
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.stop-item:hover .stop-card { border-color: color-mix(in srgb, var(--color-primary) 35%, var(--color-border)); box-shadow: 0 2px 8px rgba(0,0,0,0.08); }

/* Row 1: identity — name, remove */
.stop-row-main { display: flex; align-items: center; gap: 8px; }
.stop-name {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Row 2: planning meta, shown as small pills — wraps freely instead of
   overlapping when full */
.stop-row-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.stop-row-meta > * {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  white-space: nowrap;
}
.stop-visit-date { color: var(--color-visited); font-weight: 600; background: color-mix(in srgb, var(--color-visited) 15%, transparent); }
.stop-weather-badge { color: var(--color-text-muted); background: color-mix(in srgb, var(--color-text) 6%, transparent); }
.stop-leg-km { color: var(--color-text-muted); background: color-mix(in srgb, var(--color-text) 6%, transparent); }
.stop-planned-date-input {
  color: var(--color-text-muted);
  border: 1px dashed var(--color-border);
  background: transparent;
  font-family: inherit;
  max-width: 118px;
}
.stop-planned-date-input:hover, .stop-planned-date-input:focus { border-style: solid; border-color: var(--color-primary); color: var(--color-text); outline: none; }

/* Row 3: actions — icon toolbar with soft round backgrounds instead of bare glyphs */
.stop-row-actions { display: flex; align-items: center; gap: 4px; }
.stop-row-actions .btn-icon {
  border-radius: 50%;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stop-row-actions .btn-icon:hover { background: color-mix(in srgb, var(--color-primary) 14%, transparent); }
.stop-photo-btn { position: relative; }
.photo-count-badge {
  position: absolute;
  top: -2px; right: -2px;
  background: var(--color-primary);
  color: #fff;
  border-radius: 8px;
  font-size: 9px;
  padding: 1px 4px;
  min-width: 14px;
  text-align: center;
}
.stop-diary-btn { opacity: 0.4; }
.stop-diary-btn.has-diary { opacity: 1; color: var(--color-primary); }
.stop-diary-textarea {
  width: 100%;
  min-height: 50px;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: var(--color-bg);
  color: var(--color-text);
  resize: vertical;
  margin-bottom: 14px;
}
.stop-diary-textarea:focus { outline: none; border-color: var(--color-primary); }

/* Route */
.route-actions { display: flex; gap: 8px; margin-top: 16px; }
.route-actions .btn { flex: 1; }
.route-summary {
  margin-top: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--color-bg);
}
.summary-row { display: flex; justify-content: space-between; align-items: baseline; padding: 3px 0; font-size: 13px; }
.summary-label { color: var(--color-text-muted); }
.summary-value { font-weight: 700; }
#summary-km { color: var(--color-primary); font-family: var(--font-display); font-weight: 900; font-size: 19px; }

.editor-footer { margin-top: 24px; border-top: 1px solid var(--color-border); padding-top: 14px; }

/* Map markers */
.stop-marker-wrap { position: relative; width: 30px; height: 30px; }
.stop-marker-photo-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}
.stop-marker-inner {
  width: 28px; height: 28px;
  border-radius: 50% 50% 50% 0;
  background: var(--color-primary);
  transform: rotate(-45deg);
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.stop-marker-inner.start { background: var(--color-primary); }
.stop-marker-inner.end { background: var(--color-danger); }
.stop-marker-inner.visited { background: var(--color-visited); }
.stop-marker-inner .stop-marker-num {
  transform: rotate(45deg);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
}

/* Map popup photo previews */
.map-popup { font-size: 13px; }
.map-popup-thumbs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 8px;
  max-width: 210px;
  max-height: 45vh;
  overflow-y: auto;
}
.map-popup-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid var(--color-border);
}
.map-popup-empty { margin-top: 6px; font-size: 11px; color: var(--color-text-muted); }
.leaflet-popup-content-wrapper { border-radius: 10px; }

/* Route-wide Stellplatz overlay */
.route-campsite-marker {
  font-size: 16px;
  text-align: center;
  line-height: 22px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
}
.poi-popup-actions { display: flex; gap: 6px; margin-top: 8px; }
.poi-popup-actions .btn-small { flex: 1; text-align: center; justify-content: center; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  width: min(560px, 92vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
}
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-body p { margin: 0 0 16px; font-size: 13.5px; line-height: 1.6; color: var(--color-text-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Sign-in gate */
.signin-gate {
  position: fixed; inset: 0;
  background: var(--color-bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 5000;
  padding: 24px;
}
.signin-gate.hidden { display: none; }
.signin-card {
  max-width: 380px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.signin-brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 900; font-size: 24px;
}
.signin-brand .brand-icon { font-size: 30px; }
.signin-copy { font-size: 14px; line-height: 1.6; color: var(--color-text-muted); margin: 0; }
.signin-form { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.signin-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  box-sizing: border-box;
}
.signin-input:focus { outline: none; border-color: var(--color-primary); }
.signin-error { font-size: 13px; color: var(--color-danger); margin: 0; }

.upload-dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  margin-bottom: 16px;
  text-align: center;
  font-size: 14px;
}
.upload-dropzone.drag-active { border-color: var(--color-primary); background: var(--color-bg); }
.upload-dropzone.uploading {
  border-color: var(--color-primary);
  border-style: solid;
  animation: upload-border-pulse 1.6s ease-in-out infinite;
}
.upload-sub { font-size: 12px; color: var(--color-text-muted); }
#upload-dropzone-label { display: flex; flex-direction: column; align-items: center; gap: 4px; }
#upload-dropzone-label[hidden] { display: none; }
.upload-progress[hidden] { display: none; }

.upload-progress {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 320px;
}
.upload-spinner {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--color-primary) 25%, transparent);
  border-top-color: var(--color-primary);
  animation: upload-spin 0.8s linear infinite;
}
.upload-progress-text-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  flex: 1;
  min-width: 0;
}
.upload-progress-label {
  font-size: 12.5px;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.upload-progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-primary) 15%, transparent);
  overflow: hidden;
}
.upload-progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--color-primary), color-mix(in srgb, var(--color-primary) 60%, #e0633f));
  transition: width 0.25s ease;
}

@keyframes upload-spin {
  to { transform: rotate(360deg); }
}
@keyframes upload-border-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-primary) 35%, transparent); }
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--color-primary) 0%, transparent); }
}

.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 9999;
}

/* Tour list: loading state while Drive data is being fetched after sign-in */
.tours-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 12px;
  color: var(--color-text-muted);
  font-size: 13.5px;
}
.tours-loading-spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--color-primary) 22%, transparent);
  border-top-color: var(--color-primary);
  animation: upload-spin 0.8s linear infinite;
}

.photo-uploader {
  display: block;
  font-size: 9.5px;
  color: var(--color-text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Album (all photos across all tours) */
.modal-large { width: min(720px, 94vw); }
.btn-album { width: 100%; margin: 4px 0 2px; text-align: center; justify-content: center; }
.album-section { margin-bottom: 22px; }
.album-section-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--color-text);
}
.album-section-title span { color: var(--color-text-muted); font-weight: 400; font-family: inherit; }

/* Statistics */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.stat-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 16px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.stat-card:hover { transform: translateY(-2px); border-color: var(--color-primary); }
.stat-icon { font-size: 20px; }
.stat-value {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 24px;
  color: var(--color-primary);
  line-height: 1.1;
}
.stat-label { font-size: 12px; color: var(--color-text-muted); }
.stats-flags {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 22px;
  padding-top: 4px;
}

.users-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}
.user-row-name { font-weight: 600; }
.user-row-username { color: var(--color-text-muted); font-size: 13px; }
.user-row-owner-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  border-radius: 999px;
  padding: 2px 8px;
}
.user-row-actions { margin-left: auto; display: flex; gap: 6px; }
.users-subheading { margin: 0 0 10px; font-size: 14px; }
.new-user-form { display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.new-user-owner-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--color-text-muted); }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--color-border);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .photo-uploader {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  margin: 0;
  padding: 3px 6px;
  background: linear-gradient(to top, rgba(0,0,0,0.65), transparent);
  color: #fff;
}
.photo-thumb .video-badge {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  pointer-events: none;
}

/* Lightbox */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px;
  padding: 24px;
  z-index: 3000;
}
.lightbox-image-wrap {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-image-wrap img, .lightbox-image-wrap video { max-width: 100%; max-height: 100%; border-radius: 6px; object-fit: contain; }

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-nav:hover { background: rgba(255,255,255,0.28); }
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }

.lightbox-uploader { margin: 0; font-size: 12.5px; color: rgba(255,255,255,0.75); text-align: center; }

.lightbox-filmstrip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  max-width: 100%;
  flex-shrink: 0;
  padding: 4px;
}
.lightbox-filmstrip-thumb {
  width: 60px; height: 60px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.5;
  border: 2px solid transparent;
  flex-shrink: 0;
}
.lightbox-filmstrip-thumb.active { opacity: 1; border-color: #fff; }
.lightbox-filmstrip-thumb:hover { opacity: 0.85; }
.lightbox-filmstrip::-webkit-scrollbar { height: 6px; }
.lightbox-filmstrip::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 3px; }

.lightbox-toolbar {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 1;
}
.lightbox-toolbar-btn {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.lightbox-toolbar-btn:hover { background: rgba(255,255,255,0.28); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: var(--color-bg);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 4000;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}

/* Background-upload mini indicator (shown once the photo modal that started
   an upload is closed/navigated away from — the app stays fully usable). */
.upload-mini-widget {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
  z-index: 3500;
  cursor: pointer;
  max-width: 240px;
}
.upload-mini-spinner {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--color-primary) 25%, transparent);
  border-top-color: var(--color-primary);
  animation: upload-spin 0.8s linear infinite;
}
.upload-mini-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.upload-mini-title {
  font-size: 12px;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upload-mini-track {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-primary) 15%, transparent);
  overflow: hidden;
}
.upload-mini-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--color-primary);
  transition: width 0.25s ease;
}

/* Scrollbars */
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }

/* Mobile view toggle (hidden on desktop) */
.mobile-view-toggle {
  display: none;
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1500;
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  background: var(--color-text);
  color: var(--color-bg);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.3);
  cursor: pointer;
}

/* ===================== Mobile layout ===================== */
@media (max-width: 768px) {
  .mobile-view-toggle { display: block; }

  .app-body {
    position: relative;
    overflow: hidden;
    height: calc(100vh - 56px);
  }
  .sidebar {
    position: absolute;
    inset: 0;
    width: 100%;
    z-index: 10;
    transition: transform 0.25s ease;
  }
  /* z-index needed here (not just on .sidebar): without it, Leaflet's own
     internal panes (z-index up to 700 for popups) escape into the shared
     stacking context and render above the sidebar regardless of its z-index. */
  .map-wrap { position: absolute; inset: 0; z-index: 1; }
  .app-body.map-active .sidebar { transform: translateX(-100%); }

  /* Bigger touch targets throughout */
  .btn { padding: 11px 16px; font-size: 15px; }
  .btn-icon { padding: 10px; min-width: 40px; min-height: 40px; }
  .btn-small { padding: 9px 14px; font-size: 13px; }

  /* The header row is fixed-height and narrow — buttons must stay compact
     here even though buttons everywhere else got bigger touch targets above,
     otherwise "+ Neue Tour" wraps onto a second line and gets clipped off. */
  .app-header { padding: 0 10px; overflow-x: auto; }
  .header-actions { gap: 6px; flex-shrink: 0; }
  .app-header .btn { padding: 7px 10px; font-size: 13px; white-space: nowrap; flex-shrink: 0; }
  .brand-name { display: none; }
  .collaborator-avatar { width: 22px; height: 22px; font-size: 10px; }
  .visited-flags-row { max-width: 84px; font-size: 14px; }

  .stop-item { padding: 8px 4px; }
  .stop-drag-handle { display: none; } /* dragging doesn't work via touch */
  .stop-move-buttons { display: flex; }
  .stop-badge { width: 30px; height: 30px; font-size: 12px; }
  .stop-gutter { width: 38px; }
  .stop-timeline-track { left: 23px; }

  .tour-card { padding: 16px 14px; }
  .favorite-item { padding: 10px 10px; }

  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }

  .lightbox-nav { width: 48px; height: 48px; font-size: 28px; }
  .lightbox-filmstrip-thumb { width: 50px; height: 50px; }

  .modal { width: 100vw; max-height: 100vh; height: 100%; border-radius: 0; }
  .modal-large { width: 100vw; }
}
