/* ── DESIGN TOKENS ─────────────────────────────────────────────────────── */
:root {
  --bg:           #f8f9fb;
  --surface:      #ffffff;
  --surface2:     #f1f3f7;
  --surface3:     #e8ebf2;
  --border:       #dde1ea;
  --border-hi:    #c4cad8;
  --border-lo:    #f0f1f4;
  --text:         #111827;
  --text-muted:   #4b5563;
  --text-faint:   #9ca3af;
  --accent:       #4f46e5;
  --accent-light: #6366f1;
  --accent-pale:  #eef2ff;
  --accent-glow:  rgba(79,70,229,.15);
  --green:        #16a34a;
  --red:          #dc2626;
  --r:            8px;
  --r-sm:         5px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow:       0 4px 12px rgba(0,0,0,.10);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%; width: 100%; font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
  font-size: 14px;
}

/* ── APP SHELL ─────────────────────────────────────────────────────────── */
#app {
  overflow: hidden;
  width: 100%; max-width: 100vw; box-sizing: border-box;
  display: grid;
  grid-template-rows: 52px 1fr 100px;
  grid-template-columns: 300px 1fr;
  grid-template-areas:
    "header  header"
    "sidebar map"
    "slider  slider";
  height: 100vh;
  height: 100dvh;
}

/* ── HEADER ─────────────────────────────────────────────────────────────── */
#header {
  grid-area: header;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 18px; gap: 12px; z-index: 1100; position: relative;
  box-shadow: var(--shadow-sm);
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; margin-right: auto; }
.logo-icon {
  height: 48px; width: auto; flex-shrink: 0; display: block;
}
.logo-text {
  font-family: 'Cormorant Garamond', serif; font-weight: 600;
  font-size: 24px; letter-spacing: 2.5px; text-transform: uppercase;
  color: var(--text);
}
.sidebar-toggle-btn {
  display: none; width: 32px; height: 32px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); cursor: pointer; font-size: 16px;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar-toggle-btn:hover { background: var(--surface2); color: var(--text); }

.add-menu-toggle { display: none !important; }
.add-menu { display: flex; align-items: center; gap: 6px; }
#add-menu-backdrop { display: none; }

#sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35);
  z-index: 1199;
}

.hdivider  { width: 1px; height: 20px; background: var(--border); }
.header-right { margin-left: auto; display: flex; gap: 7px; align-items: center; }
.lang-switcher-wrap {
  display: flex; align-items: center; gap: 5px;
}
.lang-switcher-wrap .lang-globe {
  font-size: 14px; line-height: 1; flex-shrink: 0;
}
.lang-switcher {
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  background: transparent; color: var(--text);
  border: none; border-radius: 6px;
  padding: 3px 4px; cursor: pointer; height: 28px;
}
.lang-switcher:hover { color: var(--accent); }

/* ── Auth ───────────────────────────────────────────────────────────────── */
.disabled-readonly { opacity: .45; cursor: not-allowed; }

.visibility-toggle {
  display: flex; align-items: center; gap: 5px; font-size: 12px;
  color: var(--text-muted); cursor: pointer; margin-left: auto; margin-right: 10px;
  user-select: none;
}
.visibility-toggle input { cursor: pointer; }

