/* ===== Дизайн-система: графит, крупные скругления, синий акцент ===== */
:root {
  --bg: #0a0a0b;
  --sidebar: #0e0e10;
  --card: #151517;
  --card-2: #1b1b1e;
  --card-3: #222226;
  --line: #26262b;
  --line-soft: #1d1d21;
  --text: #f4f4f5;
  --text-2: #b4b4bb;
  --muted: #74747c;
  --accent: #5b7cff;
  --accent-hover: #6f8cff;
  --accent-soft: rgba(91, 124, 255, .14);
  --orange: #ff9f43;
  --orange-soft: rgba(255, 159, 67, .14);
  --red: #ff5d5d;
  --red-soft: rgba(255, 93, 93, .13);
  --green: #3fd08f;
  --green-soft: rgba(63, 208, 143, .13);
  --violet: #9d8cff;
  --violet-soft: rgba(157, 140, 255, .14);
  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 10px 30px rgba(0,0,0,.35);
  color-scheme: dark;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv11", "ss01";
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 14.5px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
.hidden { display: none !important; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
::selection { background: var(--accent-soft); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--card-3); border-radius: 99px; border: 3px solid transparent; background-clip: padding-box; }

/* ---- кнопки и поля ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--card-2); cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--card-3); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.light { background: var(--text); border-color: var(--text); color: #0a0a0b; }
.btn.light:hover { background: #fff; }
.btn.danger { color: var(--red); }
.btn.ghost { background: none; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--card-2); color: var(--text); }
.btn.wide { width: 100%; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.round-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--card-3); display: inline-grid; place-items: center; cursor: pointer; color: var(--text); transition: background .15s; }
.round-btn:hover { background: #2c2c31; }
.round-btn.light { background: var(--text); color: #0a0a0b; }
.round-btn.light:hover { background: #fff; }
.round-btn:disabled { opacity: .4; cursor: default; }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; border: 0; background: none; display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--card-3); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--text-2); }
.input { height: 44px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--card-2); outline: none; width: 100%; transition: border-color .15s; }
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; color: var(--text-2); cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---- метки (как Medium / SaaS) ---- */
.tag { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 500; background: var(--card-3); color: var(--text-2); white-space: nowrap; }
.tag.orange { background: var(--orange-soft); color: var(--orange); }
.tag.red { background: var(--red-soft); color: var(--red); }
.tag.green { background: var(--green-soft); color: var(--green); }
.tag.blue { background: var(--accent-soft); color: var(--accent); }
.tag.violet { background: var(--violet-soft); color: var(--violet); }

/* ---- карточки ---- */
.card { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-lg); padding: 20px; box-shadow: var(--shadow); }
.card h3 { margin: 0; font-size: 16px; font-weight: 600; }
.card .sub { color: var(--muted); font-size: 13px; }
.ring { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 17px; flex: none; background: conic-gradient(var(--text) var(--p, 75%), rgba(255,255,255,.12) 0); position: relative; }
.ring::after { content: ""; position: absolute; inset: 2px; border-radius: 50%; background: var(--card); }
.ring > * { position: relative; z-index: 1; }

/* ===================== ПРИЛОЖЕНИЕ ===================== */
.app { display: grid; grid-template-columns: 272px 1fr; height: 100dvh; }

