/* Штаб — mobile-first. Телефон первым, крупно и читаемо. */

:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #efefea;
  --surface-3: #e6e6e0;
  --text: #16171b;
  --muted: #676a72;
  --faint: #9a9ca3;
  --line: #e2e2dc;
  --accent: #3358d4;
  --accent-ink: #ffffff;
  --accent-soft: #e5ebfc;
  --hot: #dc3e42;
  --hot-soft: #fdeaea;
  --warn: #b86200;
  --warn-soft: #fdf0dc;
  --ok: #24864c;
  --ok-soft: #e2f3e8;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 4px 16px rgba(20, 20, 30, .05);
  --radius: 18px;
  --radius-s: 12px;
  --fs: 17px;
  --tabs-h: 62px;
  --top-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f12;
    --surface: #17191e;
    --surface-2: #1f2228;
    --surface-3: #2a2e36;
    --text: #eceef2;
    --muted: #a0a4ad;
    --faint: #6e727b;
    --line: #2a2d35;
    --accent: #7b96ff;
    --accent-ink: #0e0f12;
    --accent-soft: #1d2645;
    --hot: #ff6b70;
    --hot-soft: #3a1c1f;
    --warn: #ffb44a;
    --warn-soft: #36290f;
    --ok: #4cc782;
    --ok-soft: #12301f;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e0f12;
  --surface: #17191e;
  --surface-2: #1f2228;
  --surface-3: #2a2e36;
  --text: #eceef2;
  --muted: #a0a4ad;
  --faint: #6e727b;
  --line: #2a2d35;
  --accent: #7b96ff;
  --accent-ink: #0e0f12;
  --accent-soft: #1d2645;
  --hot: #ff6b70;
  --hot-soft: #3a1c1f;
  --warn: #ffb44a;
  --warn-soft: #36290f;
  --ok: #4cc782;
  --ok-soft: #12301f;
  --shadow: none;
  color-scheme: dark;
}

:root.big { --fs: 19.5px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs)/1.42 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg.i { width: 1.2em; height: 1.2em; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.22em; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- каркас ---------- */

#app { max-width: 720px; margin: 0 auto; min-height: 100dvh; }

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  min-height: calc(var(--top-h) + var(--safe-t));
  padding: var(--safe-t) 8px 0 16px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
}
.top h1 { flex: 1; margin: 0; font-size: 1.45em; font-weight: 750; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top.sub h1 { font-size: 1.12em; font-weight: 650; }
.top .back { margin-left: -10px; }
.top-actions { display: flex; align-items: center; gap: 2px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg.i { width: 24px; height: 24px; }
.spin svg.i { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.net { font-size: .72em; font-weight: 600; color: var(--warn); background: var(--warn-soft); padding: 4px 9px; border-radius: 99px; white-space: nowrap; }

main { padding: 4px 14px calc(var(--tabs-h) + var(--safe-b) + 28px); outline: none; }
.splash { display: grid; place-items: center; height: 60vh; color: var(--faint); font-weight: 700; font-size: 1.4em; }

.banner { margin: 0 14px 8px; padding: 10px 14px; border-radius: var(--radius-s); background: var(--warn-soft); color: var(--warn); font-size: .86em; font-weight: 550; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  padding: 0 4px var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--line);
}
.tabs a {
  position: relative; flex: 1; max-width: 140px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tabs-h); color: var(--faint); font-size: 11.5px; font-weight: 600; text-decoration: none;
}
.tabs a svg.i { width: 26px; height: 26px; }
.tabs a.on { color: var(--accent); }
.tabs .badge { position: absolute; top: 6px; left: calc(50% + 6px); }

.badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 99px; background: var(--hot); color: #fff; font-size: 12px; font-weight: 700; line-height: 1;
}
.badge.soft { background: var(--surface-3); color: var(--text); }

/* ---------- общие блоки ---------- */

