:root {
  --bg: #f1f1ee;
  --surface: #ffffff;
  --bubble: #e7e7e2;
  --text: #1b1c1e;
  --muted: #64666a;
  --border: #dcdcd6;
  --accent: #0b6e78;
  --accent-ink: #ffffff;
  --ok: #2b7a49;
  --ok-bg: #e6f1e9;
  --risk: #955700;
  --risk-bg: #fbefdb;
  --high: #b42318;
  --high-bg: #fbe8e6;
  --unknown: #5f6368;
  --unknown-bg: #ededea;
  --display: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 16px;
  color-scheme: light;
}

/* Тёмная тема: из настроек системы (если не выбрана светлая) и по явному выбору в шапке */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131415;
    --surface: #1d1f21;
    --bubble: #26292c;
    --text: #ededea;
    --muted: #9a9c9f;
    --border: #303336;
    --accent: #4cc3cc;
    --accent-ink: #0f1516;
    --ok: #74c794;
    --ok-bg: #1b3326;
    --risk: #eab25c;
    --risk-bg: #362a15;
    --high: #f78f86;
    --high-bg: #3c1f1e;
    --unknown: #b0b2b5;
    --unknown-bg: #2a2d30;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131415;
  --surface: #1d1f21;
  --bubble: #26292c;
  --text: #ededea;
  --muted: #9a9c9f;
  --border: #303336;
  --accent: #4cc3cc;
  --accent-ink: #0f1516;
  --ok: #74c794;
  --ok-bg: #1b3326;
  --risk: #eab25c;
  --risk-bg: #362a15;
  --high: #f78f86;
  --high-bg: #3c1f1e;
  --unknown: #b0b2b5;
  --unknown-bg: #2a2d30;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--sans);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* --- top bar --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; cursor: pointer; color: inherit; padding: 4px; }
