:root {
  --bg: #f6f4ef;
  --bg-sunk: #ece8e0;
  --card: #fffdf9;
  --ink: #1b1a17;
  --ink-dim: #6c675e;
  --line: #e0dbd1;
  --me: #2f6f4f;
  --me-ink: #ffffff;
  --accent: #b07a2a;
  --bad: #a3382f;
  --warn: #a8771c;
  --radius: 16px;
  --bar: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
html.dark {
  --bg: #15161a;
  --bg-sunk: #0f1013;
  --card: #1e2026;
  --ink: #e9e6df;
  --ink-dim: #9a958c;
  --line: #2b2e36;
  --me: #2e6a4e;
  --me-ink: #f2fff8;
  --accent: #d9a24a;
  --bad: #d5564a;
  --warn: #d9a24a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overscroll-behavior: none;
}
/* внешний контейнер не скроллится — иначе первый свайп тянет шапку, а не ленту */
#root, .app { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-dim); margin: 18px 4px 8px; }
h2 .count { color: var(--bad); }
.muted { color: var(--ink-dim); padding: 8px 4px; }
.err { color: var(--bad); }

/* шапка непрозрачная: стекло в тёмной теме даёт двухцветный верх */
.bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.bar.sticky { position: sticky; top: 0; z-index: 5; }
.bar-title { flex: 1; min-width: 0; }
.bar-name { font-weight: 650; font-size: 17px; }
.bar-sub { font-size: 12px; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { font-size: 28px; line-height: 1; padding: 0 6px 4px; }
.auto { font-size: 20px; opacity: .5; }
.auto.on { opacity: 1; color: var(--me); }

.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 0 12px calc(96px + var(--safe-bottom)); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.card-top { display: flex; align-items: center; gap: 8px; }
.card-name { font-weight: 600; }
.card-time { margin-left: auto; font-size: 12px; color: var(--ink-dim); }
.badge { background: var(--bad); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.card-role { font-size: 12px; color: var(--ink-dim); }
.card-prev, .card-q, .card-step { font-size: 14px; margin-top: 6px; }
.card-prev { color: var(--ink-dim); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-q { color: var(--ink); }
.card-q.blocked { color: var(--bad); }
.card-step { color: var(--me); display: flex; align-items: center; gap: 8px; }
.card-actions { display: flex; gap: 8px; margin-top: 10px; }
.card-actions button, .row button, .wide { border: 1px solid var(--line); border-radius: 12px; padding: 7px 12px; background: var(--bg-sunk); }
.wide { width: 100%; margin: 4px 0 10px; padding: 12px; }
.row { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.row span { flex: 1; min-width: 0; }
.toggle.on { background: var(--me); color: var(--me-ink); border-color: transparent; }

.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--me); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: .35; transform: scale(.85); } 50% { opacity: 1; transform: scale(1.15); } }

.limits { display: flex; align-items: center; gap: 12px; padding: 12px 2px 4px; flex-wrap: wrap; }
.lim { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-dim); }
.meter { width: 64px; height: 6px; border-radius: 3px; background: var(--bg-sunk); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); }
.refresh { margin-left: auto; font-size: 18px; color: var(--ink-dim); }

.alert { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.alert.ok { border-left-color: var(--me); }
.alert.warn { border-left-color: var(--warn); }
.alert.bad { border-left-color: var(--bad); }
.alert-act { font-size: 13px; color: var(--ink-dim); margin-top: 4px; }

/* нижнее меню — плавающая стеклянная капсула */
.nav { position: fixed; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 10px); display: flex; justify-content: center; gap: 10px; pointer-events: none; z-index: 20; }
.capsule, .gear { pointer-events: auto; background: color-mix(in srgb, var(--card) 86%, transparent); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 6px 24px rgba(0,0,0,.12); }
.capsule { display: flex; padding: 4px; }
.capsule button { padding: 8px 14px; border-radius: 18px; font-size: 14px; color: var(--ink-dim); }
.capsule button.on { background: var(--bg-sunk); color: var(--ink); }
.gear { width: 44px; height: 44px; border-radius: 50%; font-size: 18px; }

