:root {
  --bg: #f5efe6;
  --card: #ffffff;
  --card-2: #fbf7f1;
  --ink: #1b2326;
  --muted: #5d696e;
  --line: #e4dbcf;
  --sea: #0b5e7a;
  --sea-ink: #ffffff;
  --sea-soft: #dcecf1;
  --terra: #b9482f;
  --terra-soft: #f7e3dc;
  --sos: #c62828;
  --sos-ink: #ffffff;
  --sos-text: #c62828;
  --ok: #2e7d55;
  --shadow: 0 1px 2px rgba(27, 35, 38, .06), 0 4px 14px rgba(27, 35, 38, .06);
  --radius: 16px;
  --tabs-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1416;
    --card: #182023;
    --card-2: #1d272b;
    --ink: #e8eef0;
    --muted: #98a6ab;
    --line: #2a363a;
    --sea: #4fb0cf;
    --sea-ink: #062a36;
    --sea-soft: #173540;
    --terra: #e98a6f;
    --terra-soft: #3a2420;
    --sos: #d63b3b;
    --sos-ink: #ffffff;
    --sos-text: #ff7b7b;
    --ok: #5fc48f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1416;
  --card: #182023;
  --card-2: #1d272b;
  --ink: #e8eef0;
  --muted: #98a6ab;
  --line: #2a363a;
  --sea: #4fb0cf;
  --sea-ink: #062a36;
  --sea-soft: #173540;
  --terra: #e98a6f;
  --terra-soft: #3a2420;
  --sos: #d63b3b;
  --sos-ink: #ffffff;
  --sos-text: #ff7b7b;
  --ok: #5fc48f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  overflow-x: hidden;
}
a { color: var(--sea); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Верхняя панель */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: linear-gradient(160deg, #f2b45a 0 38%, var(--sea) 38% 100%);
  box-shadow: inset 0 -6px 0 rgba(255,255,255,.18);
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-sub { font-size: 13px; color: var(--muted); }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 12px; color: var(--muted); text-decoration: none;
}
.icon-btn svg { width: 24px; height: 24px; }

main { max-width: 640px; margin: 0 auto; padding: 16px; outline: none; }

/* Баннер установки */
.install {
  max-width: 640px; margin: 12px auto 0; padding: 12px 14px;
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--sea-soft); border-radius: 12px; font-size: 14px;
  width: calc(100% - 32px);
}
.install button { border: 0; background: none; font-size: 22px; line-height: 1; color: var(--muted); padding: 0 4px; }

/* Нижние вкладки */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tabs svg { width: 25px; height: 25px; }
.tabs a.active { color: var(--sea); }
.tabs a[data-tab="sos"].active { color: var(--sos-text); }

/* Общие блоки */
.h1 { font-size: 26px; line-height: 1.15; letter-spacing: -.02em; margin: 4px 0 6px; }
.h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 28px 0 10px; font-weight: 700; }
.lead { color: var(--muted); margin: 0 0 16px; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.note { font-size: 13px; color: var(--muted); margin: 12px 2px; }
.note a { color: inherit; }
.tip {
  background: var(--terra-soft); color: var(--ink); border-radius: 12px;
  padding: 12px 14px; font-size: 14px; margin: 12px 0;
}
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 52px; padding: 12px 16px; margin: 0 0 10px;
  border: 0; border-radius: 14px; font-weight: 650; font-size: 16px;
  background: var(--sea); color: var(--sea-ink); text-decoration: none;
}
.btn svg { width: 20px; height: 20px; }
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.btn.sos { background: var(--sos); color: var(--sos-ink); }
.btn.danger { background: transparent; color: var(--sos-text); box-shadow: none; border: 1px solid var(--line); }
.btn.small { min-height: 40px; font-size: 14px; padding: 8px 12px; width: auto; margin: 0; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* SOS */
.sos-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sos-btn {
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 14px 12px; border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow);
  color: var(--ink); text-decoration: none; min-height: 92px;
}
.sos-btn .num { font-size: 30px; font-weight: 800; letter-spacing: -.02em; color: var(--sos-text); font-variant-numeric: tabular-nums; }
.sos-btn .lbl { font-weight: 650; }
.sos-btn .tr { font-size: 13px; color: var(--muted); }
.sos-btn.main { background: var(--sos); color: var(--sos-ink); }
.sos-btn.main .num, .sos-btn.main .tr { color: inherit; }
.sos-btn.main .tr { opacity: .85; }
.sos-actions { margin-top: 14px; }
@media (max-width: 699px) {
  .sos-btn:last-child:nth-child(odd) { grid-column: 1 / -1; }
}

/* Фразы */
.search {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); margin-bottom: 12px;
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 12px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600; white-space: nowrap;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.phrase { padding: 14px 14px 10px; }
.phrase .ru { font-size: 14px; color: var(--muted); }
.phrase .tr { font-size: 22px; font-weight: 700; line-height: 1.2; margin: 4px 0 2px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.phrase .tl { font-size: 14px; color: var(--sea); }
.phrase .actions { display: flex; gap: 8px; margin-top: 10px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: var(--sea-soft); color: var(--ink);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600;
}
.pill svg { width: 18px; height: 18px; }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }

