:root {
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --surface-2: #EEF1F4;
  --ink: #14202B;
  --muted: #56626E;
  --line: #DDE3E9;
  --accent: #1D6FD6;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3EEFB;
  --danger: #B3261E;
  --danger-soft: #FBE9E7;
  --ready: #1E7B4F;
  --ready-soft: #E1F2E8;
  --building: #B4520F;
  --building-soft: #FCEBDD;
  --mixed: #2B5FA8;
  --mixed-soft: #E3ECF8;
  --shadow: 0 2px 10px rgba(20, 32, 43, .14);
  --radius: 12px;
  --wm: rgba(20, 32, 43, .10);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F161D;
    --surface: #17212B;
    --surface-2: #1F2B37;
    --ink: #E6EDF3;
    --muted: #9AA7B4;
    --line: #2A3642;
    --accent: #5A9DF0;
    --accent-ink: #0B1620;
    --accent-soft: #1B2C42;
    --danger: #F2847B;
    --danger-soft: #3A1E1C;
    --ready: #4CC38A;
    --ready-soft: #173327;
    --building: #F0A060;
    --building-soft: #3A2616;
    --mixed: #7FA8E8;
    --mixed-soft: #1C2A40;
    --shadow: 0 2px 12px rgba(0, 0, 0, .5);
    --wm: rgba(230, 237, 243, .09);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { filter: brightness(1.06); border-color: var(--accent); }
.btn--danger { color: var(--danger); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn--block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 96px; resize: vertical; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; }
.muted { color: var(--muted); }

/* ---------- login ---------- */
.login {
  min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
}
.login__card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 18px; padding: 28px 22px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px;
}
.login__logo {
  width: 56px; height: 56px; border-radius: 14px; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.login__logo svg { width: 30px; height: 30px; }
.login__note { font-size: 13px; color: var(--muted); }

/* ---------- app shell ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 16px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar__title { font-weight: 700; font-size: 17px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__user { font-size: 13px; color: var(--muted); white-space: nowrap; }
.main { flex: 1; min-height: 0; display: flex; position: relative; }
.side {
  width: 380px; flex-shrink: 0; display: flex; flex-direction: column; background: var(--surface);
  border-right: 1px solid var(--line); min-height: 0;
}
.filters { padding: 12px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 11px; color: var(--muted); }
.search .input { padding-left: 42px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 14px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.filters__row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.filters__row select.input { min-height: 40px; padding: 6px 10px; font-size: 14px; }
.count { font-size: 13px; color: var(--muted); padding: 4px 14px; min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.linkbtn { border: 0; background: transparent; color: var(--accent); font-weight: 600; font-size: 13px; min-height: 36px; padding: 0 4px; cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }
.tagbar { display: flex; flex-direction: column; gap: 6px; }
.tagbar__title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.chips--wrap { flex-wrap: wrap; overflow: visible; }
.chip--tag small { margin-left: 6px; opacity: .7; font-size: 12px; }
.taglist { display: flex; flex-wrap: wrap; gap: 6px; }
.badge--tag { background: var(--accent-soft); color: var(--accent); }

.list { flex: 1; min-height: 0; overflow-y: auto; }
.item {
  width: 100%; display: flex; gap: 12px; align-items: flex-start; text-align: left; padding: 12px 14px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; cursor: pointer;
}
.item:hover, .item[aria-current="true"] { background: var(--surface-2); }
.item__dot { width: 12px; height: 12px; border-radius: 6px; margin-top: 5px; flex-shrink: 0; }
.item__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item__name { font-weight: 600; }
.item__meta { font-size: 13px; color: var(--muted); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

.mapwrap { flex: 1; min-width: 0; position: relative; }
#map { position: absolute; inset: 0; background: var(--surface-2); }

.legend {
  position: absolute; left: 12px; bottom: 24px; z-index: 500; background: var(--surface); border-radius: 10px;
  box-shadow: var(--shadow); padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; font-size: 12px;
}
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 5px; display: inline-block; }

.st-ready { background: var(--ready); }
.st-building { background: var(--building); }
.st-mixed { background: var(--mixed); }
.st-unknown { background: var(--muted); }

/* ---------- map pins ---------- */
.pin-wrap { background: none; border: 0; }
.pin {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -100%);
  display: flex; flex-direction: column; align-items: center; cursor: pointer;
}
.pin__label {
  display: none; margin-bottom: 4px; padding: 3px 8px; border-radius: 10px; background: var(--surface);
  color: var(--ink); font-size: 12px; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow);
}
.show-labels .pin__label { display: block; }
.pin__dot {
  width: 18px; height: 18px; border-radius: 9px; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.pin--active .pin__dot { width: 24px; height: 24px; border-radius: 12px; box-shadow: 0 0 0 3px var(--ink); }
.pin--active .pin__label { display: block; }
.district-label {
  background: transparent; border: 0; box-shadow: none; color: var(--muted); font-weight: 700;
  font-size: 11px; letter-spacing: .06em;
}
.district-label::before { display: none; }
.district { position: absolute; transform: translate(-50%, -50%); color: var(--muted); font-weight: 700; font-size: 11px; letter-spacing: .06em; white-space: nowrap; text-shadow: 0 0 3px var(--surface), 0 0 3px var(--surface); }
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large { background: rgba(29,111,214,.25) !important; }
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div { background: var(--accent) !important; color: #fff; font-weight: 700; }

/* ---------- card ---------- */
.card {
  position: absolute; z-index: 800; right: 16px; top: 16px; bottom: 16px; width: 400px; max-width: calc(100% - 32px);
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column;
  user-select: none; -webkit-user-select: none; overflow: hidden;
}
.card__head { display: flex; align-items: flex-start; gap: 8px; padding: 16px 8px 8px 18px; }
.card__head h2 { flex: 1; font-size: 22px; }
.card__body { flex: 1; overflow-y: auto; padding: 0 18px 18px; display: flex; flex-direction: column; gap: 14px; }
.badge { align-self: flex-start; padding: 4px 10px; border-radius: 12px; font-size: 13px; font-weight: 600; }
.badge--ready { background: var(--ready-soft); color: var(--ready); }
.badge--building { background: var(--building-soft); color: var(--building); }
.badge--mixed { background: var(--mixed-soft); color: var(--mixed); }
.badge--unknown { background: var(--surface-2); color: var(--muted); }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.fact { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.fact span:first-child { font-size: 12px; color: var(--muted); }
.fact span:last-child { font-weight: 600; }
.block { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.block h3 { font-size: 14px; margin-bottom: 6px; }
.prewrap { white-space: pre-line; }
.card__actions { display: flex; flex-direction: column; gap: 8px; }
.card__loading { padding: 24px; color: var(--muted); }

/* ---------- promos ---------- */
.chip--promo { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); font-weight: 700; }
.chip--promo .i { width: 16px; height: 16px; }
.chip--promo[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.promos {
  position: absolute; z-index: 1100; left: 396px; top: 16px; bottom: 16px; width: 560px; max-width: calc(100% - 412px);
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column;
  overflow: hidden; user-select: none; -webkit-user-select: none;
}
.promos__title { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.promos__title h2 { font-size: 22px; }
.promos__title .muted { font-size: 13px; }
.promos__search { padding: 0 18px 10px; }
.promos__list { flex: 1; overflow-y: auto; padding: 0 18px 18px; display: flex; flex-direction: column; gap: 8px; }
.promo { background: var(--surface-2); border-radius: 12px; }
.promo > summary, .promo-card > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 8px 12px; font-weight: 700;
}
.promo > summary::-webkit-details-marker, .promo-card > summary::-webkit-details-marker { display: none; }
.promo > summary::after, .promo-card > summary::after { content: "›"; margin-left: auto; font-size: 20px; color: var(--muted); transition: transform .15s; }
.promo[open] > summary::after, .promo-card[open] > summary::after { transform: rotate(90deg); }
.promo > summary small { font-weight: 500; color: var(--muted); }
.promo__body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px; }
.promo__text { white-space: pre-line; overflow-wrap: anywhere; font-size: 14px; line-height: 1.5; }
.promo-card { background: var(--accent-soft); border-radius: 12px; }
.promo-card > summary { color: var(--accent); }
.promo-card .promo__body { color: var(--ink); }

/* ---------- watermark ---------- */
.wm {
  position: fixed; inset: 0; z-index: 3000; pointer-events: none; background-repeat: repeat;
}

/* ---------- install banner ---------- */
.banner {
  position: absolute; z-index: 900; left: 12px; right: 12px; top: 12px; margin: 0 auto; max-width: 460px;
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 12px;
  display: flex; gap: 10px; align-items: center; font-size: 14px;
}
.banner p { margin: 0; flex: 1; }

.toast {
  position: fixed; z-index: 4000; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: calc(100% - 32px);
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 14px;
}

.viewswitch { display: none; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .side { position: absolute; inset: 0; width: auto; z-index: 600; border-right: 0; }
  .app[data-view="map"] .side { position: absolute; inset: 0 0 auto 0; background: transparent; pointer-events: none; }
  .app[data-view="map"] .filters { background: transparent; border: 0; pointer-events: auto; }
  .app[data-view="map"] .search .input { box-shadow: var(--shadow); border-color: transparent; }
  .app[data-view="map"] .filters__row, .app[data-view="map"] .list, .app[data-view="map"] .count, .app[data-view="map"] .tagbar { display: none; }
  .app[data-view="map"] .chip { box-shadow: var(--shadow); border-color: transparent; }
  .app[data-view="map"] .chip[aria-pressed="true"] { border-color: var(--accent); }
  .app[data-view="list"] .mapwrap { visibility: hidden; }
  .viewswitch {
    display: flex; position: absolute; z-index: 700; left: 50%; transform: translateX(-50%);
    bottom: max(16px, env(safe-area-inset-bottom)); background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); padding: 4px;
  }
  .viewswitch button { min-height: 40px; padding: 0 18px; border-radius: 18px; border: 0; background: transparent; font-weight: 600; cursor: pointer; }
  .viewswitch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
  .app[data-view="list"] .list { padding-bottom: 80px; }
  .legend { bottom: 84px; }
  .card {
    left: 0; right: 0; top: auto; bottom: 0; width: auto; max-width: none; max-height: 78%;
    border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom);
  }
  .card::before { content: ""; display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; }
  .topbar__user { display: none; }
  .promos { left: 0; right: 0; top: 0; bottom: 0; width: auto; max-width: none; border-radius: 0; z-index: 1100; padding-bottom: env(safe-area-inset-bottom); }
  .app[data-view="map"] .chip--promo { border-color: var(--accent-soft); }
}

/* ---------- admin ---------- */
.admin { max-width: 1200px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  min-height: 44px; padding: 0 16px; border: 0; border-bottom: 3px solid transparent; background: transparent;
  font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.panel { display: flex; flex-direction: column; gap: 16px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; }
.tablewrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 12px; font-weight: 600; }
.tag--ok { background: var(--ready-soft); color: var(--ready); }
.tag--off { background: var(--danger-soft); color: var(--danger); }
.tag--warn { background: var(--building-soft); color: var(--building); }
.tag--info { background: var(--accent-soft); color: var(--accent); }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.box h2 { font-size: 17px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 700px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100% - 32px)); background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 16, 22, .5); }
dialog { max-height: calc(100dvh - 32px); overflow-y: auto; }
.checklist { max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 2px 12px; background: var(--surface); }
.checklist--inline { max-height: none; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.checklist .check { min-height: 40px; }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg__actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.secret {
  font: 600 20px/1.3 ui-monospace, Menlo, Consolas, monospace; background: var(--surface-2); padding: 12px; border-radius: 10px;
  user-select: all; word-break: break-all;
}
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.check input { width: 20px; height: 20px; }