.toast { position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-bottom) + 72px); background: var(--ink); color: var(--bg); border-radius: 14px; padding: 11px 14px; display: flex; gap: 12px; align-items: center; z-index: 40; }
.toast button { color: var(--accent); font-weight: 600; }
.offline { position: fixed; top: calc(var(--safe-top) + 4px); left: 50%; transform: translateX(-50%); background: var(--bad); color: #fff; font-size: 12px; padding: 3px 10px; border-radius: 10px; z-index: 50; }

.update { display: flex; gap: 10px; align-items: center; padding: 10px 12px; background: var(--bg-sunk); border-bottom: 1px solid var(--line); }
.update .note { font-size: 12px; color: var(--ink-dim); }
.update button { border: 1px solid var(--line); border-radius: 12px; padding: 7px 12px; }
.update .x { border: 0; color: var(--ink-dim); }
.inapp { position: fixed; top: calc(var(--safe-top) + 8px); left: 12px; right: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; z-index: 45; display: flex; flex-direction: column; box-shadow: 0 8px 28px rgba(0,0,0,.18); }
.inapp span { font-size: 13px; color: var(--ink-dim); }

.bind { align-items: center; justify-content: center; }
.bind-box { margin: auto; text-align: center; padding: 24px; max-width: 320px; }
.bind-box input { width: 100%; text-align: center; font-size: 28px; letter-spacing: .3em; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }

.msgs { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 6px; padding: 10px 12px 12px; }
/* во flex-колонке длинная лента сжимает пузыри в ноль */
.msgs > * { flex-shrink: 0; }

.bub { max-width: 84%; padding: 9px 12px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); align-self: flex-start; }
.bub.me { align-self: flex-end; background: var(--me); color: var(--me-ink); border-color: transparent; }
.bub.pending { opacity: .62; }
.bub-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bub-meta { font-size: 11px; opacity: .6; margin-top: 3px; display: flex; gap: 6px; justify-content: flex-end; }
.bub .src { font-weight: 600; }
.daymark, .divider { align-self: center; font-size: 11px; color: var(--ink-dim); padding: 6px 0; }
.divider { width: 100%; text-align: center; border-top: 1px solid var(--bad); color: var(--bad); margin-top: 8px; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.att-img img { max-width: 190px; border-radius: 12px; display: block; }
.att-file { font-size: 13px; text-decoration: none; color: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 5px 9px; }

.tray { display: flex; align-items: center; gap: 10px; padding: 7px 14px; background: var(--bg-sunk); border-bottom: 1px solid var(--line); font-size: 13px; }
.tray-step { flex: 1; min-width: 0; color: var(--ink-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray button { border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; }

.to-bottom { position: absolute; right: 14px; bottom: calc(96px + var(--safe-bottom)); background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 7px 12px; box-shadow: 0 4px 16px rgba(0,0,0,.14); }

.composer { flex: 0 0 auto; border-top: 1px solid var(--line); background: var(--bg); padding: 8px 10px calc(8px + var(--safe-bottom)); }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.ta-wrap { flex: 1; position: relative; }
.composer textarea { width: 100%; resize: none; border: 1px solid var(--line); border-radius: 18px; padding: 9px 34px 9px 12px; background: var(--card); max-height: 140px; }
.clear { position: absolute; right: 6px; bottom: 7px; width: 24px; height: 24px; border-radius: 50%; background: var(--bg-sunk); color: var(--ink-dim); font-size: 12px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; background: var(--bg-sunk); display: grid; place-items: center; font-size: 20px; }
.send { width: 38px; height: 38px; border-radius: 50%; background: var(--me); color: var(--me-ink); font-size: 18px; }
.send.busy { opacity: .5; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding-bottom: 6px; }
.chip { font-size: 12px; background: var(--bg-sunk); border-radius: 10px; padding: 4px 8px; }

.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 60; display: flex; align-items: flex-end; }
.sheet { width: 100%; background: var(--card); border-radius: 20px 20px 0 0; padding: 8px 12px calc(14px + var(--safe-bottom)); }
.sheet button { display: block; width: 100%; text-align: left; padding: 13px 6px; border-bottom: 1px solid var(--line); }
.sheet button.cancel { color: var(--ink-dim); border-bottom: 0; text-align: center; }

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

.bub-text { white-space: normal; }
.bub-text > div:empty { height: .5em; }
.bub-text pre { background: var(--bg-sunk); color: var(--ink); border-radius: 10px; padding: 8px 10px; overflow-x: auto; font-size: 13px; margin: 6px 0; }
.bub-text code { background: color-mix(in srgb, var(--bg-sunk) 70%, transparent); border-radius: 5px; padding: 1px 4px; font-size: .92em; }
.bub.me .bub-text pre, .bub.me .bub-text code { background: rgba(255,255,255,.16); color: inherit; }
.bub-text ul { margin: 4px 0; padding-left: 20px; }
.bub-text .md-h { font-weight: 650; margin-top: 6px; }
.bub-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* фоновая задача — не моя реплика, а служебная записка */
.bub.sys { align-self: center; max-width: 92%; background: transparent; border: 1px dashed var(--line); color: var(--ink-dim); font-size: 13px; }
.bub.me.sys { color: var(--ink-dim); }