.app-toast {
  position: fixed; left: 50%; top: 64px; transform: translateX(-50%) translateY(-10px);
  background: var(--surface, #222); color: var(--text, #fff);
  border: 1px solid var(--border, #444); border-radius: var(--r-sm, 8px);
  padding: 10px 18px; font-size: 13px; box-shadow: var(--shadow-sm, 0 4px 16px rgba(0,0,0,.2));
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  z-index: 30000;
}
.app-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#auth-area { display: flex; align-items: center; }
.user-chip {
  position: relative; display: flex; align-items: center; gap: 7px;
  cursor: pointer; padding: 3px 8px 3px 3px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface2);
}
.user-chip:hover { border-color: var(--accent); }
.user-chip-avatar { width: 24px; height: 24px; border-radius: 50%; display: block; }
.user-chip-name {
  font-size: 12px; font-weight: 600; color: var(--text);
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-menu {
  display: none; position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-sm); box-shadow: var(--shadow-sm);
  padding: 6px; z-index: 10001; min-width: 110px;
}
.user-menu.open { display: block; }
.user-menu .btn { width: 100%; justify-content: center; }

/* Buttons */
.btn {
  font-family: 'Inter', sans-serif; font-size: 12px; font-weight: 500;
  padding: 6px 13px; border-radius: var(--r-sm); border: 1px solid var(--border);
  cursor: pointer; transition: all .15s; display: inline-flex; align-items: center;
  gap: 5px; line-height: 1; white-space: nowrap; background: var(--surface);
  color: var(--text-muted);
}
.btn:hover { background: var(--surface2); color: var(--text); border-color: var(--border-hi); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #4338ca; border-color: #4338ca; }
.btn-sm { font-size: 11px; padding: 4px 9px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-icon { line-height: 1; }
.btn:disabled:hover { background: var(--surface); border-color: var(--border); }
.btn-primary:disabled:hover { background: var(--accent); border-color: var(--accent); }

/* ── MAP ────────────────────────────────────────────────────────────────── */
#map-wrap { grid-area: map; position: relative; overflow: hidden; }
#map { width: 100%; height: 100%; }

/* Vintage / aged-paper tone for the base map tiles only — markers, popups
   and UI chrome (siblings, not part of the tile pane) are unaffected.
   Light touch so terrain, vegetation, water, settlements and roads from
   OSM Standard remain clearly visible. */
#map .leaflet-tile-pane {
  filter: sepia(20%) saturate(90%) brightness(101%) contrast(98%);
}

#click-hint {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,.95); backdrop-filter: blur(8px);
  border: 1px solid var(--accent); color: var(--accent);
  font-size: 12px; font-weight: 600; padding: 7px 18px;
  border-radius: 20px; pointer-events: none; z-index: 500;
  opacity: 0; transition: opacity .25s; white-space: nowrap;
  box-shadow: var(--shadow);
}
#click-hint.show { opacity: 1; }

/* ── LEFT SIDEBAR ───────────────────────────────────────────────────────── */
#sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: var(--shadow-sm);
}

/* ── FILTER PANEL ──────────────────────────────────────────────────────── */
#filter-panel { flex-shrink: 0; border-bottom: 1px solid var(--border); }
.filter-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 13px; cursor: pointer; user-select: none;
  background: var(--surface2);
}
.filter-toggle-label {
  font-size: 10px; font-weight: 700; letter-spacing: 1.3px;
  text-transform: uppercase; color: var(--text-faint);
  display: flex; align-items: center; gap: 6px;
}
.filter-toggle-caret { font-size: 9px; color: var(--text-faint); transition: transform .2s; }
.filter-toggle-caret.open { transform: rotate(180deg); }

#filter-tree {
  padding: 6px 5px 8px; display: flex; flex-direction: column; gap: 2px;
  max-height: 30vh; overflow-y: auto;
}
#filter-tree::-webkit-scrollbar { width: 4px; }
#filter-tree::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
#filter-tree.collapsed { display: none; }

/* Tree row shared styles */
.tree-row {
  display: flex; align-items: center; gap: 5px;
  border-radius: var(--r-sm); cursor: pointer; user-select: none;
  transition: background .1s;
}
.tree-row:hover { background: var(--surface2); }

.tree-l1-row { padding: 5px 6px 5px 3px; }
.tree-l2-row { padding: 4px 6px 4px 3px; margin-left: 16px; }
.tree-l3-row { padding: 3px 6px 3px 3px; margin-left: 32px; }

.tree-caret { font-size: 8px; color: var(--text-faint); width: 11px; text-align: center;
  flex-shrink: 0; transition: transform .18s; }
