/* Буран AI — чат. Без фреймворков и встроенных стилей (строгий CSP). */
:root {
  --bg: #f2f6fb;
  --surface: #ffffff;
  --surface-2: #e8eff8;
  --text: #0b1a2e;
  --muted: #53647a;
  --border: #d3deeb;
  --accent: #1264d6;
  --accent-ink: #ffffff;
  --accent-soft: #e0ecff;
  --cta: #ff9a1f;
  --cta-ink: #1d1300;
  --ok: #11824a;
  --warn: #a86200;
  --err: #c62828;
  --shadow: 0 1px 2px rgb(11 26 46 / 6%), 0 10px 28px rgb(11 26 46 / 7%);
  --user-bubble: #e0ecff;
  --code-bg: #0b1a2e;
  --code-text: #e8eef8;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --side-w: 272px;
  --col: 780px;
  color-scheme: light;
}

/* Тёмная тема: по системе, пока тема не выбрана кнопкой (theme.js ставит data-theme), и явно — data-theme="dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #070d1a;
    --surface: #0f1829;
    --surface-2: #172338;
    --text: #e8eef8;
    --muted: #95a7c0;
    --border: #23314c;
    --accent: #5aa5ff;
    --accent-ink: #04101f;
    --accent-soft: #132746;
    --cta: #ffab3d;
    --cta-ink: #1d1300;
    --ok: #3ccf87;
    --warn: #f0b44c;
    --err: #ff6b6b;
    --shadow: 0 1px 2px rgb(0 0 0 / 35%), 0 10px 28px rgb(0 0 0 / 30%);
    --user-bubble: #1a2c4d;
    --code-bg: #050a14;
    --code-text: #e8eef8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #070d1a;
  --surface: #0f1829;
  --surface-2: #172338;
  --text: #e8eef8;
  --muted: #95a7c0;
  --border: #23314c;
  --accent: #5aa5ff;
  --accent-ink: #04101f;
  --accent-soft: #132746;
  --cta: #ffab3d;
  --cta-ink: #1d1300;
  --ok: #3ccf87;
  --warn: #f0b44c;
  --err: #ff6b6b;
  --shadow: 0 1px 2px rgb(0 0 0 / 35%), 0 10px 28px rgb(0 0 0 / 30%);
  --user-bubble: #1a2c4d;
  --code-bg: #050a14;
  --code-text: #e8eef8;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 var(--font); -webkit-text-size-adjust: 100%; overflow: hidden; }
a { color: var(--accent); text-underline-offset: 2px; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 .4em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- кнопки */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border: 1px solid var(--accent); border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn-block { width: 100%; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- экраны входа и загрузки */
.gate, .loading { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center; }
.gate-text { max-width: 420px; color: var(--muted); margin: 0 0 8px; }
.loading p { color: var(--muted); margin: 0; }

/* ---------- раскладка */
.app { display: flex; height: 100%; height: 100dvh; }
.sidebar { width: var(--side-w); flex: none; display: flex; flex-direction: column; gap: 8px; padding: 12px; background: var(--surface); border-right: 1px solid var(--border); overflow: hidden; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 35%); z-index: 30; }

.side-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 8px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; text-decoration: none; }
.side-close { display: none; }
.new-chat { justify-content: flex-start; }
.side-link { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 8px 10px; border: 0; border-radius: 10px; background: transparent; color: var(--text); text-align: left; text-decoration: none; cursor: pointer; font-size: .95rem; }
.side-link:hover, .side-link[aria-current="true"] { background: var(--surface-2); }
.chat-list { flex: 1; overflow-y: auto; margin: 4px -4px; padding: 0 4px; }
.chat-list .group { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; margin: 14px 8px 6px; }
.chat-item { display: flex; align-items: center; border-radius: 10px; }
.chat-item:hover, .chat-item[aria-current="true"] { background: var(--surface-2); }
.chat-item button.open { flex: 1; min-width: 0; padding: 9px 10px; border: 0; background: transparent; text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .93rem; }
.chat-item button.del { width: 32px; height: 32px; border: 0; background: transparent; color: var(--muted); border-radius: 8px; cursor: pointer; opacity: 0; }
.chat-item:hover button.del, .chat-item[aria-current="true"] button.del, .chat-item button.del:focus-visible { opacity: 1; }
.chat-item button.del svg { width: 16px; height: 16px; }
.side-foot { border-top: 1px solid var(--border); padding-top: 10px; display: grid; gap: 2px; }
.plan-card { padding: 6px 10px 8px; }
.plan-line { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: .95rem; }

