*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-2: #f1f5f9;
  --color-border: #e2e8f0;
  --color-primary: #f97316;
  --color-primary-hover: #ea6c0a;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-danger: #ef4444;
  --navbar-height: 56px;
  --detail-width: 320px;
  --sidebar-width: var(--detail-width);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f1117;
    --color-surface: #1a1d27;
    --color-surface-2: #22263a;
    --color-border: #2e3250;
    --color-text: #e2e8f0;
    --color-text-muted: #8892a4;
  }
}

html,
body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
}

/* Single-screen app: panes scroll internally, the page itself never does. Also
   stops .app-layout's margin-top collapsing through body and adding height. */
body {
  overflow: hidden;
}

/* ── Navbar ─────────────────────────────────────── */

.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--navbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1100; /* above Leaflet's controls (z-index 1000) */
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.navbar-logo {
  font-size: 22px;
}

.navbar-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--color-text);
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Layout ──────────────────────────────────────── */

.app-layout {
  display: flex;
  height: calc(100vh - var(--navbar-height));
  margin-top: var(--navbar-height);
}

/* ── Sidebar ─────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-header h2 {
  font-size: 15px;
  font-weight: 600;
}

.badge {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  border-radius: 99px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 600;
}

.auth-prompt {
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: var(--color-text-muted);
  font-size: 13px;
}

.tour-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
}

.tour-search,
.tour-sort {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--color-text);
  font: inherit;
}

.tour-search:focus,
.tour-sort:focus {
  outline: none;
  border-color: var(--color-primary);
}

.tour-sort {
  cursor: pointer;
}

.tour-empty {
  padding: 16px;
  color: var(--color-text-muted);
  font-size: 13px;
  text-align: center;
}

.tour-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.tour-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--color-border);
}

.tour-pager-label {
  color: var(--color-text-muted);
  font-size: 13px;
}

.tour-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background 0.15s;
}

.tour-item:hover {
  background: var(--color-surface-2);
}

.tour-item.active {
  background: var(--color-surface-2);
  border-left: 3px solid var(--color-primary);
  padding-left: 13px;
}

.tour-item-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tour-item-meta {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.show-all-btn {
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  border-top: 1px solid var(--color-border);
  color: var(--color-primary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  transition: background 0.15s;
}

.show-all-btn:hover {
  background: var(--color-surface-2);
}

.empty-state {
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: var(--color-text-muted);
  font-size: 13px;
}

/* ── Map ─────────────────────────────────────────── */

.map-container {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

.pin-toggle {
  position: absolute;
  top: 56px;
  right: 12px;
  z-index: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 7px;
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.pin-toggle input {
  cursor: pointer;
  accent-color: var(--color-primary);
}

.photo-pin img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  background: var(--color-surface-2);
}

.map-empty-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 500;
}

.map-empty-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 32px 40px;
  text-align: center;
  pointer-events: auto;
}

.map-empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.map-empty-card h3 {
  font-size: 16px;
  margin-bottom: 6px;
}

.map-empty-card p {
  color: var(--color-text-muted);
  font-size: 13px;
}

/* ── Detail panel ────────────────────────────────── */

.detail-panel {
  width: var(--detail-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  padding: 20px 16px;
  overflow-y: auto;
  position: relative;
}

.detail-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 4px;
}

.detail-close:hover {
  color: var(--color-text);
}

.detail-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 16px;
  padding-right: 28px;
}

.detail-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin-bottom: 16px;
}

.detail-meta dt {
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  align-self: center;
}

.detail-meta dd {
  font-size: 14px;
  font-weight: 500;
}

.detail-description {
  font-size: 13px;
  color: var(--color-text-muted);
  line-height: 1.6;
}

/* Stacked action buttons with consistent spacing (no per-button margins). */
.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}

/* ── User menu ───────────────────────────────────── */

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
}

#user-name {
  font-size: 13px;
  color: var(--color-text-muted);
}

/* ── Buttons ─────────────────────────────────────── */

.btn {
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  transition:
    background 0.15s,
    opacity 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn-secondary {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-danger {
  background: transparent;
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-danger);
  color: #fff;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-border);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--color-text);
}

.btn-full {
  width: 100%;
  text-align: center;
}

/* ── Modal ───────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 32px 36px;
  min-width: 300px;
  text-align: center;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 4px;
}

.modal-close:hover {
  color: var(--color-text);
}

/* ── Help modal ──────────────────────────────────── */

.help-modal {
  max-width: 480px;
}

.help-content {
  text-align: left;
  margin-top: 8px;
  max-height: 60vh;
  overflow-y: auto;
}

.help-content h3 {
  font-size: 14px;
  margin: 14px 0 4px;
}

.help-content p {
  font-size: 13px;
  color: var(--color-text-muted);
}

.help-content code {
  background: var(--color-surface-2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}

/* ── Profile modal ───────────────────────────────── */

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.profile-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}

.profile-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  text-align: left;
}