.tree-caret.open { transform: rotate(90deg); }
.tree-l1-icon { font-size: 13px; flex-shrink: 0; }
.tree-l1-label { font-size: 12px; font-weight: 700; color: var(--text); flex: 1; }
.tree-l2-label { font-size: 11px; font-weight: 600; color: var(--text-muted); flex: 1; }
.tree-l3-dot   { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.tree-l3-label { font-size: 11px; color: var(--text-muted); flex: 1; }
.tree-count    { font-size: 10px; color: var(--text-faint); font-variant-numeric: tabular-nums;
  background: var(--surface2); padding: 0 5px; border-radius: 10px; min-width: 18px; text-align: center; }
.tree-l1-row:hover .tree-count,
.tree-l2-row:hover .tree-count,
.tree-l3-row:hover .tree-count { background: var(--surface3); }

.tree-cb {
  -webkit-appearance: none; appearance: none;
  width: 13px; height: 13px; border: 1.5px solid var(--border-hi);
  border-radius: 3px; background: var(--surface); cursor: pointer;
  flex-shrink: 0; position: relative; transition: all .12s;
}
.tree-cb:checked { background: var(--accent); border-color: var(--accent); }
.tree-cb:checked::after {
  content:'✓'; position:absolute; top:-1px; left:1px;
  font-size:10px; color:#fff; line-height:1;
}
.tree-cb:indeterminate { background: var(--accent-pale); border-color: var(--accent-light); }
.tree-cb:indeterminate::after {
  content:'−'; position:absolute; top:-2px; left:2px;
  font-size:11px; color:var(--accent); line-height:1;
}
.tree-l2-group { display: flex; flex-direction: column; gap: 1px; }
.tree-l2-group.collapsed { display: none; }
.tree-l3-group { display: flex; flex-direction: column; gap: 1px; }
.tree-l3-group.collapsed { display: none; }

/* ── SEARCH BOX ─────────────────────────────────────────────────────────── */
#event-search-wrap {
  flex-shrink: 0; padding: 7px 8px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
#event-search {
  width: 100%; font-family: 'Inter', sans-serif; font-size: 12px;
  padding: 6px 10px 6px 28px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s;
}
#event-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); background: var(--surface); }
#event-search::placeholder { color: var(--text-faint); }
.search-icon {
  position: absolute; left: 18px; top: 50%; transform: translateY(-50%);
  font-size: 12px; color: var(--text-faint); pointer-events: none;
}
#event-search-wrap { position: relative; }

