/* Экраны канала и проверки. Цвета приходят из theme.js, здесь только псевдонимы. */
:root {
  --page: var(--bg);
  --card: var(--surface);
  --ink: var(--text);
  --accent: var(--primary);
  --accent-ink: var(--primary-ink);
  --series: var(--bar-now);
  --soft: var(--fill);
  --wait: var(--warn);
  --bad: var(--brand);
  --navy: #14213D;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background-color: var(--page); /* узор добавляет theme.css */
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-wrap: anywhere;
}
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(88px + env(safe-area-inset-bottom));
}
h1 { font-size: 22px; line-height: 1.25; margin: 4px 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }
.muted { color: var(--muted); font-size: 14px; }
.card { background: var(--card); border-radius: 14px; padding: 16px; margin-bottom: 12px; }

button, .button {
  font: inherit;
  border: 0;
  border-radius: 10px;
  min-height: 44px;
  padding: 10px 16px;
  cursor: pointer;
}
.button { display: block; width: 100%; text-align: center; text-decoration: none; font-weight: 600; }
.primary { background: var(--accent); color: var(--accent-ink); }
.plain { background: transparent; color: var(--link); }
.plain.danger { color: var(--danger); }
button:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.channel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--card);
  color: var(--ink);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 8px;
}
.channel .name { font-weight: 600; }
.channel .arrow { color: var(--muted); }