.profile-meta dt {
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  align-self: center;
}

.profile-meta dd {
  font-size: 14px;
}

.profile-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}

/* ── Upload form ─────────────────────────────────── */

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
  text-align: left;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.field input,
.field textarea {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--color-text);
  font: inherit;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.dropzone {
  border: 2px dashed var(--color-border);
  border-radius: 8px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.dragover {
  border-color: var(--color-primary);
  background: var(--color-surface-2);
  outline: none;
}

.dropzone-text {
  color: var(--color-text-muted);
  font-size: 13px;
}

.dropzone-filename {
  margin-top: 8px;
  color: var(--color-text);
  font-size: 13px;
  font-weight: 600;
}

.progress {
  height: 6px;
  background: var(--color-surface-2);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--color-primary);
  transition: width 0.15s ease;
}

.upload-error {
  color: var(--color-danger);
  font-size: 13px;
}

/* ── Tour images ─────────────────────────────────── */

.tour-images {
  margin-top: 20px;
}

.images-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.image-tile {
  position: relative;
  margin: 0;
  min-width: 0;
}

.image-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
  background: var(--color-surface-2);
  cursor: pointer;
  display: block;
}

.image-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.image-tile:hover .image-delete,
.image-delete:focus-visible {
  opacity: 1;
}

.image-delete:hover {
  background: var(--color-danger);
}

.dropzone-sm {
  padding: 14px 12px;
}

.image-tile-pending,
.image-tile-error {
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  background: var(--color-surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px;
  text-align: center;
}

.image-tile-error {
  border: 1px solid var(--color-danger);
}

.image-progress-ring {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: conic-gradient(
    var(--color-primary) calc(var(--progress, 0) * 1%),
    var(--color-border) 0
  );
}

.image-tile-filename {
  font-size: 10px;
  color: var(--color-text-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-tile-error-message {
  font-size: 10px;
  color: var(--color-danger);
}

.image-tile-actions {
  display: flex;
  gap: 6px;
}

.image-tile-retry,
.image-tile-dismiss {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

.image-tile-dismiss:hover {
  background: var(--color-danger);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  cursor: zoom-out;
}

.lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

/* ── Toasts ──────────────────────────────────────── */

.toasts {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-primary);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--color-text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  max-width: 320px;
}

.toast-error {
  border-left-color: var(--color-danger);
}

.toast-success {
  border-left-color: #10b981;
}

/* ── Header avatar, map expand, loading ──────────── */

.btn-avatar {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.btn-avatar:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.map-expand-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 600;
  width: 34px;
  height: 34px;
  border: 1px solid var(--color-border);
  border-radius: 7px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.app-layout.map-expanded .sidebar,
.app-layout.map-expanded .detail-panel {
  display: none;
}

.tour-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  color: var(--color-text-muted);
  font-size: 13px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Responsive (mobile / tablet) ────────────────── */

@media (max-width: 768px) {
  .app-layout {
    flex-direction: column;
  }

  /* Sidebar becomes a scrollable strip above the map. */
  .sidebar {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  .map-container {
    flex: 1;
    min-height: 55vh;
  }

  /* Detail panel overlays the map from the bottom instead of squeezing it. */
  .detail-panel {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    max-height: 78vh;
    border-left: none;
    border-top: 1px solid var(--color-border);
    z-index: 1500;
  }

  .navbar {
    padding: 0 12px;
  }

  .navbar-title {
    display: none;
  }
}

@media (max-width: 480px) {
  .btn {
    padding: 7px 10px;
  }

  .modal {
    min-width: 0;
    width: calc(100vw - 32px);
    padding: 28px 20px;
  }
}

/* ── Language switcher ───────────────────────────── */

.lang-switcher {
  position: relative;
}

.lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
}

.lang-btn .lang-flag {
  font-size: 1.1rem;
  line-height: 1;
}

.lang-btn .lang-code {
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 240px;
  padding: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  z-index: 1200;
}

.lang-search {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text);
  font-size: 0.9rem;
}

.lang-search:focus {
  outline: none;
  border-color: var(--color-primary);
}

.lang-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--color-text);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}

.lang-option:hover {
  background: var(--color-surface-2);
}

.lang-option[aria-selected='true'] {
  background: var(--color-surface-2);
  font-weight: 600;
}

.lang-option .lang-flag {
  font-size: 1.2rem;
  line-height: 1;
}

.lang-option .lang-code {
  margin-left: auto;
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

/* ── Utilities ───────────────────────────────────── */

.hidden {
  display: none !important;
}
