:root {
  --bg: #f2f5f6;
  --surface: #ffffff;
  --surface-2: #e9eef1;
  --ink: #16222b;
  --muted: #5a6873;
  --line: #d7dfe3;
  --accent: #0c7a6b;
  --accent-ink: #ffffff;
  --accent-soft: #dff1ed;
  --warn: #b4580c;
  --warn-soft: #fbeadb;
  --bad: #b3303a;
  --bad-soft: #f8e1e3;
  --shadow: 0 8px 30px rgba(22, 34, 43, 0.16);
  --display: "Unbounded", "Golos Text", system-ui, sans-serif;
  --body: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tabs-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1519;
    --surface: #172026;
    --surface-2: #1f2a31;
    --ink: #e3eaee;
    --muted: #97a4ad;
    --line: #2a363e;
    --accent: #4cc3ae;
    --accent-ink: #0b1a17;
    --accent-soft: #173a35;
    --warn: #f0a560;
    --warn-soft: #3a2a1b;
    --bad: #f07a83;
    --bad-soft: #3b1f23;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px calc(var(--tabs-h) + 20px);
  /* Блоки своей высоты и прижаты к верху — свободное место остаётся внизу. */
  align-content: start;
  display: grid;
  gap: 16px;
}
.loading, .empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* ---------- типографика ---------- */
h1, h2, h3 { margin: 0; text-wrap: balance; }
h1 { font: 600 22px/1.2 var(--display); letter-spacing: -0.01em; }
h2 { font: 600 17px/1.3 var(--body); }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.label { font: 600 12px/1 var(--body); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.head .sub { font-size: 14px; color: var(--muted); }

/* ---------- месяц ---------- */
.month { display: flex; align-items: center; gap: 4px; }
.month h1 { min-width: 0; text-align: center; flex: 1; }
.iconbtn {
  width: 40px; height: 40px; flex: none;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; font-size: 18px; line-height: 1;
}
.iconbtn:disabled { opacity: .35; cursor: default; }

.notice {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 11px 14px; font-size: 14px; display: flex; gap: 10px; align-items: center;
}
.notice.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); font-weight: 500; }

/* ---------- плитки прогресса ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; display: grid; gap: 8px;
}
.tile.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tile .big { font: 600 24px/1 var(--display); font-variant-numeric: tabular-nums; }
.tile .big small { font: 500 14px/1 var(--body); color: var(--muted); }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.tile.readings .bar i { background: var(--warn); }

/* ---------- чипы-фильтры ---------- */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin-inline: -16px; padding-inline: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; font-size: 14px; padding: 7px 13px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); white-space: nowrap;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .c { color: var(--muted); margin-left: 4px; }
.chip.on .c { color: inherit; opacity: .7; }

