:root {
  --bg: #f5f4ee;
  --surface: #fffefb;
  --surface-2: #f0eee6;
  --border: #e6e3d8;
  --border-strong: #d6d2c4;
  --text: #1f1e1c;
  --muted: #6e6c64;
  --faint: #a7a498;
  --accent: #c96442;
  --accent-hover: #b4552f;
  --accent-soft: #f5e6dd;
  --accent-text: #a8502f;
  --green: #5b8a4f;
  --green-soft: #e4eedb;
  --red: #b4473a;
  --red-soft: #f6e0db;
  --blue: #5f86ad;
  --blue-soft: #e1eaf3;
  --sand: #c49a52;
  --plum: #9a6f93;
  --radius: 16px;
  --radius-sm: 10px;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(31, 30, 28, .04), 0 4px 14px rgba(31, 30, 28, .035);
  --tabbar-h: 64px;
}
[data-theme="dark"] {
  --bg: #262624;
  --surface: #30302e;
  --surface-2: #2a2a28;
  --border: #3e3d39;
  --border-strong: #4c4b46;
  --text: #f4f2ea;
  --muted: #aaa79c;
  --faint: #75736a;
  --accent: #d97757;
  --accent-hover: #e48a6b;
  --accent-soft: #48322a;
  --accent-text: #f0ae92;
  --green: #8fbf83;
  --green-soft: #2f3c2b;
  --red: #e5897c;
  --red-soft: #4a2c27;
  --blue: #8fb1d4;
  --blue-soft: #2b3642;
  --shadow: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); }
a { color: var(--accent-text); text-decoration: none; }
.app { max-width: 760px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; letter-spacing: -.015em; margin: 0; }
h1 { font-size: 30px; line-height: 1.15; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
.hidden { display: none !important; }

/* ---------- шапка страницы ---------- */
.page-head { display: flex; align-items: center; gap: 10px; padding: 20px 0 6px; }
.page-head .grow { min-width: 0; }
.page-head .eyebrow { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; cursor: pointer;
  padding: 16px 0 0; border: 0; background: none; font-family: var(--sans); }
.back-link:hover { color: var(--text); }
.logo { width: 18px; height: 18px; fill: var(--accent); flex: none; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; color: var(--muted); flex: none; transition: .15s; }
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 30px 2px 12px; }
.section-title .sub { font-size: 13px; color: var(--muted); }