/* ---------- верхняя панель */
.topbar { display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--bg); position: relative; z-index: 10; }
.menu-btn { display: none; }
.top-title { min-width: 0; flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.limits-badge { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); font-size: .88rem; cursor: pointer; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.dot.low { background: var(--warn); }
.dot.zero { background: var(--err); }
.limits-pop { position: absolute; right: 12px; top: 52px; width: min(320px, calc(100vw - 24px)); padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.limits-pop h2 { font-size: 1rem; margin: 0 0 10px; }
.limit { margin-bottom: 12px; }
.limit-top { display: flex; justify-content: space-between; font-size: .9rem; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 6px 0 4px; }
.bar > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .3s; }
.bar > span.low { background: var(--warn); }
.bar > span.zero { background: var(--err); }
.pop-actions { display: flex; gap: 8px; margin-top: 8px; }

.banner { margin: 10px auto 0; width: min(var(--col), calc(100% - 24px)); padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); font-size: .93rem; }
.banner.err { background: color-mix(in srgb, var(--err) 12%, var(--surface)); border-color: color-mix(in srgb, var(--err) 35%, transparent); }
.banner a { font-weight: 600; }

/* ---------- лента */
.chat-view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.scroller { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.messages { width: min(var(--col), calc(100% - 24px)); margin: 0 auto; padding: 20px 0 8px; display: flex; flex-direction: column; gap: 22px; }
.empty { width: min(560px, calc(100% - 32px)); margin: 12vh auto 0; text-align: center; }
.msg { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.msg-user { align-items: flex-end; }
.msg-user .bubble { max-width: min(85%, 640px); background: var(--user-bubble); padding: 10px 14px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg-user .atts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 85%; }
.msg-ai .body { overflow-wrap: anywhere; }
.msg-ai .body > :first-child { margin-top: 0; }
.msg-ai .body > :last-child { margin-bottom: 0; }
.msg-ai .body p, .msg-ai .body ul, .msg-ai .body ol, .msg-ai .body blockquote, .msg-ai .body pre, .msg-ai .body .table-wrap { margin: 0 0 .85em; }
.msg-ai .body h1, .msg-ai .body h2, .msg-ai .body h3, .msg-ai .body h4 { font-size: 1.1rem; margin: 1.1em 0 .5em; line-height: 1.3; }
.msg-ai .body h1 { font-size: 1.3rem; }
.msg-ai .body h2 { font-size: 1.18rem; }
.msg-ai .body ul, .msg-ai .body ol { padding-left: 1.4em; }
.msg-ai .body li { margin: .2em 0; }
.msg-ai .body li > ul, .msg-ai .body li > ol { margin: .2em 0; }
.msg-ai .body blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--muted); }
.msg-ai .body hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }
.msg-ai .body code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 6px; }
.msg-ai .body pre { background: var(--code-bg); color: var(--code-text); border-radius: 12px; overflow: hidden; }
.msg-ai .body pre code { display: block; padding: 12px 14px; background: none; color: inherit; overflow-x: auto; white-space: pre; font-size: .86rem; line-height: 1.5; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px 6px 14px; font: .78rem var(--mono); color: #9aabc2; border-bottom: 1px solid rgb(255 255 255 / 8%); }
.code-head button { border: 0; background: transparent; color: #9aabc2; font-size: .8rem; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.code-head button:hover { color: #fff; background: rgb(255 255 255 / 8%); }
.table-wrap { overflow-x: auto; }
.msg-ai .body table { border-collapse: collapse; font-size: .92rem; }
.msg-ai .body th, .msg-ai .body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.msg-ai .body th { background: var(--surface-2); }
.msg-ai .body .al-c { text-align: center; }
.msg-ai .body .al-r { text-align: right; }
a.cite { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 4px; margin: 0 1px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: .72rem; font-weight: 600; text-decoration: none; vertical-align: 2px; }
a.cite:hover { background: var(--accent-soft); color: var(--accent); }
.cursor::after { content: ""; display: inline-block; width: .5em; height: 1em; margin-left: 2px; vertical-align: -2px; background: currentColor; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { display: inline-flex; gap: 4px; padding: 6px 0; }
.thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.sources { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.source { flex: none; width: 200px; display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); text-decoration: none; font-size: .82rem; }
.source:hover { border-color: var(--accent); }
.source b { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.source span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source .n { color: var(--accent); font-weight: 700; }
.sources-label { font-size: .82rem; color: var(--muted); font-weight: 600; }

.msg-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; font-size: .8rem; color: var(--muted); }
.msg-foot button { border: 0; background: transparent; color: var(--muted); padding: 4px 6px; border-radius: 8px; cursor: pointer; font-size: .8rem; display: inline-flex; align-items: center; gap: 4px; }
.msg-foot button:hover { background: var(--surface-2); color: var(--text); }
.msg-foot svg { width: 15px; height: 15px; }
.msg-error { padding: 10px 14px; border-radius: 12px; background: color-mix(in srgb, var(--err) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--err) 30%, transparent); font-size: .93rem; }
.msg-info { padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); font-size: .93rem; }
.msg-error .actions, .msg-info .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.note { font-size: .82rem; color: var(--warn); }

/* ---------- вложения */
.att { display: inline-flex; align-items: center; gap: 8px; max-width: 240px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: .82rem; }
.att img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.att .ico { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; background: var(--surface-2); color: var(--muted); font: 700 .66rem var(--font); text-transform: uppercase; }
.att .meta { min-width: 0; display: flex; flex-direction: column; }
.att .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att .size { color: var(--muted); font-size: .74rem; }
.att button { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 2px; border-radius: 6px; }
.att button svg { width: 16px; height: 16px; }
.msg-user .att-img { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); }

