:root {
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,.15);
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --shadow-lg: 0 20px 50px rgba(0,0,0,.45);
  --transition: 180ms cubic-bezier(.2,.8,.2,1);
  --nav-w: 240px;
}

[data-theme="dark"] {
  --bg: #0a0f1e;
  --bg-grad: radial-gradient(ellipse at top left, #1e1b4b 0%, #0a0f1e 45%);
  --surface: #111827;
  --surface-2: #1a2334;
  --surface-3: #232f45;
  --border: #253045;
  --border-strong: #334158;
  --text: #e5e7eb;
  --text-2: #c9d1dc;
  --muted: #8b93a7;
  --primary: #7c7af5;
  --primary-2: #a78bfa;
  --primary-hover: #9593ff;
  --danger: #ef4444;
  --success: #10b981;
  --accent: #22d3ee;
}

[data-theme="light"] {
  --bg: #f5f6fb;
  --bg-grad: radial-gradient(ellipse at top left, #eef0ff 0%, #f5f6fb 45%);
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --surface-3: #e6ebf4;
  --border: #e2e6ef;
  --border-strong: #cfd5e3;
  --text: #0f172a;
  --text-2: #1e293b;
  --muted: #64748b;
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --primary-hover: #4f46e5;
  --danger: #dc2626;
  --success: #059669;
  --accent: #0891b2;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv11', 'ss01';
}
h1, h2, h3, h4 { font-family: 'Space Grotesk', 'Inter', sans-serif; letter-spacing: -0.01em; }
h1 { font-size: 28px; font-weight: 700; margin: 0; }
h2 { font-size: 20px; font-weight: 600; margin: 0; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.muted { color: var(--muted); }
a { color: inherit; text-decoration: none; }
.link { color: var(--primary-2); font-size: 13px; font-weight: 500; background: none; border: none; cursor: pointer; padding: 0; }
.link:hover { color: var(--primary-hover); text-decoration: underline; }

/* --- SIDEBAR NAV --- */
.nav {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--nav-w); z-index: 900;
  display: flex; flex-direction: column;
  padding: 20px 14px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(14px);
  border-right: 1px solid var(--border);
  transition: transform var(--transition);
}
.nav-brand {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px 22px;
  color: var(--primary-2);
}
.nav-title { font-family: 'Space Grotesk', sans-serif; font-size: 20px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.nav-links { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-size: 14px; font-weight: 500;
  transition: background var(--transition), color var(--transition);
  border: none; background: none; cursor: pointer; text-align: left;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active {
  background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 22%, transparent), color-mix(in srgb, var(--primary-2) 15%, transparent));
  color: var(--text);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 30%, transparent);
}
.nav-footer { display: flex; flex-direction: column; gap: 3px; padding-top: 12px; border-top: 1px solid var(--border); }
.nav-btn { width: 100%; }

.nav-toggle {
  display: none;
  position: fixed; top: 14px; left: 14px; z-index: 1200;
  width: 42px; height: 42px; border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  color: var(--text); cursor: pointer;
  display: none; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}

/* --- MAIN + VIEWS --- */
.main { margin-left: var(--nav-w); min-height: 100vh; }
.view { display: none; padding: 32px 40px 80px; max-width: 1400px; margin: 0 auto; }
.view.active { display: block; animation: fadeIn 260ms ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.view-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 28px; flex-wrap: wrap; }
.view-header .subtitle { color: var(--muted); margin: 6px 0 0; font-size: 14px; }
.hello { background: linear-gradient(135deg, var(--text) 0%, var(--primary-2) 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* View: map uses full area */
.view[data-view="map"].active { padding: 0; max-width: none; display: block; }
.view[data-view="map"] { padding: 0; }
.map-wrap { position: fixed; top: 0; left: var(--nav-w); right: 0; bottom: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }

/* --- BUTTONS --- */
.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14px; font-weight: 500;
  font-family: inherit;
  transition: background var(--transition), transform 80ms, border-color var(--transition), box-shadow var(--transition);
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  border-color: transparent; color: white;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 40%, transparent);
}
.btn.primary:hover { background: linear-gradient(135deg, var(--primary-hover), var(--primary-2)); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn.block { display: flex; width: 100%; margin-top: 8px; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 26px; cursor: pointer; padding: 0 8px; line-height: 1; }
.icon-btn:hover { color: var(--text); }

/* --- CARDS --- */
.card {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.card:hover { border-color: var(--border-strong); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-header h3 { margin: 0; }
.card.card-lg { grid-column: span 2; }

/* --- STATS GRID (home) --- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 28px; }
.stat-card {
  position: relative; overflow: hidden;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow-sm);
}
.stat-card::before {
  content: ''; position: absolute; top: -20%; right: -20%; width: 140px; height: 140px;
  background: radial-gradient(circle, color-mix(in srgb, var(--primary) 40%, transparent), transparent 60%);
  opacity: .4; pointer-events: none;
}
.stat-card .v { font-family: 'Space Grotesk', sans-serif; font-size: 36px; font-weight: 700; line-height: 1; color: var(--text); position: relative; }
.stat-card .k { color: var(--muted); font-size: 12px; margin-top: 6px; text-transform: uppercase; letter-spacing: 0.1em; position: relative; }

/* --- HOME GRID --- */
.home-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.mini-map { height: 320px; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); }
.recent-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }
.recent-list li { display: flex; gap: 12px; padding: 10px 6px; border-radius: 8px; cursor: pointer; align-items: flex-start; transition: background var(--transition); }
.recent-list li:hover { background: var(--surface-2); }
.recent-list .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.recent-list .it-name { font-weight: 600; font-size: 14px; color: var(--text); }
.recent-list .it-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.flashback-body { display: flex; gap: 14px; align-items: center; }
.flashback-body img { width: 90px; height: 90px; object-fit: cover; border-radius: var(--radius-sm); flex-shrink: 0; }
.flashback-body h4 { margin: 0 0 4px; font-size: 15px; color: var(--text); font-family: 'Inter', sans-serif; text-transform: none; letter-spacing: normal; }
.flashback-body p { margin: 0; font-size: 12px; color: var(--muted); }

/* --- MAP OVERLAYS --- */
.map-overlay-top {
  position: absolute; top: 16px; left: 16px; right: 16px; z-index: 500;
  display: flex; gap: 10px; align-items: center;
}
.search {
  flex: 1; max-width: 520px; position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}
.search svg { color: var(--muted); flex-shrink: 0; }
.search input { flex: 1; padding: 11px 0; background: none; border: none; color: var(--text); outline: none; font-size: 14px; font-family: inherit; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; max-height: 320px; overflow-y: auto;
  box-shadow: var(--shadow);
}
.search-results div { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 13px; }
.search-results div:last-child { border-bottom: none; }
.search-results div:hover { background: var(--surface-2); }

.map-overlay-left {
  position: absolute; top: 78px; left: 16px; z-index: 500;
  width: 230px; padding: 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  max-height: calc(100vh - 180px); overflow-y: auto;
  transition: transform 220ms cubic-bezier(.2,.8,.2,1), opacity 160ms;
}
.map-overlay-left[hidden] {
  display: block; pointer-events: none;
  transform: translateX(calc(-100% - 24px)); opacity: 0;
}
.map-filters-toggle {
  position: absolute; top: 6px; right: 6px;
  width: 26px; height: 26px; border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--muted); border: 1px solid var(--border);
  font-size: 18px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.map-filters-toggle:hover { color: var(--text); background: var(--surface-2); }
.map-filters-show {
  position: absolute; top: 78px; left: 16px; z-index: 501;
  width: 40px; height: 40px; border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer; box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
}
.map-filters-show[hidden] { display: none; }
.map-filters-show:hover { background: var(--surface-2); border-color: var(--border-strong); }
.filter-group { margin-bottom: 14px; }
.filter-group:last-child { margin-bottom: 0; }
.filter-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border); cursor: pointer;
  font-size: 12px; font-weight: 500; font-family: inherit;
  transition: all var(--transition);
}
.chip:hover { background: var(--surface-3); }
.chip.active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); border-color: transparent; color: white; }

