/* Forge4 Agent — дизайн-система с двумя темами.
   «Кузница» (тёмная): раскалённый металл — ИИ, холодная сталь — человек.
   «Аврора» (светлая): матовое стекло на живом градиенте, фиолетовый — ИИ, мятный — человек.
   Тема: <html data-theme="dark|light">. Адаптив: широкий экран / ноутбук / планшет / телефон. */

/* ---------- шрифты (Inter, OFL — лежат в проекте) ---------- */
@font-face { font-family: "F4 Inter"; src: url(/static/fonts/Inter-Regular.woff) format("woff"); font-weight: 400; font-display: swap; }
@font-face { font-family: "F4 Inter"; src: url(/static/fonts/Inter-Medium.woff) format("woff"); font-weight: 500; font-display: swap; }
@font-face { font-family: "F4 Inter"; src: url(/static/fonts/Inter-SemiBold.woff) format("woff"); font-weight: 600; font-display: swap; }
@font-face { font-family: "F4 Inter"; src: url(/static/fonts/Inter-Bold.woff) format("woff"); font-weight: 700; font-display: swap; }
@font-face { font-family: "F4 Display"; src: url(/static/fonts/InterDisplay-SemiBold.woff) format("woff"); font-weight: 600; font-display: swap; }
@font-face { font-family: "F4 Display"; src: url(/static/fonts/InterDisplay-Bold.woff) format("woff"); font-weight: 700; font-display: swap; }

/* ---------- токены: светлая «Аврора» ---------- */
:root {
  --font: "F4 Inter", Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "F4 Display", "F4 Inter", Inter, system-ui, sans-serif;
  --bg: #F3F2F8;
  --surface: rgba(255, 255, 255, .64);
  --surface-solid: #FFFFFF;
  --surface-2: rgba(255, 255, 255, .5);
  --edge: rgba(255, 255, 255, .9);
  --line: rgba(22, 19, 31, .08);
  --line-2: rgba(22, 19, 31, .14);
  --ink: #16131F;
  --ink-2: #57526A;
  --ink-3: #8C87A0;
  --accent: #6B4EF6;
  --accent-2: #8D74FF;
  --accent-ink: #FFFFFF;
  --ai: #6B4EF6;
  --ai-soft: rgba(107, 78, 246, .11);
  --ai-line: rgba(107, 78, 246, .28);
  --human: #0C9F73;
  --human-soft: rgba(18, 184, 134, .13);
  --ok: #0C9F73; --ok-soft: rgba(18, 184, 134, .13);
  --warn: #B86200; --warn-soft: rgba(255, 168, 0, .15);
  --err: #D6334A; --err-soft: rgba(214, 51, 74, .1);
  --shadow: 0 18px 50px rgba(60, 40, 140, .09);
  --shadow-pop: 0 24px 70px rgba(40, 20, 120, .2);
  --blur: blur(22px) saturate(1.4);
  --bubble-user: #FFFFFF;
  --bubble-ai: linear-gradient(135deg, #7B61FF, #5A3FE0);
  --bubble-ai-ink: #FFFFFF;
  --bubble-op: #0C9F73;
  --code-bg: #1C1830;
  --radius: 22px;
  --radius-sm: 14px;
  --side-w: 248px;
  color-scheme: light;
}

/* ---------- токены: тёмная «Кузница» ---------- */
html[data-theme="dark"] {
  --bg: #0F1319;
  --surface: linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, .018));
  --surface-solid: #161B23;
  --surface-2: rgba(255, 255, 255, .035);
  --edge: rgba(255, 255, 255, .075);
  --line: rgba(255, 255, 255, .07);
  --line-2: rgba(255, 255, 255, .13);
  --ink: #ECEFF4;
  --ink-2: #9AA4B2;
  --ink-3: #657082;
  --accent: #FF6B1A;
  --accent-2: #FFB04A;
  --accent-ink: #1A0A00;
  --ai: #FF8A3D;
  --ai-soft: rgba(255, 107, 26, .13);
  --ai-line: rgba(255, 140, 60, .38);
  --human: #7EA6FF;
  --human-soft: rgba(126, 166, 255, .13);
  --ok: #3DD68C; --ok-soft: rgba(61, 214, 140, .12);
  --warn: #FFB547; --warn-soft: rgba(255, 181, 71, .12);
  --err: #FF6B6B; --err-soft: rgba(255, 107, 107, .12);
  --shadow: 0 18px 50px rgba(0, 0, 0, .35);
  --shadow-pop: 0 24px 70px rgba(0, 0, 0, .55);
  --blur: blur(14px);
  --bubble-user: #1E2530;
  --bubble-ai: linear-gradient(135deg, rgba(255, 107, 26, .24), rgba(255, 176, 74, .12));
  --bubble-ai-ink: #ECEFF4;
  --bubble-op: #3D63C9;
  --code-bg: #0A0D12;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body, #root { margin: 0; height: 100%; }