/* ---------- поле ввода */
.composer { width: min(var(--col), calc(100% - 24px)); margin: 0 auto; padding: 8px 0 calc(10px + env(safe-area-inset-bottom)); }
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.composer-box { position: relative; display: flex; flex-direction: column; gap: 2px; padding: 10px 10px 8px 14px; border: 1px solid var(--border); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); }
.composer-box:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.composer textarea { width: 100%; min-height: 44px; max-height: 40vh; resize: none; border: 0; outline: none; background: transparent; color: var(--text); font: 16px/1.45 var(--font); padding: 4px 2px; }
.composer-tools { display: flex; align-items: center; gap: 6px; }
.attach-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); }
.mic-btn[aria-pressed="true"] { color: #fff; background: #e5484d; border-color: #e5484d; animation: mic-pulse 1.2s ease-in-out infinite; }
@keyframes mic-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, .45); } 50% { box-shadow: 0 0 0 7px rgba(229, 72, 77, 0); } }
@media (prefers-reduced-motion: reduce) { .mic-btn[aria-pressed="true"] { animation: none; } }
.model-picker { position: relative; margin-left: auto; min-width: 0; }
.model-btn { display: inline-flex; align-items: center; gap: 8px; max-width: min(280px, 52vw); height: 36px; padding: 0 10px 0 6px; border: 0; border-radius: 999px; background: var(--surface-2); color: var(--text); font: 600 .9rem var(--font); cursor: pointer; }
.model-btn:hover { background: color-mix(in srgb, var(--accent) 12%, var(--surface-2)); }
.model-btn:disabled { opacity: .6; cursor: default; }
.model-btn-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-btn .chev { width: 16px; height: 16px; color: var(--muted); }
.model-btn .mi { width: 24px; height: 24px; border-radius: 7px; font-size: .62rem; }
.model-btn .mi:empty { display: none; }