/* ---------- нижние вкладки ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); }
.tabbar-inner { max-width: 760px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); height: var(--tabbar-h); }
.tabbar button { border: 0; background: none; color: var(--faint); font: 500 11px var(--sans); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; cursor: pointer; transition: color .15s; }
.tabbar button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--accent); }

/* ---------- базовые блоки ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card.flat { box-shadow: none; background: var(--surface-2); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h3 { font-size: 18px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt { margin-top: 12px; }
.mt2 { margin-top: 20px; }
.num { font-family: var(--serif); font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 30px 16px; font-family: var(--serif); font-size: 16px; }
.empty .tiny { font-family: var(--sans); margin-top: 6px; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }

/* ---------- сегменты, чипы, селекты ---------- */
.seg { display: flex; gap: 2px; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  overflow-x: auto; scrollbar-width: none; margin-top: 14px; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: 1 0 auto; border: 0; background: none; color: var(--muted); font: 500 13.5px var(--sans); padding: 7px 12px;
  border-radius: 9px; cursor: pointer; white-space: nowrap; transition: .15s; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.filters { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.pill-select { position: relative; flex: none; }
.pill-select select { appearance: none; -webkit-appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: 500 13.5px var(--sans); padding: 8px 30px 8px 13px; border-radius: 999px; cursor: pointer; width: auto; max-width: 230px; }
.pill-select.on select { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.pill-select::after { content: ""; position: absolute; right: 13px; top: 50%; width: 6px; height: 6px; border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted); transform: translateY(-70%) rotate(45deg); pointer-events: none; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--muted); padding: 6px 12px; border-radius: 999px;
  font: 500 13px var(--sans); cursor: pointer; white-space: nowrap; transition: .15s; }
.chip.active { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.chip.off { opacity: .45; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 500; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; line-height: 1.5; }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.badge.green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.badge.red { background: var(--red-soft); color: var(--red); border-color: transparent; }
.badge.blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 16px; }
@media (min-width: 600px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 14px 12px;
  box-shadow: var(--shadow); position: relative; overflow: hidden; min-height: 112px; display: flex; flex-direction: column; }
.kpi .label { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.kpi .value { font-family: var(--serif); font-size: 30px; line-height: 1.1; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 16px; color: var(--muted); margin-left: 3px; }
.kpi .sub { font-size: 12px; color: var(--faint); margin-top: auto; padding-top: 4px; }
.kpi .spark { position: absolute; right: 0; bottom: 0; left: 0; height: 26px; opacity: .9; pointer-events: none; }
.kpi:has(.spark) { padding-bottom: 30px; }
.kpi.hero { grid-column: 1 / -1; background: linear-gradient(135deg, var(--accent-soft), var(--surface) 75%); border-color: transparent;
  flex-direction: row; align-items: center; gap: 16px; min-height: 0; padding: 18px; }
.kpi.hero .value { font-size: 42px; color: var(--accent-text); }
.delta { font: 600 11.5px var(--sans); padding: 1px 6px; border-radius: 6px; white-space: nowrap; align-self: flex-start; }
.delta.up { color: var(--green); background: var(--green-soft); }
.delta.down { color: var(--red); background: var(--red-soft); }
.delta.flat { color: var(--faint); background: var(--surface-2); }
.ring { width: 76px; height: 76px; flex: none; }

/* ---------- графики ---------- */
.chart-wrap { position: relative; margin-top: 4px; }
.chart-wrap svg { display: block; width: 100%; overflow: visible; }
.chart-wrap .axis { font: 10.5px var(--sans); fill: var(--faint); }
.chart-tip { position: absolute; top: 0; pointer-events: none; background: var(--text); color: var(--bg); border-radius: 10px;
  padding: 8px 10px; font-size: 12.5px; line-height: 1.5; white-space: nowrap; transform: translateX(-50%); opacity: 0; transition: opacity .12s; z-index: 2; }
.chart-tip.show { opacity: 1; }
.chart-tip b { font-weight: 600; }
.chart-tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

.heat { display: grid; grid-template-columns: 22px repeat(24, 1fr); gap: 2px; font-size: 10px; color: var(--faint); }
.heat .c { aspect-ratio: 1; border-radius: 3px; background: var(--accent); }
.heat .c.z { background: var(--surface-2); }
.heat .lbl { display: flex; align-items: center; }
.heat .hl { text-align: center; }
.heat-scale { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--faint); margin-top: 10px; justify-content: flex-end; }
.heat-scale span { width: 12px; height: 12px; border-radius: 3px; background: var(--accent); }

.cols { display: flex; align-items: flex-end; gap: 8px; height: 130px; margin-top: 8px; }
.cols .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.cols .col b { font: 500 13px var(--serif); }
.cols .col i { display: block; width: 100%; max-width: 46px; background: var(--accent); border-radius: 6px 6px 3px 3px; min-height: 3px; transition: height .5s ease; }
.cols .col:nth-child(n+4) i { background: color-mix(in srgb, var(--accent) 55%, var(--surface-2)); }
.cols-labels { display: flex; gap: 8px; margin-top: 6px; }
.cols-labels span { flex: 1; text-align: center; font-size: 10.5px; color: var(--muted); line-height: 1.25; }

.hbar { padding: 7px 0; }
.hbar-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; margin-bottom: 5px; }
.track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.track > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .6s ease; }
.track.green > i { background: var(--green); }
.track.thin { height: 5px; }