/* ── EVENT LIST ─────────────────────────────────────────────────────────── */
#event-list-wrap { flex: 1; overflow-y: auto; padding: 0; }
#event-list-wrap::-webkit-scrollbar { width: 4px; }
#event-list-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── LIST HEADER (sticky sortable columns) ────────────────────────────── */
.list-header {
  display: flex; align-items: center; gap: 0;
  padding: 5px 11px 4px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
.list-header-col {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: none; letter-spacing: 0;
  cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 3px;
  transition: color .12s;
}
.list-header-col:hover { color: var(--text); }
.list-header-col.active { color: var(--accent); }
/* Override column flex-direction so label + arrow sit side-by-side */
.list-header .list-col {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
}
.list-header .col-date { justify-content: flex-end; }
.sort-arrow        { font-size: 9.75px; line-height: 1; letter-spacing: 2px; }
.sort-inactive     { opacity: .35; }
.sort-active       { opacity: 1; }

/* ── COLUMNS (shared by header + card rows) ───────────────────────────── */
.list-col { display: flex; }
.col-type {
  width: 74px; flex-shrink: 0;
  flex-direction: column; gap: 2px; overflow: hidden;
}
.col-name { flex: 1; min-width: 0; flex-direction: column; gap: 1px; }
.col-date {
  width: 60px; flex-shrink: 0;
  flex-direction: column; align-items: flex-end; gap: 3px;
}

/* ── CARD ROWS ───────────────────────────────────────────────────────── */
.event-card {
  display: flex; align-items: flex-start; gap: 0;
  padding: 7px 11px 6px; cursor: pointer;
  border-bottom: 1px solid var(--border-lo, #f1f1f1);
  transition: background .1s;
  animation: cardIn .24s ease forwards; opacity: 0;
}
@keyframes cardIn {
  from { opacity:0; transform:translateX(-4px); }
  to   { opacity:1; transform:translateX(0); }
}
.event-card:hover   { background: var(--surface2); }
.event-card.selected { background: var(--accent-pale); }
.event-card.selected .card-title { color: var(--accent); }

/* Type column content */
.type-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  display: none;   /* hidden — color conveyed by label text */
}
.type-label {
  font-size: 10px; font-weight: 600; color: var(--text-muted);
  line-height: 1.35; white-space: normal; word-break: break-word;
}
.type-icon { font-size: 15px; line-height: 1; vertical-align: middle; }

/* Name column content */
.card-title { font-size: 12px; font-weight: 600; color: var(--text); line-height: 1.35; }
.card-place { font-size: 10px; color: var(--text-faint); line-height: 1.3; margin-top: 1px; }

/* Date column content */
.card-year  {
  font-size: 11px; font-weight: 700; color: var(--accent);
  font-variant-numeric: tabular-nums; text-align: right; line-height: 1.3;
}
.card-actions { display: flex; align-items: center; gap: 3px; flex-shrink: 0; }
.card-lock-icon { font-size: 15px; line-height: 1; opacity: .7; }
.card-edit-btn {
  font-size: 15px; color: var(--text-faint); cursor: pointer; padding: 1px 4px;
  border-radius: var(--r-sm); border: 1px solid transparent; background: none;
  transition: all .12s; line-height: 1;
}
.card-edit-btn:hover { background: var(--surface3); border-color: var(--border); color: var(--text); }
.card-delete-btn {
  font-size: 15px; color: var(--text-faint); cursor: pointer; padding: 1px 4px;
  border-radius: var(--r-sm); border: 1px solid transparent; background: none;
  transition: all .12s; line-height: 1;
}
.card-delete-btn:hover { background: #fde2e1; border-color: #f5b5b3; color: #c0392b; }

.empty-state {
  display:flex; flex-direction:column; align-items:center;
  justify-content:center; padding:36px 16px; text-align:center;
  color:var(--text-faint); gap:7px;
}
.empty-icon { font-size:26px; opacity:.5; }
.empty-text { font-size:12px; line-height:1.6; color:var(--text-muted); }

.sidebar-footer {
  padding: 8px 12px; border-top: 1px solid var(--border);
  display:flex; justify-content:space-between; align-items:center; flex-shrink:0;
  background: var(--surface2); gap: 6px;
}
.sidebar-footer .event-tally { margin-right: auto; }
.event-tally { font-size:11px; color:var(--text-muted); }
.event-tally strong { color:var(--text); }

/* ── SLIDER ─────────────────────────────────────────────────────────────── */
#slider-area {
  grid-area: slider;
  background: var(--surface); border-top: 1px solid var(--border);
  display:flex; align-items:center; padding:0 20px; gap:16px;
  box-shadow: 0 -1px 0 var(--border);
}
.slider-center { flex:1; display:flex; flex-direction:column; gap:6px; }
.range-slider-wrap { position:relative; height:18px; display:flex; align-items:center; }
.range-slider-track {
  position:absolute; left:0; right:0; height:4px; border-radius:2px;
  background:var(--surface3);
}
.range-slider-fill {
  position:absolute; height:4px; border-radius:2px; background:var(--accent);
}
.range-slider-wrap input[type="range"] {
  -webkit-appearance:none; appearance:none;
  position:absolute; left:0; right:0; width:100%;
  height:18px; margin:0; background:transparent; outline:none; border:none;
  cursor:pointer; pointer-events:none; z-index:1;
}
.range-slider-wrap input[type="range"]:hover,
.range-slider-wrap input[type="range"]:focus,
.range-slider-wrap input[type="range"]:active { z-index:2; }
.range-slider-wrap input[type="range"]::-webkit-slider-runnable-track { background:transparent; height:18px; }
.range-slider-wrap input[type="range"]::-moz-range-track { background:transparent; height:18px; }
.range-slider-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance:none; pointer-events:auto;
  width:18px; height:18px; border-radius:50%; margin-top:0;
  background:#fff; border:3px solid var(--accent); cursor:pointer;
  box-shadow:0 0 0 3px var(--accent-glow),0 1px 5px rgba(0,0,0,.15);
  transition:transform .1s;
}
.range-slider-wrap input[type="range"]::-webkit-slider-thumb:hover { transform:scale(1.15); }
.range-slider-wrap input[type="range"]::-moz-range-thumb {
  pointer-events:auto; width:18px; height:18px; border-radius:50%;
  background:#fff; border:3px solid var(--accent); cursor:pointer;
}
.slider-bubble {
  position:fixed; left:0; top:0; transform:translateX(-50%) translateY(4px);
  background:var(--accent); color:#fff; font-size:11px; font-weight:600;
  font-variant-numeric:tabular-nums; padding:3px 7px; border-radius:var(--r-sm);
  white-space:nowrap; pointer-events:none; opacity:0; z-index:1150;
  transition:opacity .12s ease, transform .12s ease;
}
.slider-bubble::after {
  content:''; position:absolute; top:100%; left:50%; transform:translateX(-50%);
  border:4px solid transparent; border-top-color:var(--accent);
}
.slider-bubble.show { opacity:1; transform:translateX(-50%) translateY(0); }
.slider-ticks { display:flex; justify-content:space-between; }
.tick-label   { font-size:10px; color:var(--text-faint); font-variant-numeric:tabular-nums; font-weight:500; }
.playback-controls { display:flex; align-items:center; gap:5px; flex-shrink:0; }
.ctrl-btn {
  width:29px; height:29px; border-radius:50%;
  border:1px solid var(--border); background:var(--surface);
  color:var(--text-muted); cursor:pointer; font-size:16.5px;
  display:flex; align-items:center; justify-content:center; transition:all .15s;
}
.ctrl-btn:hover { background:var(--surface2); color:var(--text); border-color:var(--border-hi); }
.play-ctrl { width:36px; height:36px; background:var(--accent); border-color:var(--accent); color:#fff; font-size:13px; }
.play-ctrl:hover { background:#4338ca; }
.play-ctrl.playing { background:var(--green); border-color:var(--green); }

/* ── MAP GEOCODER ───────────────────────────────────────────────────────── */
#geocoder-wrap {
  position: absolute; top: 14px; right: 14px; z-index: 500;
  width: 260px; font-family: 'Inter', sans-serif;
}
#geocoder-input {
  width: 100%; font-size: 12px; font-family: 'Inter', sans-serif;
  padding: 7px 32px 7px 32px;
  border-radius: var(--r); border: 1px solid var(--border);
  background: rgba(255,255,255,.97); backdrop-filter: blur(6px);
  color: var(--text); outline: none;
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
#geocoder-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow), var(--shadow); }
#geocoder-input::placeholder { color: var(--text-faint); }
.geocoder-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 13px; pointer-events: none; line-height: 1;
}
#geocoder-clear {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  font-size: 13px; color: var(--text-faint); cursor: pointer;
  display: none; line-height: 1; background: none; border: none; padding: 0;
}
#geocoder-clear:hover { color: var(--text); }
#geocoder-results {
  display: none; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border-hi);
  border-radius: var(--r); box-shadow: var(--shadow);
  max-height: 240px; overflow-y: auto;
}
#geocoder-results.open { display: block; }
#geocoder-results::-webkit-scrollbar { width: 4px; }
#geocoder-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.geo-result {
  padding: 8px 11px; cursor: pointer; font-size: 12px; color: var(--text);
  border-bottom: 1px solid var(--surface2);
  display: flex; flex-direction: column; gap: 2px;
  transition: background .1s;
}
.geo-result:last-child { border-bottom: none; }
.geo-result:hover, .geo-result.highlighted { background: var(--accent-pale); }
.geo-result-name { font-weight: 600; line-height: 1.3; }
.geo-result-detail { font-size: 10px; color: var(--text-faint); line-height: 1.3; }
.geo-status {
  padding: 10px 12px; font-size: 11px; color: var(--text-muted);
  text-align: center;
}