/* --- PAGE FILTER BAR (countries / trips / travel log) --- */
.page-filters {
  display: flex; flex-direction: column; gap: 10px;
  margin: 0 0 22px;
  padding: 14px 18px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.page-filters .row-label {
  display: flex; align-items: center; gap: 10px;
}
.page-filters .row-label .label {
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  min-width: 60px;
}
.page-filters .chip-row { flex: 1; }

.map-overlay-bottom {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 500; width: min(520px, calc(100vw - 40px));
  padding: 14px 18px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.timeline-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
#timeline { width: 100%; accent-color: var(--primary); }

.legend {
  position: absolute; bottom: 20px; right: 20px; z-index: 500;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column; gap: 6px; font-size: 12px;
}
.legend-item { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.heat-legend {
  position: absolute; bottom: 110px; right: 20px; z-index: 500;
  padding: 10px 14px; width: 180px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
.heat-legend[hidden] { display: none; }
.heat-legend-title {
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 600; font-size: 10px; margin-bottom: 8px;
}
.heat-legend-bar {
  height: 8px; border-radius: 4px;
  background: linear-gradient(to right,
    rgb(54, 35, 120),
    rgb(109, 40, 217),
    rgb(190, 24, 180),
    rgb(244, 114, 82),
    rgb(251, 191, 36)
  );
  box-shadow: 0 1px 6px rgba(0,0,0,0.25) inset;
}
.heat-legend-scale {
  display: flex; justify-content: space-between;
  margin-top: 6px; color: var(--text-2); font-size: 11px; font-weight: 600;
}

/* --- MAP MARKERS --- */
.pin-marker {
  width: 22px; height: 22px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.pin-marker.wishlist { border-style: dashed; }

/* --- LOG FEED --- */
.log-filters input { padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius-sm); min-width: 240px; font-family: inherit; font-size: 14px; }
.log-feed { display: flex; flex-direction: column; gap: 22px; }
.log-group-title { font-family: 'Space Grotesk', sans-serif; font-size: 18px; font-weight: 700; color: var(--primary-2); margin: 20px 0 6px; padding-left: 12px; border-left: 3px solid var(--primary-2); }
.log-entry {
  display: grid; grid-template-columns: 140px 1fr; gap: 18px;
  padding: 18px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 1px solid var(--border);
  cursor: pointer; transition: all var(--transition);
}
.log-entry:hover { border-color: var(--primary); transform: translateX(4px); }
.log-entry .thumb { width: 100%; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--muted); }
.log-entry .thumb img { width: 100%; height: 100%; object-fit: cover; }
.log-entry .body h4 { margin: 0 0 6px; font-size: 17px; color: var(--text); font-family: 'Space Grotesk', sans-serif; text-transform: none; letter-spacing: normal; }
.log-entry .body .meta { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.log-entry .body .meta .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px; vertical-align: middle; }
.log-entry .body p { margin: 0; font-size: 14px; color: var(--text-2); line-height: 1.55; }
.log-entry .body .tags { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.log-entry .body .tags span { font-size: 11px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }

/* --- GALLERY --- */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.gallery-tile {
  position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden;
  cursor: pointer; background: var(--surface-2);
  transition: transform var(--transition), box-shadow var(--transition);
}
.gallery-tile:hover { transform: scale(1.02); box-shadow: var(--shadow); }
.gallery-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-tile .overlay {
  position: absolute; inset: 0; padding: 10px 12px;
  display: flex; flex-direction: column; justify-content: flex-end;
  background: linear-gradient(180deg, transparent 40%, rgba(0,0,0,0.75));
  color: white; font-size: 12px; opacity: 0; transition: opacity var(--transition);
}
.gallery-tile:hover .overlay { opacity: 1; }
.gallery-tile .overlay .c { font-weight: 600; font-size: 13px; }
.gallery-empty { grid-column: 1 / -1; text-align: center; padding: 60px; color: var(--muted); }

/* Pin modal photos */
.photo-section { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.pin-photos { display: flex; flex-wrap: wrap; gap: 8px; }
.pin-photos .thumb {
  position: relative; width: 72px; height: 72px;
  border-radius: 8px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
}
.pin-photos .thumb img { width: 100%; height: 100%; object-fit: cover; }
.pin-photos .thumb .del {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,0.7); color: white; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 14px; line-height: 1;
}

/* --- LIGHTBOX --- */
.lightbox {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 200ms;
}
.lightbox img { max-width: 92vw; max-height: 85vh; object-fit: contain; border-radius: 6px; }
.lightbox-close, .lightbox-nav {
  position: absolute; background: rgba(255,255,255,0.1); color: white;
  border: none; cursor: pointer; backdrop-filter: blur(10px);
  width: 48px; height: 48px; border-radius: 50%;
  font-size: 24px; display: flex; align-items: center; justify-content: center;
}
.lightbox-close:hover, .lightbox-nav:hover { background: rgba(255,255,255,0.2); }
.lightbox-close { top: 20px; right: 20px; }
.lightbox-nav.prev { left: 20px; top: 50%; transform: translateY(-50%); }
.lightbox-nav.next { right: 20px; top: 50%; transform: translateY(-50%); }
.lightbox-caption { position: absolute; bottom: 24px; left: 0; right: 0; text-align: center; color: white; font-size: 14px; }

/* --- TRIP GRID --- */
.trip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.trip-card {
  position: relative; padding: 0; overflow: hidden;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-radius: var(--radius);
  cursor: pointer; transition: all var(--transition);
}
.trip-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--primary); }
.trip-card .cover {
  height: 140px; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  position: relative;
}
.trip-card .cover::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle at 30% 40%, rgba(255,255,255,0.15), transparent 60%);
}
.trip-card .badge {
  position: absolute; top: 14px; right: 14px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(0,0,0,0.35); color: white; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  backdrop-filter: blur(8px);
}
.trip-card .body { padding: 18px; }
.trip-card h3 { margin: 0 0 6px; font-size: 17px; color: var(--text); text-transform: none; letter-spacing: normal; }
.trip-card .meta { font-size: 12px; color: var(--muted); }
.trip-card .stats { display: flex; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--text-2); }
.trip-card .stats b { color: var(--text); font-family: 'Space Grotesk', sans-serif; font-size: 16px; }