body { font: 15px/1.5 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; font-feature-settings: "cv11", "ss01"; transition: background-color .3s; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.hidden { display: none !important; }
.muted { color: var(--ink-3); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- фон: живые пятна (Аврора) и жар (Кузница) ---------- */
.bgfx { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bgfx i { position: absolute; border-radius: 50%; filter: blur(80px); opacity: .7; transition: opacity .4s; }
.bgfx i:nth-child(1) { width: 640px; height: 640px; left: -140px; top: -200px; background: #C7B8FF; }
.bgfx i:nth-child(2) { width: 540px; height: 540px; right: -120px; top: 40px; background: #A5EED6; }
.bgfx i:nth-child(3) { width: 600px; height: 480px; left: 35%; bottom: -260px; background: #FFD1BC; }
html[data-theme="dark"] .bgfx i { opacity: 0; }
html[data-theme="dark"] .bgfx i:nth-child(2) { opacity: .5; width: 760px; height: 600px; right: -260px; top: -260px; background: rgba(255, 107, 26, .55); filter: blur(140px); }
html[data-theme="dark"] .bgfx i:nth-child(3) { opacity: .18; background: rgba(255, 176, 74, .6); filter: blur(160px); }
@media (prefers-reduced-motion: no-preference) {
  html:not([data-theme="dark"]) .bgfx i { animation: drift 26s ease-in-out infinite alternate; }
  html:not([data-theme="dark"]) .bgfx i:nth-child(2) { animation-duration: 32s; }
  @keyframes drift { to { transform: translate(60px, 40px) scale(1.08); } }
}

/* ---------- поверхности ---------- */
.panel, .glass { background: var(--surface); border: 1px solid var(--edge); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); }
.panel-pad { padding: 22px 24px; }
.panel h2, .glass h2, .section h2 { font: 600 17px/1.3 var(--display); margin: 0 0 4px; letter-spacing: -.01em; }
.panel .lead-in, .section > p { color: var(--ink-2); margin: 0 0 16px; font-size: 14px; }

/* ---------- поля и кнопки ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: 12.5px; }
.input, .textarea, .select { width: 100%; padding: 11px 13px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--surface-solid); transition: border-color .15s, box-shadow .15s; }
html[data-theme="dark"] .input, html[data-theme="dark"] .textarea, html[data-theme="dark"] .select { background: rgba(255, 255, 255, .04); }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--ai-soft); }
.textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
.select option { background: var(--surface-solid); color: var(--ink); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 17px; border-radius: 12px; border: 1px solid transparent; font-weight: 600; cursor: pointer; background: var(--ink); color: var(--bg); white-space: nowrap; text-decoration: none; transition: transform .12s, box-shadow .2s, filter .2s; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn-ember { background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: var(--accent-ink); box-shadow: 0 10px 28px var(--ai-soft), 0 6px 18px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn-human { background: var(--human); color: #fff; }
html[data-theme="dark"] .btn-human { color: #0B1220; }
.btn-ghost { background: var(--surface-2); color: var(--ink); border-color: var(--line-2); }
.btn-ghost:hover { background: var(--ai-soft); filter: none; }
.btn-sm { padding: 7px 12px; font-size: 13.5px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-weight: 600; }
.err-text { color: var(--err); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: inline-grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); cursor: pointer; }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { color: var(--ink); }

/* ---------- бренд ---------- */
.brand { display: flex; align-items: center; gap: 11px; font: 700 17px var(--display); letter-spacing: -.01em; color: var(--ink); }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font: 700 13px var(--display); color: #fff; background: var(--ink); flex: none; }
html[data-theme="dark"] .brand-mark { background: linear-gradient(140deg, #FFB04A, #FF6B1A 60%, #C83A00); box-shadow: 0 0 26px rgba(255, 107, 26, .45); }

/* ---------- вход ---------- */
.auth { min-height: 100%; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-side { padding: clamp(28px, 5vw, 64px); display: flex; flex-direction: column; justify-content: space-between; gap: 32px; }
.auth-side h1 { font: 600 clamp(32px, 4vw, 54px)/1.05 var(--display); letter-spacing: -.035em; margin: 0 0 18px; max-width: 14em; }
html[data-theme="dark"] .auth-side h1 span { background: linear-gradient(180deg, #fff 30%, #FFC78A 80%, #FF6B1A); -webkit-background-clip: text; background-clip: text; color: transparent; }
html:not([data-theme="dark"]) .auth-side h1 span { background: linear-gradient(120deg, #6B4EF6, #0C9F73); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-side p { color: var(--ink-2); max-width: 32em; margin: 0; font-size: 16px; }
.auth-chat { margin-top: 34px; display: grid; gap: 9px; max-width: 420px; }
.auth-chat div { padding: 11px 15px; border-radius: 18px; font-size: 14.5px; width: fit-content; max-width: 92%; }
.auth-chat .c { background: var(--bubble-user); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.auth-chat .a { background: var(--bubble-ai); color: var(--bubble-ai-ink); justify-self: end; border-bottom-right-radius: 6px; border: 1px solid var(--ai-line); }
.auth-chat .s { background: var(--ok-soft); color: var(--ok); font-size: 13px; justify-self: center; padding: 6px 14px; border-radius: 999px; }
.auth-form { display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: 100%; max-width: 420px; padding: 32px; }
.auth-card h2 { font: 600 26px var(--display); margin: 0 0 6px; letter-spacing: -.02em; }
.auth-card .sub { color: var(--ink-2); margin: 0 0 24px; }
.demo-hint { margin-top: 20px; padding: 13px 15px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; font-size: 13.5px; color: var(--ink-2); }
.demo-hint button { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; font-weight: 600; }
.theme-float { position: fixed; top: 16px; right: 16px; z-index: 5; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); height: 100%; }
.side { display: flex; flex-direction: column; gap: 4px; padding: 20px 14px 16px; overflow-y: auto; border-right: 1px solid var(--line); background: var(--surface-2); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); }
.side .brand { padding: 2px 8px 22px; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: 14.5px; position: relative; transition: background .15s, color .15s; }
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a.active { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--edge), var(--shadow); }
.nav a.active::before { content: ""; position: absolute; left: -14px; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.nav svg { width: 20px; height: 20px; flex: none; }
.nav .badge { margin-left: auto; background: var(--human); color: #fff; font-size: 11.5px; min-width: 21px; height: 21px; border-radius: 11px; display: grid; place-items: center; padding: 0 6px; }
html[data-theme="dark"] .nav .badge { color: #0B1220; box-shadow: 0 0 10px var(--human); }
.nav-sep { height: 1px; background: var(--line); margin: 12px 10px; }
.side-foot { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid var(--line); font-size: 13px; display: grid; gap: 8px; }
.side-foot .co { font-weight: 700; font-size: 14.5px; }
.side-foot .plan { color: var(--ink-3); }
.side-foot .plan b { color: var(--accent); font-weight: 600; }
.side-foot .links { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.side-foot .links button { background: none; border: 0; color: var(--ink-3); cursor: pointer; padding: 0; font-size: 13px; }
.side-foot .links button:hover { color: var(--ink); }
.theme-switch { display: flex; padding: 3px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.theme-switch button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; border: 0; background: none; padding: 6px 8px; border-radius: 9px; font-size: 12.5px; font-weight: 600; color: var(--ink-3); cursor: pointer; }
.theme-switch button svg { width: 15px; height: 15px; }
.theme-switch button.on { background: var(--surface-solid); color: var(--ink); box-shadow: 0 2px 8px rgba(0, 0, 0, .08); }
.main { overflow-y: auto; min-width: 0; display: flex; flex-direction: column; }
.acting { background: var(--human); color: #fff; padding: 9px 24px; font-size: 13.5px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
html[data-theme="dark"] .acting { color: #0B1220; }
.acting button { background: rgba(255, 255, 255, .22); border: 0; color: inherit; border-radius: 8px; padding: 4px 11px; cursor: pointer; font-weight: 600; }
.page { padding: 30px clamp(16px, 3vw, 40px) 56px; max-width: 1360px; width: 100%; margin: 0 auto; }
.page-full { padding: 0; max-width: none; flex: 1; min-height: 0; display: flex; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.head h1 { font: 600 30px/1.1 var(--display); margin: 0; letter-spacing: -.025em; }
.head p { margin: 6px 0 0; color: var(--ink-2); max-width: 62ch; }
.mhead, .tabbar { display: none; }

/* ---------- метки ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ai { background: var(--ai-soft); color: var(--ai); }
.pill.ai::before { box-shadow: 0 0 8px currentColor; }
.pill.human { background: var(--human-soft); color: var(--human); }
.pill.closed { background: var(--surface-2); color: var(--ink-3); }
.pill.st-active { background: var(--ok-soft); color: var(--ok); }
.pill.st-error { background: var(--err-soft); color: var(--err); }
.pill.st-pending, .pill.st-demo, .pill.st-new { background: var(--warn-soft); color: var(--warn); }
.ch { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-3); font-weight: 600; }
.ch svg { width: 14px; height: 14px; }
.seg { display: inline-flex; padding: 4px; border-radius: 13px; background: var(--surface-2); border: 1px solid var(--line); backdrop-filter: var(--blur); }
.seg button { white-space: nowrap; border: 0; background: none; padding: 7px 13px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--ink-2); }
.seg button.on { background: var(--surface-solid); color: var(--ink); box-shadow: 0 2px 10px rgba(0, 0, 0, .08); }

/* ---------- дашборд ---------- */
.today { margin-bottom: 22px; }
.today small { color: var(--ink-3); font-size: 13.5px; }
.today h1 { font: 600 clamp(30px, 4.2vw, 50px)/1.04 var(--display); letter-spacing: -.035em; margin: 6px 0 8px; max-width: 18em; }
.today h1 em { font-style: normal; color: var(--accent); }
html[data-theme="dark"] .today h1 em { background: linear-gradient(180deg, #FFD3A1, #FF6B1A); -webkit-background-clip: text; background-clip: text; color: transparent; }
.today p { margin: 0; color: var(--ink-2); font-size: 16px; }
.live-badge { display: inline-flex; align-items: center; gap: 10px; padding: 9px 15px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface-2); font-size: 13.5px; color: var(--ink-2); backdrop-filter: var(--blur); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ai); flex: none; }
@media (prefers-reduced-motion: no-preference) { .pulse { animation: pulse 2s infinite; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 var(--ai-line); } 70% { box-shadow: 0 0 0 10px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.dash { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
.hero { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.55fr); gap: 32px; align-items: center; padding: 30px; position: relative; overflow: hidden; }
.hero-big { font: 700 clamp(64px, 8vw, 104px)/.92 var(--display); letter-spacing: -.05em; color: var(--accent); }
html[data-theme="dark"] .hero-big { background: linear-gradient(180deg, #fff 18%, #FFC78A 70%, #FF6B1A); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-big small { font-size: .45em; }
.hero-cap { color: var(--ink-2); margin-top: 10px; max-width: 28ch; font-size: 15px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 14px 16px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); }
.stat b { display: block; font: 600 26px/1.15 var(--display); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--ink-2); }
.stat.human b { color: var(--human); }
.area { width: 100%; height: 150px; display: block; overflow: visible; }
.area-x { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-3); margin-top: 8px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--ink-2); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.span-7 { grid-column: span 7; }
.span-5 { grid-column: span 5; }
.span-12 { grid-column: 1 / -1; }
.h2row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.h2row a { color: var(--ink-3); font-size: 13px; text-decoration: none; font-weight: 600; }
.h2row a:hover { color: var(--accent); }
.livelist { display: grid; gap: 2px; margin: 0 -10px; }
.liverow { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px; border-radius: 14px; color: inherit; text-decoration: none; }
.liverow:hover { background: var(--surface-2); }
.liverow b { font-weight: 600; }
.liverow p { margin: 1px 0 0; color: var(--ink-2); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.liverow .tm { font-size: 12px; color: var(--ink-3); text-align: right; display: grid; gap: 4px; justify-items: end; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: center; }
.list-plain li:last-child { border-bottom: 0; }
.share { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 7px; border: 1px solid var(--line); }
.share i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* ---------- аватары ---------- */
.ava { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff; position: relative; flex: none; background: linear-gradient(135deg, #9C88FF, #6B4EF6); }
.ava.c1 { background: linear-gradient(135deg, #9C88FF, #6B4EF6); }
.ava.c2 { background: linear-gradient(135deg, #5BD8B4, #0C9F73); }
.ava.c3 { background: linear-gradient(135deg, #FFB38A, #F76707); }
.ava.c4 { background: linear-gradient(135deg, #74C0FC, #1C7ED6); }
.ava.c5 { background: linear-gradient(135deg, #F783AC, #D6336C); }
html[data-theme="dark"] .ava { background: #232A36 !important; color: var(--ink); }
.ava .st { position: absolute; right: -3px; bottom: -3px; width: 13px; height: 13px; border-radius: 50%; border: 2.5px solid var(--bg); }
.ava .st.ai { background: var(--ai); box-shadow: 0 0 8px var(--ai); }
.ava .st.human { background: var(--human); box-shadow: 0 0 8px var(--human); }
.ava .st.closed { background: var(--ink-3); }

/* ---------- инбокс ---------- */
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr) 310px; flex: 1; min-height: 0; height: 100%; }
.inbox-list { border-right: 1px solid var(--line); background: var(--surface-2); backdrop-filter: var(--blur); display: flex; flex-direction: column; min-height: 0; }
.inbox-list .tools { padding: 20px 16px 12px; display: grid; gap: 12px; }
.inbox-list h1 { font: 600 24px var(--display); margin: 0; letter-spacing: -.02em; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 6px 11px; border-radius: 9px; font-weight: 600; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.tabs button.on { background: var(--surface-solid); color: var(--ink); box-shadow: 0 2px 8px rgba(0, 0, 0, .07); }
.convs { overflow-y: auto; flex: 1; padding: 4px 8px 12px; }
.conv { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 11px; padding: 11px 10px; border-radius: 15px; cursor: pointer; margin-bottom: 2px; }
.conv:hover { background: var(--surface-2); }
.conv.sel { background: var(--surface); box-shadow: inset 0 0 0 1px var(--edge), var(--shadow); }
.conv .nm { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .lm { color: var(--ink-2); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .tm { font-size: 12px; color: var(--ink-3); text-align: right; display: grid; gap: 5px; justify-items: end; align-content: start; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--human); box-shadow: 0 0 8px var(--human); }
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.thread-head { padding: 14px 22px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line); background: var(--surface-2); backdrop-filter: var(--blur); }
.thread-head .who { font-weight: 700; }
.thread-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.msgs { flex: 1; overflow-y: auto; padding: 24px clamp(14px, 3vw, 40px); display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: min(78%, 580px); padding: 11px 15px; border-radius: 20px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; }
.msg .t { font-size: 11.5px; margin-top: 4px; opacity: .65; }
.msg.user { background: var(--bubble-user); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 6px; }
.msg.assistant { background: var(--bubble-ai); color: var(--bubble-ai-ink); align-self: flex-end; border-bottom-right-radius: 6px; border: 1px solid var(--ai-line); }
html:not([data-theme="dark"]) .msg.assistant { box-shadow: 0 10px 28px rgba(107, 78, 246, .25); }
.msg.operator { background: var(--bubble-op); color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.msg .by { font-size: 11.5px; font-weight: 700; margin-bottom: 2px; opacity: .85; }
html[data-theme="dark"] .msg.assistant .by { color: var(--accent-2); opacity: 1; }
.msg.system { align-self: center; background: var(--surface-2); border: 1px dashed var(--line-2); color: var(--ink-2); font-size: 12.5px; text-align: center; max-width: 92%; padding: 6px 14px; border-radius: 999px; }
.msg details { margin-top: 8px; font-size: 12.5px; opacity: .9; }
.msg summary { cursor: pointer; font-weight: 600; }
.composer { border-top: 1px solid var(--line); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: grid; gap: 8px; background: var(--surface-2); backdrop-filter: var(--blur); }
.composer .row { flex-wrap: nowrap; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 46px; max-height: 160px; resize: none; border-radius: 16px; }
.composer .note { font-size: 12.5px; color: var(--ink-3); }
.info { border-left: 1px solid var(--line); background: var(--surface-2); backdrop-filter: var(--blur); overflow-y: auto; padding: 20px; }
.info h3 { font: 600 15px var(--display); margin: 0 0 12px; }
.info .kv { display: grid; gap: 2px; margin-bottom: 12px; font-size: 14px; }
.info .kv span { color: var(--ink-3); font-size: 12.5px; }
.empty { display: grid; place-items: center; text-align: center; color: var(--ink-2); padding: 40px 20px; flex: 1; }
.empty h3 { color: var(--ink); margin: 0 0 6px; font: 600 18px var(--display); }
.back-btn { display: none; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12.5px; color: var(--ink-3); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
td .select { padding: 6px 9px; font-size: 13.5px; width: auto; }

/* ---------- настройки агента ---------- */
.settings { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; align-items: start; }
.section { padding: 24px; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; padding: 7px 13px; border: 1px solid var(--line-2); border-radius: 999px; cursor: pointer; font-size: 14px; background: var(--surface-2); }
.check:has(input:checked) { border-color: var(--ai-line); background: var(--ai-soft); color: var(--ai); font-weight: 600; }
.check input { accent-color: var(--accent); margin: 0; }
.providers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.prov { border: 1px solid var(--line-2); border-radius: 16px; padding: 15px; cursor: pointer; display: grid; gap: 4px; background: var(--surface-2); }
.prov input { display: none; }
.prov b { font-size: 14.5px; }
.prov span { font-size: 12.5px; color: var(--ink-2); }
.prov:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ai-soft); }
.sticky-save { position: sticky; bottom: 0; background: var(--surface-solid); border-top: 1px solid var(--line); padding: 14px 24px; display: flex; gap: 12px; align-items: center; border-radius: 0 0 var(--radius) var(--radius); z-index: 2; }
html[data-theme="dark"] .sticky-save { background: #141920; }
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.toggle input { appearance: none; width: 44px; height: 26px; border-radius: 13px; background: var(--line-2); position: relative; cursor: pointer; transition: background .2s; margin: 0; flex: none; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { transform: translateX(18px); }
.preview-widget { padding: 20px; }
.pw-bubble { border-radius: 18px; overflow: hidden; border: 1px solid var(--line); }
.pw-top { padding: 13px 15px; color: #fff; font-weight: 700; }
.pw-top small { display: block; font-weight: 500; opacity: .85; font-size: 12px; }
.pw-body { padding: 15px; background: var(--surface-2); font-size: 14px; }
.pw-body div { background: var(--surface-solid); border: 1px solid var(--line); border-radius: 14px; padding: 10px 13px; }

/* ---------- база знаний ---------- */
.kb-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.doc { display: flex; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); align-items: center; }
.doc:last-child { border-bottom: 0; }
.doc .t { font-weight: 700; font-size: 14.5px; }
.doc .m { font-size: 12.5px; color: var(--ink-3); }
.doc .acts { margin-left: auto; display: flex; gap: 6px; flex: none; }
.drop { display: block; border: 2px dashed var(--line-2); border-radius: 18px; padding: 26px; text-align: center; color: var(--ink-2); cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--ai-soft); }
.hit { padding: 11px 13px; border-left: 3px solid var(--ai); background: var(--surface-2); margin-top: 8px; font-size: 13.5px; white-space: pre-wrap; border-radius: 0 12px 12px 0; }
.hit b { color: var(--ai); font-size: 12px; }

/* ---------- каналы ---------- */
.channels { display: grid; gap: 18px; }
.chan { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 18px; padding: 24px; }
.chan-ico { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--ai-soft); color: var(--ai); }
.chan-ico svg { width: 27px; height: 27px; }
.chan h2 { margin: 0; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; background: var(--code-bg); color: #E6EDF3; padding: 13px 15px; border-radius: 12px; overflow-x: auto; white-space: pre; }
.steps { margin: 6px 0 14px; padding-left: 20px; color: var(--ink-2); font-size: 14px; }
.steps li { margin-bottom: 4px; }
.note-box { padding: 11px 15px; border-radius: 12px; font-size: 13.5px; margin: 10px 0; }
.note-box.ok { background: var(--ok-soft); color: var(--ok); }
.note-box.error { background: var(--err-soft); color: var(--err); }
.note-box.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- песочница ---------- */
.sandbox { display: grid; grid-template-columns: minmax(0, 1fr) 410px; flex: 1; min-height: 0; height: 100%; }
.sandbox .thread { border-right: 1px solid var(--line); }
.hood { overflow-y: auto; padding: 24px; background: var(--surface); backdrop-filter: var(--blur); }
html[data-theme="dark"] .hood { background: #0B0E13; }
.hood h2 { font: 600 21px var(--display); margin: 0 0 4px; letter-spacing: -.02em; }
.hood > p { margin: 0 0 18px; font-size: 13.5px; color: var(--ink-2); }
.hood h3 { font-size: 13.5px; margin: 20px 0 8px; }
.hood .stat { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-radius: 14px; overflow: hidden; padding: 0; border: 1px solid var(--line); }
.hood .stat div { background: var(--surface-solid); padding: 11px 13px; }
html[data-theme="dark"] .hood .stat div { background: #141920; }
.hood .stat b { display: block; font: 600 18px var(--display); }
.hood .stat span { font-size: 11.5px; color: var(--ink-3); }
.frag { background: var(--surface-2); border-left: 3px solid var(--ai); border-radius: 0 12px 12px 0; padding: 10px 13px; margin-bottom: 8px; font-size: 13px; }
.frag b { color: var(--ai); font-size: 12px; display: block; margin-bottom: 2px; }
.tool { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; margin-bottom: 8px; font-size: 13px; }
.tool .n { font-weight: 700; color: var(--ok); }
.tool pre { margin: 6px 0 0; white-space: pre-wrap; font-size: 12px; color: var(--ink-2); font-family: ui-monospace, Menlo, monospace; }
.hood .kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 13.5px; }
.hood .kv span { color: var(--ink-3); }
.hood .kv b { font-weight: 600; }
.hood .none { color: var(--ink-3); font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 16px 10px; }
.chips button { border: 1px solid var(--line-2); background: var(--surface-2); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.chips button:hover { border-color: var(--ai-line); color: var(--ai); }
.typing { align-self: flex-end; color: var(--ai); font-size: 13px; padding: 4px 8px; }

/* ---------- всплывающие ---------- */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 600; font-size: 14px; opacity: 0; transition: all .25s; z-index: 50; pointer-events: none; max-width: calc(100% - 32px); box-shadow: var(--shadow-pop); }
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--err); color: #fff; }
.dlg { border: 1px solid var(--edge); border-radius: 22px; padding: 26px; width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow-pop); color: var(--ink); background: var(--surface-solid); }
.dlg::backdrop { background: rgba(10, 8, 20, .45); backdrop-filter: blur(4px); }
.dlg h2 { margin: 0 0 6px; font: 600 20px var(--display); }
.sheet { position: fixed; inset: auto 0 0 0; margin: 0; max-width: none; width: 100%; border-radius: 26px 26px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); border: 1px solid var(--edge); background: var(--surface-solid); color: var(--ink); }
.sheet::backdrop { background: rgba(10, 8, 20, .45); }
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 4px auto 14px; }
.sheet a, .sheet button.item { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 12px; border-radius: 14px; border: 0; background: none; color: var(--ink); text-decoration: none; font-weight: 600; font-size: 16px; text-align: left; cursor: pointer; }
.sheet a:active, .sheet button.item:active { background: var(--surface-2); }
.sheet svg { width: 22px; height: 22px; color: var(--ink-2); }
.sheet .sep { height: 1px; background: var(--line); margin: 6px 0; }

/* =============== адаптив =============== */
/* Широкий экран */
@media (min-width: 1680px) {
  .page { max-width: 1480px; }
  .inbox { grid-template-columns: 380px minmax(0, 1fr) 340px; }
}

/* Ноутбук поменьше: боковая панель уже, справочная колонка инбокса прячется */
@media (max-width: 1280px) {
  :root { --side-w: 220px; }
  .inbox { grid-template-columns: 310px minmax(0, 1fr); }
  .inbox .info { display: none; }
  .sandbox { grid-template-columns: minmax(0, 1fr) 340px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Планшет: боковая панель превращается в узкую полосу иконок */
@media (max-width: 1080px) {
  :root { --side-w: 80px; }
  .side { padding: 18px 10px; align-items: center; }
  .side .brand { padding: 0 0 18px; }
  .side .brand > span:not(.brand-mark), .nav a span, .side-foot { display: none; }
  .nav a { justify-content: center; width: 54px; height: 50px; padding: 0; }
  .nav a.active::before { left: -10px; }
  .nav .badge { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; font-size: 10.5px; padding: 0 5px; }
  .nav-sep { width: 40px; margin: 10px auto; }
  .side .rail-theme { display: grid !important; margin-top: auto; }
  .hero { grid-template-columns: 1fr; gap: 22px; }
  .span-7, .span-5 { grid-column: 1 / -1; }
  .settings, .kb-grid, .grid2 { grid-template-columns: 1fr; }
  .settings > aside { position: static !important; order: -1; }
  .providers { grid-template-columns: 1fr; }
  .sandbox { grid-template-columns: 1fr; grid-template-rows: minmax(480px, 1fr) auto; height: auto; }
  .sandbox .thread { border-right: 0; border-bottom: 1px solid var(--line); }
}
.side .rail-theme { display: none; }

/* Телефон: нижнее плавающее меню, шапка сверху, диалог на весь экран */
@media (max-width: 760px) {
  body { font-size: 15.5px; }
  .input, .textarea, .select { font-size: 16px; } /* без автозума на iPhone */
  .shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .side { display: none; }
  .main { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  .mhead { display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; position: sticky; top: 0; z-index: 6; background: var(--surface-2); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); border-bottom: 1px solid var(--line); }
  .mhead .brand { font-size: 16px; }
  .mhead .brand-mark { width: 34px; height: 34px; border-radius: 11px; font-size: 12px; }
  .mhead .co { margin-left: auto; font-size: 13px; color: var(--ink-2); font-weight: 600; max-width: 40vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tabbar { display: flex; position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 20; justify-content: space-around; padding: 7px 6px; border-radius: 24px; background: var(--surface-solid); border: 1px solid var(--edge); box-shadow: var(--shadow-pop); }
  html:not([data-theme="dark"]) .tabbar { background: rgba(255, 255, 255, .82); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); }
  html[data-theme="dark"] .tabbar { background: rgba(22, 27, 35, .9); backdrop-filter: var(--blur); }
  .tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px; border-radius: 16px; font-size: 10.5px; font-weight: 600; color: var(--ink-3); text-decoration: none; border: 0; background: none; position: relative; cursor: pointer; }
  .tabbar svg { width: 23px; height: 23px; }
  .tabbar .active { color: var(--accent); }
  html:not([data-theme="dark"]) .tabbar .active { background: var(--ink); color: #fff; }
  .tabbar .badge { position: absolute; top: 0; left: 50%; margin-left: 6px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--human); color: #fff; font-size: 10.5px; display: grid; place-items: center; padding: 0 5px; }
  body.thread-open .tabbar { display: none; }
  body.thread-open .main { padding-bottom: 0; }
  .page { padding: 18px 14px 24px; }
  .head { margin-bottom: 16px; }
  .head h1 { font-size: 25px; }
  .today h1 { font-size: 31px; }
  .today p { font-size: 14.5px; }
  .live-badge { display: none; }
  .dash { gap: 12px; }
  .hero { padding: 20px; border-radius: 24px; }
  .hero-big { font-size: 76px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 11px 13px; }
  .stat b { font-size: 22px; }
  .area { height: 120px; }
  .panel-pad { padding: 18px; }
  .panel, .glass { border-radius: 22px; }
  /* инбокс: список или диалог на весь экран */
  .inbox { grid-template-columns: 1fr; }
  .inbox.open .inbox-list { display: none; }
  .inbox:not(.open) .thread { display: none; }
  .inbox-list { border-right: 0; background: none; }
  .back-btn { display: inline-flex; }
  .inbox .thread { position: fixed; inset: 0; z-index: 30; background: var(--bg); }
  .thread-head { padding: calc(10px + env(safe-area-inset-top)) 12px 10px; gap: 10px; }
  .thread-head .actions { width: 100%; margin: 0; }
  .thread-head .actions .btn { flex: 1; }
  .msg { max-width: 86%; }
  /* таблицы превращаются в карточки */
  .cards-sm table, .cards-sm tbody, .cards-sm tr, .cards-sm td { display: block; width: 100%; }
  .cards-sm thead { display: none; }
  .cards-sm tr { padding: 14px 16px; border-bottom: 1px solid var(--line); }
  .cards-sm td { padding: 3px 0; border: 0; }
  .cards-sm td[data-label]::before { content: attr(data-label); display: block; font-size: 11.5px; color: var(--ink-3); font-weight: 600; }
  .sandbox { grid-template-rows: minmax(70vh, 1fr) auto; }
  .chan { grid-template-columns: minmax(0, 1fr); padding: 20px; }
  .chan .row { flex-wrap: wrap; }
  /* Телефон: кнопка стоит в конце формы; всплывает над нижним меню, только когда есть несохранённые изменения.
     bottom: 0 — от края контента .main, у которого уже есть отступ под нижнее меню. */
  .sticky-save { position: static; margin: 0 10px 10px; padding: 10px 12px; border: 1px solid var(--edge); border-radius: 18px; flex-wrap: wrap; }
  .sticky-save .btn { flex: 1 0 auto; }
  .sticky-save .dirty-note { display: none; }
  form.dirty .sticky-save { position: sticky; bottom: 0; box-shadow: var(--shadow-pop); animation: saveIn .22s ease-out; }
  form.dirty .sticky-save .dirty-note { display: block; width: 100%; text-align: center; font-size: 12.5px; color: var(--ink-3); order: -1; }
  form.dirty .sticky-save #saved { display: none; }
  @keyframes saveIn { from { transform: translateY(14px); opacity: 0; } }
  .doc { flex-wrap: wrap; padding: 14px 16px; }
  .doc .acts { margin-left: 0; width: 100%; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { padding: 28px 20px 0; }
  .auth-chat { display: none; }
  .auth-card { padding: 24px 20px; }
  .today .row, .head > .row { width: 100%; }
  .seg { width: 100%; overflow-x: auto; scrollbar-width: none; }
  .seg button { flex: 1 0 auto; }
  .cards-sm tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; }
  .cards-sm td { grid-column: 1 / -1; }
  .cards-sm td:first-child { font-size: 12.5px; }
  .cards-sm td.c-ch { grid-column: 1; }
  .cards-sm td.c-st { grid-column: 2; }
  .cards-sm td[data-empty] { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
