:root {
  --primary: #1F5FAD;
  --on-primary: #fff;
  --bg: #F8F9FC;
  --surface: #fff;
  --surface-2: #EEF1F7;
  --text: #1B1C1F;
  --muted: #5B5F68;
  --outline: #C4C7D0;
  --ok: #2E7D32;
  --error: #B3261E;
  --error-bg: #FBE3E1;
  --info-bg: #DCE5F7;
  --shadow: 0 2px 8px rgba(0, 0, 0, .12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #9EC2FF;
    --on-primary: #002E62;
    --bg: #121316;
    --surface: #1B1C20;
    --surface-2: #26282D;
    --text: #E3E2E6;
    --muted: #A9ACB4;
    --outline: #44474F;
    --ok: #7FD483;
    --error: #FFB4AB;
    --error-bg: #5A1D19;
    --info-bg: #23314A;
    --shadow: 0 2px 8px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
svg.i { width: 24px; height: 24px; fill: currentColor; flex: none; }
.container { max-width: 720px; margin: 0 auto; padding: 8px 16px 112px; }

/* --- шапка --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  min-height: 60px; padding: 4px 8px 4px 16px;
  background: var(--bg); border-bottom: 1px solid var(--outline);
}
.topbar h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar h1 small { display: block; font-size: 13px; color: var(--muted); font-weight: 400; }
.topbar #back { margin-left: -8px; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 20px; border-radius: 20px; border: 0;
  background: var(--primary); color: var(--on-primary);
  font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn svg.i { width: 20px; height: 20px; }
.btn.outline { background: transparent; color: var(--primary); border: 1px solid var(--outline); }
.btn.text { background: transparent; color: var(--primary); padding: 0 12px; }
.btn.tonal { background: var(--info-bg); color: var(--text); }
.btn.danger { color: var(--error); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.download { padding: 0 14px; }
@media (max-width: 520px) { .btn.download .label { display: none; } .btn.download { padding: 0 10px; } }

/* --- поля --- */
.field { display: block; margin: 12px 0; position: relative; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px 4px; }
.input {
  width: 100%; min-height: 52px; padding: 12px 14px;
  border: 1px solid var(--outline); border-radius: 8px;
  background: var(--surface); outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.input.code { font: 600 22px ui-monospace, Menlo, Consolas, monospace; letter-spacing: .5px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }

.search { position: relative; margin: 8px 0; }
.search svg.i { position: absolute; left: 16px; top: 15px; color: var(--muted); }
.search .input { border-radius: 28px; padding-left: 52px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--outline); background: transparent; cursor: pointer;
}
.chip svg.i { width: 18px; height: 18px; color: var(--primary); }
.chip[aria-pressed="true"] { background: var(--info-bg); border-color: transparent; font-weight: 500; }

/* --- списки и карточки --- */
.list { margin: 8px -16px 0; }
.list-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 16px; border: 0; border-bottom: 1px solid var(--outline);
  background: transparent; text-align: left; cursor: pointer;
}
.list-item:hover { background: var(--surface-2); }
.list-item .main { flex: 1; min-width: 0; }
.list-item .title { font-size: 17px; }
.list-item .sub { font-size: 14px; color: var(--muted); }
.list-item .ok { color: var(--ok); }
.pending { font-size: 12px; color: var(--muted); }

.card { background: var(--surface); border-radius: 16px; padding: 14px 16px; margin: 8px 0; box-shadow: var(--shadow); }
.card.alt { box-shadow: none; border: 1px solid var(--outline); background: transparent; }
.card.info { background: var(--info-bg); box-shadow: none; }
.card.warn { background: var(--error-bg); box-shadow: none; }
.map-card { padding: 0; overflow: hidden; }
.map-card .card-actions { margin: 0; padding: 4px 8px; }
.map { height: 200px; background: var(--surface-2); z-index: 0; }
.map.failed::after { content: 'Карта не загрузилась'; display: grid; place-items: center; height: 100%; color: var(--muted); }
.map-pin .i { width: 40px; height: 40px; fill: #1A4F94; stroke: #fff; stroke-width: 1.2; filter: drop-shadow(0 1px 2px rgba(0,0,0,.35)); }
.card-actions { display: flex; justify-content: flex-end; gap: 4px; margin: 8px -8px -6px 0; flex-wrap: wrap; }

.group-title { color: var(--primary); font-weight: 600; font-size: 14px; margin: 20px 0 4px; }
.variant-head { display: flex; align-items: center; gap: 8px; }
.code-value {
  flex: 1; min-width: 0; font: 700 26px ui-monospace, Menlo, Consolas, monospace;
  background: none; border: 0; padding: 0; text-align: left; cursor: copy; overflow-wrap: anywhere;
}
.status { font-size: 13px; padding: 4px 10px; border-radius: 8px; border: 1px solid currentColor; white-space: nowrap; }
.status.confirmed { color: var(--ok); }
.status.disputed { color: var(--error); }
.status.unconfirmed { color: var(--muted); }
.meta { font-size: 13px; color: var(--muted); }
.votes { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.votes .btn { min-height: 36px; padding: 0 14px; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.hint { font-size: 13px; color: var(--muted); margin: 4px 4px; }
.error-text { color: var(--error); }
.center { display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; padding: 48px 16px; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--outline); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* подсказки улиц */
.suggest { position: absolute; left: 0; right: 0; z-index: 5; margin-top: 4px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.suggest .cap { font-size: 12px; color: var(--muted); padding: 8px 16px 0; }
.suggest button { display: block; width: 100%; text-align: left; padding: 10px 16px; border: 0; background: none; cursor: pointer; }
.suggest button:hover { background: var(--surface-2); }
.suggest small { display: block; color: var(--muted); }

/* --- круглая кнопка «+» --- */
.fab {
  position: fixed; right: max(24px, calc(50% - 360px + 24px)); bottom: 24px; z-index: 9;
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.fab svg.i { width: 28px; height: 28px; }

/* --- плашка --- */
#snackbar {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 140%); z-index: 20;
  display: flex; align-items: center; gap: 16px; max-width: calc(100% - 32px); min-width: 280px;
  padding: 10px 10px 10px 18px; border-radius: 8px;
  background: #2F3033; color: #F1F0F4; box-shadow: var(--shadow);
  transition: transform .2s ease; visibility: hidden;
}
#snackbar.show { transform: translate(-50%, 0); visibility: visible; }
#snackbar .msg { flex: 1; }
#snackbar button { background: none; border: 0; color: #A8C8FF; font-weight: 600; cursor: pointer; padding: 6px 8px; }

/* --- диалоги --- */
dialog {
  width: min(480px, calc(100% - 32px)); max-height: calc(100% - 48px);
  border: 0; border-radius: 24px; padding: 20px 24px 12px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog h2 { margin: 0 0 8px; font-size: 22px; font-weight: 500; }
dialog .card-actions { margin-top: 16px; }