.section-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 26px 4px 10px; }
.section-h h2 { margin: 0; font-size: .8em; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.section-h .more { font-size: .86em; font-weight: 600; }

.lead { margin: 2px 4px 14px; color: var(--muted); font-size: .95em; }
.lead b { color: var(--text); }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .big { font-size: 2.6em; margin-bottom: 6px; }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 1.15em; }

.list { display: flex; flex-direction: column; gap: 10px; }
.group { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 56px; padding: 12px 16px; border: 0; background: transparent; text-align: left; color: var(--text); text-decoration: none;
}
a.row:hover { text-decoration: none; }
.group .row + .row { border-top: 1px solid var(--line); }
.row:active { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; }
.row .s { color: var(--muted); font-size: .86em; margin-top: 2px; }
.row .chev { color: var(--faint); }
.row .ico { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--surface-2); flex: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 3px 10px; border-radius: 99px; background: var(--surface-2);
  font-size: .78em; font-weight: 650; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--faint)); flex: none; }
.chip.hot { background: var(--hot-soft); color: var(--hot); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }

.filters { display: flex; gap: 8px; overflow-x: auto; margin: 0 -14px 12px; padding: 2px 14px 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--surface); font-size: .88em; font-weight: 600; color: var(--muted);
}
.filters button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.filters .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--faint)); }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; font-size: .9em; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: var(--radius-s); border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--hot-soft); color: var(--hot); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn:active { transform: scale(.98); }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .82em; font-weight: 650; color: var(--muted); margin: 0 2px 6px; }
.input, textarea.input, select.input {
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: var(--radius-s);
  border: 1.5px solid var(--line); background: var(--surface); font-size: 1em; color: var(--text);
}
textarea.input { min-height: 110px; resize: vertical; line-height: 1.4; }
.input:focus { outline: none; border-color: var(--accent); }

/* ---------- карточка-вопрос ---------- */