/* ---------- воронка ---------- */
.funnel { display: flex; flex-direction: column; gap: 4px; }
.f-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 0; align-items: center; }
.f-row + .f-row { border-top: 1px dashed var(--border); }
.f-label { font-size: 14px; }
.f-val { text-align: right; font-family: var(--serif); font-size: 18px; font-variant-numeric: tabular-nums; }
.f-val small { font-family: var(--sans); font-size: 12px; color: var(--muted); margin-left: 4px; }
.f-bar { grid-column: 1 / -1; height: 26px; border-radius: 8px; background: var(--surface-2); position: relative; overflow: hidden; }
.f-bar i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #f0b49b));
  border-radius: 8px; transition: width .6s ease; }
.f-drop { grid-column: 1 / -1; font-size: 12px; color: var(--faint); }

/* ---------- таблица-список ---------- */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; cursor: pointer; transition: background .12s; }
.item + .item { border-top: 1px solid var(--border); }
.item:hover { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.item:active { background: var(--surface-2); }
.item .title { font-weight: 500; }
.item .meta { font-size: 12.5px; color: var(--muted); }
.item .stat { text-align: right; flex: none; }
.item .stat b { display: block; font: 500 19px var(--serif); font-variant-numeric: tabular-nums; }
.item .stat span { font-size: 11.5px; color: var(--muted); }
.avatar { width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center; font: 500 16px var(--serif);
  background: var(--accent-soft); color: var(--accent-text); }
.avatar.lg { width: 54px; height: 54px; font-size: 22px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: right; font-weight: 500; color: var(--muted); font-size: 11.5px; padding: 0 6px 8px; white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; padding-left: 0; }
.tbl td { text-align: right; padding: 10px 6px; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.tbl .name { font-weight: 500; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl .conv { color: var(--accent-text); font-weight: 600; }
.scroll-x { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }

.feed-item { display: flex; gap: 12px; padding: 11px 16px; font-size: 14px; cursor: pointer; }
.feed-item + .feed-item { border-top: 1px solid var(--border); }
.ev-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--faint); }
.ev-dot.accent { background: var(--accent); }
.ev-dot.green { background: var(--green); }
.ev-dot.red { background: var(--red); }
.ev-dot.blue { background: var(--blue); }

/* ---------- сценарии ---------- */
.sc-card { cursor: pointer; transition: border-color .15s, transform .15s; }
.sc-card:hover { border-color: var(--border-strong); }
.sc-card:active { transform: scale(.995); }
.sc-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.sc-stats b { display: block; font: 500 20px var(--serif); font-variant-numeric: tabular-nums; }
.sc-stats span { font-size: 11.5px; color: var(--muted); }
.title-input { font: 500 26px var(--serif); letter-spacing: -.015em; border: 0; background: transparent; padding: 2px 0; width: 100%;
  color: var(--text); border-bottom: 1px dashed transparent; border-radius: 0; box-shadow: none !important; }
.title-input:focus { border-bottom-color: var(--border-strong); background: transparent; }

.timeline { position: relative; padding-left: 30px; margin-top: 6px; }
.timeline::before { content: ""; position: absolute; left: 11px; top: 14px; bottom: 30px; width: 2px; background: var(--border); border-radius: 2px; }
.tl-gap { position: relative; display: flex; align-items: center; gap: 8px; padding: 10px 0; min-height: 44px; }
.tl-gap .delay { font-size: 12.5px; color: var(--muted); background: var(--bg); padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); }
.tl-gap .delay.wait { color: var(--accent-text); border-color: var(--accent-soft); background: var(--accent-soft); }
.tl-gap .insert { margin-left: auto; width: 28px; height: 28px; border-radius: 50%; border: 1px dashed var(--border-strong); background: var(--bg);
  color: var(--muted); cursor: pointer; font-size: 17px; line-height: 1; opacity: .7; transition: .15s; }
