:root {
  --bg: #1f1f1f;
  --side: #181818;
  --surface: #252526;
  --surface-2: #2d2d2d;
  --hover: #2a2d2e;
  --active: #37373d;
  --border: #2b2b2b;
  --border-2: #3c3c3c;
  --text: #cccccc;
  --text-strong: #e7e7e7;
  --muted: #8b8b8b;
  --accent: #0e78d5;
  --accent-hover: #1a86e8;
  --accent-soft: rgba(14, 120, 213, 0.16);
  --danger: #f14c4c;
  --ok: #4ec9b0;
  --code-bg: #181818;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; height: 100dvh; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
body { overflow: hidden; overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: #4daafc; }
[hidden] { display: none !important; }
::selection { background: rgba(14, 120, 213, .45); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(121, 121, 121, .35); border: 2px solid transparent; background-clip: padding-box; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

.icon { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; color: var(--text); flex: none; transition: background .12s, color .12s; }
.icon-btn:hover { background: var(--hover); color: var(--text-strong); }
.icon-btn:active { background: var(--active); }
.icon-btn.active { color: #4daafc; }

.btn { height: 38px; padding: 0 16px; border-radius: 6px; background: var(--accent); color: #fff; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; transition: background .12s; }
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border-2); }
.btn.ghost:hover { background: var(--hover); color: var(--text-strong); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid rgba(241, 76, 76, .4); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }

.input, .textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--border-2); border-radius: 6px;
  padding: 8px 12px; outline: none; transition: border-color .15s; font-size: 14px;
}
.input:focus, .textarea:focus { border-color: var(--accent); }
.textarea {
  resize: none; min-height: 38px; max-height: 104px; line-height: 20px;
  overflow-y: hidden; font-family: inherit; box-sizing: border-box;
}
.textarea.scrollable { overflow-y: auto !important; }
.label { display: block; font-size: 11px; color: var(--muted); margin: 12px 0 4px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.4; }

/* Кастомный темный селект */
.custom-select {
  width: 100%; background: var(--surface); border: 1px solid var(--border-2); border-radius: 6px;
  padding: 8px 32px 8px 12px; outline: none; font-size: 14px; color: var(--text-strong);
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b8b8b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; cursor: pointer;
}
.custom-select:focus { border-color: var(--accent); }
.custom-select option { background: #252526; color: #e7e7e7; padding: 8px; }

/* ---------- auth ---------- */
.auth { height: 100%; display: grid; place-items: center; padding: 24px; overflow: auto; }
.auth-card { width: 100%; max-width: 380px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.brand-logo { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, #0e78d5, #3b9cff); display: grid; place-items: center; color: #fff; flex: none; box-shadow: 0 4px 16px rgba(14, 120, 213, .3); }
.brand h1 { margin: 0; font-size: 22px; color: var(--text-strong); font-weight: 600; letter-spacing: -.02em; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 8px; gap: 4px; }
.tab { flex: 1; padding: 10px 0; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; font-size: 14px; text-align: center; }
.tab.active { color: var(--text-strong); border-color: var(--accent); }
.auth form .btn { width: 100%; margin-top: 20px; height: 42px; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- layout ---------- */
.app { height: 100%; height: 100dvh; display: flex; overflow: hidden; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: min(86vw, 300px); background: var(--side);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 30;
  transform: translateX(-100%); transition: transform .22s cubic-bezier(0.16, 1, 0.3, 1); padding-top: var(--safe-t);
}
.sidebar.open { transform: none; box-shadow: 0 0 50px rgba(0, 0, 0, .6); }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 25; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.show { opacity: 1; pointer-events: auto; }
.side-head { display: flex; align-items: center; gap: 4px; padding: 10px 10px 6px; }
.side-head .title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); flex: 1; padding-left: 6px; }
.new-chat { margin: 4px 10px 8px; justify-content: flex-start; height: 36px; }
.chat-list { flex: 1; overflow-y: auto; padding: 0 6px 8px; }

.chat-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 8px 4px; display: flex; align-items: center; gap: 6px; }
.chat-section-title .icon { width: 13px; height: 13px; }

.chat-item {
  width: 100%; display: flex; align-items: center; gap: 6px; text-align: left; padding: 7px 8px; border-radius: 6px;
  color: var(--text); font-size: 14px; position: relative; margin-bottom: 1px;
}
.chat-item:hover { background: var(--hover); color: var(--text-strong); }
.chat-item.active { background: var(--active); color: var(--text-strong); }
.chat-item .name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13.5px; }
.chat-item .actions { display: none; align-items: center; gap: 2px; }
.chat-item:hover .actions, .chat-item.active .actions { display: flex; }
.chat-item .action-btn { width: 26px; height: 26px; border-radius: 4px; display: grid; place-items: center; color: var(--muted); }
.chat-item .action-btn:hover { color: var(--text-strong); background: rgba(255, 255, 255, .08); }
.chat-item .action-btn.pinned { color: #4daafc; }
.chat-item .action-btn.del:hover { color: var(--danger); }

.side-foot { border-top: 1px solid var(--border); padding: 10px 12px calc(10px + var(--safe-b)); display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 14px; flex: none; }
.side-foot .who { flex: 1; min-width: 0; }
.side-foot .who b { display: block; font-weight: 500; color: var(--text-strong); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-foot .who span { font-size: 11.5px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; height: 100dvh; overflow: hidden; }
.topbar {
  height: calc(50px + var(--safe-t)); padding: var(--safe-t) 8px 0; display: flex; align-items: center; gap: 4px;
  border-bottom: 1px solid var(--border); background: var(--bg); flex: none;
}
.crumbs { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; display: flex; align-items: center; }
.crumbs b { color: var(--text-strong); font-weight: 500; cursor: pointer; border-radius: 4px; padding: 2px 4px; transition: background .12s; }
.crumbs b:hover { background: var(--hover); }
.crumbs-input {
  background: var(--surface); border: 1px solid var(--accent); border-radius: 4px;
  padding: 2px 8px; color: var(--text-strong); font-size: 14px; font-weight: 500;
  outline: none; width: min(100%, 280px);
}

/* ---------- messages ---------- */
.messages { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }
.thread { max-width: 780px; margin: 0 auto; padding: 16px 14px 24px; }
.msg { margin: 0 0 22px; animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg.user .bubble {
  background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius);
  padding: 10px 14px; white-space: pre-wrap; word-wrap: break-word; color: var(--text-strong);
}
.msg.user .imgs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.msg.user .imgs img { width: 120px; height: 120px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border-2); cursor: zoom-in; }
.msg.assistant .content { word-wrap: break-word; overflow-wrap: anywhere; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.msg .meta button { color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px; border-radius: 4px; }
.msg .meta button:hover { color: var(--text); background: var(--hover); }
.tool-note { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin: 4px 0 8px; }
.tool-note .icon { width: 14px; height: 14px; }
.notice { font-size: 13px; color: #cca700; margin: 4px 0 8px; }
.msg.error .content { color: var(--danger); font-size: 14px; }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* markdown */
.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content p { margin: 0 0 12px; }
.content h1, .content h2, .content h3, .content h4 { color: var(--text-strong); margin: 18px 0 8px; line-height: 1.3; font-weight: 600; }
.content h1 { font-size: 20px; } .content h2 { font-size: 18px; } .content h3 { font-size: 16px; } .content h4 { font-size: 15px; }
.content ul, .content ol { margin: 0 0 12px; padding-left: 22px; }
.content li { margin: 3px 0; }
.content strong { color: var(--text-strong); font-weight: 600; }
.content code { font-family: var(--mono); font-size: 13px; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; color: #e2c08d; }
.content blockquote { margin: 0 0 12px; padding: 2px 12px; border-left: 3px solid var(--border-2); color: var(--muted); }
.content hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.content table { border-collapse: collapse; margin: 0 0 12px; display: block; overflow-x: auto; max-width: 100%; font-size: 14px; }
.content th, .content td { border: 1px solid var(--border-2); padding: 6px 10px; text-align: left; }
.content th { background: var(--surface); color: var(--text-strong); font-weight: 600; }
.codeblock { background: var(--code-bg); border: 1px solid var(--border-2); border-radius: 8px; margin: 0 0 12px; overflow: hidden; }
.codeblock .code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
.codeblock .code-head button { color: var(--muted); font-size: 12px; padding: 2px 6px; border-radius: 4px; }
.codeblock .code-head button:hover { background: var(--hover); color: var(--text); }
.codeblock pre { margin: 0; padding: 12px; overflow-x: auto; }
.codeblock code { background: none; padding: 0; color: #d4d4d4; font-size: 13px; line-height: 1.5; }

/* empty state — чистый и стильный */
.empty { min-height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 32px 18px; }
.empty .brand-logo { width: 56px; height: 56px; border-radius: 16px; margin-bottom: 18px; }
.empty .brand-logo .icon { width: 28px; height: 28px; }
.empty h2 { margin: 0 0 8px; font-size: 26px; color: var(--text-strong); font-weight: 600; letter-spacing: -.02em; }
.empty p { margin: 0; color: var(--muted); font-size: 14px; max-width: 380px; line-height: 1.5; }

/* ---------- composer ---------- */
.composer-wrap { padding: 6px 12px max(20px, calc(10px + var(--safe-b))); flex: none; background: var(--bg); }
.composer { max-width: 780px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border-2); border-radius: 12px; transition: border-color .15s; position: relative; }
.composer:focus-within { border-color: #4a4a4a; }
.attachments { display: flex; gap: 8px; padding: 8px 10px 0; flex-wrap: wrap; }
.attachments .thumb { position: relative; width: 60px; height: 60px; }
.attachments img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--border-2); }
.attachments .x { position: absolute; top: -5px; right: -5px; width: 20px; height: 20px; border-radius: 50%; background: #444; color: #fff; display: grid; place-items: center; font-size: 13px; line-height: 1; }

/* Поле ввода растет ровно до 4 строк (~96px), затем скролл */
.composer textarea {
  display: block; width: 100%; border: 0; outline: none; background: transparent; resize: none;
  padding: 10px 12px 2px; min-height: 42px; max-height: 100px; line-height: 20px; font-size: 15px;
  overflow-y: hidden;
}
.composer textarea.scrollable { overflow-y: auto; }
.composer textarea::placeholder { color: #6e6e6e; }

.composer-bar { display: flex; align-items: center; gap: 2px; padding: 2px 6px 6px; }
.composer-bar .icon-btn { width: 34px; height: 34px; color: var(--muted); }
.composer-bar .icon-btn:hover { color: var(--text-strong); }

.model-pick {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted);
  padding: 5px 8px; border-radius: 6px; min-width: 0; background: rgba(255, 255, 255, .03); border: 1px solid transparent;
}
.model-pick:hover, .model-pick.open { background: var(--hover); color: var(--text-strong); border-color: var(--border-2); }
.model-pick span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; font-weight: 500; }
.model-pick .icon { width: 13px; height: 13px; opacity: .7; }

.spacer { flex: 1; }
.send { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; transition: background .15s, opacity .15s; }
.send:hover { background: var(--accent-hover); }
.send:disabled { background: #333; color: #666; cursor: default; }
.send.stop { background: var(--text-strong); color: #1f1f1f; }
.send .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.rec { display: flex; align-items: center; gap: 8px; padding: 10px 12px 2px; min-height: 42px; color: var(--text); font-size: 14px; }
.rec .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
.rec .wave { flex: 1; height: 20px; display: flex; align-items: center; gap: 2px; overflow: hidden; }
.rec .wave i { width: 3px; border-radius: 2px; background: var(--accent); min-height: 3px; }
.mic.recording { color: var(--danger) !important; background: rgba(241, 76, 76, .12); }
.foot-note { max-width: 780px; margin: 4px auto 0; padding-bottom: 2px; text-align: center; font-size: 11px; color: #5a5a5a; }

/* ---------- Поповер выбора модели (лаконичный и чистый) ---------- */
.model-popover {
  position: absolute; bottom: 50px; left: 6px; width: min(92vw, 320px); background: #252526;
  border: 1px solid var(--border-2); border-radius: 12px; box-shadow: 0 16px 40px rgba(0, 0, 0, .7);
  z-index: 50; overflow: hidden; animation: popIn .15s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes popIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.model-popover-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.model-popover-list { padding: 6px; display: flex; flex-direction: column; gap: 4px; }

.model-item {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; border-radius: 8px;
  text-align: left; color: var(--text); transition: background .12s, border-color .12s; border: 1px solid transparent; background: transparent;
}
.model-item:hover { background: var(--hover); color: var(--text-strong); }
.model-item.active { background: rgba(14, 120, 213, 0.14); border-color: rgba(14, 120, 213, 0.35); color: var(--text-strong); }
.model-item .m-main { flex: 1; min-width: 0; }
.model-item .m-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.model-item .m-name { font-weight: 600; color: var(--text-strong); font-size: 13.5px; letter-spacing: -0.01em; }
.model-item .m-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.model-item .check { color: #4daafc; font-weight: 600; width: 18px; height: 18px; display: grid; place-items: center; flex: none; }

.badge { display: inline-flex; align-items: center; gap: 3px; font-size: 10.5px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); font-weight: 500; }
.badge.blue { background: var(--accent-soft); color: #4daafc; }

/* ---------- Полноэкранная страница профиля ---------- */
.profile-page {
  position: fixed; inset: 0; background: var(--bg); z-index: 45;
  display: flex; flex-direction: column; overflow: hidden; animation: fadeIn .18s ease;
}
.profile-page-head {
  height: calc(52px + var(--safe-t)); padding: var(--safe-t) 12px 0;
  display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border);
  background: var(--side); flex: none;
}
.profile-page-head h2 { margin: 0; font-size: 16px; font-weight: 600; color: var(--text-strong); flex: 1; }
.profile-page-body {
  flex: 1; overflow-y: auto; padding: 18px 16px calc(24px + var(--safe-b)); max-width: 680px; width: 100%; margin: 0 auto;
}
.profile-hero {
  display: flex; align-items: center; gap: 16px; padding: 16px; background: var(--surface);
  border: 1px solid var(--border-2); border-radius: 12px; margin-bottom: 16px;
}
.profile-hero-avatar {
  width: 64px; height: 64px; border-radius: 50%; background: linear-gradient(135deg, #0e78d5, #3b9cff);
  color: #fff; font-size: 26px; font-weight: 700; display: grid; place-items: center; flex: none;
  box-shadow: 0 4px 16px rgba(14, 120, 213, .35);
}
.profile-hero-info { flex: 1; min-width: 0; }
.profile-hero-info h3 { margin: 0 0 2px; font-size: 18px; font-weight: 600; color: var(--text-strong); }
.profile-hero-info span { color: var(--muted); font-size: 13px; display: block; }
.profile-hero-info .joined { font-size: 11.5px; color: #777; margin-top: 4px; }
.side-foot { cursor: pointer; transition: background .12s; border-radius: 8px; margin: 4px 6px max(14px, calc(4px + var(--safe-b))); }
.side-foot:hover { background: var(--hover); }

/* ---------- sheet (модалки) ---------- */
.sheet-scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-height: 90vh; background: var(--side); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 14px 14px 0 0; display: flex; flex-direction: column; animation: up .2s ease; padding-bottom: var(--safe-b);
}
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--border); gap: 8px; flex: none; }
.sheet-head h3 { margin: 0; flex: 1; font-size: 15px; font-weight: 600; color: var(--text-strong); }
.sheet-body { overflow-y: auto; padding: 12px 16px 20px; flex: 1; }
.sheet .tabs { padding: 0 16px; margin: 0; border-bottom: 1px solid var(--border); }
.sheet .tab { flex: 1; padding: 10px 8px; font-size: 13px; }

.list-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item .li-main { flex: 1; min-width: 0; font-size: 13.5px; }
.list-item .li-main b { color: var(--text-strong); font-weight: 500; }
.list-item .li-main small { color: var(--muted); font-size: 12px; display: block; margin-top: 2px; line-height: 1.4; }
.list-item .actions { display: flex; gap: 2px; }
.list-item .icon-btn { width: 30px; height: 30px; color: var(--muted); }
.list-item .icon-btn:hover { color: var(--text-strong); }
.add-row { display: flex; gap: 8px; margin: 10px 0 4px; }
.add-row .input { flex: 1; }

.switch { position: relative; width: 34px; height: 18px; flex: none; margin-top: 2px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 20px; background: #3c3c3c; transition: background .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: #ccc; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); background: #fff; }

.stat { display: flex; gap: 10px; margin: 4px 0 12px; }
.stat div { flex: 1; background: var(--surface); border: 1px solid var(--border-2); border-radius: 8px; padding: 10px 12px; }
.stat b { display: block; font-size: 18px; color: var(--text-strong); font-weight: 600; }
.stat span { font-size: 11.5px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%); background: #2d2d2d;
  color: var(--text-strong); padding: 8px 14px; border-radius: 6px; font-size: 13px; z-index: 60; max-width: 90vw;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4); animation: fade .15s; border: 1px solid var(--border-2); display: flex; align-items: center; gap: 8px;
}
.toast.err { border-color: rgba(241, 76, 76, .5); }
.toast .icon { width: 15px; height: 15px; }

.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .92); z-index: 70; display: grid; place-items: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.spinner { width: 16px; height: 16px; border: 2px solid rgba(255, 255, 255, .2); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  .sidebar { position: static; transform: none; box-shadow: none; width: 260px; flex: none; }
  .scrim { display: none; }
  .menu-btn { display: none !important; }
  .thread { padding: 24px 20px 32px; }
  .composer-wrap { padding: 6px 20px 14px; }
  .sheet-scrim { align-items: center; }
  .sheet { max-width: 540px; border-radius: 12px; border-bottom: 1px solid var(--border); max-height: 84vh; }
  .model-pick span { max-width: 200px; }
  .model-popover { left: 16px; }
}

/* Мобильный компактный режим */
@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .composer-wrap { padding: 6px 10px max(22px, calc(12px + var(--safe-b))); }
  .composer textarea { padding: 9px 10px 2px; font-size: 14.5px; }
  .composer-bar { padding: 2px 4px 4px; }
  .composer-bar .icon-btn { width: 32px; height: 32px; }
  .model-pick { padding: 4px 6px; font-size: 11.5px; }
  .model-pick span { max-width: 110px; }
  .model-popover { min-width: 280px; max-width: 320px; }
}

/* ---------- Profile Full-Page View ---------- */
.profile-page {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn .15s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.profile-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.profile-topbar h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-strong);
  flex: 1;
}

.profile-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}
.profile-container {
  max-width: 640px;
  margin: 0 auto;
}

.profile-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}
.avatar.lg {
  width: 56px;
  height: 56px;
  font-size: 22px;
  border-radius: 50%;
  background: #333;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  flex: none;
  border: 2px solid var(--accent);
}
.profile-hero-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.profile-hero-info h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-strong);
}
.profile-hero-sub {
  font-size: 13px;
  color: var(--muted);
}
.profile-hero-badge {
  font-size: 11px;
  color: #88c0d0;
  background: rgba(136, 192, 208, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
  width: fit-content;
  margin-top: 4px;
}

.profile-stat {
  margin-bottom: 14px;
}
.profile-tabs {
  margin-bottom: 16px;
}
.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-strong);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 10px;
}