/* --- COUNTRIES GRID --- */
.country-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.country-card {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  cursor: pointer; transition: all var(--transition);
}
.country-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.country-card .flag { font-size: 28px; line-height: 1; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3)); }
.country-card .name { font-weight: 600; font-size: 14px; color: var(--text); }
.country-card .count { font-size: 12px; color: var(--muted); }

/* --- SETTINGS --- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.settings-grid .card label { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.settings-grid .card input[type="text"], .settings-grid .card input[type="password"], .settings-grid .card select {
  padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; font-family: inherit; font-size: 13px; max-width: 180px;
}
.settings-grid .card input[type="color"] { width: 48px; height: 32px; border: 1px solid var(--border); border-radius: 6px; background: none; padding: 0; cursor: pointer; }

/* Helper hint paragraph beneath a settings card field. */
.settings-grid .card .hint { font-size: 11px; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }

/* Trail upload row: file-input label + optional Remove button side by side. */
.settings-grid .card .trail-upload-row { display: flex; gap: 8px; margin-top: 4px; }
.settings-grid .card .trail-upload-row .btn.block { flex: 1; margin-top: 0; }

/* Settings card h3 is an inline-flex so badges and help-tips sit inline. */
.settings-grid .card h3 {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 0 0 8px;
}

/* Wide card spans the full row so long walkthroughs aren't crammed. */
.settings-grid .card-wide { grid-column: 1 / -1; }