/* Шаги */
.guide-link {
  display: flex; align-items: center; gap: 14px; text-decoration: none; color: var(--ink);
}
.guide-link .gl-body { flex: 1; min-width: 0; }
.guide-link .gl-title { font-weight: 700; font-size: 17px; }
.guide-link .gl-lead { color: var(--muted); font-size: 14px; }
.ring { --p: 0; width: 44px; height: 44px; flex: none; border-radius: 50%;
  background: conic-gradient(var(--ok) calc(var(--p) * 1%), var(--line) 0);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.ring span { width: 34px; height: 34px; border-radius: 50%; background: var(--card); display: grid; place-items: center; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--sea); text-decoration: none; font-weight: 600; margin-bottom: 8px; min-height: 40px; }
.back svg { width: 20px; height: 20px; }
.step { display: flex; gap: 12px; align-items: flex-start; padding: 14px; cursor: pointer; }
.step input { appearance: none; -webkit-appearance: none; flex: none; width: 26px; height: 26px; margin: 1px 0 0; border-radius: 8px; border: 2px solid var(--line); background: var(--card); display: grid; place-items: center; }
.step input:checked { background: var(--ok); border-color: var(--ok); }
.step input:checked::after { content: ""; width: 7px; height: 13px; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translate(-1px, -1px); }
.step .st { font-weight: 650; }
.step .sd { color: var(--muted); font-size: 14px; margin-top: 2px; }
.step .ss { font-size: 12px; margin-top: 6px; }
.step.done .st { text-decoration: line-through; text-decoration-color: var(--muted); color: var(--muted); }

/* Квартира */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card-2);
}
.field textarea { min-height: 80px; resize: vertical; }
.room-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.room-title { font-weight: 700; }
.room-hint { font-size: 13px; color: var(--muted); }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 12px; }
.thumbs:empty { display: none; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 0; padding: 0; background: var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .tag { position: absolute; left: 4px; bottom: 4px; font-size: 10px; background: rgba(0,0,0,.6); color: #fff; padding: 1px 5px; border-radius: 6px; }
.counter { font-size: 13px; color: var(--muted); }

/* Отчёт */
.report h1 { font-size: 22px; margin: 0 0 4px; }
.report .meta { font-size: 14px; color: var(--muted); margin-bottom: 16px; }
.report .meta div { margin: 2px 0; }
.report h2 { font-size: 17px; margin: 20px 0 8px; }
.report figure { margin: 0 0 14px; break-inside: avoid; }
.report figure img { width: 100%; border-radius: 10px; display: block; }
.report figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; }
.report .sign { margin-top: 28px; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; font-size: 13px; color: var(--muted); }
.report .sign div { border-top: 1px solid var(--line); padding-top: 6px; }

/* Адрес */
.preview { white-space: pre-wrap; font-size: 15px; background: var(--card-2); border-radius: 12px; padding: 12px; overflow-wrap: anywhere; }
.coords { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); margin: 8px 0 12px; }

/* Оверлей */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  overflow-y: auto; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 24px);
}
.overlay .close {
  position: sticky; top: 0; margin-left: auto; display: flex;
  width: 44px; height: 44px; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); font-size: 26px; line-height: 1;
}
.big-tr { font-size: clamp(30px, 9vw, 54px); font-weight: 800; line-height: 1.12; letter-spacing: -.02em; margin: 16px 0 10px; overflow-wrap: anywhere; }
.big-ru { font-size: 18px; color: var(--muted); }
.big-tl { font-size: 18px; color: var(--sea); margin-top: 6px; }
.em-title { font-size: clamp(34px, 11vw, 60px); font-weight: 900; color: var(--sos-text); letter-spacing: .02em; margin: 8px 0; }
.em-line { font-size: 22px; font-weight: 700; margin: 6px 0; overflow-wrap: anywhere; }
.em-en { font-size: 17px; color: var(--muted); margin-bottom: 18px; }
.em-addr { font-size: 20px; line-height: 1.35; white-space: pre-wrap; background: var(--card); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); margin: 14px 0; overflow-wrap: anywhere; }
.viewer img { width: 100%; border-radius: 12px; display: block; margin: 12px 0; }

/* Тост */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100% - 32px); box-shadow: var(--shadow);
}

/* О приложении */
.about li { margin: 6px 0; }

@media (min-width: 700px) {
  .sos-grid { grid-template-columns: repeat(3, 1fr); }
}

@media print {
  body { background: #fff; color: #000; padding: 0; }
  .topbar, .tabs, .install, .no-print, .toast { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; padding: 0; }
  .report figure { width: 48%; display: inline-block; vertical-align: top; margin-right: 2%; }
}