/* Карточки моделей в профиле и поповере */
.models-selection-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.model-card-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: all .15s;
  text-align: left;
}
.model-card-item:hover {
  background: var(--panel);
  border-color: var(--accent);
}
.model-card-item.active {
  border-color: var(--accent);
  background: rgba(14, 120, 213, 0.08);
}
.model-card-item .m-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text-strong);
  font-size: 14px;
}
.model-card-item .badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
  background: #333;
  color: var(--text);
}
.model-card-item .badge.blue {
  background: rgba(14, 120, 213, 0.2);
  color: #70b7ff;
}
.model-card-item .desc {
  font-size: 12.5px;
  color: var(--text);
  margin-top: 4px;
  line-height: 1.4;
}
.model-card-item .pros-cons {
  font-size: 11.5px;
  color: #9cdcfe;
  margin-top: 4px;
  line-height: 1.35;
}
.model-card-item .pricing {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 4px;
}

/* Обновленный список моделей в поповере */
.model-popover {
  max-height: 420px;
  overflow-y: auto;
  min-width: 320px;
  max-width: 380px;
}
.model-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  background: none;
  border: none;
  width: 100%;
  cursor: pointer;
  border-radius: 6px;
}
.model-item:hover {
  background: var(--surface);
}
.model-item.active {
  background: rgba(14, 120, 213, 0.12);
}
.model-item .m-desc {
  font-size: 12px;
  color: var(--text);
  margin: 3px 0 2px;
  line-height: 1.35;
}
.model-item .m-pc {
  font-size: 11px;
  color: #9cdcfe;
  line-height: 1.3;
  margin-bottom: 3px;
}