/* -- Map right-click context menu -------------------------------------------- */
.map-context-menu {
  display: none; position: absolute; z-index: 15000;
  background: var(--surface); border: 1px solid var(--border-hi);
  border-radius: var(--r); box-shadow: var(--shadow);
  min-width: 180px; padding: 4px; overflow: hidden;
}
.map-context-menu.open { display: block; }
.map-context-item {
  padding: 8px 11px; cursor: pointer; font-size: 12px; color: var(--text);
  border-radius: var(--r-sm); transition: background .1s; white-space: nowrap;
}
.map-context-item:hover { background: var(--accent-pale); }

/* ── LEAFLET POPUP ──────────────────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  border-radius:var(--r) !important;
  box-shadow:var(--shadow) !important;
  border:1px solid var(--border) !important;
  padding:0 !important;
}
.leaflet-popup-content { margin:0 !important; font-family:'Inter',sans-serif; min-width:220px; }
.leaflet-popup-tip-container { margin-top:-1px; }
.popup-inner { padding:13px 15px; }
.popup-crumb { font-size:9px; font-weight:700; letter-spacing:.7px; text-transform:uppercase;
  padding:2px 8px; border-radius:20px; display:inline-block; margin-bottom:7px; }
.popup-title { font-size:14px; font-weight:700; color:var(--text); margin-bottom:2px; line-height:1.3; }
.popup-place { font-size:11px; color:var(--text-muted); margin-bottom:7px; display:flex; align-items:center; gap:4px; }
.popup-year  { font-variant-numeric:tabular-nums; font-weight:600; }
.popup-notes { font-size:11px; line-height:1.6; color:var(--text-muted);
  border-top:1px solid var(--border); padding-top:7px; margin-top:2px; }
.popup-doc { margin-top:8px; padding:6px 9px; background:var(--surface2);
  border-radius:var(--r-sm); font-size:11px; }
.popup-doc-label { font-size:9px; font-weight:700; letter-spacing:.4px;
  text-transform:uppercase; color:var(--text-faint); margin-bottom:2px; }
.popup-doc a { color:var(--accent); text-decoration:none; font-weight:500; }
.popup-doc a:hover { text-decoration:underline; }
.leaflet-popup-close-button { color:var(--text-muted) !important; top:6px !important; right:8px !important; }

/* ── MODAL ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  display:none; position:fixed; inset:0;
  background:rgba(0,0,0,.35); backdrop-filter:blur(3px);
  z-index:10000; align-items:flex-start; justify-content:flex-start;
}
.modal-overlay.open { display:flex; }
.modal {
  background:var(--surface); border:1px solid var(--border);
  border-radius:13px; width:500px; max-width:96vw;
  margin:64px 12px 12px 312px; max-height:calc(100vh - 76px); max-height:calc(100dvh - 76px);
  overflow:hidden; display:flex; flex-direction:column;
  box-shadow:0 24px 64px rgba(0,0,0,.18);
  animation:modalIn .18s ease;
}
.modal-sm { width:380px; }
/* When the viewport is too narrow for the modal to fit beside the sidebar,
   snap it to the left edge (covering the results pane) instead of overlapping the map. */
