:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --bg-sunk: #f1f3f6;
  --line: #e6e8ee;
  --line-strong: #d5d9e2;
  --text: #1a1d26;
  --text-2: #4b5263;
  --text-3: #8a91a3;
  --primary: #3b5bdb;
  --primary-soft: #edf1ff;
  --primary-text: #2f4bc0;
  --ai-1: #7c3aed;
  --ai-2: #db2777;
  --ai-soft: #f6f0ff;
  --green: #12a150;
  --green-soft: #e7f7ee;
  --amber: #c27803;
  --amber-soft: #fff6e0;
  --red: #d92d20;
  --red-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 60px rgba(16, 24, 40, .18);
  --radius: 12px;
  --sidebar-w: 268px;
  --assistant-w: 420px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
}
:root[data-theme='dark'] {
  --bg: #14161c;
  --bg-soft: #191c23;
  --bg-sunk: #20232c;
  --line: #2a2e39;
  --line-strong: #363b48;
  --text: #e8eaf0;
  --text-2: #b4bac8;
  --text-3: #7d8496;
  --primary: #6b8afd;
  --primary-soft: #1f2640;
  --primary-text: #9db1ff;
  --ai-soft: #251c38;
  --green-soft: #13291e;
  --amber-soft: #2e2512;
  --red-soft: #33191a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--text); background: var(--bg); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--primary-text); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { font-family: var(--mono); font-size: 11px; padding: 1px 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; color: var(--text-3); background: var(--bg); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
::selection { background: color-mix(in srgb, var(--primary) 25%, transparent); }

/* ---------- Каркас ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr var(--assistant-w); height: 100vh; overflow: hidden; transition: grid-template-columns .25s ease; }
.app.as-hidden { grid-template-columns: var(--sidebar-w) 1fr 0; }
.app.as-hidden .assistant { visibility: hidden; }

/* ---------- Сайдбар ---------- */
.sidebar { background: var(--bg-soft); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 12px; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 14px; color: var(--text); }
.brand-logo { width: 36px; height: 36px; flex: none; display: grid; place-items: center; font-size: 20px; border-radius: 10px; background: linear-gradient(135deg, #2b8a3e, #0ca678); box-shadow: var(--shadow); overflow: hidden; }
.brand-logo.has-img { background: #fff; padding: 2px; }
.brand-logo img, .login-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.login-logo.has-img { width: 72px; height: 72px; margin: 0 auto; }
.org-settings section { margin-bottom: 28px; max-width: 640px; }
.org-settings h3 { margin: 0 0 4px; }
.org-row { display: flex; gap: 8px; }
.backup-settings .bk-list { max-width: 900px; }
.bk-form { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; margin-top: 10px; }
.bk-check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.bk-row { display: flex; gap: 18px; flex-wrap: wrap; }
.bk-row label { display: flex; gap: 8px; align-items: center; }
.bk-row input { font: inherit; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg); color: var(--text); }
.bk-row input[type=number] { width: 80px; }
.bk-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.bk-head h3 { margin: 0; }
.bk-actions { white-space: nowrap; text-align: right; }
.bk-actions .btn { margin-left: 4px; }
.bk-warn { padding: 10px 12px; border-radius: 8px; background: #f08c001a; border: 1px solid #f08c0066; margin-bottom: 16px; }
.org-row input { flex: 1; font: inherit; font-size: 15px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg); color: var(--text); }
.org-logo-row { display: flex; gap: 18px; align-items: center; }
.org-logo-preview.brand-logo { width: 96px; height: 96px; font-size: 48px; border-radius: 20px; }
.org-logo-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.brand b { display: block; font-size: 15px; }
.brand small { color: var(--text-3); font-size: 12px; }
.search-trigger { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 1px solid var(--line); background: var(--bg); border-radius: 9px; color: var(--text-3); margin-bottom: 12px; transition: border-color .15s; }
.search-trigger:hover { border-color: var(--line-strong); }
.search-trigger span { flex: 1; text-align: left; }
.nav a, .space-link, .space-article { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500; font-size: 14px; }
.nav a:hover, .space-link:hover, .space-article:hover { background: var(--bg-sunk); color: var(--text); }
.nav a.active, .space-link.active, .space-article.active { background: var(--primary-soft); color: var(--primary-text); }
.nav a .ni { display: none; width: 20px; text-align: center; }
.brand-row { display: flex; align-items: flex-start; gap: 4px; }
.brand-row .brand { flex: 1; min-width: 0; }
.brand-text { min-width: 0; }
.sb-toggle { flex: none; border: 1px solid transparent; background: none; color: var(--text-3); width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; margin-top: 7px; }
.sb-toggle:hover { border-color: var(--line-strong); background: var(--bg-sunk); color: var(--text); }
/* Свёрнутая панель: только иконки, навигация по пространствам скрыта */
.app.sb-collapsed { --sidebar-w: 64px; }
.sb-collapsed .sidebar { padding: 16px 10px; overflow: visible; align-items: center; }
.sb-collapsed .brand-row { flex-direction: column; align-items: center; gap: 6px; margin-bottom: 8px; }
.sb-collapsed .brand { padding: 0; }
.sb-collapsed .sb-toggle { margin-top: 0; }
.sb-collapsed .sb-toggle svg { transform: scaleX(-1); }
.sb-collapsed .brand-text, .sb-collapsed .search-trigger span, .sb-collapsed .search-trigger kbd,
.sb-collapsed .nav-title, .sb-collapsed .spaces, .sb-collapsed .user-chip > span:not(.avatar) { display: none; }
.sb-collapsed .search-trigger { width: 40px; height: 40px; padding: 0; justify-content: center; }
.sb-collapsed .nav { display: flex; flex-direction: column; gap: 2px; }
.sb-collapsed .nav a { font-size: 0; width: 40px; height: 40px; padding: 0; justify-content: center; gap: 0; }
.sb-collapsed .nav a .ni { display: block; font-size: 18px; }
.sb-collapsed .sidebar-footer { flex-direction: column; align-items: center; }
.sb-collapsed .user-menu { flex: none; }
.sb-collapsed .user-chip { width: 40px; height: 40px; padding: 0; justify-content: center; border-color: transparent; background: none; }
.sb-collapsed .user-chip:hover { border-color: var(--line-strong); }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); font-weight: 700; padding: 18px 10px 6px; display: flex; align-items: center; justify-content: space-between; }
.nav-add { border: 1px solid transparent; background: none; color: var(--text-3); font-size: 15px; line-height: 1; width: 22px; height: 22px; border-radius: 6px; cursor: pointer; }
.nav-add:hover { border-color: var(--line-strong); color: var(--text); background: var(--bg-sunk); }
.space-link .sp-icon { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 13px; flex: none; }
.space-link .sp-count { margin-left: auto; font-size: 12px; color: var(--text-3); }
.space-link .chev { width: 14px; height: 14px; color: var(--text-3); transition: transform .15s; flex: none; margin-left: -4px; }
.space.open .chev { transform: rotate(90deg); }
.space-articles { display: none; padding-left: 22px; margin: 2px 0 6px; border-left: 1px solid var(--line); margin-left: 20px; }
.space.open .space-articles { display: block; }
.space-article { font-size: 13px; font-weight: 400; padding: 4px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.space-article.on-shelf { padding-left: 18px; }
.shelf-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--text-3); padding: 8px 10px 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer { margin-top: auto; padding-top: 16px; display: flex; gap: 6px; align-items: stretch; }
.user-menu { flex: 1; min-width: 0; }
.user-chip { width: 100%; display: flex; gap: 8px; align-items: center; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 5px 8px; text-align: left; cursor: pointer; color: var(--text); }
.user-chip:hover { border-color: var(--line-strong); }
.user-chip span { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.user-chip b { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip small { font-size: 11px; color: var(--text-3); }
.dropdown-menu.up { top: auto; bottom: calc(100% + 6px); left: 0; right: auto; min-width: 200px; }
.sidebar-footer .ghost-btn { flex: none; width: 40px; }
.ghost-btn { flex: 1; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 8px; font-size: 12px; color: var(--text-2); }
.ghost-btn:hover { border-color: var(--line-strong); color: var(--text); }

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; container-type: inline-size; }
.topbar { position: relative; z-index: 5; height: 56px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 20px 0 28px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); }
.crumbs { flex: 1; min-width: 0; display: flex; gap: 6px; align-items: center; color: var(--text-3); font-size: 14px; white-space: nowrap; overflow: hidden; }
.crumbs a { color: var(--text-2); }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { color: var(--line-strong); }
.crumbs .cur { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; }
.ai-toggle { display: flex; align-items: center; gap: 8px; border: 0; padding: 7px 14px; border-radius: 999px; color: #fff; font-weight: 600; font-size: 14px; background: linear-gradient(135deg, var(--ai-1), var(--ai-2)); box-shadow: 0 4px 14px rgba(124, 58, 237, .35); }
.ai-dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.3); }
.view { flex: 1; overflow-y: auto; scroll-behavior: smooth; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--bg); padding: 6px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--text-2); white-space: nowrap; transition: all .15s; }
.btn:hover { border-color: var(--line-strong); color: var(--text); background: var(--bg-soft); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ai { border-color: color-mix(in srgb, var(--ai-1) 35%, var(--line)); color: var(--ai-1); background: var(--ai-soft); }
:root[data-theme='dark'] .btn.ai { color: #c4a5ff; }
.btn.ai:hover { border-color: var(--ai-1); }
.btn.danger:hover { color: var(--red); border-color: var(--red); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; width: 32px; height: 32px; border-radius: 8px; color: var(--text-3); font-size: 15px; }
.icon-btn:hover { background: var(--bg-sunk); color: var(--text); }

/* ---------- Главная ---------- */
.page { max-width: 1080px; margin: 0 auto; padding: 36px 40px 80px; }
.hero { position: relative; border-radius: 20px; padding: 40px 44px; margin-bottom: 36px; overflow: hidden; background: radial-gradient(1200px 300px at 0% 0%, color-mix(in srgb, var(--primary) 16%, transparent), transparent), radial-gradient(800px 300px at 100% 100%, color-mix(in srgb, var(--ai-2) 14%, transparent), transparent), var(--bg-soft); border: 1px solid var(--line); }
.hero h1 { margin: 0 0 6px; font-size: 32px; letter-spacing: -.02em; }
.hero p { margin: 0 0 22px; color: var(--text-2); }
.hero-search { display: flex; align-items: center; gap: 10px; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 14px; padding: 6px 6px 6px 16px; box-shadow: var(--shadow); max-width: 720px; }
.hero-search:focus-within { border-color: var(--ai-1); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ai-1) 15%, transparent); }
.hero-search input { flex: 1; border: 0; outline: 0; background: transparent; font: inherit; font-size: 16px; color: var(--text); padding: 8px 0; }
.hero-search button { border: 0; border-radius: 10px; padding: 10px 16px; color: #fff; font-weight: 600; background: linear-gradient(135deg, var(--ai-1), var(--ai-2)); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 5px 12px; font-size: 13px; color: var(--text-2); }
.chip:hover { border-color: var(--ai-1); color: var(--ai-1); }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 34px 0 14px; }
.section-title h2 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
.section-title small { color: var(--text-3); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; background: var(--bg); transition: all .15s; color: var(--text); display: block; }
.card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.space-card .sp-icon { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; font-size: 22px; margin-bottom: 12px; }
.space-card h3 { margin: 0 0 4px; font-size: 16px; }
.space-card p { margin: 0 0 12px; color: var(--text-2); font-size: 13px; line-height: 1.5; }
.space-card .meta { font-size: 12px; color: var(--text-3); }
.list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--text); }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--bg-soft); }
.row .emoji { font-size: 20px; width: 28px; text-align: center; }
.row .t { flex: 1; min-width: 0; }
.row .t b { display: block; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t small { color: var(--text-3); font-size: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.two-col .section-title { margin-top: 0; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.ok { background: var(--green-soft); color: var(--green); }
.badge.warn { background: var(--amber-soft); color: var(--amber); }
.badge.ai { background: var(--ai-soft); color: var(--ai-1); }
.badge.draft { background: var(--bg-sunk); color: var(--text-2); border: 1px dashed var(--line-strong); }
.badge.public { background: color-mix(in srgb, #1098ad 14%, transparent); color: #0b7285; }
:root[data-theme='dark'] .badge.public { color: #66d9e8; }
h1 .badge { vertical-align: middle; font-size: 12px; }
:root[data-theme='dark'] .badge.ai { color: #c4a5ff; }
.tag { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 6px; background: var(--bg-sunk); color: var(--text-2); margin: 0 4px 4px 0; }

/* ---------- Пространство ---------- */
.shelf-title { margin-top: 28px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.space-head + .shelf-title { margin-top: 0; }
.shelf-title small a { color: var(--primary-text); }
.shelf-title h2 { display: flex; align-items: center; gap: 6px; }
.shelf-title { align-items: center; }
.shelf-side { display: flex; align-items: center; gap: 12px; flex: none; white-space: nowrap; }
.shelf-title h2 { min-width: 0; }
.btn.btn-sm { padding: 3px 9px; font-size: 13px; }
.dd-chev { width: 14px; height: 14px; margin-right: -3px; transition: transform .15s; }
.dropdown.open .dd-chev { transform: rotate(180deg); }
.actions-menu .dropdown-menu { min-width: 220px; }
.dropdown-menu button.danger { color: var(--red); }
.dropdown-menu button.danger:hover { background: var(--red-soft); }
.icon-btn { border: 1px solid transparent; background: none; padding: 0; cursor: pointer; line-height: 1; transition: border-color .15s, background .15s; }
.icon-btn:hover { border-color: var(--line-strong); background: var(--bg-soft); }
.space-head .icon-btn:hover { border-style: dashed; }
.shelf-icon { font-size: 18px; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.link-btn { border: 0; background: none; padding: 0; font: inherit; color: var(--primary-text); cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--text-3); }
.link-btn.danger:hover { color: var(--red); }
.shelf-empty { grid-column: 1 / -1; padding: 18px; font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--text-2); font-weight: 500; }
.field input { font: inherit; font-size: 14px; font-weight: 400; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg); color: var(--text); }
.field:has(+ .icon-grid) { margin-bottom: 6px; }
.icon-custom input { width: 120px; font-size: 20px; text-align: center; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; margin-bottom: 14px; }
.icon-opt { height: 42px; font-size: 22px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg-soft); cursor: pointer; }
.icon-opt:hover { border-color: var(--line-strong); background: var(--bg); }
.icon-opt.sel { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 2px var(--primary-soft); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.field select { font: inherit; font-size: 14px; font-weight: 400; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg); color: var(--text); }
.color-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.color-opt { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--line-strong); cursor: pointer; }
.color-opt.sel { box-shadow: 0 0 0 2px var(--text); }

.radio { display: flex; gap: 8px; align-items: baseline; font-size: 14px; color: var(--text-2); margin: 4px 0; cursor: pointer; }
.copy-row { display: flex; gap: 6px; }
.copy-row input { flex: 1; font: inherit; font-size: 13px; padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg-soft); color: var(--text); min-width: 0; }
.draft-check { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text-2); cursor: pointer; }

/* Комментарии */
.comments { margin-top: 42px; padding-top: 22px; border-top: 1px solid var(--line); }
.comments h2 { font-size: 18px; margin: 0 0 14px; }
.comment { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.comment .avatar { width: 30px; height: 30px; font-size: 12px; }
.c-body { flex: 1; min-width: 0; }
.c-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.c-head small { color: var(--text-3); font-size: 12px; }
.c-actions { margin-left: auto; display: flex; gap: 10px; font-size: 12.5px; }
.c-text { margin-top: 4px; font-size: 14.5px; line-height: 1.55; white-space: normal; overflow-wrap: anywhere; }
.c-text textarea, .comment-form textarea { width: 100%; font: inherit; font-size: 14px; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--bg); color: var(--text); resize: vertical; }
.comment-form { margin-top: 14px; }
.comment-form .dlg-actions { margin-top: 8px; }
.comment-note { color: var(--text-3); font-size: 13px; }

/* Вложения в чате */
.as-tool { flex: none; align-self: flex-end; width: 32px; height: 32px; border: 0; border-radius: 8px; background: none; cursor: pointer; color: var(--text-3); display: grid; place-items: center; padding: 0; }
.as-tool svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.as-tool:hover { background: var(--bg-sunk); color: var(--text); }
.as-tool.recording { color: #fff; background: var(--red); animation: rec-pulse 1.4s ease-in-out infinite; }
.as-tool.busy { color: var(--ai-1); pointer-events: none; }
@keyframes rec-pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--red) 45%, transparent); } 50% { box-shadow: 0 0 0 6px transparent; } }
.as-chip.rec { border-color: var(--red); color: var(--red); }
.as-chip.rec .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); animation: rec-blink 1s steps(2) infinite; }
@keyframes rec-blink { 50% { opacity: .2; } }
.as-files { display: flex; flex-wrap: wrap; gap: 6px; }
.as-files:not(:empty) { margin-bottom: 8px; }
.as-chip { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; padding: 4px 8px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--bg); font-size: 12.5px; color: var(--text-2); }
.as-chip .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.as-chip small { color: var(--text-3); }
.as-chip button { border: 0; background: none; color: var(--text-3); cursor: pointer; padding: 0 0 0 2px; font-size: 12px; }
.as-chip button:hover { color: var(--red); }
.as-chip.uploading { border-style: dashed; }
.as-chip.failed { border-color: var(--red); color: var(--red); }
.as-chip.failed [data-voice-retry] { color: var(--ai-1); font-weight: 600; }
.msg-failed .msg-error .btn { margin-top: 6px; }
.msg-files { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.msg-user .as-chip { background: color-mix(in srgb, var(--bg) 85%, transparent); }
.assistant.drop-target { outline: 2px dashed var(--primary); outline-offset: -6px; }

/* Память Луны */
.mem-guide { padding: 10px 12px; border-radius: 10px; background: var(--ai-soft); font-size: 13.5px; margin-bottom: 12px; }
.mem-add { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-soft); margin-bottom: 14px; }
.mem-add input, .mem-add textarea { font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg); color: var(--text); resize: vertical; }
.mem-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.mem-head { display: flex; gap: 8px; align-items: center; }
.mem-head .link-btn { margin-left: auto; font-size: 12.5px; }
.mem-text { font-size: 14px; margin: 4px 0; overflow-wrap: anywhere; }
.mem-item small { color: var(--text-3); font-size: 12px; }
.mem-card { width: 100%; text-align: left; font: inherit; cursor: pointer; }