/* ---- боковая панель ---- */
.sidebar { background: var(--sidebar); border-right: 1px solid var(--line-soft); display: flex; flex-direction: column; padding: 18px 14px 14px; gap: 14px; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand .logo-full { height: 28px; width: 98px; color: var(--text); flex: none; }
.brand .grow { flex: 1; }
.brand b { font-size: 16px; font-weight: 600; flex: 1; letter-spacing: -.01em; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, #5b7cff, #9d8cff); font-size: 13px; font-weight: 600; color: #fff; flex: none; }
.search { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 12px; border-radius: var(--r-sm); background: var(--card); border: 1px solid var(--line-soft); color: var(--muted); }
.search input { border: 0; background: none; outline: none; flex: 1; min-width: 0; color: var(--text); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 12px; height: 38px; padding: 0 12px; border-radius: 10px; border: 0; background: none; color: var(--text-2); cursor: pointer; text-align: left; width: 100%; }
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--card-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.nav-item .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.divider { height: 1px; background: var(--line-soft); margin: 2px 4px; }
.section-label { font-size: 12px; color: var(--muted); padding: 0 12px; display: flex; align-items: center; justify-content: space-between; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 60px; margin: 0 -4px; padding: 0 4px; }
.conv { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 6px 0 12px; border-radius: 10px; cursor: pointer; color: var(--text-2); font-size: 14px; }
.conv:hover { background: var(--card); color: var(--text); }
.conv.active { background: var(--card-2); color: var(--text); }
.conv .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--orange); flex: none; }
.conv .icon-btn { width: 28px; height: 28px; visibility: hidden; }
.conv:hover .icon-btn { visibility: visible; }
.side-card { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-md); padding: 16px; display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden; }
.side-card::before { content: ""; position: absolute; inset: -40% -30% auto auto; width: 160px; height: 160px; background: radial-gradient(circle, rgba(91,124,255,.22), transparent 70%); pointer-events: none; }
.side-card b { font-size: 15px; }
.side-card p { margin: 0; color: var(--muted); font-size: 13px; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 4px 4px 0; }
.user-row .who { flex: 1; min-width: 0; }
.user-row .who div { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row .who small { color: var(--muted); font-size: 12px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- основная область ---- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; height: 60px; padding: 0 28px; border-bottom: 1px solid var(--line-soft); flex: none; }
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; min-width: 0; }
.crumbs b { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page { flex: 1; overflow-y: auto; padding: 28px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -.02em; flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; }
.page-head h1 .folder { width: 34px; height: 28px; border-radius: 6px; background: linear-gradient(180deg, #6d8bff, #3f5fe6); position: relative; flex: none; }
.page-head h1 .folder::before { content: ""; position: absolute; left: 0; top: -5px; width: 14px; height: 8px; border-radius: 3px 3px 0 0; background: #6d8bff; }
.page-head p { width: 100%; margin: -6px 0 0; color: var(--muted); }

/* ---- чат ---- */
.messages { flex: 1; overflow-y: auto; padding: 28px 28px 12px; display: flex; flex-direction: column; gap: 22px; }
.messages > * { width: 100%; max-width: 800px; margin-left: auto; margin-right: auto; }
.msg-user { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.msg-user .bubble { background: var(--card-2); border: 1px solid var(--line); padding: 12px 16px; border-radius: 18px 18px 6px 18px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-ai { display: flex; gap: 14px; }
/* Сфера по центру первой строки текста (строка ≈ 22.5px, сфера 28px) */
.msg-ai > .orb { margin-top: -3px; }
.msg-ai .body > div:empty { display: none; }
.msg-ai .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }

.md { overflow-wrap: anywhere; color: #e8e8ea; }
.md > :first-child { margin-top: 0; }
.md p { margin: 0 0 .75em; }
.md h1, .md h2, .md h3 { margin: 1.2em 0 .5em; line-height: 1.3; letter-spacing: -.01em; color: var(--text); }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.05em; }
.md ul, .md ol { padding-left: 1.3em; margin: 0 0 .75em; }
.md li { margin: .2em 0; }
.md strong { color: var(--text); }
.md table { border-collapse: separate; border-spacing: 0; margin: .5em 0 1em; display: block; overflow-x: auto; width: max-content; max-width: 100%; border: 1px solid var(--line); border-radius: var(--r-sm); }
.md th, .md td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line-soft); }
.md tr:last-child td { border-bottom: 0; }
.md th { background: var(--card-2); font-weight: 600; font-size: 13px; color: var(--text-2); }
.md code { background: var(--card-2); padding: 2px 6px; border-radius: 6px; font-size: .88em; }
.md pre { background: var(--card); border: 1px solid var(--line-soft); padding: 14px; border-radius: var(--r-sm); overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md blockquote { margin: 0 0 .75em; padding: 2px 0 2px 14px; border-left: 2px solid var(--accent); color: var(--text-2); }
.md hr { border: 0; height: 1px; background: var(--line); margin: 1.2em 0; }

.opt { display: inline-flex; align-items: center; gap: 8px; margin: 4px 6px 4px 0; padding: 9px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; text-align: left; font-size: 14px; transition: border-color .15s, background .15s; }
.opt::after { content: "→"; color: var(--muted); transition: transform .15s, color .15s; }
.opt:hover { border-color: var(--accent); background: var(--accent-soft); }
.opt:hover::after { color: var(--accent); transform: translateX(2px); }

.status { color: var(--text-2); font-size: 14px; display: inline-flex; align-items: center; gap: 10px; }
.status::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--card-3); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
details.meta { font-size: 13px; color: var(--muted); }
details.meta summary { cursor: pointer; user-select: none; list-style: none; display: inline-flex; align-items: center; gap: 6px; }
details.meta summary::-webkit-details-marker { display: none; }
details.meta summary::before { content: "›"; display: inline-block; transition: transform .15s; font-size: 16px; line-height: 1; }
details.meta[open] summary::before { transform: rotate(90deg); }
details.meta .inner { margin-top: 8px; padding: 10px 14px; border-left: 2px solid var(--line); white-space: pre-wrap; color: var(--text-2); max-height: 280px; overflow-y: auto; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sources a { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); text-decoration: none; background: var(--card); border: 1px solid var(--line-soft); padding: 4px 10px; border-radius: 8px; max-width: 280px; }
.sources a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sources a:hover { border-color: var(--accent); color: var(--text); }
.sources a b { color: var(--accent); font-weight: 600; }
.err { color: var(--red); background: var(--red-soft); padding: 10px 14px; border-radius: var(--r-sm); font-size: 14px; }
.decision { font-size: 13px; display: inline-flex; gap: 8px; align-items: center; }

.act-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; white-space: normal; }
.act-row svg { width: 14px; height: 14px; color: var(--muted); }
.act-row span { overflow-wrap: anywhere; }
details.meta .inner:has(.act-row) { white-space: normal; }
.file-links { display: flex; flex-wrap: wrap; gap: 8px; }
.file-link { display: inline-flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); text-decoration: none; font-size: 13.5px; max-width: 100%; transition: border-color .15s; }
.file-link:hover { border-color: var(--accent); }
.file-link .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-link svg { width: 15px; height: 15px; color: var(--muted); }
.msg-actions { display: flex; align-items: center; gap: 6px; margin-left: -6px; opacity: .7; flex-wrap: wrap; }
.usage-line { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.usage-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.usage-col { background: var(--card-2); border: 1px solid var(--line-soft); border-radius: var(--r-md); padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.usage-col b { font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.usage-col small { color: var(--muted); font-size: 12px; }
@media (max-width: 860px) { .usage-stats { grid-template-columns: 1fr; } }
.msg-ai:hover .msg-actions { opacity: 1; }
.send.stop { background: var(--card-3); box-shadow: none; }
.crumbs .icon-btn { width: 28px; height: 28px; }
.crumbs .icon-btn svg { width: 15px; height: 15px; }
.conv .icon-btn svg { width: 15px; height: 15px; }
#view-chat { position: relative; }
.drop-overlay { position: absolute; inset: 12px; z-index: 10; border: 1.5px dashed var(--accent); border-radius: var(--r-lg); background: rgba(10,10,11,.85); display: grid; place-items: center; text-align: center; pointer-events: none; backdrop-filter: blur(4px); }
.drop-overlay div { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.drop-overlay svg { width: 28px; height: 28px; color: var(--accent); }
.drop-overlay span { color: var(--muted); font-size: 13px; }

/* ---- подтверждение действий ---- */
.approval { border: 1px solid rgba(255,159,67,.35); background: linear-gradient(180deg, rgba(255,159,67,.06), transparent 60%), var(--card); border-radius: var(--r-lg); padding: 20px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.approval .head { display: flex; align-items: center; gap: 12px; }
.approval .head .ico { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--orange-soft); color: var(--orange); }
.approval .head b { display: block; font-size: 15px; }
.approval .head small { color: var(--muted); }
.ap-item { background: var(--card-2); border: 1px solid var(--line-soft); border-radius: var(--r-md); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.ap-item label { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.ap-item label input { width: 16px; height: 16px; accent-color: var(--accent); }
.ap-item label code { background: var(--card-3); padding: 2px 8px; border-radius: 6px; font-size: 13px; }
.diff { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; border-radius: 10px; padding: 10px 12px; max-height: 240px; overflow-y: auto; margin: 0; }
.diff.old { background: var(--red-soft); color: #ffb4b4; }
.diff.new { background: var(--green-soft); color: #aef0cf; }
.ap-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- поле ввода ---- */
.composer-wrap { padding: 10px 28px 22px; flex: none; }
.composer { max-width: 800px; margin: 0 auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 10px; box-shadow: var(--shadow); transition: border-color .15s; }
.composer:focus-within { border-color: #33333a; }
.composer textarea { width: 100%; resize: none; border: 0; background: none; outline: none; padding: 8px 10px 4px; max-height: 220px; min-height: 28px; display: block; }
.composer textarea::placeholder { color: var(--muted); }
.composer .row { display: flex; align-items: center; gap: 8px; }
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 6px 6px; }
.attach-list:empty { display: none; }
.file-chip { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 6px 0 10px; border-radius: 10px; background: var(--card-2); border: 1px solid var(--line); font-size: 13px; }
.file-chip button { border: 0; background: none; cursor: pointer; color: var(--muted); display: grid; place-items: center; }

/* ---- память: канбан ---- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.column { flex: 0 0 290px; background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-lg); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.column-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 4px; }
.column-head::before { content: ""; width: 3px; height: 14px; border-radius: 2px; background: var(--c, var(--accent)); }
.column-head b { font-weight: 600; font-size: 14px; flex: 1; }
.column-head span { color: var(--muted); font-size: 13px; }
.fact-card { background: var(--card-2); border: 1px solid var(--line-soft); border-radius: var(--r-md); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.fact-card .txt { font-size: 14px; overflow-wrap: anywhere; }
.fact-card .foot { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.fact-card .foot .grow { flex: 1; }
.fact-card .icon-btn { width: 28px; height: 28px; }
.fact-card textarea { width: 100%; resize: vertical; min-height: 64px; border: 1px solid var(--accent); border-radius: 10px; background: var(--card); padding: 8px 10px; outline: none; }
.add-new { display: flex; align-items: center; gap: 8px; color: var(--text-2); background: none; border: 0; cursor: pointer; padding: 6px 4px; border-radius: 8px; }
.add-new:hover { color: var(--text); }

/* ---- файлы ---- */
.files-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.file-card { display: flex; flex-direction: column; gap: 14px; }
.file-card .top { display: flex; align-items: center; gap: 8px; }
.file-card .top .grow { flex: 1; }
.file-card .name { font-weight: 600; overflow-wrap: anywhere; }
.file-card .meta-row { display: flex; gap: 12px; color: var(--muted); font-size: 12.5px; }
.dropzone { border: 1.5px dashed var(--line); border-radius: var(--r-lg); min-height: 150px; display: grid; place-items: center; text-align: center; color: var(--muted); cursor: pointer; padding: 20px; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.dropzone .plus { font-size: 34px; font-weight: 300; line-height: 1; margin-bottom: 6px; color: var(--text-2); }

/* ---- настройки ---- */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; max-width: 980px; }
.settings-grid .card { display: flex; flex-direction: column; gap: 14px; }
.settings-grid .span2 { grid-column: span 2; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: 14px; }
.kv span { color: var(--muted); }
.ok-line { display: flex; align-items: center; gap: 10px; }
.ok-line .badge { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--green-soft); color: var(--green); }
.session-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.session-row:first-child { border-top: 0; }
.session-row .ico { width: 36px; height: 36px; border-radius: 10px; background: var(--card-2); display: grid; place-items: center; color: var(--text-2); }
.session-row .info { flex: 1; min-width: 0; }
.session-row .info div { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-row .info small { color: var(--muted); }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.codes code { background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: center; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 15px; letter-spacing: .06em; }
.form-msg { font-size: 13px; min-height: 18px; }
.form-msg.bad { color: var(--red); } .form-msg.good { color: var(--green); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* ---- модальное окно ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 16px; backdrop-filter: blur(4px); }
.modal { width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; }

.scrim { display: none; }

/* ===================== СТРАНИЦА ВХОДА ===================== */
.auth-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(600px 400px at 15% 10%, rgba(91,124,255,.16), transparent 70%),
  radial-gradient(500px 400px at 90% 90%, rgba(157,140,255,.10), transparent 70%), var(--bg); }
.auth-card { width: min(420px, 100%); background: var(--card); border: 1px solid var(--line-soft); border-radius: 26px; padding: 30px; box-shadow: 0 30px 80px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 18px; }
.auth-card .brand { padding: 0; }
.auth-card .brand .logo-full { height: 30px; width: 105px; }
.auth-card section { display: flex; flex-direction: column; gap: 18px; }
.auth-card h1 { margin: 8px 0 0; font-size: 26px; line-height: 1.2; letter-spacing: -.02em; }
.auth-card .lead { margin: -8px 0 4px; color: var(--muted); line-height: 1.45; }
.auth-card .form-msg:empty { display: none; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-switch { color: var(--muted); font-size: 14px; text-align: center; }
.auth-switch button { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; }
.steps { display: flex; flex-direction: column; gap: 12px; }
.step { display: flex; gap: 12px; align-items: flex-start; color: var(--text-2); font-size: 14px; }
.step .n { width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; font-size: 12px; font-weight: 600; color: var(--text); flex: none; }
.qr-box { background: #fff; border-radius: 18px; padding: 10px; width: 200px; height: 200px; margin: 0 auto; display: grid; place-items: center; }
.qr-box img { width: 100%; height: 100%; image-rendering: pixelated; }
.secret { display: flex; align-items: center; gap: 8px; background: var(--card-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 8px 8px 14px; }
.secret code { flex: 1; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; letter-spacing: .04em; overflow-wrap: anywhere; color: var(--text-2); }
.otp { height: 56px; text-align: center; font-size: 26px; letter-spacing: .5em; padding-left: .5em; font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, monospace; }


/* ===================== СФЕРА ===================== */
.orb { --size: 96px; position: relative; width: var(--size); height: var(--size); flex: none; animation: orb-float 6s ease-in-out infinite; }
.orb::before { content: ""; position: absolute; inset: -50%; border-radius: 50%; background: radial-gradient(circle, rgba(110,120,255,.42), rgba(214,120,255,.16) 45%, transparent 70%); filter: blur(10px); animation: orb-glow 4s ease-in-out infinite; }
.orb .core { position: absolute; inset: 0; border-radius: 50%; overflow: hidden; isolation: isolate;
  background: radial-gradient(circle at 35% 30%, #dfe4ff 0%, #8c9cff 28%, #5a49d8 58%, #231c63 100%);
  box-shadow: inset -10px -12px 26px rgba(10,8,40,.65), inset 6px 8px 18px rgba(255,255,255,.35), 0 12px 44px rgba(91,124,255,.35);
  animation: orb-breathe 5s ease-in-out infinite; }
.orb .layer { position: absolute; inset: -35%; border-radius: 50%; filter: blur(9px); }
.orb .l1 { background: conic-gradient(from 0deg, #ff7ac6, #7a5cff, #49d3ff, #8cffd9, #ffb36b, #ff7ac6); mix-blend-mode: overlay; opacity: .95; animation: orb-spin 10s linear infinite; }
.orb .l2 { background: radial-gradient(circle at 28% 72%, rgba(255,120,210,.85) 0 14%, transparent 36%), radial-gradient(circle at 74% 30%, rgba(80,220,255,.8) 0 12%, transparent 34%); mix-blend-mode: screen; opacity: .7; animation: orb-spin 7s linear infinite reverse; }
.orb .l3 { background: conic-gradient(from 90deg, transparent 0 20%, rgba(255,255,255,.55) 30%, transparent 45% 70%, rgba(180,150,255,.6) 82%, transparent 95%); mix-blend-mode: soft-light; animation: orb-spin 4.5s linear infinite; }
.orb .shine { position: absolute; inset: 0; border-radius: 50%; background: radial-gradient(circle at 33% 26%, rgba(255,255,255,.9) 0 5%, rgba(255,255,255,.28) 13%, transparent 30%); }
.orb.busy .l1 { animation-duration: 2.2s; }
.orb.busy .l2 { animation-duration: 3.4s; }
.orb.busy .l3 { animation-duration: 1.6s; }
.orb.busy .core { animation-duration: 1.6s; }
.orb.busy::before { animation-duration: 1.4s; }
.orb.sm { --size: 28px; animation: none; }
.orb.sm::before { inset: -30%; filter: blur(5px); }
.orb.sm .layer { filter: blur(3px); }
.orb.sm .core { box-shadow: inset -2px -3px 6px rgba(40,40,90,.45), inset 2px 2px 5px rgba(255,255,255,.55); }
@keyframes orb-spin { to { transform: rotate(360deg); } }
@keyframes orb-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.045); } }
@keyframes orb-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes orb-glow { 0%, 100% { opacity: .75; transform: scale(.95); } 50% { opacity: 1; transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { .orb, .orb *, .orb::before { animation: none !important; } }

/* ===================== ПУСТОЙ ЧАТ (hero) ===================== */
.view.is-empty .messages { justify-content: flex-end; padding-bottom: 6px; }
.view.is-empty .composer-wrap { padding-bottom: max(8vh, 22px); }
.hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; margin-top: auto !important; }
.hero h1 { margin: 10px 0 0; font-size: 34px; line-height: 1.2; font-weight: 600; letter-spacing: -.025em; }
.hero h1 .name { color: var(--muted); }
.hero h1 .accent { background: linear-gradient(90deg, #8ea2ff, #c49bff 55%, #ff9ad5); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { margin: 0; color: var(--muted); max-width: 520px; }
.cats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; width: 100%; margin-top: 12px; }
.cat-card { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-md); padding: 14px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, transform .15s, background .15s; color: inherit; font: inherit; }
.cat-card:hover { border-color: var(--line); background: var(--card-2); transform: translateY(-2px); }
.cat-card .ci { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--c-soft); color: var(--c); margin-bottom: 4px; }
.cat-card .ci svg { width: 16px; height: 16px; }
.cat-card b { font-weight: 600; font-size: 14px; }
.cat-card span { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.c-blue { --c: var(--accent); --c-soft: var(--accent-soft); }
.c-orange { --c: var(--orange); --c-soft: var(--orange-soft); }
.c-green { --c: var(--green); --c-soft: var(--green-soft); }
.c-violet { --c: var(--violet); --c-soft: var(--violet-soft); }
.c-red { --c: var(--red); --c-soft: var(--red-soft); }
.suggest { max-width: 800px; margin: 12px auto 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; }
.suggest:empty { display: none; }
.suggest button { display: flex; align-items: center; gap: 10px; border: 0; background: none; color: var(--muted); cursor: pointer; text-align: left; padding: 6px 8px; border-radius: 10px; font-size: 13.5px; }
.suggest button:hover { color: var(--text); background: var(--card); }
.suggest button svg { width: 15px; height: 15px; }

/* ---- панель поля ввода ---- */
.composer .row { flex-wrap: wrap; padding: 4px 2px 0; }
.composer .grow { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2); color: var(--text-2); font-size: 13px; cursor: pointer; position: relative; }
.pill:hover { color: var(--text); background: var(--card-3); }
.pill svg { width: 15px; height: 15px; }
.pill.select select { appearance: none; -webkit-appearance: none; border: 0; background: none; outline: none; cursor: pointer; padding-right: 14px; color: inherit; font-size: 13px; }
.pill.select::after { content: ""; position: absolute; right: 11px; top: 50%; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: translateY(-70%) rotate(45deg); pointer-events: none; }
.pill.select option { background: var(--card-2); color: var(--text); }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; user-select: none; height: 34px; padding: 0 4px; }
.toggle svg { width: 15px; height: 15px; }
.toggle input { display: none; }
.toggle i { width: 32px; height: 18px; border-radius: 99px; background: var(--card-3); position: relative; transition: background .15s; }
.toggle i::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-2); transition: transform .15s, background .15s; }
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { transform: translateX(14px); background: #fff; }
.send { width: 38px; height: 38px; border-radius: 12px; border: 0; display: grid; place-items: center; cursor: pointer; color: #fff; background: linear-gradient(135deg, #5b7cff, #8a6bff); box-shadow: 0 6px 18px rgba(91,124,255,.35); transition: filter .15s, opacity .15s; }
.send:hover { filter: brightness(1.1); }
.send:disabled { opacity: .4; cursor: default; box-shadow: none; }

/* ---- мелочи для настроек и списков ---- */
.row-form { display: flex; gap: 8px; flex-wrap: wrap; }
.row-form .input { flex: 1; min-width: 150px; }
.col-form { display: flex; flex-direction: column; gap: 10px; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conv-group { font-size: 12px; color: var(--muted); padding: 10px 12px 4px; }
.conv-group:first-child { padding-top: 2px; }

@media (max-width: 1100px) { .cats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .hero h1 { font-size: 26px; }
  .orb { --size: 76px; }
  .cats { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
  .cat-card { flex-direction: row; align-items: center; padding: 6px 12px 6px 6px; border-radius: 99px; gap: 8px; }
  .cat-card .ci { width: 24px; height: 24px; border-radius: 50%; margin: 0; }
  .cat-card span { display: none; }
  .cat-card b { font-size: 13px; font-weight: 500; }
  .suggest { grid-template-columns: 1fr; }
  .pill span, .toggle span { display: none; }
}

/* ===================== КАРТА СЕССИИ ===================== */
.session-bar { flex: none; margin: 14px 28px 0; max-width: 800px; width: calc(100% - 56px); align-self: center; background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--r-md); box-shadow: var(--shadow); overflow: hidden; animation: block-in .35s ease both; }
.session-bar.flash { animation: session-flash 1.2s ease; }
@keyframes session-flash { 0% { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); } 100% { border-color: var(--line-soft); } }
.session-head { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: none; border: 0; cursor: pointer; text-align: left; position: relative; }
.session-ring { --p: 0%; width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center; background: conic-gradient(var(--accent) var(--p), var(--card-3) 0); position: relative; font-size: 10.5px; font-weight: 600; transition: background .4s; }
.session-ring::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--card); }
.session-ring span { position: relative; z-index: 1; }
.session-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.session-title b { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-title small { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-progress { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; background: transparent; }
.session-progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #5b7cff, #9d8cff); transition: width .5s ease; }
.session-head .chev { color: var(--muted); transition: transform .2s; }
.session-bar.open .chev { transform: rotate(180deg); }
.session-body { display: none; padding: 4px 16px 16px; max-height: 50vh; overflow-y: auto; border-top: 1px solid var(--line-soft); }
.session-bar.open .session-body { display: flex; flex-direction: column; gap: 14px; padding-top: 14px; }
.session-sec h4 { margin: 0 0 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.session-sec p { margin: 0; }
.steps-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.steps-list li { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-2); }
.st-mark { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; font-size: 11px; flex: none; }
.steps-list .st-done { color: var(--muted); text-decoration: line-through; }
.steps-list .st-done .st-mark { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.steps-list .st-doing { color: var(--text); font-weight: 500; }
.steps-list .st-doing .st-mark { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.plain-list { margin: 0; padding-left: 18px; color: var(--text-2); font-size: 14px; display: flex; flex-direction: column; gap: 3px; }
@media (max-width: 860px) { .session-bar { margin: 10px 16px 0; width: calc(100% - 32px); } }

/* ===================== АНИМАЦИИ СООБЩЕНИЙ ===================== */
@keyframes msg-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes orb-pop { 0% { opacity: 0; transform: scale(.3); } 60% { opacity: 1; transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes block-in { from { opacity: 0; transform: translateY(6px); filter: blur(3px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes hero-out { to { opacity: 0; transform: translateY(-16px) scale(.98); filter: blur(4px); } }

.msg-user.live { animation: msg-in .38s cubic-bezier(.2, .8, .2, 1) both; transform-origin: bottom right; }
.msg-ai.live > .orb { animation: orb-pop .5s cubic-bezier(.3, 1.3, .5, 1) both; }
.msg-ai.live .status, .msg-ai.live details.meta:not(.hidden) { animation: fade-in .3s ease both; }
.md .appear { animation: block-in .45s cubic-bezier(.2, .8, .2, 1) both; }
.msg-ai.live .file-links:not(.hidden), .msg-ai.live .sources:not(.hidden), .msg-ai.live .msg-actions:not(.hidden) { animation: block-in .4s ease both; }
.approval.live { animation: msg-in .4s cubic-bezier(.2, .8, .2, 1) both; }
.hero.leaving { animation: hero-out .22s ease-in forwards; }
.leaving-hero .suggest { animation: hero-out .22s ease-in forwards; }
@media (prefers-reduced-motion: reduce) {
  .msg-user.live, .msg-ai.live > .orb, .md .appear, .approval.live, .hero.leaving, .msg-ai.live * { animation: none !important; }
}

/* ===================== АДАПТИВНОСТЬ ===================== */
@media (max-width: 980px) {
  .settings-grid { grid-template-columns: 1fr; }
  .settings-grid .span2 { grid-column: auto; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 40; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; box-shadow: 20px 0 60px rgba(0,0,0,.5); }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30; }
  .topbar { padding: 0 16px; }
  .page { padding: 20px 16px; }
  .messages { padding: 20px 16px 8px; }
  .composer-wrap { padding: 8px 16px 14px; }
  .page-head h1 { font-size: 24px; }
  .column { flex-basis: 260px; }
}
@media (min-width: 861px) { .mobile-only { display: none !important; } }
