:root {
  --bg: #14110e;
  --panel: #1d1916;
  --panel-2: #262019;
  --panel-3: #2f2820;
  --line: #3a3128;
  --line-soft: #2c2620;
  --ink: #ece3d4;
  --ink-dim: #9a8f7d;
  --accent: #c9a24b;
  --accent-soft: rgba(201,162,75,.16);
  --green: #6f9c4f;
  --amber: #d99b3a;
  --red: #c6553f;
  --grey: #6b6256;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --sh-1: 0 2px 10px rgba(0,0,0,.35);
  --sh-2: 0 10px 30px rgba(0,0,0,.5);
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --serif: "Georgia", "Times New Roman", serif;
  --t: .15s ease;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--ui);
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
#app { display: flex; height: 100dvh; }
#map { flex: 1; min-width: 0; position: relative; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Dark theme is applied to tiles server-side (see backend tile proxy), so no
   CSS filter on the WebGL canvas — that rendered blank in Safari/WebKit. */

/* ---- floating top bar ---- */
#topbar {
  position: absolute;
  top: 12px; left: 58px; right: 432px;
  z-index: 8;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  background: rgba(20,17,14,.72);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--sh-1);
  font-family: var(--ui);
}
.tb-title {
  font-family: var(--serif); font-size: 17px; font-weight: 700;
  white-space: nowrap; letter-spacing: .3px;
}
.tb-title .mark { color: var(--accent); }
.basemap-switch {
  display: flex; background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 3px; gap: 2px;
}
.basemap-switch button {
  border: none; background: none; color: var(--ink-dim);
  font: inherit; font-size: 12px; padding: 6px 14px; border-radius: 7px;
  cursor: pointer; transition: all var(--t);
}
.basemap-switch button:hover { color: var(--ink); }
.basemap-switch button.active { background: var(--accent); color: #14110e; font-weight: 600; box-shadow: var(--sh-1); }
.auth-bar {
  margin-left: auto;
  font-size: 12px; display: flex; gap: 12px; align-items: center;
}
.auth-bar a, .auth-bar button {
  color: var(--accent); background: none; border: none; cursor: pointer;
  font: inherit; text-decoration: none;
}
.auth-bar a:hover, .auth-bar button:hover { text-decoration: underline; }

/* ---- панель ---- */
#side {
  width: 420px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 10;
}
header {
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
}
.hdr-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
header .sub {
  font-size: 13px;
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", sans-serif;
  font-weight: 600;
}
.panel-close {
  display: none;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink-dim);
  width: 30px; height: 30px; border-radius: 8px; font-size: 20px; line-height: 1;
  cursor: pointer; flex-shrink: 0;
}

#panel-toggle {
  display: none;
  position: absolute; z-index: 9;
  left: 50%; transform: translateX(-50%); bottom: 16px;
  background: var(--accent); color: #14110e; border: none;
  padding: 11px 20px; border-radius: 22px; font-weight: 700; font-size: 14px;
  font-family: -apple-system, "Segoe UI", sans-serif; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.5); gap: 7px; align-items: center;
}
#panel-toggle .pt-ico { font-size: 17px; }

.controls {
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-family: -apple-system, "Segoe UI", sans-serif;
}
.ctl-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--ink-dim); margin-bottom: -3px;
}
#search, #region, #layer, #brand {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 11px 13px;
  font-size: 13px;
  border-radius: var(--r-sm);
  font-family: inherit;
  transition: border-color var(--t), box-shadow var(--t);
}
#search::placeholder { color: var(--ink-dim); }
#search:focus, #region:focus, #layer:focus, #brand:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
#brand.hidden { display: none; }

/* color legend */
.legend .legend-title { color: var(--ink); font-weight: 600; margin: 6px 0 4px; }
.legend .swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle; border: 1px solid #14110e;
}
.legend .cluster-swatch {
  display:inline-block; width:14px; height:14px; border-radius:50%;
  background:#c9a24b; border:1.5px solid #14110e; margin-right:6px; vertical-align:middle;
}