/* Help tooltip: a tiny circular ? that reveals a styled bubble on hover
 * or keyboard focus. Pure CSS, no JS. */
.help-tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  background: color-mix(in srgb, var(--primary) 22%, transparent);
  color: var(--primary-2);
  font-size: 10px; font-weight: 700;
  cursor: help; position: relative; user-select: none;
  font-family: 'Inter', sans-serif;
  text-transform: none; letter-spacing: normal;
  flex-shrink: 0;
  transition: background var(--transition);
}
.help-tip:hover, .help-tip:focus { background: color-mix(in srgb, var(--primary) 40%, transparent); outline: none; }
.help-tip::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%) translateY(4px);
  width: max-content; max-width: 260px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-size: 12px; font-weight: 500; line-height: 1.5;
  text-align: left; white-space: normal;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none;
  transition: opacity 160ms, transform 160ms;
  z-index: 2500;
}
.help-tip::before {
  content: ''; position: absolute; bottom: 100%; left: 50%;
  transform: translateX(-50%) translateY(-2px);
  border: 6px solid transparent;
  border-top-color: var(--surface);
  opacity: 0; transition: opacity 160ms;
  z-index: 2501;
}
.help-tip:hover::after, .help-tip:focus::after { opacity: 1; transform: translateX(-50%) translateY(0); }
.help-tip:hover::before, .help-tip:focus::before { opacity: 1; }