.tl-gap .insert:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }
.tl-step { position: relative; }
.tl-node { position: absolute; left: -30px; top: 16px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font: 600 12px var(--sans); box-shadow: 0 0 0 4px var(--bg); }
.tl-step.off .tl-node { background: var(--faint); }
.tl-step.off .card { opacity: .62; }
.step-card { cursor: pointer; padding: 14px 16px; transition: border-color .15s; }
.step-card:hover { border-color: var(--border-strong); }
.step-text { font-size: 14px; color: var(--text); margin-top: 8px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.step-media { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); background: var(--surface-2);
  padding: 4px 9px; border-radius: 8px; margin-top: 8px; max-width: 100%; }
.step-btns { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.step-btn { font-size: 12.5px; padding: 4px 10px; border-radius: 8px; background: var(--blue-soft); color: var(--blue); font-weight: 500; }
.step-btn.pay { background: var(--green-soft); color: var(--green); }
.step-btn.next { background: var(--accent-soft); color: var(--accent-text); }
.step-stats { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }
.step-stats b { color: var(--text); font-weight: 600; }

.fstep { padding: 14px 0; }
.fstep + .fstep { border-top: 1px dashed var(--border); }
.fstep-head { display: flex; gap: 10px; align-items: baseline; }
.fstep-n { width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); font: 600 11.5px var(--sans);
  display: grid; place-items: center; flex: none; }
.fstep-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.fstep-metrics div { background: var(--surface-2); border-radius: 10px; padding: 7px 9px; }
.fstep-metrics b { display: block; font: 500 17px var(--serif); font-variant-numeric: tabular-nums; }
.fstep-metrics span { font-size: 11px; color: var(--muted); }
.btn-stat { display: flex; justify-content: space-between; font-size: 12.5px; padding: 5px 0 0; color: var(--muted); gap: 8px; }