.geo-status {
  font-size: 11px;
  color: var(--ink-dim);
  min-height: 14px;
}
/* ---- overlay layers control ---- */
.overlays-wrap {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--bg);
  font-family: -apple-system, "Segoe UI", sans-serif;
}
.overlays-wrap > summary {
  cursor: pointer;
  padding: 8px 11px;
  font-size: 12px;
  color: var(--ink);
  list-style: none;
  user-select: none;
}
.overlays-wrap > summary::-webkit-details-marker { display: none; }
.overlays-wrap > summary::before { content: "▸ "; color: var(--accent); }
.overlays-wrap[open] > summary::before { content: "▾ "; }
.overlays { padding: 4px 11px 10px; display: flex; flex-direction: column; gap: 10px; }
.ov-group { display: flex; flex-direction: column; gap: 5px; }
.ov-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--ink-dim); margin-bottom: 2px;
}
.ov-item {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--ink); cursor: pointer;
}
.ov-item input { accent-color: var(--accent); margin: 0; }
.ov-swatch {
  width: 12px; height: 4px; border-radius: 2px; flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.4);
}
.ov-item.ov-sub { color: var(--ink-dim); font-size: 11px; margin-top: 3px; padding-left: 2px; }
.ov-item.ov-sub span { width: 12px; flex-shrink: 0; }
.row-2 { display: flex; gap: 7px; }
.row-2 button {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  padding: 9px;
  font-size: 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}
.row-2 button:hover { color: var(--ink); border-color: var(--accent); }

/* ---- список ---- */
#list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.item {
  padding: 12px 18px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background var(--t), box-shadow var(--t);
}
.item:hover { background: var(--panel-2); }
.item.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.item.hidden { display: none; }
.item .nm { font-family: var(--serif); font-size: 14px; font-weight: 700; line-height: 1.3; }
.item .meta {
  font-size: 12px;
  color: var(--ink-dim);
  margin-top: 3px;
  font-family: var(--ui);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.d-verified { background: var(--green); }
.d-house { background: var(--green); }
.d-manual { background: var(--green); }
.d-street { background: var(--amber); }
.d-city { background: var(--amber); }
.d-none { background: var(--grey); }
.d-risk { background: var(--red); }

/* ---- детали ---- */
#detail {
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height .2s ease;
}
#detail.open { max-height: 340px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.detail-inner { padding: 16px 20px; }
.detail-inner h2 { font-family: var(--serif); font-size: 16px; margin-bottom: 8px; }
.detail-inner .fld {
  font-family: -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  margin: 7px 0;
  display: flex;
  gap: 8px;
}
.detail-inner .fld .k {
  color: var(--ink-dim);
  min-width: 110px;
  flex-shrink: 0;
}
.detail-inner .fld a { color: var(--accent); text-decoration: none; }
.detail-inner .fld a:hover { text-decoration: underline; }
.badge {
  display: inline-block;
  font-family: -apple-system, "Segoe UI", sans-serif;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 3px;
  margin-top: 4px;
}
.badge.warn { background: rgba(198,85,63,.18); color: var(--red); border: 1px solid var(--red); }

/* ---- легенда ---- */
.legend {
  position: absolute;
  bottom: 14px; left: 14px;
  max-height: 46vh; overflow-y: auto; max-width: 240px;
  background: rgba(20,17,14,.86);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px 13px;
  font-family: var(--ui);
  font-size: 11px;
  color: var(--ink-dim);
  box-shadow: var(--sh-1);
  z-index: 5;
}
.legend div { margin: 3px 0; }
.legend:empty { display: none; }

.marker {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid #14110e;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.marker.sel {
  width: 22px; height: 22px; border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft), 0 1px 6px rgba(0,0,0,.6);
}

.maplibregl-popup-content {
  background: var(--panel-2);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", sans-serif;
  border: 1px solid var(--line);
  font-size: 12px;
}
.maplibregl-popup-tip { border-top-color: var(--panel-2) !important; }

#list::-webkit-scrollbar, #detail::-webkit-scrollbar { width: 9px; }
#list::-webkit-scrollbar-thumb, #detail::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 4px;
}

