/* Архив чатов — Telegram Mini App.
   Цвета берутся из CSS-переменных темы Telegram (--tg-theme-*), их задаёт telegram-web-app.js.
   Вне Telegram — фолбэки для светлой/тёмной схемы (data-scheme ставит js/tg.js). */

:root {
  --bg: var(--tg-theme-secondary-bg-color, #f0f1f5);
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #0f1419);
  --hint: var(--tg-theme-hint-color, #6b7178);
  --subtitle: var(--tg-theme-subtitle-text-color, var(--hint));
  --link: var(--tg-theme-link-color, #2272c3);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --header-bg: var(--tg-theme-header-bg-color, var(--bg));
  --section-header: var(--tg-theme-section-header-text-color, #6b7178);
  --sep: var(--tg-theme-section-separator-color, rgba(60, 60, 67, 0.16));
  --destructive: var(--tg-theme-destructive-text-color, #d93838);
  --press: rgba(0, 0, 0, 0.05);
  --skel: rgba(0, 0, 0, 0.07);
  --skel-hi: rgba(0, 0, 0, 0.03);
  --overlay: rgba(0, 0, 0, 0.45);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);

  /* События */
  --c-del: #c92a2a;     --c-del-bg: rgba(224, 49, 49, 0.10);
  --c-edit: #a35c00;    --c-edit-bg: rgba(245, 159, 0, 0.14);
  --c-react: #c2255c;   --c-react-bg: rgba(230, 73, 128, 0.11);
  --c-profile: #5f3dc4; --c-profile-bg: rgba(112, 72, 232, 0.11);
  --c-story: #0b7a6b;   --c-story-bg: rgba(18, 184, 134, 0.12);
  --c-gift: #2b8a3e;    --c-gift-bg: rgba(64, 192, 87, 0.12);
  --c-ok: #2b8a3e;      --c-warn: #a35c00;  --c-bad: #c92a2a;  --c-muted: #6b7178;
  --diff-del-bg: rgba(224, 49, 49, 0.16);  --diff-del-fg: #a61e1e;
  --diff-ins-bg: rgba(64, 192, 87, 0.20);  --diff-ins-fg: #1f6f30;
  --mark-bg: #ffe066; --mark-fg: #1a1a1a;

  --radius: 12px;
  --gutter: 12px;
  --topbar-h: 52px;
  --tabbar-h: 58px;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --safe-top: var(--tg-content-safe-area-inset-top, 0px);
  color-scheme: light;
}

:root[data-scheme="dark"] {
  --bg: var(--tg-theme-secondary-bg-color, #0f0f10);
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c1c1e));
  --text: var(--tg-theme-text-color, #f2f2f5);
  --hint: var(--tg-theme-hint-color, #98989f);
  --link: var(--tg-theme-link-color, #6ab3f3);
  --accent: var(--tg-theme-button-color, #3e88f7);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --section-header: var(--tg-theme-section-header-text-color, #98989f);
  --sep: var(--tg-theme-section-separator-color, rgba(84, 84, 88, 0.55));
  --destructive: var(--tg-theme-destructive-text-color, #ff6b6b);
  --press: rgba(255, 255, 255, 0.06);
  --skel: rgba(255, 255, 255, 0.08);
  --skel-hi: rgba(255, 255, 255, 0.03);
  --overlay: rgba(0, 0, 0, 0.6);
  --shadow: none;

  --c-del: #ff8787;     --c-del-bg: rgba(255, 107, 107, 0.15);
  --c-edit: #ffc35c;    --c-edit-bg: rgba(255, 179, 71, 0.15);
  --c-react: #ff8fb8;   --c-react-bg: rgba(255, 122, 168, 0.15);
  --c-profile: #b1a4ff; --c-profile-bg: rgba(151, 135, 255, 0.17);
  --c-story: #4fe0c9;   --c-story-bg: rgba(61, 214, 192, 0.14);
  --c-gift: #77e08f;    --c-gift-bg: rgba(110, 224, 138, 0.14);
  --c-ok: #77e08f;      --c-warn: #ffc35c;  --c-bad: #ff8787;  --c-muted: #98989f;
  --diff-del-bg: rgba(255, 107, 107, 0.22); --diff-del-fg: #ffb3b3;
  --diff-ins-bg: rgba(110, 224, 138, 0.22); --diff-ins-fg: #b9f5c6;
  --mark-bg: #8a6d00; --mark-fg: #fff;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
a { color: var(--link); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
h1, h2, h3, p { margin: 0; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--section); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { left: 8px; }
.muted { color: var(--hint); }
.accent { color: var(--accent); }
[hidden] { display: none !important; }
.noscript { padding: 24px; text-align: center; }

/* ---------- Каркас ---------- */
.app { max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
@media (min-width: 600px) {
  body { background: color-mix(in srgb, var(--bg) 85%, var(--text) 4%); }
  .app { background: var(--bg); box-shadow: 0 0 0 1px var(--sep); }
}

.topbar {
  position: sticky; top: 0; z-index: 20;
  min-height: calc(var(--topbar-h) + var(--safe-top)); padding: var(--safe-top) 12px 0;
  display: flex; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--header-bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 0.5px solid var(--sep);
}
.topbar-title { font-size: 17px; font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 4px; }
.back-btn { margin-left: -6px; color: var(--link); }
.demo-badge { font-size: 11px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--hint); border: 1px solid var(--sep); border-radius: 6px; padding: 2px 6px; }

.source-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 52%;
  border: 0; background: var(--section); border-radius: 16px; padding: 6px 10px 6px 10px; min-height: 32px;
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow);
}
.source-chip.is-compact { padding: 0; width: 32px; justify-content: center; }
.source-chip.is-compact .status-dot { width: 10px; height: 10px; }
.source-chip-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-chip .icon { color: var(--hint); flex-shrink: 0; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; display: inline-block; background: var(--c-muted); }
.status-dot.tone-ok { background: #34c759; }
.status-dot.tone-warn { background: #ff9f0a; }
.status-dot.tone-bad { background: #ff3b30; }
.status-dot.tone-muted { background: #8e8e93; }

.view { flex: 1; padding: 8px 0 24px; }
body.has-tabbar .view { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); }
body.has-mainbtn .view { padding-bottom: calc(80px + var(--safe-bottom)); }
.screen { animation: fade-in .18s ease-out; }
.center-screen { min-height: 60vh; display: flex; align-items: center; justify-content: center; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; max-width: 560px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 4px 4px var(--safe-bottom);
  background: color-mix(in srgb, var(--section) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px);
  border-top: 0.5px solid var(--sep);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 50px; color: var(--hint); text-decoration: none; border-radius: 10px; }
.tab-label { font-size: 11px; font-weight: 500; }
.tab[aria-current="page"] { color: var(--accent); }
.tab:active { background: var(--press); }

.mainbtn-fallback { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; max-width: 560px; margin: 0 auto; padding: 10px 16px calc(10px + var(--safe-bottom)); background: color-mix(in srgb, var(--bg) 92%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 48px; padding: 12px 16px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 15px; text-decoration: none;
  transition: opacity .15s, transform .1s;
}
.btn:active:not(:disabled) { transform: scale(0.985); opacity: .9; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-inline { width: auto; min-height: 40px; padding: 8px 18px; }
.btn-small { width: auto; min-height: 34px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn-secondary { background: transparent; color: var(--link); box-shadow: inset 0 0 0 1px var(--sep); }
.btn-tonal { background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--link); }
.btn-danger-solid { background: #e03131; color: #fff; }
.link-btn { border: 0; background: none; color: var(--link); padding: 4px 2px; font-weight: 500; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; background: transparent; border-radius: 50%; color: var(--hint); flex-shrink: 0; }
.icon-btn:active { background: var(--press); }

/* ---------- Секции/строки (как в настройках Telegram) ---------- */
.section-wrap { margin: 0 var(--gutter) 18px; }
.section { background: var(--section); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.section.pad { padding: 14px 16px; }
.section-title { font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: .02em; color: var(--section-header); padding: 4px 16px 7px; }
.section-footer { font-size: 13px; color: var(--hint); padding: 7px 16px 0; line-height: 1.35; }
.section-empty { padding: 14px 16px; color: var(--hint); }

.row {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 46px; padding: 10px 16px; border: 0; background: transparent; text-align: left;
  color: var(--text); text-decoration: none;
}
.row + .row::before, .row + .switch-row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--sep); }
.row.has-left + .row::before, .section > .row.has-left + .row.has-left::before { left: 64px; }
a.row:active, button.row:active, label.row:active { background: var(--press); }
.row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-title.wrap { white-space: normal; overflow-wrap: anywhere; }
.row-subtitle { font-size: 13px; color: var(--subtitle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-value { color: var(--hint); font-size: 15px; text-align: right; flex-shrink: 0; max-width: 55%; overflow-wrap: anywhere; }
.row-chevron { color: var(--hint); opacity: .6; flex-shrink: 0; }
.row-icon, .src-icon { width: 32px; height: 32px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.src-icon.tone-ok { background: color-mix(in srgb, var(--c-ok) 16%, transparent); color: var(--c-ok); }
.src-icon.tone-warn { background: color-mix(in srgb, var(--c-warn) 16%, transparent); color: var(--c-warn); }
.src-icon.tone-bad { background: color-mix(in srgb, var(--c-bad) 16%, transparent); color: var(--c-bad); }
.src-icon.tone-muted { background: var(--press); color: var(--hint); }
.row.is-link .row-title { color: var(--link); }
.row.is-danger .row-title { color: var(--destructive); }
.row.is-selected { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.row-title-line, .row-subtitle-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.row-title-line .row-title { flex: 1; font-weight: 500; }
.row-time { font-size: 12px; color: var(--hint); flex-shrink: 0; }
.row-subtitle-line .row-subtitle { flex: 1; }
.kv-row .row-value { color: var(--text); }
.row-value.tone-text-ok { color: var(--c-ok); } .row-value.tone-text-bad { color: var(--c-bad); } .row-value.tone-text-warn { color: var(--c-warn); }
.row-value.tone-text-del { color: var(--c-del); } .row-value.tone-text-edit { color: var(--c-edit); }
.row-value.is-mono { font: 13px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; max-width: 62%; }
.field-row .row-body { gap: 2px; }

/* ---------- Поиск, чипы, сегменты ---------- */
.toolbar { padding: 4px var(--gutter) 10px; }
.search { position: relative; display: block; }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--hint); pointer-events: none; }
.search-input {
  width: 100%; height: 38px; border: 0; border-radius: 10px; padding: 0 12px 0 36px;
  background: var(--section); color: var(--text); font-size: 15px; box-shadow: var(--shadow);
  -webkit-appearance: none; appearance: none;
}
.search-input::placeholder { color: var(--hint); }
.search-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 var(--gutter) 10px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 5px 12px; border-radius: 16px; border: 0;
  background: var(--section); color: var(--text); font-size: 14px; font-weight: 500; box-shadow: var(--shadow);
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chip-dot.tone-del { background: var(--c-del); } .chip-dot.tone-edit { background: var(--c-edit); }
.chip-dot.tone-react { background: var(--c-react); } .chip-dot.tone-profile { background: var(--c-profile); }
.chip-dot.tone-story { background: var(--c-story); } .chip-dot.tone-gift { background: var(--c-gift); }
.chip[aria-pressed="true"] .chip-dot { background: var(--accent-text); }

.segmented { display: flex; width: 100%; background: var(--press); border-radius: 10px; padding: 2px; gap: 2px; }
.seg-btn { flex: 1; min-height: 32px; border: 0; border-radius: 8px; background: transparent; font-size: 13px; font-weight: 500; color: var(--text); padding: 4px 6px; }
.seg-btn[aria-checked="true"] { background: var(--section); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
:root[data-scheme="dark"] .seg-btn[aria-checked="true"] { background: color-mix(in srgb, var(--section) 70%, #fff 12%); }

/* ---------- Аватар ---------- */
.avatar {
  position: relative; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  border-radius: 50%; overflow: hidden; color: #fff; font-weight: 600; letter-spacing: .01em; user-select: none;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* ---------- Бейджи и тона ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; line-height: 1; padding: 4px 7px; border-radius: 7px; white-space: nowrap; }
.tone-del { --ev: var(--c-del); --ev-bg: var(--c-del-bg); }
.tone-edit { --ev: var(--c-edit); --ev-bg: var(--c-edit-bg); }
.tone-react { --ev: var(--c-react); --ev-bg: var(--c-react-bg); }
.tone-profile { --ev: var(--c-profile); --ev-bg: var(--c-profile-bg); }
.tone-story { --ev: var(--c-story); --ev-bg: var(--c-story-bg); }
.tone-gift { --ev: var(--c-gift); --ev-bg: var(--c-gift-bg); }
.tone-muted { --ev: var(--c-muted); --ev-bg: var(--press); }
.badge[class*="tone-"] { color: var(--ev); background: var(--ev-bg); }
.tone-text-del { color: var(--c-del); } .tone-text-edit { color: var(--c-edit); } .tone-text-react { color: var(--c-react); }
.tone-text-ok { color: var(--c-ok); } .tone-text-warn { color: var(--c-warn); } .tone-text-bad { color: var(--c-bad); }

/* ---------- Журнал ---------- */
.day-header { position: sticky; top: calc(var(--topbar-h) + var(--safe-top) + 6px); z-index: 5; display: flex; justify-content: center; margin: 8px 0 8px; pointer-events: none; }
.day-header span {
  font-size: 13px; font-weight: 600; color: var(--text); padding: 3px 10px; border-radius: 12px;
  background: color-mix(in srgb, var(--section) 85%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}
.card {
  position: relative; display: block; margin: 0 var(--gutter) 8px; padding: 12px 14px 12px 16px;
  background: var(--section); border-radius: var(--radius); color: var(--text); text-decoration: none;
  box-shadow: var(--shadow); overflow: hidden;
}
.ev-card::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: var(--ev, var(--sep)); }
a.card:active { background: color-mix(in srgb, var(--section) 94%, var(--text) 6%); }
.ev-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.ev-who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ev-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-sub { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ev-out { font-size: 12px; color: var(--hint); }
.ev-time { font-size: 12px; color: var(--hint); align-self: flex-start; padding-top: 2px; }
.ev-body { display: flex; flex-direction: column; gap: 8px; }
.ev-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.ev-meta { font-size: 13px; color: var(--hint); }
.ev-quote { margin: 0; padding: 4px 0 4px 10px; border-left: 2px solid var(--sep); color: var(--subtitle); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ev-reaction { display: flex; align-items: center; gap: 10px; }
.reaction-emoji { font-size: 26px; line-height: 1; width: 34px; text-align: center; flex-shrink: 0; }
.reaction-emoji.is-removed { opacity: .5; filter: grayscale(.8); }
.ev-profile { display: flex; flex-direction: column; gap: 2px; }
.ev-field { font-size: 13px; color: var(--hint); }
.ev-change, .tl-change { overflow-wrap: anywhere; }
.old { color: var(--hint); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--hint) 60%, transparent); }
.new { font-weight: 500; }
.arrow { color: var(--hint); }
.stars { color: var(--c-edit); font-weight: 600; }
.ev-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.before-after { display: flex; flex-direction: column; gap: 6px; }
.ba-row { display: grid; grid-template-columns: 52px 1fr; gap: 8px; align-items: baseline; }
.ba-label { font-size: 12px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .02em; }
.ba-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.diff del { background: var(--diff-del-bg); color: var(--diff-del-fg); text-decoration: line-through; border-radius: 3px; padding: 0 1px; }
.diff ins { background: var(--diff-ins-bg); color: var(--diff-ins-fg); text-decoration: none; border-radius: 3px; padding: 0 1px; }
mark { background: var(--mark-bg); color: var(--mark-fg); border-radius: 3px; padding: 0 1px; }

/* ---------- Медиа-превью ---------- */
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; }
.thumb { position: relative; width: 76px; height: 76px; border-radius: 10px; overflow: hidden; background: var(--press); flex-shrink: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-video_note { border-radius: 50%; }
.thumb-sticker { background: transparent; }
.thumb-sticker img { object-fit: contain; }
.thumb-play { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 28px; height: 28px; border-radius: 50%; background: rgba(0, 0, 0, .5); color: #fff; display: flex; align-items: center; justify-content: center; }
.thumb-dur { position: absolute; left: 4px; bottom: 4px; font-size: 11px; font-weight: 600; color: #fff; background: rgba(0, 0, 0, .55); padding: 1px 5px; border-radius: 6px; }
.thumb-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 6px 10px; border-radius: 10px; background: var(--press); color: var(--subtitle); }

/* ---------- Чат ---------- */
.chat-header { display: flex; align-items: center; gap: 10px; margin: 0 var(--gutter) 10px; padding: 10px 12px; background: var(--section); border-radius: var(--radius); box-shadow: var(--shadow); }
.chat-peer { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; border-radius: 10px; }
.chat-peer-body { min-width: 0; display: flex; flex-direction: column; }
.chat-peer-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-peer-sub { font-size: 13px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list, .journal-list { min-height: 40vh; }
.plist-items { display: flex; flex-direction: column; }
.chat-list .plist-items, .search-results .plist-items { padding: 0 var(--gutter); }

.bubble {
  position: relative; display: flex; flex-direction: column; gap: 6px; max-width: 86%; margin: 0 0 6px;
  padding: 8px 12px 6px; border-radius: 16px; background: var(--section); color: var(--text); text-decoration: none;
  box-shadow: var(--shadow); align-self: flex-start; border-bottom-left-radius: 6px;
}
.bubble.is-out { align-self: flex-end; border-bottom-left-radius: 16px; border-bottom-right-radius: 6px; background: color-mix(in srgb, var(--section) 86%, var(--accent) 14%); }
.bubble.is-deleted { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--c-del) 55%, transparent); }
.bubble.is-deleted .bubble-text { color: color-mix(in srgb, var(--text) 80%, var(--c-del)); }
.bubble:active { filter: brightness(.97); }
.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; font-size: 12px; color: var(--hint); }
.bubble-meta .badge { font-size: 11px; padding: 3px 6px; }
.bubble-chat { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--link); }
.plist-items > .day-header { align-self: stretch; }

.counters { display: inline-flex; gap: 4px; flex-shrink: 0; }
.counter { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 600; padding: 2px 6px; border-radius: 8px; color: var(--ev); background: var(--ev-bg); }

/* ---------- Экран сообщения ---------- */
.status-banner { display: flex; align-items: center; gap: 8px; margin: 0 var(--gutter) 10px; padding: 10px 14px; border-radius: var(--radius); color: var(--ev); background: var(--ev-bg); font-weight: 500; }
.msg-full { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.msg-full.is-deleted { box-shadow: inset 3px 0 0 var(--c-del); }
.msg-chat { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: var(--text); text-decoration: none; align-self: flex-start; }
.msg-text { font-size: 16px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.msg-date { font-size: 13px; color: var(--hint); }

.media-figure { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.media-figure figcaption { font-size: 12px; color: var(--hint); }
.media-img-btn { padding: 0; border: 0; background: var(--press); border-radius: 12px; overflow: hidden; display: block; width: 100%; }
.media-img-btn img { display: block; width: 100%; max-height: 60vh; object-fit: contain; }
.media-figure.is-sticker .media-img-btn { background: transparent; width: 160px; }
.media-video { position: relative; border-radius: 12px; overflow: hidden; background: #000; }
.media-video video { display: block; width: 100%; max-height: 60vh; }
.media-video.is-round { width: 220px; height: 220px; border-radius: 50%; align-self: center; }
.media-video.is-round video, .media-video.is-round img { width: 100%; height: 100%; object-fit: cover; }
.media-video-start { position: relative; display: block; width: 100%; padding: 0; border: 0; background: #000; }
.media-video-start img { display: block; width: 100%; max-height: 60vh; object-fit: cover; opacity: .92; }
.media-video.is-round .media-video-start { height: 100%; }
.media-video-blank { display: block; aspect-ratio: 16 / 9; }
.media-play-big { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 56px; height: 56px; border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff; display: flex; align-items: center; justify-content: center; }
.media-fallback { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 18px; color: #eee; font-size: 14px; background: #222; }
.media-fallback a { color: #8cc8ff; }
.media-audio { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--press); }
.media-audio-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--subtitle); }
.media-audio-icon { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: inline-flex; align-items: center; justify-content: center; }
.media-audio audio { width: 100%; height: 40px; }
.transcript { font-size: 14px; }
.transcript summary { cursor: pointer; color: var(--link); font-weight: 500; font-size: 13px; padding: 2px 0; }
.transcript p { margin-top: 4px; padding: 8px 10px; border-radius: 10px; background: var(--section); white-space: pre-wrap; font-style: italic; color: var(--subtitle); }
.media-doc { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--press); }
.media-doc-icon { width: 44px; height: 44px; border-radius: 10px; background: var(--accent); color: var(--accent-text); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.media-doc-ext { font-size: 11px; font-weight: 700; letter-spacing: .03em; }
.media-doc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.media-doc-title { font-weight: 500; }
.media-doc-meta { font-size: 12px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.timeline { list-style: none; margin: 0; padding: 12px 16px 6px; }
.tl-item { position: relative; display: flex; gap: 12px; padding-bottom: 14px; }
.tl-item::before { content: ""; position: absolute; left: 5px; top: 14px; bottom: -2px; border-left: 2px solid var(--sep); }
.tl-item.is-last::before, .tl-item:last-child::before { display: none; }
.tl-dot { width: 12px; height: 12px; margin-top: 4px; border-radius: 50%; background: var(--c-edit); flex-shrink: 0; box-shadow: 0 0 0 3px var(--section); z-index: 1; }
.tl-dot.tone-profile { background: var(--c-profile); }
.tl-item.is-last .tl-dot { background: var(--accent); }
.tl-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.tl-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--hint); }
.tl-label { font-weight: 600; color: var(--text); }
.tl-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.tl-day { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; color: var(--section-header); padding: 4px 0 8px 24px; }
.reaction-row .row-body { gap: 2px; }
.reaction-row .row-subtitle { white-space: normal; }

/* ---------- Профиль ---------- */
.profile-head { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 16px 18px; text-align: center; }
.profile-name { font-size: 22px; font-weight: 600; margin-top: 6px; overflow-wrap: anywhere; }
.profile-sub { color: var(--link); }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; }
.gallery-item { position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 8px; overflow: hidden; background: var(--press); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-item.is-removed img { filter: grayscale(.7) brightness(.85); }
.gallery-badge { position: absolute; top: 5px; left: 5px; display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; color: #fff; background: rgba(201, 42, 42, .9); padding: 2px 6px; border-radius: 6px; }
.gallery-badge.is-current { background: rgba(0, 0, 0, .55); }
.gallery-date { position: absolute; left: 0; right: 0; bottom: 0; font-size: 11px; color: #fff; padding: 12px 6px 4px; background: linear-gradient(transparent, rgba(0, 0, 0, .6)); text-align: left; }
.gallery-blank { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--hint); }

/* ---------- Настройки ---------- */
.switch-row { cursor: pointer; }
.switch-row .row-subtitle { white-space: normal; }
.switch {
  -webkit-appearance: none; appearance: none; flex-shrink: 0; position: relative;
  width: 51px; height: 31px; margin: 0; border-radius: 16px; background: color-mix(in srgb, var(--hint) 35%, transparent); cursor: pointer; transition: background .2s;
}
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .2); transition: transform .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { opacity: .5; cursor: default; }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.select {
  max-width: 60%; min-height: 34px; border: 0; border-radius: 8px; padding: 4px 28px 4px 10px; background-color: var(--press); color: var(--text); font-size: 14px;
  -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--hint) 50%), linear-gradient(135deg, var(--hint) 50%, transparent 50%);
  background-position: calc(100% - 14px) 55%, calc(100% - 9px) 55%; background-size: 5px 5px; background-repeat: no-repeat;
}
.warn-note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; font-size: 13px; line-height: 1.4; color: var(--c-warn); background: var(--c-edit-bg); }
.warn-note .icon { flex-shrink: 0; margin-top: 1px; }
.warn-note span { color: var(--text); }
.warn-note.is-danger { color: var(--c-del); background: var(--c-del-bg); border-radius: 12px; margin-bottom: 14px; }
.section-wrap.is-warn .warn-note + .row::before { display: none; }
.inline-error { margin: 0 var(--gutter) 14px; padding: 10px 14px; border-radius: 12px; background: var(--c-del-bg); color: var(--c-del); font-size: 14px; }
.sheet-body .inline-error { margin: 10px 0 0; }

/* ---------- Источник ---------- */
.status-card { display: flex; gap: 12px; align-items: flex-start; margin: 0 var(--gutter) 18px; padding: 14px 16px; border-radius: var(--radius); background: var(--section); box-shadow: var(--shadow); }
.status-card-icon { width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.status-card.tone-ok .status-card-icon { background: color-mix(in srgb, var(--c-ok) 16%, transparent); color: var(--c-ok); }
.status-card.tone-warn .status-card-icon { background: color-mix(in srgb, var(--c-warn) 16%, transparent); color: var(--c-warn); }
.status-card.tone-bad .status-card-icon { background: color-mix(in srgb, var(--c-bad) 16%, transparent); color: var(--c-bad); }
.status-card.tone-muted .status-card-icon { background: var(--press); color: var(--hint); }
.status-card-title { font-size: 17px; font-weight: 600; }
.status-card-text { color: var(--subtitle); font-size: 14px; margin-top: 2px; }
.actions-block { margin: 0 var(--gutter) 18px; }

/* ---------- Состояния ---------- */
.state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 40px 28px; }
.state-icon { width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); margin-bottom: 4px; }
.state-error .state-icon { background: var(--c-del-bg); color: var(--c-del); }
.state-title { font-size: 17px; font-weight: 600; }
.state-text { color: var(--hint); max-width: 340px; }
.state .btn { margin-top: 8px; }
.plist-footer { padding: 4px var(--gutter) 8px; }
.plist-more { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px; color: var(--hint); font-size: 14px; }
.plist-more.is-error { color: var(--c-del); flex-wrap: wrap; }
.plist-end { text-align: center; color: var(--hint); font-size: 13px; padding: 12px; }
.plist-sentinel { height: 1px; }

.skel { display: block; border-radius: 6px; background: linear-gradient(90deg, var(--skel) 25%, var(--skel-hi) 50%, var(--skel) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite linear; }
.skel-line { height: 12px; margin: 6px 0; }
.skel-avatar { width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; }
.skel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.skel-head .skel-line { margin: 0; }
.push { margin-left: auto !important; }
.w15 { width: 15%; } .w30 { width: 30%; } .w40 { width: 40%; } .w50 { width: 50%; } .w60 { width: 60%; } .w70 { width: 70%; } .w90 { width: 90%; }
.skeleton-list { padding-top: 6px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; }
.spinner-sm { width: 16px; height: 16px; border-width: 2px; }
.btn .spinner { border-color: color-mix(in srgb, var(--accent-text) 35%, transparent); border-top-color: var(--accent-text); }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { display: flex; justify-content: center; padding: 30vh 0; }

/* ---------- Шторка и диалоги ---------- */
dialog { color: var(--text); }
dialog::backdrop { background: var(--overlay); }
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 88vh;
  background: var(--bg); border-radius: 16px 16px 0 0; overflow: auto; animation: sheet-in .22s ease-out;
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 16px; max-width: 480px; } }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; gap: 8px; padding: 12px 8px 8px 16px; background: var(--bg); z-index: 1; }
.sheet-title { flex: 1; font-size: 17px; font-weight: 600; }
.sheet-body { padding: 4px 16px calc(20px + var(--safe-bottom)); }
.sheet-body > .section { margin-bottom: 4px; }
.sheet-text { color: var(--subtitle); margin-bottom: 14px; line-height: 1.45; }
.sheet-actions { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { display: block; font-size: 14px; color: var(--subtitle); margin-bottom: 6px; }
.field .field-label { margin-bottom: 0; }
.field-hint { font-size: 12px; color: var(--hint); margin-top: 6px; }
.text-input { width: 100%; height: 44px; border-radius: 10px; border: 1px solid var(--sep); background: var(--section); padding: 0 12px; font-size: 16px; letter-spacing: .04em; }
.text-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.export-status:empty { display: none; }
.export-status { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--section); }
.export-line { display: flex; align-items: center; gap: 10px; }
.export-line.is-done { color: var(--c-ok); }
.export-line.is-error { color: var(--c-del); }
.export-line span { color: var(--text); }
.lightbox { padding-bottom: 20px; }
.lightbox-img { display: block; width: 100%; max-height: 75vh; object-fit: contain; border-radius: 12px; background: var(--press); }

.dialog { border: 0; border-radius: 14px; padding: 20px 20px 12px; width: min(340px, calc(100% - 32px)); background: var(--section); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.dialog-title { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.dialog-text { color: var(--subtitle); line-height: 1.45; white-space: pre-wrap; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 4px; margin-top: 16px; }
.dialog-btn { border: 0; background: none; color: var(--link); font-weight: 600; padding: 10px 12px; border-radius: 8px; min-width: 64px; }
.dialog-btn:active { background: var(--press); }
.dialog-btn.is-cancel { font-weight: 500; }
.dialog-btn.is-danger { color: var(--destructive); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px); z-index: 50;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100% - 32px); background: rgba(28, 28, 30, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Согласие ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
@media (max-width: 360px) {
  :root { --gutter: 8px; }
  .source-chip { max-width: 46%; }
  .ba-row { grid-template-columns: 1fr; gap: 2px; }
}