/* Step-by-step walkthroughs inside settings cards. */
.settings-grid .card details.steps {
  margin: 10px 0 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  padding: 0;
  overflow: hidden;
}
.settings-grid .card details.steps[open] {
  background: color-mix(in srgb, var(--primary) 6%, var(--bg));
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
}
.settings-grid .card details.steps summary {
  padding: 12px 16px; cursor: pointer;
  font-size: 13px; color: var(--text);
  list-style: none;
  user-select: none;
  display: flex; align-items: center; gap: 8px;
}
.settings-grid .card details.steps summary::-webkit-details-marker { display: none; }
.settings-grid .card details.steps summary::before {
  content: '▸'; color: var(--primary-2); font-size: 12px;
  transition: transform 160ms; display: inline-block;
}
.settings-grid .card details.steps[open] summary::before { transform: rotate(90deg); }
.settings-grid .card details.steps summary strong { font-weight: 600; }
.settings-grid .card details.steps summary:hover { background: color-mix(in srgb, var(--surface) 60%, transparent); }

.settings-grid .card details.steps ol,
.settings-grid .card details.steps ul {
  margin: 0; padding: 0 20px 16px 36px;
  color: var(--text-2); font-size: 13px; line-height: 1.7;
}
.settings-grid .card details.steps ol li,
.settings-grid .card details.steps ul li { margin-bottom: 6px; }
.settings-grid .card details.steps code {
  background: color-mix(in srgb, var(--surface-2) 80%, transparent);
  border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 4px;
  font-size: 11px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
}
.settings-grid .card details.steps a {
  color: var(--primary-2); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--primary-2) 40%, transparent);
}
.settings-grid .card details.steps a:hover { text-decoration-color: var(--primary-2); }