@media (max-width: 880px) and (min-width: 769px) {
  .modal { margin-left:12px; }
}
@keyframes modalIn {
  from { opacity:0; transform:scale(.97) translateY(6px); }
  to   { opacity:1; transform:scale(1)   translateY(0); }
}
.modal-body::-webkit-scrollbar { width:4px; }
.modal-body::-webkit-scrollbar-thumb { background:var(--border); border-radius:4px; }
.modal-header { padding:15px 18px 12px; border-bottom:1px solid var(--border);
  display:flex; align-items:center; justify-content:space-between; flex-shrink:0; }
.modal-title  { font-size:15px; font-weight:700; color:var(--text); }
.modal-close  { width:26px; height:26px; border-radius:50%; background:var(--surface2);
  border:none; color:var(--text-muted); cursor:pointer; font-size:13px;
  display:flex; align-items:center; justify-content:center; transition:all .15s; }
.modal-close:hover { background:var(--surface3); color:var(--text); }
.modal-body   { padding:16px 18px; overflow-y:auto; flex:1 1 auto; min-height:0; }
.modal-footer { padding:12px 18px; border-top:1px solid var(--border);
  display:flex; gap:8px; justify-content:flex-end; align-items:center; background:var(--surface2);
  border-radius:0 0 13px 13px; flex-shrink:0; }