/* ---- responsive: tablet — narrower docked panel ---- */
@media (min-width: 821px) and (max-width: 1180px) {
  #side { width: 340px; }
  #topbar { right: 352px; left: 52px; }
}

/* ---- responsive: phone/tablet portrait — panel becomes a slide-up drawer ---- */
@media (max-width: 820px) {
  #topbar {
    left: 10px; right: 10px; top: 10px;
    flex-wrap: wrap; gap: 8px; padding: 8px 12px;
  }
  .tb-title { font-size: 15px; }
  .auth-bar { font-size: 13px; }
  .basemap-switch button { padding: 8px 16px; font-size: 13px; }  /* larger touch targets */

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

  #panel-toggle { display: inline-flex; }

  #side {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 80dvh;
    max-height: 80dvh;
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    box-shadow: var(--sh-2);
    transform: translateY(100%);
    transition: transform .3s cubic-bezier(.32,.72,0,1);
    padding-bottom: env(safe-area-inset-bottom);
  }
  #side.open { transform: translateY(0); }
  .panel-close { display: flex; align-items: center; justify-content: center; }
  .panel-close:hover { color: var(--ink); border-color: var(--accent); }

  /* grab handle */
  #side header::before {
    content: ""; display: block; width: 42px; height: 4px; border-radius: 2px;
    background: var(--line); margin: 0 auto 12px;
  }

  #detail.open { max-height: 52dvh; }
  .legend { bottom: 76px; font-size: 10px; padding: 8px 10px; max-width: 56vw; }

  /* bigger touch targets */
  #search, #region, #layer, #brand { padding: 13px; font-size: 16px; }  /* 16px avoids iOS zoom */
  .row-2 button { padding: 12px; font-size: 13px; }
  .item { padding: 14px 16px; }
  .item .nm { font-size: 15px; }
  .ov-item { font-size: 13px; padding: 3px 0; }
  #panel-toggle { bottom: calc(16px + env(safe-area-inset-bottom)); }
}

@media (max-width: 480px) {
  #topbar { gap: 6px; }
  .tb-title { font-size: 14px; }
  .controls { padding: 11px 14px; }
  #side { height: 85dvh; max-height: 85dvh; }
}

@media (prefers-reduced-motion: reduce) {
  #side { transition: none; }
  .online-dot { animation: none; }
}

/* ---- auth / admin pages ---- */
.center-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh; overflow: auto; padding: 20px;
  background:
    radial-gradient(900px 480px at 50% -8%, rgba(201,162,75,.10), transparent 60%),
    var(--bg);
}
.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 30px 30px 26px;
  width: 100%; max-width: 380px;
  box-shadow: var(--sh-2);
}
.card h1 { font-family: var(--serif); font-size: 22px; margin-bottom: 6px; }
.card h1 .mark { color: var(--accent); }
.card p.sub { font-family: var(--ui); color: var(--ink-dim); font-size: 12.5px; margin-bottom: 22px; line-height: 1.4; }
.field { margin-bottom: 14px; font-family: var(--ui); }
.field label { display:block; font-size:12px; color: var(--ink-dim); margin-bottom:6px; }
.field input, .field select {
  width: 100%; background: var(--bg); border: 1px solid var(--line);
  color: var(--ink); padding: 12px 13px; font-size: 15px; border-radius: var(--r-sm);
  font-family: var(--ui); transition: border-color var(--t), box-shadow var(--t);
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.btn {
  background: var(--accent); color: #14110e; border: none; cursor: pointer;
  padding: 12px 16px; font-size: 14px; font-weight: 700; border-radius: var(--r-sm);
  font-family: var(--ui); width: 100%; transition: filter var(--t), transform var(--t);
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); }
.err { color: var(--red); font-size: 12px; font-family: -apple-system, "Segoe UI", sans-serif; min-height: 16px; margin-top: 6px; }
.ok { color: var(--green); font-size: 12px; font-family: -apple-system, "Segoe UI", sans-serif; min-height: 16px; margin-top: 6px; }

