:root {
  color-scheme: dark;
  --bg: #0b1220;
  --panel: #0f172a;
  --card: #111827;
  --border: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --red: #dc2626;
  --amber: #f59e0b;
  --blue: #3b82f6;
  --green: #22c55e;
  --control-height: 44px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

a {
  color: #93c5fd;
}

button,
input {
  font: inherit;
}

button,
.button {
  min-height: 40px;
  border: 1px solid #475569;
  border-radius: 8px;
  padding: 9px 12px;
  background: #1e293b;
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  touch-action: manipulation;
}

button:hover,
.button:hover {
  background: #334155;
}

button:focus-visible,
.button:focus-visible,
input:focus-visible {
  outline: 3px solid #60a5fa;
  outline-offset: 2px;
}

button.primary {
  border-color: #2563eb;
  background: #1d4ed8;
}

button.danger {
  border-color: #991b1b;
  background: #7f1d1d;
}

button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand-block {
  min-width: 0;
}

.brand {
  font-weight: 800;
}

.sub {
  color: var(--muted);
  font-size: 12px;
}

.controls {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.controls input[type="search"],
input[type="text"],
input[type="password"],
input[type="file"] {
  min-height: 40px;
  border: 1px solid #475569;
  border-radius: 8px;
  padding: 8px 11px;
  background: #0b1220;
  color: var(--text);
  font-size: 16px;
}

.controls input[type="search"] {
  min-width: 200px;
  max-width: 320px;
  flex: 1 1 240px;
}

.filter-group,
.action-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-option {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.filter-option input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: #2563eb;
}

.controls-toggle {
  display: none;
}

.map-page {
  display: flex;
  height: 100dvh;
  min-height: 560px;
  flex-direction: column;
  overflow: hidden;
}

.map-layout {
  display: grid;
  min-height: 0;
  flex: 1;
  grid-template-columns: minmax(0, 1fr) 340px;
}

.map-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.map {
  width: 100%;
  height: 100%;
}

.side {
  overflow: auto;
  padding: 14px;
  border-left: 1px solid var(--border);
  background: var(--panel);
  overscroll-behavior: contain;
}

.card {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: var(--card);
}

.k {
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.v {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.big {
  font-size: clamp(20px, 4vw, 24px);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 800;
}

.badge.red {
  background: #7f1d1d;
  color: #fecaca;
}

.badge.amber {
  background: #78350f;
  color: #fde68a;
}

.badge.blue {
  background: #1e3a8a;
  color: #bfdbfe;
}

.legend {
  position: absolute;
  z-index: 800;
  bottom: 24px;
  left: 10px;
  border: 1px solid #475569;
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(15, 23, 42, .93);
  font-size: 12px;
  pointer-events: none;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  border-radius: 3px;
}

.status {
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #172033;
}

.status.ok {
  border-color: #166534;
}

.status.err {
  border-color: #991b1b;
}

.admin-shell {
  width: min(1050px, 100%);
  margin: 0 auto;
  padding: 22px max(22px, env(safe-area-inset-right)) calc(22px + env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.spacer {
  flex: 1;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  background: #172033;
  color: #cbd5e1;
}

.login-shell {
  display: grid;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  place-items: center;
}

.login-card {
  width: min(420px, 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  background: var(--panel);
}

.login-card label {
  display: block;
  margin: 12px 0 5px;
  color: #cbd5e1;
}

.login-card input {
  width: 100%;
}

.login-card button {
  width: 100%;
  margin-top: 16px;
}

.mini {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.muted-block {
  margin-top: 8px;
  color: var(--muted);
}

.notice {
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.5;
}

.section-title {
  margin-top: 0;
}

.row .section-title {
  margin-bottom: 0;
}

.form-row,
.archive-table {
  margin-top: 12px;
}

.back-link {
  margin-top: 12px;
}

.hidden {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .map-topbar {
    flex-wrap: wrap;
  }

  .map-topbar .brand-block {
    width: 100%;
  }

  .controls {
    justify-content: flex-start;
  }
}

@media (max-width: 900px) {
  .map-page {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .map-layout {
    display: grid;
    min-height: 0;
    flex: none;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(440px, 65dvh) auto;
  }

  .side {
    border-top: 1px solid var(--border);
    border-left: 0;
    overflow: visible;
  }
}

@media (max-width: 700px) {
  .topbar {
    gap: 8px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: 8px;
  }

  .map-topbar {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .map-topbar .brand-block {
    width: auto;
  }

  .brand {
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sub {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .controls-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--control-height);
  }

  .map-topbar .controls {
    display: grid;
    width: 100%;
    grid-column: 1 / -1;
    grid-template-columns: 1fr;
  }

  .map-topbar.controls-collapsed .controls {
    display: none;
  }

  .controls input[type="search"] {
    width: 100%;
    max-width: none;
    min-height: var(--control-height);
  }

  .filter-group,
  .action-group {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .filter-option {
    justify-content: center;
    min-height: var(--control-height);
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 6px;
    background: #172033;
    font-size: 12px;
    white-space: normal;
    text-align: center;
  }

  .action-group button,
  .action-group .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--control-height);
    padding-inline: 7px;
    font-size: 12px;
  }

  .map-layout {
    grid-template-rows: minmax(430px, 68dvh) auto;
  }

  .legend {
    right: 8px;
    bottom: 22px;
    left: 8px;
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 7px 8px;
    font-size: 10px;
  }

  .legend div {
    display: flex;
    align-items: center;
  }

  .map-wrap .leaflet-bar a {
    width: var(--control-height);
    height: var(--control-height);
    line-height: var(--control-height);
  }

  .leaflet-control-attribution {
    max-width: calc(100vw - 16px);
    font-size: 9px;
  }

  .side {
    padding: 10px;
  }

  .card {
    padding: 12px;
  }

  .admin-topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

  .admin-topbar .spacer {
    display: none;
  }

  .admin-topbar .button,
  .admin-topbar button {
    min-height: var(--control-height);
  }

  .admin-shell {
    padding: 12px max(10px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .admin-shell > .card {
    margin-bottom: 12px;
  }

  .form-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .form-row input[type="file"],
  .form-row button {
    width: 100%;
    min-width: 0;
    min-height: var(--control-height);
  }

  .archive-table {
    overflow: visible;
    border: 0;
  }

  .archive-table table {
    min-width: 0;
  }

  .archive-table thead {
    display: none;
  }

  .archive-table tbody {
    display: grid;
    gap: 10px;
  }

  .archive-table tr {
    display: block;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #0f172a;
  }

  .archive-table td {
    display: grid;
    grid-template-columns: minmax(90px, 34%) minmax(0, 1fr);
    gap: 8px;
    padding: 8px 10px;
    overflow-wrap: anywhere;
  }

  .archive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }

  .archive-table .table-action,
  .archive-table .empty-row td,
  .archive-table .invalid-row td {
    display: block;
  }

  .archive-table .table-action::before,
  .archive-table .empty-row td::before,
  .archive-table .invalid-row td::before {
    content: none;
  }

  .archive-table .table-action button {
    width: 100%;
    min-height: var(--control-height);
  }

  .login-shell {
    align-items: center;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .login-card {
    padding: 18px;
  }

  .login-card input,
  .login-card button {
    min-height: var(--control-height);
  }
}

@media (max-width: 420px) {
  .admin-topbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .admin-topbar .brand-block {
    grid-column: 1 / -1;
  }

  .admin-topbar .button {
    grid-column: 1;
  }

  .admin-topbar #logout {
    grid-column: 2;
  }

  .map-layout {
    grid-template-rows: minmax(400px, 66dvh) auto;
  }

  .legend {
    flex-wrap: wrap;
    row-gap: 3px;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .map-topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .map-topbar .brand-block {
    width: auto;
  }

  .map-topbar .brand,
  .map-topbar .sub {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .map-topbar .controls-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .map-topbar .controls {
    width: 100%;
    grid-column: 1 / -1;
  }

  .map-topbar.controls-collapsed .controls {
    display: none;
  }

  .map-page {
    min-height: 100dvh;
  }

  .map-layout {
    min-height: 320px;
    grid-template-rows: minmax(320px, 78dvh) auto;
  }

  .login-shell {
    align-items: start;
  }
}

@media (pointer: coarse) {
  button,
  .button {
    min-height: var(--control-height);
  }
}
