*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6366F1;
  --primary-hover: #4F46E5;
  --accent: #F97316;
  --surface: #ffffff;
  --bg: #F1F5F9;
  --text: #1E293B;
  --text-muted: #64748B;
  --border: #E2E8F0;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --radius: 12px;
  --radius-sm: 8px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: var(--text); background: var(--bg); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius-sm); border: none; cursor: pointer;
  font-size: 14px; font-weight: 600; transition: all .15s ease; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,.4); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-full { width: 100%; }

/* ── Inputs ── */
.input {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text); background: #fff; transition: border-color .15s;
  outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }

/* ── Form groups ── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
select.input { cursor: pointer; }

/* ── Language selector ── */
.lang-selector { display: flex; gap: 4px; }
.lang-btn { padding: 4px 10px; border: 1.5px solid var(--border); border-radius: 20px; background: transparent; font-size: 12px; font-weight: 600; color: var(--text-muted); cursor: pointer; transition: all .15s; }
.lang-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.lang-btn:hover:not(.active) { border-color: var(--primary); color: var(--primary); }

/* ── Error msg ── */
.error-msg { background: #FEF2F2; color: #DC2626; border: 1px solid #FECACA; border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; }
.hidden { display: none !important; }

/* ─────────────── LANDING PAGE ─────────────── */
.landing-page { min-height: 100vh; display: flex; flex-direction: column; }

.landing-header {
  padding: 16px 32px; display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.logo { font-size: 20px; font-weight: 800; color: var(--primary); letter-spacing: -.5px; }
.logo span { color: var(--accent); }

.landing-hero { text-align: center; padding: 64px 24px 48px; }
.landing-hero h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; color: var(--text); line-height: 1.15; margin-bottom: 16px; }
.landing-hero h1 em { font-style: normal; color: var(--primary); }
.landing-hero p { font-size: 18px; color: var(--text-muted); }

.landing-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; max-width: 800px; margin: 0 auto; padding: 0 24px 64px; }
@media (max-width: 640px) { .landing-cards { grid-template-columns: 1fr; } }

.card { background: var(--surface); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.card-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.card-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.card-divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.card-form { display: flex; flex-direction: column; gap: 14px; }

/* ─────────────── SESSION PAGE ─────────────── */
.session-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.session-header {
  flex-shrink: 0; padding: 12px 20px; display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-bottom: 1px solid var(--border); gap: 12px;
}
.session-header-left { display: flex; align-items: center; gap: 12px; }
.session-header-right { display: flex; align-items: center; gap: 12px; }
.code-badge { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; }
.code-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.code-value { font-size: 18px; font-weight: 800; color: var(--primary); letter-spacing: 2px; font-family: monospace; }

.session-layout { flex: 1; display: flex; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 300px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-content { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 20px; }
.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); flex-shrink: 0; }

.section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px; color: var(--text-muted); margin-bottom: 10px; }

/* Participants */
.participant-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.participant-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--bg); }
.participant-avatar { width: 30px; height: 30px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex-shrink: 0; }
.participant-name { font-size: 14px; font-weight: 500; }
.participant-you { font-size: 11px; color: var(--text-muted); margin-left: auto; }
.participant-empty { font-size: 13px; color: var(--text-muted); padding: 12px 0; text-align: center; }

/* ─────────────── PRESENCE DOT ─────────────── */
.participant-avatar-wrap { position: relative; display: flex; flex-shrink: 0; }
.presence-dot {
  position: absolute;
  bottom: 0; right: 0;
  width: 9px; height: 9px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  transition: background-color 0.4s ease;
}
.presence-dot.online {
  background: #22C55E;
  animation: pulse-presence 2.5s ease-in-out infinite;
}
.presence-dot.offline { background: #94A3B8; }
@keyframes pulse-presence {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,.5); }
  50%       { box-shadow: 0 0 0 4px rgba(34,197,94,0); }
}