/* Per-person trail block */
.settings-grid .card .trail-person {
  padding: 12px 14px; margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg) 60%, transparent);
}
.settings-grid .card .trail-person-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
}
.settings-grid .card .trail-person-head label {
  margin: 0; padding: 0; display: inline-flex; align-items: center; gap: 4px;
  color: var(--text); font-weight: 600;
}
.settings-grid .card .trail-info {
  font-size: 12px; color: var(--muted); margin: 2px 0 10px;
  text-transform: none; letter-spacing: normal;
}
.settings-grid .card .trail-progress {
  margin-top: 12px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--primary) 10%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border));
  border-radius: 10px;
  font-size: 12px; color: var(--text);
}
.settings-grid .card .trail-progress[hidden] { display: none; }

/* --- MODAL --- */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000; padding: 16px;
  animation: fadeIn 200ms;
}
.modal[hidden], .wiki-preview[hidden], .weather-preview[hidden], .lightbox[hidden] { display: none; }
.modal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  max-width: 600px; width: 100%; max-height: 92vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  animation: slideUp 260ms cubic-bezier(.2,.8,.2,1);
}
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 18px; font-family: 'Space Grotesk', sans-serif; }
.modal-body { padding: 18px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-footer {
  display: flex; gap: 8px; padding: 14px 0 0; margin-top: 6px;
  border-top: 1px solid var(--border); align-items: center;
}
.spacer { flex: 1; }
.modal-body label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 5px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.modal-body input, .modal-body select, .modal-body textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  text-transform: none;
  letter-spacing: normal;
}
.modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.modal-body textarea { resize: vertical; min-height: 60px; }
.row { display: grid; gap: 10px; }
.row.row-2 { grid-template-columns: 1fr 1fr; }
.row.row-3 { grid-template-columns: 1fr 1fr 1fr; }

.wiki-preview {
  display: flex; gap: 12px; padding: 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
.wiki-preview img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.wiki-preview h4 { margin: 0 0 4px; font-size: 14px; color: var(--text); font-family: 'Inter', sans-serif; text-transform: none; letter-spacing: normal; }
.wiki-preview p { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; max-height: 72px; overflow: hidden; }

.weather-preview {
  display: flex; gap: 8px; padding: 10px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; overflow-x: auto;
}
.weather-day { text-align: center; flex-shrink: 0; padding: 4px 10px; }
.weather-day .d { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.weather-day .t { font-weight: 600; color: var(--text); font-size: 12px; margin-top: 2px; }

/* --- TOAST --- */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border);
  padding: 12px 20px; border-radius: var(--radius-sm); z-index: 3001;
  box-shadow: var(--shadow); font-size: 14px; color: var(--text);
  animation: slideUp 220ms;
}