/* Вход */
.login-screen { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: var(--bg-soft); padding: 16px; }
.login-screen[hidden] { display: none; }
.login-box { width: min(380px, 100%); background: var(--bg); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 30px 28px; text-align: center; }
.login-box .field { text-align: left; }
.login-logo { font-size: 44px; }
.login-box h1 { margin: 6px 0 2px; font-size: 24px; }
.login-box > p { margin: 0 0 22px; color: var(--text-3); }
.login-btn { width: 100%; justify-content: center; padding: 9px; margin-top: 4px; }
.login-error { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.login-public { display: block; margin-top: 18px; font-size: 13px; color: var(--text-3); }

/* Администрирование */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tab { padding: 8px 14px; border-bottom: 2px solid transparent; color: var(--text-2); font-weight: 500; margin-bottom: -1px; }
.tab.active { border-color: var(--primary); color: var(--text); }
.report-form, .user-add { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.report-form input, .user-add input, .user-add select, .admin-table select { font: inherit; font-size: 13.5px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg); color: var(--text); }
.user-add { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-soft); }
.user-add input { min-width: 170px; flex: 1; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--bg); }
.stat small { display: block; color: var(--text-3); font-size: 12px; }
.stat b { font-size: 18px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.admin-table th, .admin-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.admin-table th { font-size: 12px; color: var(--text-3); font-weight: 600; background: var(--bg-soft); }
.admin-table .n { text-align: right; white-space: nowrap; }
.admin-table tfoot td { font-weight: 700; background: var(--bg-soft); }
.admin-table tr.inactive td { opacity: .55; }
.admin-table small { color: var(--text-3); }

/* Файлы */
.drop-zone { border: 2px dashed var(--line-strong); border-radius: 12px; padding: 18px; text-align: center; color: var(--text-3); margin-bottom: 18px; font-size: 14px; transition: all .15s; }
.drop-zone.over, textarea.drop-target { border-color: var(--primary); background: var(--primary-soft); }
.file-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.file-grid.pick { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.file-card { display: flex; flex-direction: column; gap: 4px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--bg); min-width: 0; text-align: left; font: inherit; color: inherit; }
.file-card img, .file-card video, .file-card .audio-thumb { width: 100%; height: 130px; object-fit: contain; background: var(--bg-sunk); border-radius: 8px; display: block; }
.file-card video { background: #000; }
.file-card .audio-thumb { display: grid; place-items: center; font-size: 42px; }
.file-card > a, .file-card > button { position: relative; }
.file-card { position: relative; }
.ft-badge { position: absolute; top: 16px; left: 16px; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: rgba(0, 0, 0, .6); color: #fff; }
.file-grid.pick .file-card video, .file-grid.pick .file-card .audio-thumb { height: 100px; }
.file-grid.pick .file-card { cursor: pointer; }
.file-grid.pick .file-card:hover { border-color: var(--primary); }
.file-grid.pick .file-card img { height: 100px; }
.file-card b, .file-card > span { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-grid.pick .file-card > span { font-weight: 400; color: var(--text-2); }
.file-card small { font-size: 12px; color: var(--text-3); }
.file-card .used a { color: var(--primary-text); }
.file-actions { display: flex; gap: 6px; margin-top: 6px; }
.file-actions .btn { font-size: 12.5px; padding: 4px 8px; }
.space-head { display: flex; gap: 18px; align-items: center; margin-bottom: 28px; }
.space-head .sp-icon { width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; font-size: 32px; flex: none; }
.space-head h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.space-head p { margin: 4px 0 0; color: var(--text-2); }
.space-head { flex-wrap: wrap; }
.space-head > div:not(.actions):not(.sp-icon) { flex: 1 1 260px; min-width: 0; }
.space-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.article-card h3 { margin: 6px 0 6px; font-size: 15px; }
.article-card .emoji { font-size: 24px; }
.article-card p { margin: 0 0 10px; font-size: 13px; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.article-card .meta { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--text-3); flex-wrap: wrap; }

/* ---------- Статья ---------- */
.article-layout { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 48px; max-width: 1080px; margin: 0 auto; padding: 40px 40px 120px; }
.article-head .emoji { font-size: 46px; line-height: 1; margin-bottom: 14px; }
.article-head h1 { font-size: 36px; line-height: 1.2; margin: 0 0 14px; letter-spacing: -.025em; }
.article-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; color: var(--text-3); font-size: 13px; padding-bottom: 18px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.avatar { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; flex: none; }
.author { display: inline-flex; gap: 8px; align-items: center; color: var(--text-2); font-weight: 500; }
.article-tags { margin: 14px 0 0; }
.tldr { margin: 22px 0 6px; border-radius: var(--radius); padding: 16px 18px; background: var(--ai-soft); border: 1px solid color-mix(in srgb, var(--ai-1) 25%, transparent); }
.tldr-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px; color: var(--ai-1); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .05em; }
:root[data-theme='dark'] .tldr-head { color: #c4a5ff; }
.tldr .md ul { margin: 0; }
.flash { animation: flash 2s ease; }
@keyframes flash { 0% { background: color-mix(in srgb, var(--ai-1) 18%, transparent); } 100% { background: transparent; } }
.toc { position: sticky; top: 24px; align-self: start; font-size: 13px; }
.toc-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); font-weight: 700; margin-bottom: 10px; }
.toc a { display: block; color: var(--text-3); padding: 4px 0 4px 12px; border-left: 2px solid var(--line); line-height: 1.35; }
.toc a.h3 { padding-left: 24px; font-size: 12.5px; }
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--primary-text); border-left-color: var(--primary); font-weight: 500; }
.ai-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.ai-actions .btn { font-size: 13px; padding: 5px 11px; }
@container (max-width: 1040px) {
  .article-layout { grid-template-columns: minmax(0, 1fr); padding: 32px 36px 120px; }
  .toc { display: none; }
}

