html[data-theme="dark"], :root {
  --bg: #0d0d0d;
  --bg-elev: #161616;
  --bg-panel: #1c1c1c;
  --bg-head: #2a2a2a;
  --border: #2e2e2e;
  --border-soft: #3a3a3a;
  --text: #f2f2f0;
  --muted: #9a9690;
  --accent: #ff9500;
  --accent-dim: rgba(255, 149, 0, 0.15);
  --ok: #34c759;
  --danger: #ff453a;
  --radius: 12px;
  --gap: 10px;
  --topbar-h: 58px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: var(--gap);
  gap: var(--gap);
  max-width: 100%;
}

/* —— Top bar —— */
.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: grid;
  grid-template-columns: 1fr minmax(180px, 420px) auto;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  flex-shrink: 0;
}
.brand { display: flex; flex-direction: column; line-height: 1.15; }
.brand strong { font-size: 15px; letter-spacing: 0.02em; color: var(--accent); }
.brand-sub { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.top-nav { display: flex; gap: 4px; margin-left: 8px; }
.nav-btn {
  border: 0; background: transparent; color: var(--muted);
  font: 600 12px/1 var(--font); text-transform: uppercase; letter-spacing: 0.06em;
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
}
.nav-btn:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-btn.is-active { color: var(--accent); background: var(--accent-dim); }

.search-wrap { display: block; width: 100%; }
.search-wrap input {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  outline: none;
}
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.search-wrap input::placeholder { color: #666; }

.clock {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: 0.04em;
}

/* —— Main grid —— */
.main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr minmax(280px, 340px);
  gap: var(--gap);
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.panel-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-head);
  border-bottom: 1px solid var(--border);
}
.panel-head h1, .panel-head h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.map-tools { display: flex; align-items: center; gap: 8px; }
.map-tools select {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  max-width: 180px;
}
.btn {
  border: 0; border-radius: 10px; cursor: pointer;
  font: 600 13px/1.2 var(--font);
  padding: 10px 14px;
  background: var(--accent); color: #111;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border-soft); padding: 6px 10px;
}
.btn.ghost:hover { color: var(--text); border-color: var(--muted); }
.btn.block { width: 100%; }
.btn.secondary { background: #333; color: var(--text); }

.chip {
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--accent);
  background: var(--accent-dim); padding: 4px 8px; border-radius: 999px;
}

.map-panel { min-width: 0; }
.map-body { position: relative; flex: 1; min-height: 0; }
.map-canvas { position: absolute; inset: 0; }
.map-loading {
  position: absolute; inset: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  background: #1a1a1a; color: var(--muted); font-weight: 600; font-size: 14px;
  pointer-events: none; transition: opacity 0.3s;
}
.map-loading.hide { opacity: 0; }

.side {
  display: flex; flex-direction: column; gap: var(--gap); min-height: 0;
}
.user-panel { flex: 1; min-height: 0; }
.panel-body {
  flex: 1; min-height: 0; overflow: auto;
  padding: 14px;
  scrollbar-width: thin;
  scrollbar-color: #444 transparent;
}

.status-panel { flex-shrink: 0; padding: 12px 14px; }
.status-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
}
.stat-val {
  display: block;
  font-size: 16px; font-weight: 700; color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.stat-lbl {
  display: block;
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
  margin-top: 2px;
}

/* —— Side content —— */
.hero-empty {
  text-align: center; padding: 28px 12px 16px; color: var(--muted);
}
.hero-empty strong {
  display: block; color: var(--accent); font-size: 18px;
  letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 8px;
}
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: grid; grid-template-columns: 36px 1fr auto; gap: 10px;
  align-items: center;
  padding: 10px 8px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent;
}
.list-item:hover, .list-item.is-active {
  background: rgba(255,255,255,0.04);
  border-color: var(--border);
}
.list-ico {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; font-size: 16px;
  background: #222;
}
.list-title { font-size: 13px; font-weight: 600; line-height: 1.25; }
.list-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.list-rating { font-size: 11px; color: var(--accent); font-weight: 600; }

.detail-cover {
  width: 100%; aspect-ratio: 16/10; object-fit: cover;
  border-radius: 10px; background: #222; margin-bottom: 12px;
}
.detail-title { font-size: 18px; font-weight: 700; margin: 0 0 6px; line-height: 1.25; }
.detail-cat {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted); margin-bottom: 10px;
}
.detail-desc {
  font-size: 13px; line-height: 1.5; color: #c8c4bc;
  margin: 0 0 14px; white-space: pre-wrap;
}
.kv { display: grid; gap: 6px; margin-bottom: 14px; }
.kv-row {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 12px; padding: 8px 10px; background: #222; border-radius: 8px;
}
.kv-row span:first-child { color: var(--muted); }
.kv-row span:last-child { text-align: right; font-weight: 600; }