.logo svg { width: 30px; height: 30px; display: block; }
.logo svg { color: var(--accent); }
.brand-name { font: 800 18px/1 var(--display); letter-spacing: .06em; }
.brand-sub { color: var(--muted); font-size: 14px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.badge {
  font-size: 12px; color: var(--muted); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}
.ghost {
  background: none; border: 1px solid var(--border); color: var(--text);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font: inherit; font-size: 14px;
}
.ghost:hover { background: var(--bubble); }
.theme { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; }
.theme svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.theme .ic { display: none; }
:root:not([data-theme]) .theme .ic-auto, :root[data-theme="light"] .theme .ic-light, :root[data-theme="dark"] .theme .ic-dark { display: block; }

/* --- main scroll --- */
main { flex: 1; overflow-y: auto; padding: 0 16px; }
.welcome { max-width: 720px; margin: 12vh auto 24px; text-align: center; }
.welcome h1 { font: 800 38px/1.15 var(--display); letter-spacing: -.01em; margin: 0 0 14px; text-wrap: balance; }
.lead { color: var(--muted); margin: 0 auto 20px; max-width: 560px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 14px; cursor: pointer; font: inherit; font-size: 14px;
}
.chip:hover { border-color: var(--accent); }
.chip small { color: var(--muted); margin-left: 6px; }
.hidden { display: none !important; }

.thread { max-width: 768px; margin: 0 auto; padding: 16px 0 24px; }
.msg { margin: 18px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: var(--bubble); border-radius: 18px; padding: 10px 16px; max-width: 85%;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.assistant { display: flex; gap: 12px; align-items: flex-start; }
.avatar { flex: 0 0 28px; margin-top: 2px; }
.avatar svg { width: 30px; height: 30px; }
.avatar svg { color: var(--accent); }
.msg.assistant .content { flex: 1; min-width: 0; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md em { color: var(--muted); }
.meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

.typing span {
  display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%;
  background: var(--accent); animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

/* --- passport card --- */
.passport {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  margin: 0 0 14px; overflow: hidden;
}
.pp-head { display: flex; gap: 14px; padding: 16px 18px 12px; align-items: flex-start; }
.pp-shape { flex: 0 0 64px; height: 64px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.pp-shape svg { width: 100%; height: 100%; }
.pp-shape polygon { fill: color-mix(in srgb, var(--accent) 18%, transparent); stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.pp-shape circle { fill: var(--surface); stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.pp-title { flex: 1; min-width: 0; }
.pp-map { margin: 0 18px 12px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--bg); }
.pp-map-canvas { height: 240px; }
.pp-map-note { font-size: 12px; color: var(--muted); padding: 6px 10px; border-top: 1px solid var(--border); }
.leaflet-container { font: inherit; background: var(--bg); }
@media print { .pp-map { display: none; } }
.pp-kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.pp-cn { font: 700 19px/1.3 var(--sans); font-variant-numeric: tabular-nums; }
.pp-addr { color: var(--muted); font-size: 14px; }
.demo-tag {
  display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .04em;
  color: var(--risk); background: var(--risk-bg); border-radius: 6px; padding: 1px 7px; margin-left: 6px; vertical-align: middle;
}
.verdict { margin: 0 18px 12px; padding: 10px 14px; border-radius: 10px; font-weight: 500; }
.verdict.ok { background: var(--ok-bg); color: var(--ok); }
.verdict.attention { background: var(--risk-bg); color: var(--risk); }
.verdict.high_risk { background: var(--high-bg); color: var(--high); }
.verdict.insufficient_data, .verdict.not_found { background: var(--unknown-bg); color: var(--unknown); }
.counts { display: flex; gap: 8px; padding: 0 18px 12px; flex-wrap: wrap; font-size: 13px; }
.count { border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px 2px 6px; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 18px; padding: 4px 18px 14px; font-size: 14px; }
.fact .k { color: var(--muted); font-size: 12px; }
.fact .v { word-wrap: break-word; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .facts { grid-template-columns: 1fr; } }

.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 12px 18px 4px; border-top: 1px solid var(--border); }
details.check { border-top: 1px solid var(--border); }
.group-title + details.check { border-top: 0; }
.group-n { display: inline-block; margin-right: 8px; padding: 1px 6px; border-radius: 6px; background: var(--border); color: var(--muted); font-size: 11px; letter-spacing: 0; text-transform: none; }
details.check > summary {
  list-style: none; cursor: pointer; padding: 10px 18px; display: flex; gap: 10px; align-items: flex-start;
}
details.check > summary::-webkit-details-marker { display: none; }
details.check > summary:hover { background: var(--bg); }
.st { flex: 0 0 22px; width: 22px; height: 22px; display: inline-grid; place-items: center; vertical-align: middle; }
.st svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 2.2; fill: none; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }
.st.confirmed { color: var(--ok); }
.st.risk { color: var(--risk); }
.st.high { color: var(--high); }
.st.unknown { color: var(--unknown); }
.count { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.count .st, .count .st svg { flex-basis: 18px; width: 18px; height: 18px; }
.check-main { flex: 1; min-width: 0; }
.check-title { font-weight: 600; font-size: 15px; }
.check-summary { font-size: 14px; color: var(--muted); }
.sev { font-size: 11px; font-weight: 600; border-radius: 6px; padding: 0 6px; margin-left: 6px; vertical-align: 1px; }
.sev.high { color: var(--high); background: var(--high-bg); }
.sev.medium { color: var(--risk); background: var(--risk-bg); }
.sev.low { color: var(--unknown); background: var(--unknown-bg); }
.chev { color: var(--muted); transition: transform .15s; }
details[open] .chev { transform: rotate(90deg); }
.check-body { padding: 0 18px 12px 50px; font-size: 14px; }
.check-body ul { margin: 0 0 8px; padding-left: 18px; }
.rec { background: var(--bg); border-left: 3px solid var(--accent); padding: 6px 10px; border-radius: 4px; margin: 6px 0; }
.src { font-size: 12px; color: var(--muted); margin-top: 4px; }

details.extra { border-top: 1px solid var(--border); }
details.extra > summary { cursor: pointer; padding: 12px 18px; font-weight: 600; list-style: none; }
details.extra > summary::-webkit-details-marker { display: none; }
details.extra ol { margin: 0 18px 14px; padding-left: 20px; font-size: 14px; }
.disclaimer { font-size: 12px; color: var(--muted); padding: 12px 18px 14px; border-top: 1px solid var(--border); }
.pp-actions { display: flex; gap: 8px; padding: 0 18px 14px; }
.pp-actions a, .pp-actions button {
  font-size: 13px; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 3px 10px;
  background: none; cursor: pointer; text-decoration: none; font-family: inherit;
}

/* --- composer --- */
.composer-wrap { padding: 8px 16px 12px; }
.composer {
  max-width: 768px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 10px 10px 10px 16px; box-shadow: 0 2px 10px rgba(0,0,0,.04);
}
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--text);
  font: inherit; max-height: 200px; padding: 6px 0;
}
.send {
  flex: 0 0 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); cursor: pointer;
  display: grid; place-items: center;
}
.send:disabled { opacity: .35; cursor: default; }
.attach {
  flex: 0 0 36px; height: 36px; border-radius: 50%; border: 0; background: transparent; cursor: pointer;
  display: grid; place-items: center; color: var(--muted); margin-left: -8px;
}
.attach:hover { color: var(--accent); background: var(--bubble); }
.attach svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.send svg { width: 18px; height: 18px; stroke: var(--accent-ink); stroke-width: 2.4; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.fineprint { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 0; }

@media print {
  .topbar, .composer-wrap, .msg.user, .msg.assistant .md, .pp-actions { display: none; }
  details.check .check-body { display: block; }
}

@media (max-width: 560px) {
  .brand-sub { display: none; }
  .badge { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
  .ghost { white-space: nowrap; padding: 6px 10px; }
  .welcome { margin-top: 6vh; }
  .welcome h1 { font-size: 30px; }
  .check-body { padding-left: 18px; }
}

/* --- выбор участка по адресу --- */
.matches { display: grid; gap: 8px; margin-top: 12px; }
.match {
  display: grid; gap: 2px; text-align: left; cursor: pointer;
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); font: inherit;
}
.match:hover, .match:focus-visible { border-color: var(--accent); }
.match-cn { font-weight: 600; font-variant-numeric: tabular-nums; }
.match-addr { font-size: 14px; }
.match-meta { font-size: 13px; color: var(--muted); }