/* ============ admin dashboard (modern) ============ */
body.admin { overflow: auto; }
.admin-shell {
  min-height: 100vh;
  font-family: -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(201,162,75,.08), transparent 60%),
    var(--bg);
}
.admin-topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 32px;
  background: rgba(20,17,14,.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.admin-topbar .brand { font-family: "Georgia", serif; font-size: 18px; font-weight: 700; }
.admin-topbar .brand .mark { color: var(--accent); }
.admin-topbar .brand .who { color: var(--ink-dim); font-size: 12px; font-weight: 400; margin-left: 10px; }
.admin-main { max-width: 1180px; margin: 0 auto; padding: 26px 32px 60px; }

/* stat cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px;
  position: relative; overflow: hidden;
}
.stat::after { content: ""; position: absolute; right: -20px; top: -20px; width: 70px; height: 70px;
  border-radius: 50%; background: rgba(201,162,75,.10); }
.stat .num { font-family: "Georgia", serif; font-size: 30px; font-weight: 700; color: var(--ink); line-height: 1; }
.stat .lbl { color: var(--ink-dim); font-size: 12px; margin-top: 8px; text-transform: uppercase; letter-spacing: .4px; }
.stat .num .accent { color: var(--accent); }

.section {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 22px 24px; margin-bottom: 22px;
  box-shadow: 0 6px 22px rgba(0,0,0,.22);
}
.section h2 {
  font-family: "Georgia", serif; font-size: 16px; margin-bottom: 4px; color: var(--ink);
  display: flex; align-items: center; gap: 9px;
}
.section h2 .ic { color: var(--accent); }
.section .hint { color: var(--ink-dim); font-size: 12px; margin-bottom: 16px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 10px 12px; color: var(--ink-dim); font-weight: 600;
  border-bottom: 1px solid var(--line); position: sticky; top: 0;
  text-transform: uppercase; font-size: 11px; letter-spacing: .4px;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: var(--panel-2); }

.role-pill { display:inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.role-pill.admin { background: rgba(201,162,75,.15); color: var(--accent); border: 1px solid var(--accent); }
.role-pill.user  { background: var(--panel-2); color: var(--ink-dim); border: 1px solid var(--line); }

.online-dot { display:inline-block; width:8px; height:8px; border-radius:50%; background: var(--green);
  margin-right:7px; box-shadow: 0 0 7px var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
.ip-mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; color: var(--ink); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 4px; }
.form-grid .full { grid-column: 1 / -1; }

/* pill checkbox groups (layers / regions) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { max-height: 150px; overflow-y: auto; padding: 4px; border: 1px solid var(--line); border-radius: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  padding: 6px 12px; border-radius: 999px; font-size: 12px;
  background: var(--bg); border: 1px solid var(--line); color: var(--ink-dim);
  transition: all .12s; user-select: none;
}
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip input { display: none; }
.chip.on { background: rgba(201,162,75,.16); border-color: var(--accent); color: var(--ink); }
.chip .tick { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.chip.on .tick { background: var(--accent); }

.btn-row { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.btn { width: auto; }
.inline-actions { white-space: nowrap; }
.inline-actions button { margin-right: 6px; font-size: 11px; padding: 6px 11px; }
.muted { color: var(--ink-dim); font-size: 12px; }
.region-tags .tag, .layer-tags .tag {
  display:inline-block; background: var(--panel-2); border:1px solid var(--line);
  border-radius: 999px; padding: 2px 9px; font-size: 11px; margin: 0 4px 4px 0; color: var(--ink-dim);
}
.cell-editor { margin-top: 8px; }
.cell-editor summary { cursor: pointer; color: var(--accent); font-size: 12px; outline: none; }
.cell-editor[open] summary { margin-bottom: 8px; }

/* ---- admin responsive ---- */
@media (max-width: 760px) {
  .admin-topbar { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
  .admin-main { padding: 18px 16px 50px; }
  .section { padding: 16px 16px; border-radius: var(--r-md); }
  .form-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
  .stat .num { font-size: 24px; }
  /* horizontal-scroll tables on narrow screens */
  .section table { display: block; overflow-x: auto; white-space: nowrap; }
  .field input, .field select { font-size: 16px; }  /* avoid iOS zoom */
}