/* ---------- Markdown ---------- */
.md { font-size: 16px; line-height: 1.72; color: var(--text); }
.md > *:first-child { margin-top: 0; }
.md h2 { font-size: 23px; margin: 40px 0 12px; letter-spacing: -.015em; line-height: 1.3; scroll-margin-top: 20px; }
.md h3 { font-size: 18px; margin: 28px 0 8px; scroll-margin-top: 20px; }
.md h4 { font-size: 15px; margin: 22px 0 6px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }
.md p { margin: 0 0 14px; }
.md ul, .md ol { padding-left: 24px; margin: 0 0 16px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--text-3); }
.md ol > li::marker { font-weight: 600; color: var(--primary-text); }
.md strong { font-weight: 650; }
.md a { color: var(--primary-text); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--primary) 35%, transparent); text-underline-offset: 3px; }
.md a:hover { text-decoration-color: currentColor; }
.md code { font-family: var(--mono); font-size: .86em; background: var(--bg-sunk); padding: 2px 6px; border-radius: 5px; border: 1px solid var(--line); }
.md pre { background: #0f1320; color: #dfe6f5; border-radius: 10px; padding: 16px 18px; overflow-x: auto; margin: 0 0 18px; font-size: 13.5px; line-height: 1.6; position: relative; }
.md pre code { background: none; border: 0; padding: 0; color: inherit; font-size: inherit; }
.md pre[data-lang]::before { content: attr(data-lang); position: absolute; top: 8px; right: 12px; font-size: 11px; color: #7f8aa8; font-family: var(--mono); text-transform: uppercase; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 32px 0; }
.md img { max-width: 100%; border-radius: 10px; }

/* Сравнение версий и правки AI */
.modal.wide { width: min(1100px, 95vw); max-height: 88vh; }
.diff { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
.diff-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--bg-soft); font-size: 12.5px; }
.d-legend { padding: 1px 8px; border-radius: 6px; font-weight: 600; }
.d-legend.del { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.d-legend.add { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.d-stats { margin-left: auto; color: var(--text-3); }
.d-stats .add { color: var(--green); } .d-stats .del { color: var(--red); }
.diff-scroll { overflow: auto; max-height: 62vh; }
.diff-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; }
.diff-table td { padding: 1px 8px; vertical-align: top; }
.diff-table .ln { width: 1%; min-width: 34px; text-align: right; color: var(--text-3); user-select: none; border-right: 1px solid var(--line); background: var(--bg-soft); }
.diff-table .sg { width: 1%; color: var(--text-3); user-select: none; }
.diff-table .cd { white-space: pre-wrap; overflow-wrap: anywhere; }
.d-del { background: color-mix(in srgb, var(--red) 9%, transparent); }
.d-add { background: color-mix(in srgb, var(--green) 10%, transparent); }
.d-del .sg { color: var(--red); } .d-add .sg { color: var(--green); }
.diff-table del { background: color-mix(in srgb, var(--red) 30%, transparent); color: inherit; text-decoration: line-through; border-radius: 2px; }
.diff-table ins { background: color-mix(in srgb, var(--green) 32%, transparent); color: inherit; text-decoration: none; border-radius: 2px; }
.d-skip td { text-align: center; background: var(--bg-soft); padding: 3px; }
.d-expand { border: 0; background: none; color: var(--primary-text); font: inherit; font-size: 12px; cursor: pointer; }
.diff-empty { padding: 16px; color: var(--text-3); }
.ai-proposal { display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: 18px 0 0; padding: 12px 16px; border-radius: 12px; background: var(--ai-soft); border: 1px solid color-mix(in srgb, var(--ai-1) 30%, transparent); font-size: 14px; }
.ai-proposal small { color: var(--text-2); }
.badge-btn { border: 0; cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; }
.badge-btn:hover { filter: brightness(.95); text-decoration: underline; }
.rv-note { margin: 0 0 16px; }
.rv-title-change { margin: 0 0 10px; font-size: 14px; }
.rv-title-change del { color: var(--red); } .rv-title-change ins { color: var(--green); text-decoration: none; font-weight: 600; }
.rv-preview { border: 1px solid var(--line); border-radius: 12px; padding: 20px 26px; }

/* Плеер видео и аудио в статьях */
.media-player { margin: 18px 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg-soft); max-width: 100%; }
.media-player.is-video .mp-media { display: block; width: 100%; max-height: 70vh; background: #000; }
.media-player.is-audio { max-width: 640px; }
.media-player.is-audio .mp-media { display: block; width: 100%; padding: 10px 10px 0; }
.mp-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 13px; color: var(--text-2); }
.mp-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mp-speed { flex: none; border: 1px solid var(--line-strong); background: var(--bg); color: var(--text-2); border-radius: 7px; padding: 2px 9px; font: inherit; font-size: 12.5px; cursor: pointer; text-decoration: none; }
.mp-speed:hover { border-color: var(--primary); color: var(--text); }
.mp-error { padding: 10px 12px; font-size: 13px; color: var(--red); background: var(--bg); }
.md .table-wrap { overflow-x: auto; margin: 0 0 20px; border: 1px solid var(--line); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
.md th { background: var(--bg-soft); text-align: left; font-weight: 600; color: var(--text-2); font-size: 13px; }
.md th, .md td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.md tr:last-child td { border-bottom: 0; }
.md tbody tr:hover { background: var(--bg-soft); }
.md blockquote { margin: 0 0 18px; padding: 4px 18px; border-left: 3px solid var(--line-strong); color: var(--text-2); }
.md li.task { list-style: none; margin-left: -24px; display: flex; gap: 10px; align-items: flex-start; }
.md li.task input { margin-top: 6px; width: 16px; height: 16px; accent-color: var(--primary); flex: none; }
.md .callout { border: 0; border-radius: 10px; padding: 14px 18px 4px; margin: 0 0 20px; color: var(--text); background: var(--primary-soft); border-left: 4px solid var(--primary); }
.md .callout-title { font-weight: 700; font-size: 14px; margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }
.md .callout p { margin-bottom: 10px; }
.md .callout-note { --c: var(--primary); --cs: var(--primary-soft); }
.md .callout-tip { --c: var(--green); --cs: var(--green-soft); }
.md .callout-warning { --c: var(--amber); --cs: var(--amber-soft); }
.md .callout-important, .md .callout-caution { --c: var(--red); --cs: var(--red-soft); }
.md .callout { background: var(--cs); border-left-color: var(--c); }
.md .callout-title { color: var(--c); }

/* ---------- Редактор ---------- */
.editor { display: flex; flex-direction: column; height: 100%; }
.editor-head { padding: 22px 28px 14px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr; gap: 6px 14px; align-items: center; }
.emoji-input { width: 56px; height: 56px; font-size: 30px; text-align: center; border: 1px dashed var(--line-strong); border-radius: 12px; background: var(--bg-soft); grid-row: span 2; }
.title-input { border: 0; outline: 0; font: inherit; font-size: 28px; font-weight: 700; letter-spacing: -.02em; background: transparent; color: var(--text); width: 100%; }
.editor-fields { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.editor-fields select, .editor-fields input { font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--text); }
.editor-fields input { min-width: 260px; }
.editor-fields #edShelf { min-width: 220px; }
/* Панель редактора — в одну строку: при нехватке места сначала скрываются подписи кнопок вставки файлов, затем все подписи;
   перенос строки — только если не помещаются даже значки (очень узкое окно) */
.toolbar { display: flex; align-items: center; gap: 1px; padding: 6px 16px; border-bottom: 1px solid var(--line); background: var(--bg-soft); flex-wrap: wrap; container-type: inline-size; }
.tb { flex: none; white-space: nowrap; border: 0; background: transparent; padding: 5px 8px; border-radius: 6px; font-size: 13px; color: var(--text-2); min-width: 30px; }
.toolbar .dropdown { flex: none; }
.toolbar #aiMenuBtn { font-size: 13px; padding: 5px 11px; }
/* пороги по фактической ширине содержимого: все подписи ~1125px, без подписей файлов ~840px, только значки ~645px */
@container (max-width: 1210px) { .tb-lbl-media { display: none; } }
@container (max-width: 930px) { .tb-lbl { display: none; } .tb-sep { margin: 0 3px; } }.tb:hover { background: var(--bg-sunk); color: var(--text); }
.tb-sep { width: 1px; height: 20px; background: var(--line-strong); margin: 0 6px; }
.tb-spacer { flex: 1; }
.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px; min-width: 260px; z-index: 20; display: none; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu button { display: flex; width: 100%; gap: 10px; align-items: center; border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 7px; font-size: 14px; }
.dropdown-menu button:hover { background: var(--ai-soft); }
.dropdown-menu small { display: block; color: var(--text-3); font-size: 12px; }
.editor-split { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.editor-split textarea { border: 0; outline: 0; resize: none; padding: 24px 28px; font-family: var(--mono); font-size: 13.5px; line-height: 1.7; background: var(--bg); color: var(--text); border-right: 1px solid var(--line); }
.editor-preview { overflow-y: auto; padding: 24px 32px; background: var(--bg-soft); }
.editor-preview .md { font-size: 15px; }
.editor-foot { display: flex; align-items: center; gap: 10px; padding: 12px 24px; border-top: 1px solid var(--line); }
/* Визуальный редактор */
.editor.mode-visual .editor-split { grid-template-columns: 1fr; }
.ve-wrap { overflow-y: auto; background: var(--bg); min-height: 0; }
.ve-wrap .ProseMirror { max-width: 860px; margin: 0 auto; padding: 24px 32px 80px; outline: none; min-height: 100%; font-size: 15px; }
.ve-doc .callout::before { content: attr(data-label); display: block; font-weight: 700; font-size: 14px; margin-bottom: 4px; color: var(--c); }
.ve-doc .tableWrapper { overflow-x: auto; margin: 0 0 18px; }
.ve-doc table { margin: 0; }
.ve-doc th, .ve-doc td { border: 1px solid var(--line); position: relative; min-width: 60px; }
.ve-doc th p, .ve-doc td p { margin: 0 0 6px; }
.ve-doc th p:last-child, .ve-doc td p:last-child { margin-bottom: 0; }
.ve-doc .selectedCell::after { content: ''; position: absolute; inset: 0; background: color-mix(in srgb, var(--primary) 16%, transparent); pointer-events: none; }
.ve-doc a { cursor: text; }
.ve-doc img.ProseMirror-selectednode, .ve-doc .ve-media.ProseMirror-selectednode { outline: 2px solid var(--primary); outline-offset: 2px; }
.ve-media { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin: 0 0 18px; background: var(--bg-soft); }
.ve-media video { width: 100%; max-height: 360px; border-radius: 8px; display: block; background: #000; }
.ve-media audio { width: 100%; display: block; }
.ve-media-cap { font-size: 13px; color: var(--text-2); margin-top: 6px; }
.generating .ve-wrap { opacity: .85; }
.tb.on { background: var(--primary-soft); color: var(--primary-text); }
.tb:disabled { opacity: .4; cursor: default; background: none; }
#tbUndo { font-size: 16px; line-height: 1; }
.tb.danger:hover { color: var(--red); }
.tb-table { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; padding: 4px 16px; border-bottom: 1px solid var(--line); background: var(--bg-soft); font-size: 13px; color: var(--text-3); }
.tb-table > span { margin-right: 6px; }
.callout-menu { min-width: 210px; }
.ai-long-note { max-width: 260px; margin: 4px 4px 2px; padding: 8px 10px 4px; border-top: 1px solid var(--line); font-size: 12px; line-height: 1.4; color: var(--text-3); }
.mode-switch { display: inline-flex; flex: none; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--bg-soft); }
.mode-switch button { border: 0; background: none; padding: 4px 10px; border-radius: 6px; font-size: 13px; color: var(--text-2); }
.mode-switch button.on { background: var(--bg); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.editor-foot .status { flex: 1; font-size: 13px; color: var(--text-3); }
.ai-banner { margin: 14px 28px 0; display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 12px; background: var(--ai-soft); border: 1px solid color-mix(in srgb, var(--ai-1) 25%, transparent); }
.ai-banner b { color: var(--ai-1); white-space: nowrap; }
:root[data-theme='dark'] .ai-banner b { color: #c4a5ff; }
.ai-banner input { flex: 1; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 14px; color: var(--text); outline: 0; }
.ai-banner input:focus { border-color: var(--ai-1); }
.ai-banner[hidden] { display: none; }
.ai-banner.custom-ins { margin: 0 28px 12px; }
.generating textarea { opacity: .6; }
.generating .editor-preview { position: relative; }
.generating .editor-preview::after { content: '✨ Луна пишет…'; position: sticky; bottom: 0; float: right; padding: 6px 12px; border-radius: 999px; background: linear-gradient(135deg, var(--ai-1), var(--ai-2)); color: #fff; font-size: 12px; font-weight: 600; }

/* ---------- Поиск ---------- */
.search-head { display: flex; gap: 10px; margin-bottom: 20px; }
.search-head .hero-search { flex: 1; max-width: none; }
.ai-answer { border-radius: 14px; padding: 18px 20px; margin-bottom: 24px; background: linear-gradient(var(--bg), var(--bg)) padding-box, linear-gradient(135deg, var(--ai-1), var(--ai-2)) border-box; border: 1.5px solid transparent; box-shadow: var(--shadow); }
.ai-answer-head { display: flex; align-items: center; gap: 10px; font-weight: 700; margin-bottom: 10px; }
.ai-answer-head .as-avatar { width: 26px; height: 26px; font-size: 13px; }
.ai-answer-head .btn { margin-left: auto; font-size: 13px; padding: 4px 10px; }
.ai-answer .md { font-size: 15px; }
.result { display: block; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; color: var(--text); }
.result:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.result h3 { margin: 0 0 4px; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.result .where { font-size: 12px; color: var(--text-3); margin-bottom: 6px; }
.result p { margin: 0; font-size: 14px; color: var(--text-2); }
mark { background: color-mix(in srgb, #fab005 35%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- Ассистент ---------- */
.assistant { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; overflow: hidden; background: var(--bg); }
.as-head { height: 56px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 12px 0 16px; border-bottom: 1px solid var(--line); }
.as-avatar { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-size: 16px; background: linear-gradient(135deg, var(--ai-1), var(--ai-2)); flex: none; }
.as-title { flex: 1; line-height: 1.25; }
.as-title b { display: block; font-size: 15px; }
.as-title small { color: var(--text-3); font-size: 12px; }
.as-title code { font-family: var(--mono); font-size: 11px; }
.as-body { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 16px; }
.as-empty { text-align: center; padding: 28px 8px 0; }
.as-empty .as-avatar { width: 56px; height: 56px; font-size: 26px; border-radius: 16px; margin: 0 auto 14px; }
.as-empty h3 { margin: 0 0 6px; }
.as-empty p { color: var(--text-2); font-size: 14px; margin: 0 0 18px; }
.suggestions { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.suggestion { border: 1px solid var(--line); background: var(--bg-soft); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; text-align: left; color: var(--text-2); display: flex; gap: 10px; }
.suggestion:hover { border-color: var(--ai-1); color: var(--text); background: var(--ai-soft); }
.msg-user { align-self: flex-end; max-width: 88%; background: var(--primary); color: #fff; padding: 9px 14px; border-radius: 16px 16px 4px 16px; font-size: 14px; white-space: pre-wrap; }
.msg-ai { align-self: stretch; font-size: 14px; }
.msg-ai .md { font-size: 14px; line-height: 1.62; }
.msg-ai .md h2 { font-size: 16px; margin: 16px 0 6px; }
.msg-ai .md h3 { font-size: 15px; margin: 14px 0 6px; }
.msg-ai .md p { margin-bottom: 8px; }
.msg-ai .md ul, .msg-ai .md ol { margin-bottom: 8px; padding-left: 20px; }
.msg-ai .md pre { font-size: 12px; }
.msg-ai .md table { font-size: 13px; }
.msg-ai .md th, .msg-ai .md td { padding: 6px 9px; }
.steps { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.step { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--text-3); padding: 5px 10px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px; }
.step .ic { flex: none; }
.step .lbl { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step .res { font-size: 11.5px; white-space: nowrap; }
.step .spin, .typing span { display: inline-block; }
.spin { width: 12px; height: 12px; border: 2px solid var(--line-strong); border-top-color: var(--ai-1); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.typing { display: inline-flex; gap: 4px; padding: 6px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--ai-1); opacity: .4; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: 1; transform: translateY(-2px); } }
.art-card { display: flex; gap: 12px; align-items: center; border: 1px solid color-mix(in srgb, var(--ai-1) 30%, var(--line)); background: var(--ai-soft); border-radius: 12px; padding: 12px 14px; margin: 8px 0; color: var(--text); }
.art-card .emoji { font-size: 24px; }
.art-card .t { flex: 1; min-width: 0; }
.art-card small { display: block; font-size: 11.5px; color: var(--ai-1); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
:root[data-theme='dark'] .art-card small { color: #c4a5ff; }
.art-card b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.art-card .open { font-size: 13px; font-weight: 600; color: var(--primary-text); white-space: nowrap; }
.msg-error { color: var(--red); background: var(--red-soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.as-foot { flex: none; padding: 10px 14px 12px; border-top: 1px solid var(--line); }
.as-context { display: none; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.as-context.show { display: flex; gap: 6px; align-items: center; }
.as-context span { background: var(--bg-sunk); border-radius: 6px; padding: 2px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }
/* Поле ввода чата в две строки: текст на всю ширину, под ним компактные кнопки — скрепка и микрофон слева, отправка справа */
.as-form { display: grid; grid-template-columns: auto auto 1fr auto; grid-template-areas: "input input input input" "attach mic . send"; align-items: center; gap: 2px; border: 1px solid var(--line-strong); border-radius: 14px; padding: 8px 8px 6px 12px; background: var(--bg); }
.as-form:focus-within { border-color: var(--ai-1); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ai-1) 14%, transparent); }
.as-form textarea { grid-area: input; width: 100%; min-height: 24px; border: 0; outline: 0; resize: none; font: inherit; font-size: 14px; background: transparent; color: var(--text); max-height: 160px; padding: 2px 0 4px; }
.as-send { grid-area: send; width: 30px; height: 30px; border: 0; border-radius: 10px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--ai-1), var(--ai-2)); flex: none; }
.as-send:disabled { opacity: .45; }
.as-send svg { width: 17px; height: 17px; }
.as-form #asAttach { grid-area: attach; margin-left: -6px; }
.as-form #asMic { grid-area: mic; }
.as-form .as-tool { width: 28px; height: 28px; border-radius: 7px; }
.as-form .as-tool svg { width: 17px; height: 17px; }

/* ---------- Палитра / модалки ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 18, 30, .45); backdrop-filter: blur(2px); z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; }
.overlay[hidden] { display: none; }
.confirm-overlay { z-index: 70; padding-top: 18vh; }
.confirm-box { width: min(480px, 92vw); }
.confirm-text p { margin: 0 0 10px; font-size: 14.5px; line-height: 1.5; }
.btn.danger-fill { background: var(--red); border-color: var(--red); color: #fff; }

/* Вставка ссылок в редакторе */
.link-search { width: 100%; font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg); color: var(--text); margin-bottom: 10px; }
.link-list { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; }
.link-item { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 8px 12px; cursor: pointer; font: inherit; color: var(--text); }
.link-item:last-child { border-bottom: 0; }
.link-item small { color: var(--text-3); font-size: 12px; }
.link-item:hover, .link-item.sel { background: var(--primary-soft); }
.link-item mark { background: color-mix(in srgb, var(--amber) 35%, transparent); color: inherit; border-radius: 2px; }
.palette { width: min(640px, 92vw); background: var(--bg); border-radius: 16px; box-shadow: var(--shadow-lg); border: 1px solid var(--line); overflow: hidden; }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--text-3); }
.palette-input input { flex: 1; border: 0; outline: 0; font: inherit; font-size: 17px; background: transparent; color: var(--text); }
.palette-list { max-height: 420px; overflow-y: auto; padding: 6px; }
.p-item { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 10px; cursor: pointer; color: var(--text); }
.p-item.sel { background: var(--bg-sunk); }
.p-item .emoji { font-size: 18px; width: 24px; text-align: center; }
.p-item .t { flex: 1; min-width: 0; }
.p-item .t b { display: block; font-weight: 500; font-size: 14px; }
.p-item .t small { display: block; color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-item.ask .emoji { color: var(--ai-1); }
.p-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); font-weight: 700; padding: 10px 12px 4px; }
.modal { width: min(720px, 92vw); max-height: 76vh; overflow-y: auto; background: var(--bg); border-radius: 16px; box-shadow: var(--shadow-lg); border: 1px solid var(--line); padding: 22px 24px; }
.modal h2 { margin: 0 0 16px; font-size: 20px; }
.version { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.version .t { flex: 1; }
.version .t b { display: block; font-size: 14px; }
.version .t small { color: var(--text-3); font-size: 12px; }
.version.is-current { background: var(--green-soft); margin: 0 -12px; padding: 12px; border-radius: 8px; }
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1a1d26; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow-lg); animation: up .25s ease; }
@keyframes up { from { transform: translateY(10px); opacity: 0; } }
.empty { text-align: center; color: var(--text-3); padding: 40px; }

@media (max-width: 1280px) {
  :root { --assistant-w: 380px; }
}
@media (max-width: 900px) {
  .app, .app.as-hidden { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .assistant { position: fixed; inset: 0; z-index: 40; }
  .app.as-hidden .assistant { display: none; }
  .page, .article-layout { padding: 24px 16px 80px; }
  .two-col, .editor-split { grid-template-columns: 1fr; }
  .editor-preview { display: none; }
}
.md li.task > div > p { margin: 0; }
[hidden] { display: none !important; }
.msg-model { margin-top: 6px; font-size: 11px; color: var(--text-3); cursor: help; }