.modal-footer-spacer { flex: 1 1 auto; }
.btn-danger { color: #c0392b; border-color: #f5b5b3; }
.btn-danger:hover { background: #fde2e1; border-color: #e7837f; }
.form-group   { margin-bottom:13px; }
.form-label   { display:block; font-size:10px; font-weight:700; letter-spacing:.9px;
  text-transform:uppercase; color:var(--text-muted); margin-bottom:5px; }
.form-group-inline { display:flex; align-items:flex-start; gap:8px; margin-bottom:13px; }
.form-group-inline .form-label { flex:0 0 15%; max-width:15%; margin-bottom:0;
  padding-top:8px; box-sizing:border-box; }
.form-group-inline .form-field { flex:1 1 auto; min-width:0; }
.form-ctrl {
  width:100%; font-family:'Inter',sans-serif; font-size:13px;
  padding:7px 11px; border-radius:var(--r-sm); border:1px solid var(--border);
  background:var(--surface); color:var(--text); outline:none;
  transition:border-color .15s, box-shadow .15s;
}
.form-ctrl:focus { border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-glow); }
.form-ctrl::placeholder { color:var(--text-faint); }
select.form-ctrl { cursor:pointer; }
textarea.form-ctrl { min-height:68px; resize:vertical; }
.form-row2 { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.form-hint { font-size:10px; color:var(--text-faint); margin-top:4px; }
.date-row { display:flex; gap:6px; align-items:center; }
.date-row + .date-row { margin-top:5px; }
.date-dq   { flex:0 0 110px; min-width:0; }
.date-year { flex:0 0 76px;  min-width:0; }
.date-month { flex:0 0 82px; min-width:0; }
.date-day  { flex:0 0 66px;  min-width:0; }
.date-end-label { flex:0 0 110px; font-size:11px; font-weight:600; color:var(--text-muted);
  text-align:right; padding-right:4px; }
.rich-text-toolbar { display:flex; gap:4px; margin:8px 0 4px; }
.rich-text-toolbar button {
  border:1px solid var(--border); background:var(--surface); border-radius:6px;
  padding:3px 8px; font-size:12px; cursor:pointer; color:var(--text);
}
.rich-text-toolbar button:hover { background:var(--surface-hover, #f0f0f0); }
.rich-text-box {
  min-height:120px; max-height:300px; overflow-y:auto;
  border:1px solid var(--border); border-radius:var(--r);
  padding:8px 10px; font-size:13px; line-height:1.5;
  background:var(--surface); margin-top:4px;
}
.rich-text-box:focus { outline:2px solid var(--accent, #6366f1); outline-offset:-1px; }
.image-gallery { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:8px; }
.image-gallery-bordered {
  border:1px solid var(--border); border-radius:var(--r); padding:8px;
  min-height:96px; align-items:center;
}
.image-placeholder {
  width:100%; text-align:center; color:var(--text-faint); font-size:12px;
  padding:18px 0;
}
.image-thumb {
  position:relative; width:84px; height:84px; border-radius:var(--r);
  overflow:hidden; border:1px solid var(--border); background:var(--surface2);
  flex-shrink:0;
}
.image-thumb img { width:100%; height:100%; object-fit:cover; display:block; }
.image-thumb.uploading {
  display:flex; align-items:center; justify-content:center;
  color:var(--text-faint); font-size:10px; text-align:center; padding:6px;
}
.image-thumb .img-remove {
  position:absolute; top:3px; right:3px; width:20px; height:20px; border-radius:50%;
  background:rgba(0,0,0,.55); color:#fff; border:none; cursor:pointer; font-size:11px;
  display:flex; align-items:center; justify-content:center; line-height:1; padding:0;
  transition:background .12s;
}
.image-thumb .img-remove:hover { background:rgba(220,38,38,.85); }
.popup-images { margin-top:8px; }
.popup-doc-images { display:flex; flex-wrap:wrap; gap:6px; margin-top:6px; }
.popup-doc-images img {
  width:48px; height:48px; object-fit:cover; border-radius:6px; border:1px solid var(--border);
  cursor:pointer;
}

/* ── PLACE SELECTOR in modal ────────────────────────────────────────────── */
.place-selector-wrap { position:relative; }
.place-search-input { }
.place-dropdown {
  position:absolute; top:calc(100% + 4px); left:0; right:0; z-index:100;
  background:var(--surface); border:1px solid var(--border-hi);
  border-radius:var(--r); box-shadow:var(--shadow);
  max-height:200px; overflow-y:auto; display:none;
}
.place-dropdown.open { display:block; }
.place-dropdown::-webkit-scrollbar { width:4px; }
.place-dropdown::-webkit-scrollbar-thumb { background:var(--border); border-radius:4px; }
.place-opt {
  padding:8px 12px; cursor:pointer; display:flex; align-items:center;
  gap:9px; transition:background .1s; border-bottom:1px solid var(--surface2);
  font-size:12px; color:var(--text);
}
.place-opt:last-child { border-bottom:none; }
.place-opt:hover, .place-opt.highlighted { background:var(--accent-pale); }
.place-opt-dot { width:8px; height:8px; border-radius:50%; flex-shrink:0; }
.place-opt-name { flex:1; font-weight:500; }
.place-opt-type { font-size:10px; color:var(--text-faint); text-transform:uppercase; letter-spacing:.3px; }
.place-opt-divider {
  padding:6px 12px; font-size:10px; font-weight:700; letter-spacing:1px;
  text-transform:uppercase; color:var(--text-faint); background:var(--surface2);
  border-bottom:1px solid var(--border); cursor:default;
}
.place-opt.action-opt {
  color:var(--accent); font-weight:600; background:var(--accent-pale);
  border-top:1px solid var(--border);
}
.place-opt.action-opt:hover { background:#e0e7ff; }

/* Selected place chip */
.place-chip {
  display:flex; align-items:center; gap:8px; padding:7px 11px;
  border:1px solid var(--accent); border-radius:var(--r-sm);
  background:var(--accent-pale); font-size:12px; color:var(--text);
}
.place-chip-dot { width:8px; height:8px; border-radius:50%; flex-shrink:0; }
.place-chip-name { flex:1; font-weight:600; }
.place-chip-change { font-size:11px; color:var(--accent); cursor:pointer; font-weight:600; }
.place-chip-change:hover { text-decoration:underline; }
.place-chip-coords { font-size:10px; color:var(--text-faint); }

/* ── MOBILE LAYOUT ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  html, body { font-size: 15px; }

  #app {
    grid-template-rows: 52px 1fr auto;
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "map"
      "slider";
  }

  .sidebar-toggle-btn { display: flex; }
  .logo-icon { display: none; }
  #header { padding: 0 10px; gap: 8px; }
  .header-right { gap: 4px; }
  .header-right .btn-label { display: none; }
  .header-right .btn { padding: 6px 9px; }
  .lang-switcher-wrap .lang-globe { display: none; }
  .lang-switcher-wrap .lang-switcher { font-size: 11px; padding: 2px 4px; }
  .header-right .hdivider { display: none; }

  #sidebar {
    position: fixed; top: 52px; left: 0; bottom: 0; width: 86vw; max-width: 340px;
    z-index: 1200; transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-backdrop.open { display: block; }

  .add-menu-toggle { display: flex !important; }
  .add-menu {
    display: none; position: absolute; top: 48px; right: 10px; z-index: 1300;
    flex-direction: column; align-items: stretch; gap: 4px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-sm); box-shadow: var(--shadow); padding: 6px;
    min-width: 160px;
  }
  .add-menu.open { display: flex; }
  .add-menu .btn-label { display: inline; }
  .add-menu .btn { justify-content: flex-start; }
  #add-menu-backdrop.open { display: block; position: fixed; inset: 0; z-index: 1299; }

  #auth-area { flex-shrink: 0; }

  #header, #map-wrap, #slider-area { min-width: 0; }
  #map-wrap { grid-area: map; }

  #slider-area {
    flex-direction: column; align-items: stretch; padding: 8px 12px; gap: 8px;
    overflow-x: hidden; overflow-y: visible; min-width: 0; max-width: 100vw; box-sizing: border-box;
  }
  .slider-center { order: -1; width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; }
  .range-slider-wrap { width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; }
  .slider-ticks { width: 100%; max-width: 100%; min-width: 0; overflow: hidden; box-sizing: border-box; }
  .tick-label { flex-shrink: 1; overflow: hidden; white-space: nowrap; }
  .playback-controls { width: 100%; max-width: 100%; justify-content: center; box-sizing: border-box; }

  #geocoder-wrap { width: calc(100vw - 28px); max-width: 320px; }

  /* Modals go full-screen on small viewports */
  .modal {
    width: 100vw; max-width: 100vw; height: 100%; max-height: 100%;
    margin: 0; border-radius: 0; animation: none;
  }
  .modal-overlay { padding: 0; }
  .form-group-inline .form-label { flex: 0 0 78px; max-width: 78px; font-size: 9px; }

  .date-row { flex-wrap: wrap; }
  .date-dq, .date-end-label { flex: 1 1 100%; }
  .date-year, .date-month, .date-day { flex: 1 1 calc(33.33% - 4px); }

  .form-field > div[style*="display:flex"] { flex-wrap: wrap; }
  .form-field > div[style*="display:flex"] > select,
  .form-field > div[style*="display:flex"] > input { flex: 1 1 100% !important; }
  .form-field > div[style*="display:flex"] > button { flex: 0 0 auto; }
}

/* ── TYPE SELECTOR in modal ─────────────────────────────────────────────── */
