/* Раскладка: карта на весь экран, поверх неё плавающие панели.
   Широкий экран — панель слева, инструменты сверху, масштаб справа, координаты снизу.
   Узкий экран — панель становится шторкой снизу. */
:root {
  --ocean: #213f63;          /* фон за краем карты, уточняется из map.json */
  --panel: rgba(240, 242, 236, 0.95);
  --panel-solid: #f0f2ec;
  --ink: #1a1f1b;
  --ink-dim: #59625a;
  --line: rgba(26, 31, 27, 0.14);
  --chip: rgba(26, 31, 27, 0.06);
  --chip-hover: rgba(26, 31, 27, 0.11);
  --accent: #a3121d;         /* кровь алтаря: зона и главные действия */
  --accent-ink: #ffffff;
  --ok: #2f7a3d;
  --warn: #9a6200;
  --focus: #2459c2;
  --shadow: 0 6px 22px rgba(8, 12, 10, 0.22);
  --font-display: "Tiny5", "Pixelify Sans", "Golos Text", system-ui, sans-serif;
  --font-body: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --panel: rgba(19, 23, 20, 0.93);
    --panel-solid: #131714;
    --ink: #e4e8df;
    --ink-dim: #98a298;
    --line: rgba(228, 232, 223, 0.13);
    --chip: rgba(228, 232, 223, 0.07);
    --chip-hover: rgba(228, 232, 223, 0.13);
    --accent: #e0414b;
    --accent-ink: #1a0a0b;
    --ok: #79c784;
    --warn: #e2b05a;
    --focus: #86b2ff;
    --shadow: 0 8px 26px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --panel: rgba(19, 23, 20, 0.93);
  --panel-solid: #131714;
  --ink: #e4e8df;
  --ink-dim: #98a298;
  --line: rgba(228, 232, 223, 0.13);
  --chip: rgba(228, 232, 223, 0.07);
  --chip-hover: rgba(228, 232, 223, 0.13);
  --accent: #e0414b;
  --accent-ink: #1a0a0b;
  --ok: #79c784;
  --warn: #e2b05a;
  --focus: #86b2ff;
  --shadow: 0 8px 26px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

html, body { height: 100%; }
body {
  font-synthesis-weight: none;
  background: var(--ocean);
  color: var(--ink);
  font-family: var(--font-body);
  overflow: hidden;
  overscroll-behavior: none;
}

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
  background: var(--ocean);
}
#map.dragging { cursor: grabbing; }
#map.crosshair { cursor: crosshair; }
#map.pointer { cursor: pointer; }

.ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: grid;
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "panel tools zoom"
    "panel .     zoom"
    "panel status status";
  gap: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: max(14px, env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-bottom, 0px));
}
.ui > * { pointer-events: auto; }
.ui > .spacer { pointer-events: none; }

/* ---------------------------------------------------------------- панель */
.panel {
  grid-area: panel;
  align-self: start;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow: hidden;
}

.brand { padding: 16px 16px 10px; display: grid; gap: 6px; }
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0.02em;
  flex: 1;
  min-width: 0;
}
.brand h1 .ver { font-family: var(--font-body); font-weight: 700; font-size: 0.82em; letter-spacing: 0; }
.brand h1 small {
  display: block;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-top: 6px;
}
.facts {
  margin: 4px 0 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.facts div { background: var(--chip); border-radius: 8px; padding: 7px 8px; min-width: 0; }
.facts dt { font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-dim); }
.facts dd { margin: 2px 0 0; font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.facts dd.zone-on { color: var(--accent); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px 12px 0;
  border-bottom: 1px solid var(--line);
}
.tabs button {
  appearance: none;
  border: 0;
  background: none;
  color: var(--ink-dim);
  font: 500 13.5px var(--font-body);
  padding: 9px 8px 10px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs button:hover { color: var(--ink); }
.tabs .count { font-family: var(--font-mono); font-size: 12px; color: var(--ink-dim); }

.tab { padding: 12px 16px 16px; overflow-y: auto; min-height: 0; display: grid; gap: 10px; align-content: start; }
.tab p { margin: 0; line-height: 1.5; }
.muted { color: var(--ink-dim); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

input[type="search"], input[type="text"], input[type="number"], input[type="password"], textarea {
  width: 100%;
  box-sizing: border-box;
  font: 14px var(--font-body);
  color: var(--ink);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
textarea { font-family: var(--font-mono); font-size: 12.5px; resize: vertical; min-height: 90px; }
input:focus-visible, textarea:focus-visible, button:focus-visible, .claim-item:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

/* список приватов */
.claims { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.claim-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 2px 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.claim-item:hover { background: var(--chip); }
.claim-item.active { background: var(--chip-hover); }
.claim-item .dot { width: 12px; height: 12px; border-radius: 3px; grid-row: span 2; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25); }
.claim-item .owner { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.claim-item .where { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 14px; border: 1px dashed var(--line); border-radius: 8px; color: var(--ink-dim); line-height: 1.5; }

/* карточка выбранного привата */
.card {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 12px;
  display: grid;
  gap: 8px;
  background: var(--panel-solid);
}
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head .dot { width: 14px; height: 14px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25); }
.card-head h2 { margin: 0; font-size: 16px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; flex: 1; }
.card .kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; font-size: 13px; }
.card .kv dt { color: var(--ink-dim); }
.card .kv dd { margin: 0; font-family: var(--font-mono); font-size: 12.5px; overflow-wrap: anywhere; }
.card .note { font-size: 13.5px; line-height: 1.45; overflow-wrap: anywhere; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn {
  appearance: none;
  font: 500 13.5px var(--font-body);
  color: var(--ink);
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--chip-hover); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--accent); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--panel-solid); border-color: transparent; }

/* формы владельца */
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 12.5px; color: var(--ink-dim); }
.form .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatches button {
  width: 24px; height: 24px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25);
}
.swatches button[aria-pressed="true"] { border-color: var(--ink); }
.swatches input[type="color"] { width: 30px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.form .error { color: var(--accent); font-size: 12.5px; }
.check { display: flex !important; grid-auto-flow: column; align-items: center; gap: 8px !important; color: var(--ink) !important; font-size: 13.5px !important; }
.confirm { border: 1px solid var(--accent); border-radius: 8px; padding: 10px; display: grid; gap: 8px; font-size: 13.5px; }

/* слои и легенда */
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.legend li { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 13.5px; }
.legend li span:nth-child(2) { min-width: 0; }
.legend canvas { width: 34px; height: 20px; border-radius: 4px; }
.legend input { width: 18px; height: 18px; accent-color: var(--accent); }
.tips { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 13px; color: var(--ink-dim); line-height: 1.45; }

/* ---------------------------------------------------------------- инструменты, масштаб, статус */
.toolbar {
  grid-area: tools;
  justify-self: center;
  align-self: start;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 100%;
  box-sizing: border-box;
}
.toolbar .label { font-family: var(--font-display); font-size: 15px; padding: 0 6px; }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 2px; }
.toolbar .hint { flex-basis: 100%; margin: 2px 4px 0; font-size: 12.5px; color: var(--ink-dim); }
.toolbar .hint:empty { display: none; }
.dirty-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent-ink); margin-left: 6px; vertical-align: 1px; }