.card {
  position: relative;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 16px 12px;
  transition: transform .28s ease, opacity .28s ease, max-height .32s ease, margin .32s ease, padding .32s ease;
  overflow: hidden;
}
.card.urgent { box-shadow: inset 4px 0 0 var(--hot), var(--shadow); }
.card.leaving { opacity: 0; transform: translateX(28px) scale(.98); }
.card.collapsed { max-height: 0 !important; padding-top: 0; padding-bottom: 0; margin: -5px 0; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.card .q { margin: 0; font-size: 1.16em; line-height: 1.32; font-weight: 680; letter-spacing: -.01em; cursor: pointer; overflow-wrap: anywhere; }
.card .ctx { margin: 6px 0 0; color: var(--muted); font-size: .92em; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .answer-line { margin-top: 8px; font-weight: 600; color: var(--ok); }

.opts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.opt {
  flex: 1 1 auto; min-width: calc(50% - 4px); min-height: 50px; padding: 10px 14px;
  border-radius: var(--radius-s); border: 1.5px solid var(--line); background: var(--surface);
  font-weight: 650; font-size: .98em; text-align: center; line-height: 1.25; color: var(--text);
  transition: transform .08s ease, background .15s ease;
}
.opt:active { transform: scale(.97); background: var(--surface-2); }
.opt.def { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.opt.def small { display: block; font-size: .72em; font-weight: 600; opacity: .8; }
.opt.own { color: var(--muted); border-style: dashed; font-weight: 600; }
.opt.long { min-width: 100%; text-align: left; }
.opt.chosen { background: var(--ok); border-color: var(--ok); color: #fff; }

.card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.link-btn { border: 0; background: transparent; color: var(--muted); font-weight: 600; font-size: .88em; padding: 10px 6px; min-height: 44px; }
.link-btn.accent { color: var(--accent); }
.link-btn:active { color: var(--text); }

/* компактная строка карточки (в «Ждёт», в чате) */
.mini { display: flex; gap: 10px; align-items: flex-start; }
.mini .flame { color: var(--hot); }

/* ---------- детальная карточка ---------- */

.detail { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 18px 8px; }
.detail .q { font-size: 1.32em; line-height: 1.28; font-weight: 750; margin: 6px 0 4px; letter-spacing: -.015em; overflow-wrap: anywhere; }
.kv { margin: 16px 0 0; }
.kv h4 { margin: 0 0 4px; font-size: .76em; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.kv div { white-space: pre-wrap; overflow-wrap: anywhere; }
.answer-box { margin-top: 18px; padding: 14px 16px; border-radius: var(--radius-s); background: var(--ok-soft); color: var(--ok); }
.answer-box b { display: block; color: var(--text); font-size: 1.08em; margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 10px; }
.actions .btn { flex: 1 1 auto; }

.history { margin: 0; padding: 0; list-style: none; }
.history li { position: relative; padding: 0 0 14px 22px; font-size: .88em; color: var(--muted); }
.history li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--surface-3); }
.history li::after { content: ""; position: absolute; left: 8.5px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.history li:last-child::after { display: none; }
.history b { color: var(--text); font-weight: 600; }

/* ---------- чаты ---------- */

.chat-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: block; color: var(--text); text-decoration: none !important; }
.chat-card + .chat-card { margin-top: 10px; }
.chat-card .head { display: flex; align-items: center; gap: 8px; }
.chat-card .title { flex: 1; font-weight: 680; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-card .when { color: var(--faint); font-size: .8em; white-space: nowrap; }
.chat-card .wait { margin-top: 8px; padding: 8px 12px; border-radius: 10px; background: var(--hot-soft); color: var(--hot); font-weight: 600; font-size: .92em; }
.chat-card .next { margin-top: 6px; color: var(--muted); font-size: .9em; }
.ctxbar { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: .78em; color: var(--muted); font-weight: 600; }
.ctxbar .bar { flex: 1; height: 6px; border-radius: 9px; background: var(--surface-2); overflow: hidden; }
.ctxbar .bar i { display: block; height: 100%; border-radius: 9px; background: var(--ok); }
.ctxbar.warn .bar i { background: var(--warn); }
.ctxbar.hot .bar i { background: var(--hot); }
.ctxbar.hot { color: var(--hot); }

.status-block { display: grid; gap: 10px; margin-top: 12px; }
.status-block > div { padding: 12px 14px; border-radius: var(--radius-s); background: var(--surface-2); }
.status-block h4 { margin: 0 0 3px; font-size: .74em; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.status-block .w { background: var(--hot-soft); }
.status-block .w h4, .status-block .w div { color: var(--hot); }

/* ---------- план дня ---------- */

.day-nav { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; }
.day-nav .d { flex: 1; text-align: center; font-weight: 700; }
.day-nav .d small { display: block; color: var(--muted); font-weight: 550; font-size: .78em; }
.check { display: flex; align-items: flex-start; gap: 14px; padding: 13px 16px; min-height: 56px; }
.group .check + .check { border-top: 1px solid var(--line); }
.check .box {
  flex: none; display: grid; place-items: center; width: 28px; height: 28px; margin-top: -1px;
  border-radius: 9px; border: 2px solid var(--faint); background: transparent; color: transparent; padding: 0;
}
.check.done .box { background: var(--ok); border-color: var(--ok); color: #fff; }
.check.done .t { color: var(--faint); text-decoration: line-through; }
.check .time { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; margin-right: 6px; }
.add-line { display: flex; gap: 8px; margin-top: 10px; }
.add-line .input { flex: 1; }
.add-line .btn { min-width: 52px; padding: 0 14px; }

/* ---------- тревоги, публикации, Канон ---------- */

.alert-card { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border-radius: var(--radius); padding: 14px 14px 14px 16px; box-shadow: var(--shadow); }
.alert-card + .alert-card { margin-top: 10px; }
.alert-card.crit { background: var(--hot-soft); }
.alert-card.warn { background: var(--warn-soft); }
.alert-card .lvl { font-size: 1.3em; line-height: 1.2; }
.alert-card .grow { flex: 1; min-width: 0; }
.alert-card .t { font-weight: 650; overflow-wrap: anywhere; }
.alert-card .s { font-size: .82em; color: var(--muted); margin-top: 3px; }
.alert-card.resolved { opacity: .6; }
.alert-card .btn { min-height: 40px; padding: 0 12px; font-size: .86em; }

.alerts-banner { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; padding: 12px 14px; border-radius: var(--radius); background: var(--hot-soft); color: var(--hot); font-weight: 650; text-decoration: none !important; }
.alerts-banner .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pub-status { border: 0; border-radius: 99px; padding: 6px 12px; min-height: 36px; font-weight: 700; font-size: .8em; white-space: nowrap; }
.pub-status.scheduled { background: var(--surface-2); color: var(--muted); }
.pub-status.published { background: var(--ok-soft); color: var(--ok); }
.pub-status.failed { background: var(--hot-soft); color: var(--hot); }

.dec-status { border: 0; background: var(--surface-2); border-radius: 10px; width: 44px; height: 44px; font-size: 1.25em; flex: none; }

.journal-entry { padding: 10px 16px; font-size: .88em; }
.group .journal-entry + .journal-entry { border-top: 1px solid var(--line); }
.journal-entry .when { color: var(--faint); font-size: .86em; }
.journal-entry .chg { color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }

/* ---------- поиск ---------- */

.search-box { position: sticky; top: calc(var(--top-h) + var(--safe-t)); z-index: 5; padding: 2px 0 10px; background: var(--bg); }
.search-box .input { padding-left: 44px; border-radius: 99px; }
.search-box svg.i { position: absolute; left: 15px; top: 17px; color: var(--faint); pointer-events: none; }
mark { background: color-mix(in srgb, var(--warn) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- лист снизу и всплывашки ---------- */

.sheet-bg { position: fixed; inset: 0; z-index: 60; background: rgba(8, 8, 12, .45); animation: fade .18s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; max-width: 720px; margin: 0 auto;
  max-height: 92dvh; overflow-y: auto;
  padding: 10px 18px calc(18px + var(--safe-b));
  border-radius: 22px 22px 0 0; background: var(--surface);
  animation: up .24s cubic-bezier(.2, .9, .3, 1);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--surface-3); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 4px; font-size: 1.15em; }
.sheet .sub { color: var(--muted); font-size: .9em; margin: 0 0 14px; }
.sheet .opts { margin: 0 0 14px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + var(--safe-b) + 12px); z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; max-width: 560px; width: 100%;
  padding: 12px 10px 12px 16px; border-radius: 14px; background: var(--text); color: var(--bg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); font-weight: 550; font-size: .94em; animation: up .22s ease;
}
.toast .grow { flex: 1; min-width: 0; }
.toast button { border: 0; background: transparent; color: var(--accent); font-weight: 800; padding: 8px 10px; min-height: 40px; filter: brightness(1.25); }
.toast.err { background: var(--hot); color: #fff; }
.toast.err button { color: #fff; }

/* ---------- вход ---------- */

.login { display: grid; place-items: center; min-height: 78dvh; text-align: center; }
.login img { width: 84px; height: 84px; border-radius: 20px; margin-bottom: 16px; }
.login h2 { margin: 0 0 6px; font-size: 1.6em; }
.login p { color: var(--muted); margin: 0 0 20px; }
.login form { width: min(420px, 100%); }

.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .86em; overflow-wrap: anywhere; }
.copy-box { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: var(--radius-s); background: var(--surface-2); margin: 6px 0 12px; }
.copy-box .mono { flex: 1; min-width: 0; }
.note { font-size: .86em; color: var(--muted); }
.prose { background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.prose p { margin: 0 0 10px; }
.prose ol, .prose ul { margin: 0 0 10px; padding-left: 20px; }
.prose li { margin-bottom: 4px; }

@media (min-width: 760px) {
  main { padding-left: 20px; padding-right: 20px; }
  .tabs { left: 50%; right: auto; transform: translateX(-50%); width: min(720px, 100%); border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; }
}

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