/* список моделей */
.model-menu { position: absolute; right: 0; bottom: calc(100% + 10px); z-index: 25; width: 340px; max-width: calc(100vw - 24px); display: flex; flex-direction: column; max-height: min(64vh, 560px); background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 12px 40px rgb(15 27 45 / 22%); overflow: hidden; }
.mm-search { padding: 10px 10px 6px; border-bottom: 1px solid var(--border); }
.mm-search input { width: 100%; height: 36px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); font: 400 .93rem var(--font); outline: none; }
.mm-search input:focus { border-color: var(--accent); }
.mm-list { overflow-y: auto; padding: 6px; overscroll-behavior: contain; }
.mm-sec { margin: 8px 8px 4px; padding-top: 8px; border-top: 1px solid var(--border); color: var(--muted); font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.mm-list > .mm-sec:first-child { border-top: 0; padding-top: 0; }
.mm-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 12px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.mm-item:hover, .mm-item:focus-visible { background: var(--surface-2); outline: none; }
.mm-item[aria-selected="true"] { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.mm-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mm-name { font-weight: 600; font-size: .93rem; line-height: 1.3; }
.mm-badge { margin-left: 4px; color: var(--muted); font-weight: 500; font-size: .82rem; white-space: nowrap; }
.mm-price { color: var(--accent); }
.mm-desc { color: var(--muted); font-size: .78rem; line-height: 1.3; margin-top: 1px; }
.mm-item.mm-down { cursor: not-allowed; }
.mm-item.mm-down .mm-name { color: var(--muted); }
.mm-item.mm-down .mi { opacity: .45; }
.mm-down-badge { color: #d9480f; }
.mm-check { width: 18px; flex: none; color: var(--accent); }
.mm-check svg { width: 18px; height: 18px; }
.mm-empty { margin: 14px; color: var(--muted); font-size: .9rem; text-align: center; }

/* значки моделей: свои монограммы и значки, не логотипы компаний */
.mi { width: 28px; height: 28px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; font: 800 .68rem/1 var(--font); letter-spacing: -.02em; color: #fff; background: var(--muted); }
.mi svg { width: 17px; height: 17px; stroke-width: 2.2; }
.mi-logo { position: relative; background: transparent; }
.mi-logo img { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; }
.mi-logo::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px rgb(15 27 45 / 9%); pointer-events: none; }
.fam-gpt { background: linear-gradient(135deg, #1fb88a, #0d7a5f); }
.fam-claude { background: linear-gradient(135deg, #e3926b, #c4623c); }
.fam-gemini { background: linear-gradient(135deg, #5b8def, #9b6bf0); }
.fam-grok { background: linear-gradient(135deg, #4a4f5c, #16181d); }
.fam-sonar { background: linear-gradient(135deg, #2fb5c4, #1a7f8f); }
.fam-kimi { background: linear-gradient(135deg, #3d3f8f, #1d1f52); }
.fam-glm { background: linear-gradient(135deg, #3a6df0, #1b3fa8); }
.fam-nemotron { background: linear-gradient(135deg, #8cc63f, #4f8a12); }
.fam-deepseek { background: linear-gradient(135deg, #5a7cf5, #2f4fcf); }
.fam-qwen { background: linear-gradient(135deg, #7b5cf0, #5136c4); }
.fam-other { background: linear-gradient(135deg, #8a97ab, #5b6b80); }
.mi-research { background: linear-gradient(135deg, #4aa8ff, #1160d6); }
.mi-labs { background: linear-gradient(135deg, #a07cf5, #6d3fd1); }
.mi-image { background: linear-gradient(135deg, #ff9a62, #f0567a); }
.mi-video { background: linear-gradient(135deg, #f0567a, #a83fd1); }
.mi-music { background: linear-gradient(135deg, #34c3a0, #2b7fd6); }

.send-btn { width: 40px; height: 40px; flex: none; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-ink); cursor: pointer; }
.send-btn:disabled { opacity: .4; cursor: default; }
.send-btn.stop { background: var(--text); color: var(--bg); }
.hint { text-align: center; margin: 6px 0 0; }
.drop-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--accent) 12%, transparent); border: 2px dashed var(--accent); border-radius: 16px; font-weight: 600; color: var(--accent); pointer-events: none; }

/* ---------- генерации в чате */
.media-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-bottom: 8px; font-size: .85rem; }
.media-opts .opt { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.media-opts select { height: 32px; padding: 0 26px 0 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); font: 600 .85rem var(--font); }
.media-opts .price { margin-left: auto; color: var(--muted); }
.media-progress { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 1px dashed var(--border); border-radius: 16px; background: var(--surface); }
.media-progress-text { display: flex; flex-direction: column; gap: 2px; }
.media-out { display: grid; gap: 12px; }
.media-item { display: grid; gap: 6px; justify-items: start; }
.media-item img { max-width: min(100%, 560px); max-height: 70vh; border-radius: 16px; border: 1px solid var(--border); background: var(--surface-2); object-fit: contain; }
.media-item video { width: min(100%, 640px); max-height: 70vh; border-radius: 16px; background: #000; }
.media-item audio { width: min(100%, 480px); }
.media-dl { display: inline-flex; align-items: center; gap: 4px; font-size: .8rem; color: var(--muted); text-decoration: none; padding: 2px 6px; border-radius: 8px; }
.media-dl:hover { color: var(--text); background: var(--surface-2); }
.media-dl svg { width: 15px; height: 15px; }
img[data-zoom] { cursor: zoom-in; }
img[data-zoom]:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- просмотр картинки */
.viewer { position: fixed; inset: 0; z-index: 70; background: rgb(5 10 20 / 94%); }
.viewer-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; cursor: zoom-out; user-select: none; -webkit-user-select: none; }
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: center center; will-change: transform; cursor: zoom-in; -webkit-user-drag: none; }
.viewer.zoomed .viewer-stage, .viewer.zoomed .viewer-stage img { cursor: grab; }
.viewer.zoomed .viewer-stage:active, .viewer.zoomed .viewer-stage:active img { cursor: grabbing; }
.viewer-bar { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px; display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 14px; background: rgb(0 0 0 / 55%); color: #fff; }
.viewer-pct { min-width: 48px; text-align: center; font-size: .85rem; font-variant-numeric: tabular-nums; opacity: .85; }
.viewer-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; color: #fff; cursor: pointer; }
.viewer-btn:hover { background: rgb(255 255 255 / 14%); }
.viewer-btn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); z-index: 60; font-size: .93rem; }
.toast.err { background: var(--err); color: #fff; }

/* ---------- телефон */
@media (max-width: 860px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(86vw, 320px); transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .side-close, .menu-btn { display: inline-flex; }
  .chat-item button.del { opacity: 1; }
  .limits-badge [data-limits-text] { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; }
  .model-menu { position: fixed; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); width: auto; max-width: none; max-height: 72vh; border-radius: 20px; }
  .mm-item { padding: 10px; }
  .media-opts .price { margin-left: 0; width: 100%; }
  .viewer-pct { display: none; }
  .messages { padding-top: 14px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* отметка в ленте: выше — пересказ, ниже модель видит дословно */
.ctx-note { display: flex; align-items: center; gap: 12px; margin: 6px 0; color: var(--muted); font-size: .8rem; text-align: center; }
.ctx-note::before, .ctx-note::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* сообщение с другого устройства: вложения не синхронизируются */
.att-omitted { align-self: flex-end; color: var(--muted); font-size: .78rem; }
.side-link[aria-pressed="true"] { color: var(--accent); }

