:root {
  --bg: #101114;
  --panel: #17181d;
  --panel-2: #1e1f26;
  --line: #2c2e38;
  --text: #f4f1ea;
  --muted: #9a9aaa;
  --accent: #cb11ab;
  --accent-2: #ff4fc3;
  --pending: #8b90a0;
  --ok: #3dcc7a;
  --no: #ef5b5b;
  --work: #f5a524;
  --official: #5b8def;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --radius: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(203, 17, 171, 0.28), transparent 55%),
    radial-gradient(700px 400px at 0% 100%, rgba(61, 204, 122, 0.12), transparent 50%),
    var(--bg);
}

.gate-card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 32px 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 10px;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.lede, .who {
  color: var(--muted);
  line-height: 1.5;
}

.lede { margin: 0 0 24px; }

label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
}

input:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

button {
  font: inherit;
  cursor: pointer;
}

.gate-card button[type="submit"],
.actions button {
  border: 0;
  background: var(--accent);
  color: white;
  font-weight: 700;
  border-radius: 12px;
  padding: 13px 16px;
}

.gate-card button[type="submit"] { width: 100%; margin-top: 6px; }
.gate-card button[type="submit"]:hover { background: #b10e96; }

.error { color: var(--no); font-size: 13px; margin: 0 0 10px; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(320px, 380px) 1fr;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.brand {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.brand h1 { font-size: 22px; margin: 0; }

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
}

.who { margin: 0; font-size: 14px; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
}

.stat b { display: block; font-size: 20px; letter-spacing: -0.03em; }
.stat span { color: var(--muted); font-size: 12px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
}

.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip[data-filter="не отработан"].active { background: var(--pending); color: #111; border-color: var(--pending); }
.chip[data-filter="договорились"].active { background: var(--ok); color: #062; border-color: var(--ok); }
.chip[data-filter="взял в работу"].active { background: var(--work); color: #3a2500; border-color: var(--work); }
.chip[data-filter="отказались"].active { background: var(--no); color: #fff; border-color: var(--no); }
.chip[data-filter="официальный пвз"].active { background: var(--official); color: #fff; border-color: var(--official); }
.chip[data-filter="рядом"].active { background: #3b82f6; color: #fff; border-color: #3b82f6; }

.list-head {
  margin: 2px 0 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.address-list {
  flex: 1;
  min-height: 140px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}

.addr {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  align-items: start;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.35;
}

.addr:last-child { border-bottom: 0; }
.addr:hover { background: #272833; }
.addr.active { background: #2d2030; }
.addr small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.pip {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--pending);
}
.pip.ok { background: var(--ok); }
.pip.no { background: var(--no); }
.pip.work { background: var(--work); }
.pip.official { background: var(--official); }

.empty-note, .list-more {
  margin: 0;
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.detail {
  flex: 1 1 280px;
  max-height: 58%;
  min-height: 250px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.detail-fixed { flex: 0 0 auto; }
.detail-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.detail.empty {
  color: var(--muted);
  display: grid;
  place-items: center;
  text-align: center;
  min-height: 72px;
  flex: 0 0 auto;
  max-height: none;
}
.detail h2 { margin: 0 0 8px; font-size: 18px; line-height: 1.3; }
.detail .meta { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}
.badge.pending { background: rgba(139, 144, 160, 0.2); color: #c6cad6; }
.badge.ok { background: rgba(61, 204, 122, 0.16); color: var(--ok); }
.badge.no { background: rgba(239, 91, 91, 0.16); color: var(--no); }
.badge.work { background: rgba(245, 165, 36, 0.18); color: var(--work); }
.badge.official { background: rgba(91, 141, 239, 0.18); color: var(--official); }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.actions button {
  min-height: 40px;
  padding: 8px 10px;
  font-size: 13px;
}
.lock-note {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(245, 165, 36, 0.12);
  color: var(--work);
  font-size: 13px;
  line-height: 1.45;
}
#status-error { margin: 8px 0 0; }
.actions button.ok { background: var(--ok); color: #062813; }
.actions button.no { background: var(--no); }
.actions button.work { background: var(--work); color: #3a2500; }
.actions button.official { background: var(--official); color: #06122a; }
.actions button.reset {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  grid-column: 1 / -1;
}

.comment-box {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}
.comment-label {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.comment-input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 72px;
}
.comment-input:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}
.comment-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.comment-save {
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 12px;
  min-height: 40px;
}
.status-comment {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
}

.pvz-popup .leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--text);
  border-radius: 18px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.pvz-popup .leaflet-popup-tip {
  background: var(--panel);
}
.pvz-popup .leaflet-popup-content {
  margin: 12px;
  width: 280px !important;
}
.pvz-popup .leaflet-popup-close-button {
  color: var(--muted) !important;
  top: 8px;
  right: 8px;
  font-size: 22px;
}
.map-popup { display: grid; gap: 8px; }
.map-popup strong {
  font-size: 14px;
  line-height: 1.35;
}
.map-popup .actions button { min-height: 42px; }

.history {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.history p { margin: 0 0 8px; font-weight: 700; color: var(--text); }
.history ul { margin: 0; padding-left: 16px; }
.history li { margin: 0 0 6px; }

.locate {
  position: absolute;
  z-index: 2000;
  right: 16px;
  bottom: 24px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 700;
  pointer-events: auto;
}

.map-wrap { position: relative; isolation: isolate; }
#map { height: 100%; background: #1a1c22; z-index: 1; }
.map-hint {
  position: absolute;
  z-index: 1500;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
}

.marker-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-sizing: border-box;
}

.pvz-marker,
.pvz-pin {
  background: transparent !important;
  border: 0 !important;
}
.pvz-dot {
  display: block;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
}
.pvz-dot.marked {
  border-width: 3px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 18px;
}
.tab {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 10px 12px;
  font-weight: 700;
}
.tab.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.field-label {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.role-pick {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}
.role {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
}
.role input { width: auto; accent-color: var(--accent); }

.hint-inline {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  opacity: 0.8;
}
.city-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
}
.city-pick .city {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
}
.city-pick .city input { width: auto; accent-color: var(--accent); }
.city-pick .city:has(input:checked) {
  border-color: var(--accent);
  background: rgba(203, 17, 171, 0.14);
}
.city-filters { margin-bottom: 8px; }

.bot-link {
  display: block;
  text-align: center;
  text-decoration: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 12px;
  padding: 14px 16px;
  margin: 8px 0 16px;
}
.hint, .wait-exit { color: var(--muted); font-size: 13px; line-height: 1.45; }
#supervisor-hint { margin: -6px 0 14px; }
.wait-exit { width: 100%; margin-top: 16px; }

.brand-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
}

.admin {
  min-height: 100dvh;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: var(--bg);
}
.admin-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}
.admin-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.admin-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  -webkit-overflow-scrolling: touch;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  vertical-align: top;
}
.admin-table th {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  background: var(--panel);
}
.admin-table td small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}
.admin-table .badge { margin: 0; }

@media (max-width: 860px) {
  .gate {
    place-items: start center;
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .gate-card {
    padding: 22px 16px;
    border-radius: 20px;
  }
  h1 { font-size: 24px; }
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(42dvh, 46dvh) 1fr;
    height: 100dvh;
    height: 100svh;
  }
  .map-wrap {
    min-height: 42dvh;
    order: 0;
  }
  .sidebar {
    border-right: 0;
    border-top: 1px solid var(--line);
    max-height: none;
    min-height: 0;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
    order: 1;
  }
  .brand h1 { font-size: 18px; }
  .ghost, .chip, .locate, .bot-link, .tab {
    min-height: 44px;
  }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat { padding: 8px; }
  .stat b { font-size: 16px; }
  .address-list { min-height: 64px; }
  .detail:not(.empty) {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 4000;
    flex: none;
    width: auto;
    max-height: min(68dvh, 520px);
    min-height: 0;
    box-shadow: var(--shadow);
  }
  .detail.from-map {
    display: none;
  }
  .map-hint {
    left: 12px;
    right: 12px;
    transform: none;
    width: auto;
    text-align: center;
    top: 10px;
    font-size: 12px;
  }
  .locate {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .admin-filters { grid-template-columns: 1fr; }
}