.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.form input, .form textarea, .form select {
  width: 100%; background: #141414; border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 10px 12px; font: 14px/1.3 var(--font);
}
.form textarea { min-height: 88px; resize: vertical; }
.form .hp { position: absolute; left: -9999px; opacity: 0; height: 0; width: 0; }
.msg { font-size: 12px; padding: 10px; border-radius: 8px; margin-top: 4px; }
.msg.ok { background: rgba(52,199,89,0.15); color: var(--ok); }
.msg.err { background: rgba(255,69,58,0.15); color: var(--danger); }
.section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted); margin: 16px 0 8px; font-weight: 700;
}
.back-link {
  background: none; border: 0; color: var(--accent); font: 600 12px var(--font);
  cursor: pointer; padding: 0; margin-bottom: 10px;
}

/* MapLibre dark tweaks */
.maplibregl-ctrl-group {
  background: #1c1c1c !important;
  border: 1px solid var(--border) !important;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4) !important;
}
.maplibregl-ctrl-group button { filter: invert(1); opacity: 0.85; }
.maplibregl-ctrl-attrib {
  background: rgba(20,20,20,0.85) !important;
  color: #888 !important;
  font-size: 10px !important;
}
.maplibregl-ctrl-attrib a { color: #aaa !important; }
.maplibregl-popup-content {
  background: #1c1c1c !important; color: var(--text) !important;
  border-radius: 10px !important; padding: 10px 12px !important;
  box-shadow: 0 12px 32px rgba(0,0,0,0.5) !important;
  border: 1px solid var(--border);
  font-family: var(--font);
}
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #1c1c1c !important; }
.maplibregl-popup-close-button { color: var(--muted) !important; font-size: 18px !important; }

.go-marker {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; border: 2px solid #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.45);
  cursor: pointer;
}


/* —— Light theme —— */
html[data-theme="light"] {
  --bg: #e8e6e1;
  --bg-elev: #f7f6f3;
  --bg-panel: #ffffff;
  --bg-head: #f0eeea;
  --border: #d5d1c8;
  --border-soft: #c8c3b8;
  --text: #161514;
  --muted: #6b6560;
  --accent: #e68600;
  --accent-dim: rgba(230, 134, 0, 0.14);
  --ok: #248a3d;
  --danger: #d70015;
}

html[data-theme="light"] .maplibregl-ctrl-group {
  background: #fff !important;
  border-color: var(--border) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12) !important;
}
html[data-theme="light"] .maplibregl-ctrl-group button { filter: none; opacity: 1; }
html[data-theme="light"] .maplibregl-ctrl-attrib {
  background: rgba(255,255,255,0.9) !important;
  color: #555 !important;
}
html[data-theme="light"] .maplibregl-ctrl-attrib a { color: #333 !important; }
html[data-theme="light"] .maplibregl-popup-content {
  background: #fff !important;
  color: var(--text) !important;
  border-color: var(--border);
}
html[data-theme="light"] .maplibregl-popup-anchor-bottom .maplibregl-popup-tip {
  border-top-color: #fff !important;
}
html[data-theme="light"] .form input,
html[data-theme="light"] .form textarea,
html[data-theme="light"] .form select {
  background: #f7f6f3;
  border-color: var(--border);
  color: var(--text);
}
html[data-theme="light"] .kv-row { background: #f0eeea; }
html[data-theme="light"] .list-ico { background: #eee; }
html[data-theme="light"] .btn.secondary { background: #e8e4dc; color: var(--text); }
html[data-theme="light"] .search-wrap input { background: #fff; }
html[data-theme="light"] .map-tools select { background: #fff; color: var(--text); }
html[data-theme="light"] .map-loading { background: #f0eeea; color: var(--muted); }

/* Theme toggle */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--accent);
  cursor: pointer;
  display: grid;
  place-items: center;
  position: relative;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.15s, border-color 0.15s;
}
.theme-toggle:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}






@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    height: auto; padding: 10px 12px;
  }
  .topbar-center { grid-column: 1 / -1; }
  .top-nav { display: none; }
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(45vh, 1fr) minmax(280px, 40vh);
  }
  .status-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Lucide icons */
.lucide-wrap { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }
.lucide-wrap svg, .theme-icon svg, .icon-btn svg, .back-link svg, .list-ico svg, .detail-cat-ico svg, .go-marker svg {
  display: block;
  flex-shrink: 0;
}
.theme-icon { display: none; align-items: center; justify-content: center; }
html[data-theme="dark"] .theme-icon-sun { display: inline-flex; }
html[data-theme="light"] .theme-icon-moon { display: inline-flex; }
html[data-theme="dark"] .theme-icon-moon { display: none; }
html[data-theme="light"] .theme-icon-sun { display: none; }
.theme-toggle { color: var(--text); }
.go-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  line-height: 0;
  overflow: hidden;
}
.list-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-width: 36px;
}
.detail-cat-ico { display: inline-flex; align-items: center; }