/* --- LOGIN (unchanged but theme-aware) --- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  background: radial-gradient(ellipse at top, #1e1b4b 0%, #0a0f1e 60%);
}
.login-card {
  max-width: 360px; width: 100%; padding: 36px;
  background: #111827; border: 1px solid #253045;
  border-radius: 18px; text-align: center; box-shadow: var(--shadow);
  color: #e5e7eb;
}
.login-card .logo { color: #a78bfa; margin-bottom: 8px; }
.login-card h1 { margin: 0 0 4px; font-size: 26px; font-family: 'Space Grotesk', sans-serif; }
.login-card .muted { color: #8b93a7; margin: 0 0 24px; font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.login-card label { font-size: 12px; color: #8b93a7; }
.login-card input {
  padding: 12px 14px; border-radius: 10px;
  border: 1px solid #253045; background: #0a0f1e; color: #e5e7eb;
  font-family: inherit; font-size: 14px;
}
.login-card button {
  padding: 12px; border-radius: 10px; border: none;
  background: linear-gradient(135deg, #7c7af5, #a78bfa);
  color: white; font-weight: 600; cursor: pointer; margin-top: 6px; font-family: inherit; font-size: 14px;
}
.login-card .error { color: #ef4444; font-size: 13px; text-align: center; margin: 4px 0 0; }

/* --- RESPONSIVE --- */
@media (max-width: 960px) {
  .home-grid { grid-template-columns: 1fr 1fr; }
  .card.card-lg { grid-column: span 2; }
}
@media (max-width: 720px) {
  :root { --nav-w: 0px; }
  .nav {
    transform: translateX(-100%);
    width: 260px;
  }
  .nav.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .nav-toggle { display: flex !important; }
  .main { margin-left: 0; }
  .view { padding: 74px 18px 80px; }
  .view-header { margin-bottom: 18px; }
  .map-wrap { left: 0; top: 0; }
  .map-overlay-top { top: 70px; left: 12px; right: 12px; gap: 8px; }
  .map-overlay-top .search { min-width: 0; }
  .map-overlay-left {
    top: 130px; width: min(calc(100vw - 24px), 260px);
    max-height: 48vh;
  }
  .map-filters-show { top: 130px; left: 12px; width: 44px; height: 44px; }
  .home-grid { grid-template-columns: 1fr; }
  .card.card-lg { grid-column: span 1; }
  .log-entry { grid-template-columns: 90px 1fr; }
  .legend { display: none; }
  .heat-legend { bottom: 80px; right: 12px; width: 150px; }
  .map-overlay-bottom { bottom: 12px; }
  /* Page filter bars: stack the label on top of the chip row, chip row
   * scrolls horizontally so small screens don't explode. */
  .page-filters { padding: 12px 14px; gap: 8px; margin-bottom: 16px; }
  .page-filters .row-label { flex-direction: column; align-items: flex-start; gap: 6px; }
  .page-filters .row-label .label { min-width: 0; }
  .page-filters .chip-row {
    flex-wrap: nowrap; overflow-x: auto;
    margin: -2px -14px -2px 0; padding: 2px 14px 2px 0;
    scrollbar-width: none;
  }
  .page-filters .chip-row::-webkit-scrollbar { display: none; }
  .page-filters .chip { flex-shrink: 0; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-card .v { font-size: 28px; }
  .diary-header { padding: 14px 16px; gap: 10px; }
  .diary-head-info h2 { font-size: 18px; }
  .diary-body { padding: 16px 14px 80px; }
  .modal { padding: 0; }
  .modal-card { max-height: 100vh; border-radius: 0; }
  .country-grid { grid-template-columns: 1fr !important; }
  .trip-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-grid .card input[type="text"],
  .settings-grid .card input[type="password"],
  .settings-grid .card select { max-width: 100%; }
}
@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .home-quick-pin { padding: 8px 12px; }
  .log-entry { grid-template-columns: 80px 1fr; }
}

/* --- LEGS section in trip modal --- */
.legs-section { padding-top: 12px; border-top: 1px solid var(--border); }
.legs-list { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 6px; }
.legs-list li { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.legs-list .mode { font-size: 16px; }
.legs-list .leg-body { flex: 1; color: var(--text); }
.legs-list .leg-date { font-size: 11px; color: var(--muted); }
.legs-list .del { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 18px; }
.leg-form { display: grid; grid-template-columns: 1.3fr 1fr 1.3fr 1fr; gap: 6px; align-items: stretch; }
.leg-form select, .leg-form input { padding: 8px; font-size: 12px; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 6px; font-family: inherit; text-transform: none; letter-spacing: normal; }
.leg-form button { grid-column: 1 / -1; margin-top: 4px; }

/* --- DIARY (full-screen journal view) --- */
.diary {
  position: fixed; inset: 0; z-index: 2100;
  background: var(--bg);
  display: flex; flex-direction: column;
  animation: fadeIn 220ms;
}
.diary[hidden] { display: none; }
.diary-header {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 28px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}
.diary-header .diary-back { font-size: 22px; }
.diary-head-info { flex: 1; min-width: 0; }
.diary-head-info h2 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 22px; color: var(--text); }
.diary-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.diary-body {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 28px;
  padding: 28px 32px 60px;
  max-width: 1100px;
  width: 100%; margin: 0 auto;
  overflow-y: auto; flex: 1;
}
.diary-meta {
  position: sticky; top: 28px; align-self: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm);
}
.diary-meta img { width: 100%; border-radius: var(--radius-sm); margin-bottom: 10px; object-fit: cover; max-height: 180px; }
.diary-meta h4 { margin: 0 0 4px; font-family: 'Inter', sans-serif; text-transform: none; letter-spacing: normal; color: var(--text); font-size: 15px; }
.diary-meta p { margin: 6px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.diary-meta .diary-meta-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding: 4px 0; border-top: 1px dashed var(--border); margin-top: 8px; }
.diary-meta .diary-meta-row b { color: var(--text); font-weight: 600; }