/* ---------- формы ---------- */
label.field { display: block; margin-top: 16px; }
label.field > span, .field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
input, textarea, select { width: 100%; font: 15px var(--sans); color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
textarea { min-height: 140px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.hint { font-size: 12px; color: var(--faint); margin-top: 6px; line-height: 1.45; }
.input-row { display: flex; gap: 8px; }
.input-row > * { flex: 1; min-width: 0; }
.input-row > .narrow { flex: 0 0 110px; }

.switch-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; cursor: pointer; }
.switch-row + .switch-row { border-top: 1px solid var(--border); }
.switch-row .grow b { font-weight: 500; display: block; font-size: 14.5px; }
.switch-row .grow span { font-size: 12.5px; color: var(--muted); }
.switch { position: relative; width: 42px; height: 25px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; background: var(--border-strong); border-radius: 99px; transition: .2s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 19px; height: 19px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: .2s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(17px); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: 500 14.5px var(--sans); padding: 10px 16px; border-radius: var(--radius-sm); cursor: pointer; transition: .15s; white-space: nowrap; }
.btn:hover { border-color: var(--border-strong); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.dark { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.actions .btn { flex: 1; }
.actions.sticky { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); margin-bottom: -32px; z-index: 2; }

.link-box { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 6px 6px 12px; font: 13px var(--mono); }
.link-box span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- редактор сообщения ---------- */
.fmt-bar { display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: 6px; }
.fmt-bar button { border: 0; background: var(--surface-2); color: var(--muted); min-width: 32px; height: 30px; padding: 0 9px; border-radius: 8px;
  cursor: pointer; font: 600 13px var(--sans); }
.fmt-bar button:hover { color: var(--text); background: var(--border); }
.counter { text-align: right; }
.counter.over { color: var(--red); }
.media-pick { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px dashed var(--border-strong); border-radius: 12px; background: var(--surface-2); }
.media-ico { width: 42px; height: 42px; border-radius: 10px; background: var(--accent-soft); display: grid; place-items: center; font-size: 19px; flex: none; }
.media-lib { margin-top: 8px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.media-lib .item { padding: 10px 12px; }
.media-lib .item.sel { background: var(--accent-soft); }
.media-lib-head { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); align-items: center; }
.btn-edit { display: grid; grid-template-columns: 110px 1fr; gap: 6px; padding: 10px; background: var(--surface-2); border-radius: 12px; margin-top: 8px; }
.btn-edit .full { grid-column: 1 / -1; }
.btn-edit .tools { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 4px; }
.btn-edit input, .btn-edit select { padding: 8px 10px; font-size: 14px; }

.tg-preview { background: #d5e3cf url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Ccircle cx='10' cy='10' r='1.5' fill='%23ffffff' fill-opacity='.35'/%3E%3Ccircle cx='40' cy='35' r='1' fill='%23ffffff' fill-opacity='.3'/%3E%3C/svg%3E");
  border-radius: 14px; padding: 16px 14px; }
[data-theme="dark"] .tg-preview { background-color: #1c2a22; }
.tg-msg { background: #fff; color: #000; border-radius: 14px 14px 14px 4px; max-width: 88%; overflow: hidden; box-shadow: 0 1px 1px rgba(0, 0, 0, .08); font: 14.5px/1.42 -apple-system, "Segoe UI", Roboto, sans-serif; }
[data-theme="dark"] .tg-msg { background: #2b3a31; color: #f2f2f2; }
.tg-msg .tg-media { background: linear-gradient(135deg, #e9e4d8, #d9d1c0); height: 130px; display: grid; place-items: center; font-size: 36px; color: #8a8270; }
.tg-msg .tg-media.doc { height: auto; display: flex; gap: 10px; padding: 10px 12px 0; background: none; font-size: 13.5px; color: inherit; place-items: unset; align-items: center; }
.tg-msg .tg-media.doc span { width: 40px; height: 40px; border-radius: 50%; background: #5aa9e6; display: grid; place-items: center; color: #fff; font-size: 18px; flex: none; }
.tg-msg .tg-media.round { width: 150px; height: 150px; border-radius: 50%; margin: 10px auto; }
.tg-msg .tg-text { padding: 8px 12px 9px; word-wrap: break-word; }
.tg-msg .tg-text:empty { display: none; }
.tg-msg .tg-text a { color: #2a7fc4; }
.tg-msg .tg-text code { font-family: var(--mono); font-size: 13px; background: rgba(0, 0, 0, .06); padding: 0 3px; border-radius: 4px; }
.tg-msg .tg-text tg-spoiler, .tg-msg .tg-text .tg-spoiler { background: #b9b9b9; color: transparent; border-radius: 3px; }
.tg-msg .tg-text blockquote { margin: 4px 0; padding-left: 9px; border-left: 3px solid #5aa9e6; }
.tg-msg .tg-text .var { background: #fff3c4; border-radius: 3px; padding: 0 2px; }
[data-theme="dark"] .tg-msg .tg-text .var { background: #5b4b1d; }
.tg-btns { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; max-width: 88%; }
.tg-btns span { background: rgba(70, 90, 70, .35); color: #fff; text-align: center; padding: 8px; border-radius: 10px; font: 500 14px -apple-system, "Segoe UI", Roboto, sans-serif;
  backdrop-filter: blur(4px); }

/* ---------- выезжающая панель ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(20, 20, 18, .38); opacity: 0; pointer-events: none; transition: .22s; z-index: 30; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px 18px 32px; transform: translateY(102%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); z-index: 31;
  max-width: 760px; margin: 0 auto; overscroll-behavior: contain; }
.sheet.open { transform: translateY(0); }
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: var(--border-strong); margin: 4px auto 12px; }
.sheet h2 { font-size: 23px; }

.tl-ev { display: flex; gap: 10px; padding: 9px 0; font-size: 14px; }
.tl-ev + .tl-ev { border-top: 1px solid var(--border); }
.tl-ev .time { color: var(--faint); font-size: 12px; min-width: 86px; padding-top: 1px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); transform: translate(-50%, 16px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; transition: .22s;
  pointer-events: none; z-index: 50; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.skeleton { height: 96px; border-radius: var(--radius); margin-top: 14px;
  background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }
.fade { animation: fade .28s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.live { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 60%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