/* ---------- карточки и списки ---------- */
.list { display: grid; gap: 8px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px;
  display: grid; gap: 10px;
}
.card.tap { text-align: left; width: 100%; }
.addr { display: grid; gap: 2px; min-width: 0; }
.addr b { font-weight: 600; overflow-wrap: anywhere; }
.addr span { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pills { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pill {
  border: 0; border-radius: 12px; padding: 9px 11px; text-align: left;
  display: grid; gap: 2px; font-size: 13px; background: var(--surface-2); color: var(--muted);
}
.pill b { font-size: 14px; font-weight: 600; color: var(--ink); }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.ok b { color: var(--accent); }
.pill.wait { background: var(--warn-soft); color: var(--warn); }
.pill.wait b { color: var(--warn); }
.pill.fail { background: var(--bad-soft); color: var(--bad); }
.pill.fail b { color: var(--bad); }

.group { display: grid; gap: 8px; }
.group > .label { padding: 6px 2px 0; }

.item {
  width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 14px; display: flex; align-items: center; gap: 12px;
}
.item .grow { flex: 1; min-width: 0; display: grid; gap: 2px; }
.item .grow b { font-weight: 600; overflow-wrap: anywhere; }
.item .grow span { font-size: 13.5px; color: var(--muted); overflow-wrap: anywhere; }
.item .chev { color: var(--muted); font-size: 18px; }
.badge { flex: none; font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- кнопки ---------- */
.btn {
  border: 0; border-radius: 14px; padding: 13px 16px; font-weight: 600; background: var(--accent); color: var(--accent-ink);
  width: 100%; display: flex; justify-content: center; align-items: center; gap: 8px;
}
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: grid; gap: 8px; }
.btns.two { grid-template-columns: 1fr 1fr; }
.linkbtn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 4px 0; }

/* ---------- формы ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; font-weight: 500; }
.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 13px;
  font-size: 16px; /* 16px — чтобы iOS не увеличивал страницу при фокусе */
}
textarea.input { min-height: 150px; resize: vertical; line-height: 1.45; }
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.search { position: relative; display: block; }
.search .input { padding-left: 38px; }
.search::before { content: "🔍"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 14px; opacity: .6; }
.hint { font-size: 13px; color: var(--muted); }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.suggest .chip { font-size: 13px; padding: 6px 11px; }
.error { color: var(--bad); font-size: 14px; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper .input { text-align: center; width: 80px; }

/* ---------- чат-превью ---------- */
.bubble {
  background: var(--surface-2); border-radius: 16px 16px 16px 4px; padding: 12px 14px; font-size: 15px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.bubble .fakebtn {
  display: block; margin-top: 10px; text-align: center; padding: 8px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); font-weight: 600; color: var(--accent); white-space: normal;
}

/* ---------- чекбоксы получателей ---------- */
.check { display: flex; align-items: center; gap: 12px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; margin: 0; }

/* ---------- переключатель ---------- */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; position: absolute; inset: 0; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background .2s; pointer-events: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }

/* ---------- история ---------- */
.hist { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.hist th { text-align: left; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 6px 4px; font-weight: 600; }
.hist td { padding: 10px 4px; border-top: 1px solid var(--line); }
.hist .yes { color: var(--accent); font-weight: 600; }
.hist .no { color: var(--muted); }

/* ---------- нижние вкладки ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs button {
  border: 0; background: none; height: var(--tabs-h); display: grid; place-content: center; gap: 2px;
  font-size: 12px; font-weight: 500; color: var(--muted);
}
.tabs .ti { font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabs button.on { color: var(--accent); }
.tabs button.on .ti { filter: none; opacity: 1; }
body.sub .tabs { display: none; }
body.sub main { padding-bottom: 24px; }

/* кнопка действия внизу экрана */
.sticky {
  position: sticky; bottom: calc(var(--tabs-h) + 12px);
  z-index: 5; box-shadow: var(--shadow); border-radius: 14px;
}
body.sub .sticky { bottom: 12px; }

/* ---------- шторка ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 16, 20, .45); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 640px; margin: 0 auto;
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  padding: 10px 18px 18px; display: grid; gap: 14px;
  max-height: 85vh; overflow-y: auto;
}
.sheet::before { content: ""; width: 40px; height: 4px; border-radius: 99px; background: var(--line); justify-self: center; }
@media (prefers-reduced-motion: no-preference) {
  .sheet:not([hidden]) { animation: up .22s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } }
}

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + 16px); z-index: 30;
  max-width: 480px; margin: 0 auto; background: var(--ink); color: var(--bg); border-radius: 14px; padding: 12px 16px;
  font-size: 15px; box-shadow: var(--shadow); text-align: center;
}
.toast.bad { background: var(--bad); color: #fff; }

.center { display: grid; place-items: center; text-align: center; gap: 12px; padding: 36px 10px; }
.center .big { font-size: 44px; }

/* кнопка без оформления (кликабельная область внутри карточки) */
.linkish { border: 0; background: none; padding: 0; margin: 0; text-align: left; width: 100%; color: inherit; font: inherit; }
.item .linkish { display: grid; gap: 2px; }
.card-head { display: flex; }

.backbtn { justify-self: start; border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 15px; padding: 2px 0; margin-bottom: -6px; }

/* экран жильца */
.grid-tight { display: grid; gap: 6px; }
.tcard { gap: 14px; padding: 18px; }
.tcard .row { justify-content: flex-start; align-items: flex-start; }
.tcard .grow { display: grid; gap: 2px; }
.ticon { font-size: 30px; line-height: 1; }
.tdone { background: var(--accent-soft); color: var(--accent); font-weight: 600; border-radius: 12px; padding: 12px 14px; text-align: center; }

body.sub .toast { bottom: 16px; }
html, body { height: 100%; }

/* ---------- широкие экраны (планшет, MAX на компьютере) ---------- */
@media (min-width: 720px) {
  main { max-width: 860px; padding-inline: 24px; }
  #view > .list:has(> .card) { grid-template-columns: 1fr 1fr; }
  .tabs { max-width: 860px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-radius: 16px 16px 0 0; }
}
/* ---------- совсем узкие экраны ---------- */
@media (max-width: 350px) {
  main { padding-inline: 12px; }
  .pills { grid-template-columns: 1fr; }
  .tile .big { font-size: 20px; }
  h1 { font-size: 19px; }
}

/* ---------- анимации ---------- */
.btn, .item, .tile, .pill, .chip, .iconbtn, .tabs button, .card.tap {
  transition: transform .12s ease, background-color .2s, border-color .2s, box-shadow .2s, opacity .2s;
}
.btn:active:not(:disabled), .pill:active, .chip:active, .iconbtn:active:not(:disabled), .tile:active, button.item:active {
  transform: scale(.97);
}
.bar i { transition: width .7s cubic-bezier(.2, .8, .2, 1); }
.tabs button.on .ti { animation: tabpop .28s ease-out; }
.sheet-backdrop:not([hidden]) { animation: fadein .2s ease-out; }
.toast:not([hidden]) { animation: toastin .25s cubic-bezier(.2, .8, .2, 1); }
.rise { animation: rise .32s cubic-bezier(.2, .8, .2, 1) backwards; animation-delay: calc(var(--i, 0) * 28ms); }
.enter-forward { animation: fromright .26s cubic-bezier(.2, .8, .2, 1); }
.enter-back { animation: fromleft .26s cubic-bezier(.2, .8, .2, 1); }
.enter-tab { animation: fadein .2s ease-out; }
.flash { animation: flash 1.1s ease-out; }
.check input:checked { animation: tick .2s ease-out; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes fromright { from { opacity: 0; transform: translateX(22px); } }
@keyframes fromleft { from { opacity: 0; transform: translateX(-22px); } }
@keyframes fadein { from { opacity: 0; } }
@keyframes toastin { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes tabpop { 40% { transform: scale(1.18); } }
@keyframes tick { 50% { transform: scale(1.18); } }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- раздел «Рассылка» ---------- */
.hero {
  width: 100%; text-align: left; border: 0; border-radius: 18px; padding: 18px;
  background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; gap: 14px; box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 30%, transparent);
}
.hero .grow { flex: 1; display: grid; gap: 3px; min-width: 0; }
.hero b { font-size: 17px; }
.hero .grow span { font-size: 13.5px; opacity: .85; }
.hero .chev { color: inherit; opacity: .8; font-size: 20px; }
.hero-ico { font-size: 28px; line-height: 1; }
.hero:active { transform: scale(.98); }
.hero { transition: transform .12s ease; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.seg button { border: 0; background: none; border-radius: 10px; padding: 9px 8px; font-weight: 600; font-size: 14.5px; color: var(--muted); transition: background-color .2s, color .2s, box-shadow .2s; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.bubble.placeholder { color: var(--muted); font-style: italic; }

/* заголовок экрана с компактной кнопкой действия */
.title-block { display: grid; gap: 2px; min-width: 0; }
.btn-sm {
  flex: none; border: 0; border-radius: 999px; padding: 9px 15px; font-weight: 600; font-size: 14.5px;
  background: var(--accent); color: var(--accent-ink); transition: transform .12s ease;
}
.btn-sm:active { transform: scale(.96); }

.backbar { max-width: 640px; margin: 0 auto; padding: 10px 16px 0; }
.backbar + main { padding-top: 6px; }
@media (min-width: 720px) { .backbar { max-width: 860px; padding-inline: 24px; } }