.diary-entries { display: flex; flex-direction: column; gap: 22px; }
.diary-entry {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 26px; box-shadow: var(--shadow-sm);
  cursor: pointer; transition: border-color var(--transition), transform 80ms;
}
.diary-entry:hover { border-color: var(--border-strong); }
.diary-entry header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.diary-entry .date { font-family: 'Space Grotesk', sans-serif; font-size: 15px; color: var(--primary-2); font-weight: 600; }
.diary-entry .mood { font-size: 12px; color: var(--muted); }
.diary-entry h4 { margin: 0 0 10px; font-family: 'Inter', sans-serif; text-transform: none; letter-spacing: normal; font-size: 17px; color: var(--text); }
.diary-entry .body { white-space: pre-wrap; font-size: 14px; line-height: 1.65; color: var(--text); }
.diary-empty {
  padding: 80px 20px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
}

/* Editor slides in as a side panel on top of the diary. */
.diary-editor {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border);
  z-index: 2200; display: flex; flex-direction: column;
  box-shadow: -20px 0 60px rgba(0,0,0,0.35);
  animation: slideInRight 260ms cubic-bezier(.2,.8,.2,1);
}
.diary-editor[hidden] { display: none; }
@keyframes slideInRight { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.diary-editor-inner { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.diary-editor header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.diary-editor header h3 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 16px; }
.diary-editor form {
  display: flex; flex-direction: column; gap: 12px;
  padding: 18px 22px 22px; flex: 1; overflow-y: auto;
}
.diary-editor form label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 5px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.diary-editor form input, .diary-editor form textarea {
  padding: 10px 12px; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 8px; font-size: 14px; font-family: inherit; text-transform: none; letter-spacing: normal;
}
.diary-editor form textarea { resize: vertical; min-height: 240px; line-height: 1.6; }
.diary-editor-footer {
  display: flex; gap: 8px; padding-top: 12px; margin-top: auto; border-top: 1px solid var(--border); align-items: center;
}

/* Trip modal → journal section */
.trip-journal-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 10px; }
.trip-journal-list .tj-entry {
  padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; cursor: pointer;
}
.trip-journal-list .tj-entry:hover { border-color: var(--border-strong); }
.trip-journal-list .tj-entry .tj-meta { display: flex; gap: 10px; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.trip-journal-list .tj-entry .tj-meta .tj-date { color: var(--primary-2); font-weight: 600; }
.trip-journal-list .tj-entry .tj-title { color: var(--text); font-weight: 600; margin-bottom: 2px; }
.trip-journal-list .tj-entry .tj-preview { color: var(--muted); font-size: 12px; line-height: 1.5; }

.badge-soft {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  background: color-mix(in srgb, var(--primary) 18%, transparent);
  color: var(--primary-2); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  vertical-align: middle; margin-left: 6px; font-weight: 600;
}

/* Log entries: click affordance */
.log-entry { cursor: pointer; transition: border-color var(--transition); }
.log-entry:hover { border-color: var(--border-strong); }

/* Responsive: diary stacks */
@media (max-width: 900px) {
  .diary-body { grid-template-columns: 1fr; padding: 20px 16px 60px; }
  .diary-meta { position: static; }
  .diary-editor { width: 100vw; border-left: none; }
}