/* Filters display */
.filters-display { font-size: 14px; color: var(--text); display: flex; flex-wrap: wrap; gap: 6px; }
.filter-tag { background: var(--primary); color: #fff; border-radius: 20px; padding: 3px 10px; font-size: 12px; font-weight: 600; }

/* Results */
.result-card {
  border: 1.5px solid var(--border); border-radius: var(--radius-sm); padding: 12px;
  cursor: pointer; transition: all .15s; background: #fff;
}
.result-card:hover, .result-card.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
.result-card-header { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.result-rank { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.result-name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.result-cuisine { font-size: 12px; color: var(--text-muted); text-transform: capitalize; }
.result-meta { display: flex; gap: 12px; font-size: 12px; color: var(--text-muted); }
.result-score { color: var(--primary); font-weight: 700; }
.result-distances { margin-top: 8px; font-size: 11px; color: var(--text-muted); }
.result-distances span { display: inline-block; margin-right: 8px; }

/* Map container */
#map-container { flex: 1; }
.leaflet-container { height: 100% !important; }

/* Custom map markers */
.participant-pin {
  width: 36px; height: 36px; border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
  border: 3px solid white;
}
.result-pin {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
  border: 3px solid white; box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

/* ─────────────── JOIN OVERLAY ─────────────── */
.join-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15,23,42,.5); backdrop-filter: blur(4px);
  animation: fadeIn .2s ease;
}
.join-overlay.leaving { animation: fadeOut .2s ease forwards; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

.join-card {
  background: var(--surface); border-radius: var(--radius); padding: 32px;
  width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.2);
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.join-logo { font-size: 22px; font-weight: 800; color: var(--primary); margin-bottom: 4px; }
.join-logo span { color: var(--accent); }
.join-session-badge { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.join-session-badge strong { color: var(--primary); font-family: monospace; font-size: 16px; letter-spacing: 2px; }
.join-form { display: flex; flex-direction: column; gap: 16px; }

/* Autocomplete */
.autocomplete-wrapper { position: relative; }
.autocomplete-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 100;
  background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); overflow: hidden; max-height: 200px; overflow-y: auto;
}
.autocomplete-item {
  padding: 10px 14px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border);
  transition: background .1s; line-height: 1.4;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item.focused { background: #F1F5F9; }
.autocomplete-loading { padding: 10px 14px; font-size: 13px; color: var(--text-muted); }

/* ─────────────── RESPONSIVE ─────────────── */
@media (max-width: 768px) {
  .session-layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); max-height: 45vh; }
  #map-container { flex: 1; min-height: 200px; }
}

/* ─────────────── SEARCH NOTIFICATION ─────────────── */
.search-notification {
  position: fixed;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  background: var(--primary);
  color: #fff;
  padding: 10px 22px;
  border-radius: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 24px rgba(99,102,241,.45);
  animation: slideDownIn .25s ease;
  white-space: nowrap;
  pointer-events: none;
}
@keyframes slideDownIn {
  from { transform: translateX(-50%) translateY(-16px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}

/* ─────────────── DARK MODE TOGGLE ─────────────── */
.theme-toggle {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: all .15s;
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--bg); border-color: var(--primary); }

/* ─────────────── DARK MODE ─────────────── */
html.dark {
  --surface: #1E293B;
  --bg: #0F172A;
  --text: #F1F5F9;
  --text-muted: #94A3B8;
  --border: #334155;
  --shadow: 0 1px 4px rgba(0,0,0,.5), 0 4px 20px rgba(0,0,0,.4);
  --primary: #818CF8;
  --primary-hover: #6366F1;
  --accent: #FB923C;
}

html.dark body { background: var(--bg); }

html.dark .input {
  background: #0F172A;
  color: var(--text);
  border-color: var(--border);
}

html.dark .card { background: var(--surface); }

html.dark .autocomplete-dropdown { background: #1E293B; border-color: var(--border); }
html.dark .autocomplete-item:hover,
html.dark .autocomplete-item.focused { background: #0F172A; }
html.dark .autocomplete-loading { color: var(--text-muted); }

html.dark .result-card { background: #1E293B; border-color: var(--border); }
html.dark .result-card:hover,
html.dark .result-card.active { border-color: var(--primary); }

html.dark .participant-item { background: #0F172A; }
html.dark .code-badge { background: #0F172A; }

html.dark .join-card { background: var(--surface); }

/* Dark map tiles — invert + hue-rotate keeps colors but darkens the base */
html.dark .leaflet-tile-pane {
  filter: brightness(0.65) invert(1) hue-rotate(200deg);
}
/* Keep markers, bbox, popups unfiltered by applying counter-filter to overlay pane */
html.dark .leaflet-overlay-pane,
html.dark .leaflet-marker-pane,
html.dark .leaflet-popup-pane,
html.dark .leaflet-shadow-pane { filter: none; }

html.dark .leaflet-control-zoom a {
  background: #1E293B !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
html.dark .leaflet-control-zoom a:hover { background: #0F172A !important; }
html.dark .leaflet-control-attribution { background: rgba(15,23,42,.8) !important; color: var(--text-muted) !important; }
html.dark .leaflet-control-attribution a { color: var(--primary) !important; }
html.dark .leaflet-popup-content-wrapper,
html.dark .leaflet-popup-tip { background: #1E293B; color: var(--text); box-shadow: 0 4px 16px rgba(0,0,0,.5); }

/* ─────────────── FRIEND CURSORS ─────────────── */
.friend-cursor-marker {
  pointer-events: none !important;
  transition: transform 0.09s linear !important;
}
.friend-cursor { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.friend-cursor-label {
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 700; color: #fff;
  opacity: 0.92; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}

.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.full-error { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; gap: 16px; text-align: center; padding: 24px; }
.full-error h2 { font-size: 24px; color: var(--text); }
.full-error p { color: var(--text-muted); }