.problems { margin: 0 0 12px; padding-left: 20px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.switch { position: relative; flex: none; width: 52px; min-height: 32px; height: 32px; padding: 0; border-radius: 16px; background: var(--line); }
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.15s;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.tile .value { font-size: 26px; font-weight: 600; line-height: 1.2; }
.tile .label { color: var(--muted); font-size: 14px; }

.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .bar { fill: var(--series); }
.chart .hit { fill: transparent; outline: none; cursor: default; }
.chart g:hover .bar, .chart g.active .bar { opacity: 0.78; }
.chart .hit:focus-visible { stroke: var(--accent); stroke-width: 2; }
.chart .base { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 12px; text-anchor: middle; }
.chart text.cap { fill: var(--ink); font-weight: 600; }
.readout { min-height: 22px; font-size: 14px; color: var(--muted); margin-top: 4px; }
.readout b { color: var(--ink); }
details summary { cursor: pointer; color: var(--link); font-size: 14px; padding: 10px 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 0; border-bottom: 1px solid var(--line); font-weight: 400; }
th { color: var(--muted); }
td:last-child, th:last-child { text-align: right; }

.tools { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.tools button { min-width: 44px; padding: 8px 10px; background: var(--page); color: var(--ink); }
textarea {
  display: block;
  width: 100%;
  min-height: 140px;
  resize: vertical;
  font: inherit;
  color: inherit;
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
}
.error { color: var(--danger); font-size: 14px; margin-bottom: 8px; }
.bubble {
  background: var(--page);
  border-radius: 14px 14px 14px 4px;
  padding: 10px 14px;
  margin-bottom: 12px;
  white-space: pre-wrap;
}
.bubble a { color: var(--link); }
.bubble pre { margin: 4px 0; white-space: pre-wrap; }
.bubble blockquote { margin: 4px 0; padding-left: 10px; border-left: 3px solid var(--accent); }
.bubble tg-spoiler { background: var(--muted); color: transparent; border-radius: 4px; }
.bubble tg-spoiler:hover { background: transparent; color: inherit; }


#tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  background: #23282c;
  color: #ffffff;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
}
@media (prefers-reduced-motion: reduce) { .switch::after { transition: none; } }

/* --- экран канала --- */
.sections { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin-bottom: 12px; }
.sections::-webkit-scrollbar { display: none; }
.sections button { flex: 1 0 auto; padding: 8px 7px; font-size: 14px; background: none; color: var(--muted); border-radius: 10px; }
.sections button[aria-selected="true"] { background: var(--card); color: var(--ink); font-weight: 600; }
.choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  background: var(--page);
  color: var(--ink);
  margin-bottom: 8px;
}
.choice .name { font-weight: 600; }
.choice[aria-checked="true"] { outline: 2px solid var(--accent); outline-offset: -2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { background: var(--page); color: var(--ink); padding: 8px 14px; }
.chip[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.pair { display: flex; gap: 8px; }
.small { min-height: 44px; padding: 8px 12px; background: var(--page); color: var(--ink); font-size: 14px; }
.small.danger { color: var(--danger); }
input[type="text"], input[type="url"] {
  width: 100%;
  min-height: 44px;
  font: inherit;
  color: inherit;
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 8px;
}
.grid-scroll { overflow-x: auto; margin-bottom: 8px; }
.grid-row { display: flex; gap: 4px; }
.grid-row input { min-width: 110px; margin-bottom: 4px; }
.button-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 4px; align-items: start; }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.check input {
  flex: none;
  width: 24px;
  height: 24px;
  margin: 0;
  appearance: none;
  border: 2px solid var(--muted);
  border-radius: 6px;
  background: var(--page) center / 16px no-repeat;
}
.check input:checked { border-color: var(--accent); background-color: var(--accent); display: grid; place-items: center; }
.check input:checked::after {
  content: "";
  width: 6px;
  height: 11px;
  margin-top: -2px;
  border: solid var(--accent-ink);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.media { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-bottom: 8px; }
.bubble { white-space: normal; }
.bubble-text { white-space: pre-wrap; margin-bottom: 8px; }
.preview-table { width: auto; min-width: 60%; }
.preview-table td, .preview-table th { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.preview-table th { color: var(--ink); font-weight: 600; }
.fake-button {
  margin-top: 6px;
  padding: 8px 12px;
  text-align: center;
  border-radius: 8px;
  background: var(--card);
  color: var(--link);
}
.numbers td:not(:first-child), .numbers th:not(:first-child) { text-align: right; padding-left: 12px; white-space: nowrap; }

/* --- страница проверки --- */
.guard { text-align: center; }
.guard .pictures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.guard .pictures button { font-size: 40px; min-height: 88px; background: var(--page); }
.guard .word { font-size: 22px; font-weight: 600; }

/* --- фирменный стиль: тёмно-синий, латунь, бордо --- */
.card { border-radius: 18px; }
.center { text-align: center; }
.icon { flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.button { border-radius: 14px; min-height: 48px; padding: 12px 16px; }
.with-icon { display: flex; align-items: center; justify-content: center; gap: 8px; }
.soft { background: var(--soft); color: var(--link); margin-bottom: 12px; }
button:not(:disabled):active, .button:active { transform: scale(0.98); }
button, .button { transition: transform 0.1s; }
.portrait { display: block; width: 112px; height: 112px; margin: 0 auto 12px; }

.channel { gap: 12px; border-radius: 18px; padding: 12px 14px; justify-content: flex-start; }
.channel-text { flex: 1; min-width: 0; }
.channel .name { display: block; margin-bottom: 2px; }
.avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: #ffffff;
  font-size: 20px;
  font-weight: 600;
}
.tint0 { background: #7B1E3A; }
.tint1 { background: #2F4A73; }
.tint2 { background: #1E6B4A; }
.tint3 { background: #4B3B73; }
.tint4 { background: #6B4E00; }
.badge { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; line-height: 1.3; }
.badge::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.good { color: var(--good); }
.badge.wait { color: var(--wait); }
.badge.bad { color: var(--bad); }
.channel-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.channel-head h1 { margin: 0; }


.sections { padding: 4px; border-radius: 14px; background: var(--soft); }
.sections button { border-radius: 11px; }
.choice { border-radius: 14px; }

#toast { border-radius: 14px; animation: rise 0.2s ease-out; z-index: 2; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }
@media (prefers-reduced-motion: reduce) {
  #toast { animation: none; }
  button, .button { transition: none; }
}

/* --- нижнее меню и мелочи новой системы --- */
main { padding-top: calc(16px + var(--safe-top)); }
main:has(.dm) { max-width: 560px; }
#tabs { justify-content: center; padding: 0 4px var(--safe-bottom); z-index: 1; }
#tabs button { position: relative; flex: 1; max-width: 136px; min-width: 0; min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 0; background: none; border-radius: 0; color: var(--muted); font-size: 12px; line-height: 16px; }
#tabs button[aria-current="page"] { color: var(--tab-active); font-weight: 600; }
#tabs button[aria-current="page"] .icon { stroke-width: 2.25; }
#tabs button[aria-current="page"]::before { content: ""; position: absolute; top: -1px; width: 24px; height: 2px; border-radius: 0 0 2px 2px; background: var(--gold); }
#toast { background: var(--text); color: var(--bg); }
.icon { stroke-width: 1.75; }
.portrait { border-radius: 50%; }
.switch { width: 52px; height: 44px; min-height: 44px; background: none !important; }
.switch::before { content: ""; position: absolute; inset: 6px 0; border-radius: 16px; background: var(--bar); transition: background 0.16s; }
.switch[aria-checked="true"]::before { background: var(--primary); }
.switch::after { top: 9px; background: var(--surface); }
.switch[aria-checked="true"]::after { background: var(--primary-ink); }
details summary { display: flex; align-items: center; min-height: 44px; padding: 0; }
.sections button[aria-selected="true"] { background: var(--surface); }
:focus-visible { outline-color: var(--text); }
::placeholder { color: var(--muted); opacity: 1; }

/* --- поля настроек --- */
.tight { margin-bottom: 4px; }
.fields { margin-top: 16px; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 4px; font-weight: 600; font-size: 14px; }
.field small { display: block; margin-top: 4px; }
.field input, .field textarea, .field select { margin-bottom: 0; }
select { appearance: none; padding-right: 40px !important; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%) !important; background-position: calc(100% - 20.5px) 50%, calc(100% - 15px) 50% !important; background-size: 6px 6px !important; background-repeat: no-repeat !important; }
[data-theme="dark"] { color-scheme: dark; }
[data-theme="light"] { color-scheme: light; }
select, input[type="time"] { width: 100%; min-height: 48px; font: inherit; color: inherit; background: var(--page); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
textarea.short { min-height: 72px; resize: none; field-sizing: content; }
.chip { border-radius: 12px; min-width: 44px; min-height: 44px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.field .chips { margin-top: 0; }
.pair > * { flex: 1; min-width: 0; }
.line { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.line input { margin-bottom: 0; }
.line .grow { flex: 1; min-width: 0; }
.line .small { display: grid; place-items: center; flex: none; width: 44px; padding: 0; border-radius: 12px; }
.answer { margin: 8px 0; padding: 8px 12px; border-radius: 12px; background: var(--page); white-space: pre-wrap; }
.decision .button { margin-top: 8px; }

/* --- защита чата --- */
.group { margin: 24px 0 8px; font-size: 16px; }
.tiles.four { grid-template-columns: 1fr 1fr; margin-bottom: 0; }
.card-error { margin: 12px 0 0; }
.entry { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.entry:first-child { padding-top: 0; }
.entry:last-child { padding-bottom: 0; border-bottom: 0; }
.entry .grow { flex: 1; min-width: 0; }
.entry .small { flex: none; border-radius: 12px; color: var(--link); }
.card-error .button { margin: 12px 0 0; }

/* --- панель владельца --- */
.head-mark { flex: none; width: 46px; height: 46px; border-radius: 50%; }
.tiles.two { grid-template-columns: 1fr 1fr; }
.tile .muted { font-size: 13px; line-height: 1.3; }
.funnel { margin-bottom: 12px; }
.funnel .row { gap: 8px; }
.funnel b { text-align: right; }
.funnel-bar { height: 8px; margin-top: 4px; border-radius: 4px; background: var(--fill); overflow: hidden; }
.funnel-bar i { display: block; height: 100%; border-radius: 4px; background: var(--bar-now); }
.card > textarea.short + small { display: block; margin-bottom: 12px; }
.card-error + .bubble, .button + div > .bubble { margin-top: 16px; }
.clip { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }

/* --- приветствие, правила, метки --- */
.fields > textarea + small { display: block; margin-bottom: 12px; }
.fields .button-row { margin-bottom: 8px; }
.fields .button-row .small { display: grid; place-items: center; width: 44px; padding: 0; border-radius: 12px; }
.tag { padding: 12px 0; border-bottom: 1px solid var(--line); }
.tag:first-child { padding-top: 0; }
.tag .pair { margin-top: 4px; }
.tag .pair .button { padding: 12px 4px; }
.fields > div > input[type="text"] { margin-top: 12px; }
.fields textarea { resize: none; field-sizing: content; }
.fields > div + p.muted { margin-top: 12px; }

/* --- аналитика: пара цветов проверена на различимость в обеих темах --- */
[data-theme="light"] { --flow-in: #3d63b8; --flow-out: #b0405f; }
[data-theme="dark"] { --flow-in: #4f86d9; --flow-out: #c98500; }
.chart .in { fill: var(--flow-in); }
.chart .out { fill: var(--flow-out); }
.chart g:hover .in, .chart g:hover .out, .chart g.active .in, .chart g.active .out { opacity: 0.78; }
.legend { display: flex; gap: 16px; margin-bottom: 8px; font-size: 14px; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 6px; border-radius: 3px; background: var(--flow-in); vertical-align: -1px; }
.legend .out::before { background: var(--flow-out); }
.chips.period { margin: 0 0 16px; }
.tag .line { margin: 4px 0 0; }
.tag .line input { flex: 1; min-width: 0; }
.tag .line .small { display: block; width: auto; padding: 8px 12px; }
.tag:last-child { border-bottom: 0; padding-bottom: 0; }
.cost-label { margin-top: 8px; }
.total { font-weight: 600; }

/* --- тарифы --- */
.plan-tag { display: inline-block; margin-left: 8px; padding: 1px 8px; border: 1px solid currentColor; border-radius: 8px; color: var(--muted); font-size: 12px; font-weight: 600; vertical-align: 1px; }
.plan-notice { border: 1px solid var(--danger); }
.price { font-size: 20px; font-weight: 600; }
.agree { display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; }
.agree input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.card .button + .button, .card .line + div > .button { margin-top: 8px; }
.card a.button.soft { margin-top: 8px; }