.zoom { grid-area: zoom; align-self: start; display: grid; gap: 6px; justify-items: end; }
.zoom .stack {
  display: grid;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.zoom .stack button {
  appearance: none;
  width: 40px;
  height: 40px;
  border: 0;
  background: none;
  color: var(--ink);
  font: 600 20px/1 var(--font-body);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.zoom .stack button + button { border-top: 1px solid var(--line); }
.zoom .stack button:hover { background: var(--chip); }
.zoom .stack svg { width: 18px; height: 18px; }
.zoom .scale {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #f1f0ea;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  text-align: right;
}
.zoom .scale i { display: block; height: 4px; border: 1.5px solid #f1f0ea; border-top: 0; margin-top: 2px; box-shadow: 0 1px 2px rgba(0,0,0,0.6); }

.edit-toggle { box-shadow: var(--shadow); }
a.edit-toggle { text-decoration: none; background: var(--panel-solid); }

.status {
  grid-area: status;
  justify-self: start;
  align-self: end;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: baseline;
  padding: 7px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 13px;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
}
.status .mono { font-size: 12.5px; }
.status .here { min-width: 0; overflow-wrap: anywhere; }
.status .in { color: var(--ok); }
.status .out { color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(max(14px, env(safe-area-inset-bottom, 0px)) + 56px);
  transform: translateX(-50%);
  max-width: min(520px, calc(100% - 32px));
  box-sizing: border-box;
  background: var(--panel-solid);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  z-index: 5;
}
.toast.bad { border-color: var(--accent); }

.banner {
  grid-area: tools;
  justify-self: center;
  align-self: start;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  max-width: 100%;
  box-sizing: border-box;
}

/* окно входа владельца (свой хостинг) */
.modal {
  width: min(380px, calc(100% - 32px));
  box-sizing: border-box;
  padding: 18px;
  color: var(--ink);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(8, 12, 10, 0.55); }
.modal h2 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 20px; }
.modal p { margin: 0; line-height: 1.45; font-size: 13.5px; }
.account { font-size: 12.5px; display: grid; gap: 6px; justify-items: start; }

.fatal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
  color: #f1f0ea;
  text-align: center;
  line-height: 1.5;
}

.sheet-toggle { display: none; }

/* карта в плитке на главной kriand.ru (?embed): только карта и масштаб */
.embed .panel, .embed .status, .embed .edit-toggle, .embed .toolbar, .embed .banner { display: none !important; }
.embed .ui { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: ". zoom" ". zoom" ". zoom"; padding-top: 70px; }

/* ---------------------------------------------------------------- телефон */
@media (max-width: 720px) {
  .ui {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "tools  zoom"
      ".      zoom"
      "status status"
      "panel  panel";
    gap: 8px;
  }
  .panel { align-self: end; max-height: 62vh; }
  .panel:not(.open) .tab, .panel:not(.open) .tabs, .panel:not(.open) .facts { display: none; }
  .panel:not(.open) .brand { padding-bottom: 12px; }
  .brand h1 { font-size: 21px; }
  .brand h1 small { display: inline; margin: 0 0 0 8px; }
  .sheet-toggle { display: inline-flex; }
  .toolbar { justify-self: stretch; }
  .toolbar .label { display: none; }
  .status { border-radius: 10px; }
  .zoom .stack button { width: 38px; height: 38px; }
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .tabs button, .claim-item { transition: background-color 0.12s ease, color 0.12s ease; }
}
