/* kotbot AI Workspace — дизайн-система kotbot black, только светлая тема */

/* ── токены (design/ds/tokens.css) ───────────────────────────────────────── */
:root {
  --ink: #171717; --page: #fff; --surface: #f5f5f5; --border: #ebebeb; --border-strong: #bfbfbf;
  --tertiary: #aaa; --secondary: #5a5a5a; --accent: #5e77fd; --accent-10: rgba(94, 119, 253, .1);
  --error: #ef4444; --error-10: rgba(239, 68, 68, .1); --success: #22c55e; --success-10: rgba(34, 197, 94, .1);
  --placeholder: rgba(23, 23, 23, .3);
  --shadow-menu: 0 12px 33.7px rgba(0, 0, 0, .15);
  --ring-ink: inset 0 0 0 2px #171717; --ring-field: inset 0 0 0 2px #5a5a5a;
  --motion: 160ms cubic-bezier(.4, 0, .2, 1);
  --r4: 4px; --r8: 8px; --r12: 12px; --r16: 16px; --r24: 24px; --r32: 32px; --r36: 36px; --pill: 555px;
  --font: "Museo Sans Cyrl", "Nunito Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --s1: #5e77fd; --s2: #171717; --s3: #aaa; --s4: #bfbfbf;
  --side-w: 258px; --col-pad: 72px;
}

/* ── база ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-weight: 300; font-size: 16px; line-height: 20px; color: var(--ink); background: var(--page); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; transition: background-color var(--motion), color var(--motion), box-shadow var(--motion); }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; transition: color var(--motion); }
:focus-visible { outline: none; box-shadow: var(--ring-ink); }
::placeholder { color: var(--placeholder); font-weight: 300; opacity: 1; }
h1, h2, h3, p { margin: 0; }
h1 { font-weight: 700; }
b, strong { font-weight: 700; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.spacer { flex: 1; }
.ic { width: 20px; height: 20px; flex: none; display: block; }
.meta { font-weight: 300; font-size: 12px; line-height: 16px; color: var(--tertiary); }
.sub { font-weight: 300; font-size: 14px; line-height: 18px; color: var(--tertiary); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ── кнопки (kb-btn) ─────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 12px 16px; border-radius: var(--r32); font-weight: 500; font-size: 16px; line-height: 20px; white-space: nowrap; background: var(--ink); color: #fff; }
.btn:hover, .btn:focus-visible { background: #fff; color: var(--ink); box-shadow: var(--ring-ink); }
.btn.sec { background: var(--surface); color: var(--ink); }
.btn.sec:hover, .btn.sec:focus-visible { background: var(--surface); color: var(--secondary); box-shadow: none; }
.btn.elev { background: #fff; color: var(--ink); }
.btn.elev:hover, .btn.elev:focus-visible { color: var(--secondary); box-shadow: none; }
.btn.m { height: 34px; padding: 8px 12px; }
.btn:disabled { background: var(--surface); color: var(--border-strong); box-shadow: none; }
.btn .ic { width: 20px; height: 20px; }
a.btn { text-decoration: none; }
.tbtn { display: inline-flex; align-items: center; gap: 8px; height: 18px; font-weight: 500; font-size: 14px; line-height: 18px; color: var(--secondary); white-space: nowrap; }
.tbtn:hover { color: var(--ink); }
.tbtn:focus-visible { box-shadow: 0 0 0 1px var(--secondary); }
.tbtn:disabled { color: var(--border-strong); }
.tbtn .ic { width: 16px; height: 16px; }
.chip { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 34px; padding: 8px 16px; border-radius: var(--r36); background: var(--surface); color: var(--secondary); font-weight: 500; font-size: 14px; line-height: 18px; white-space: nowrap; }
.chip:hover { color: var(--ink); }
.chip:focus-visible { background: var(--surface); color: var(--ink); box-shadow: var(--ring-ink); }
.chip .ic { width: 16px; height: 16px; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; }
.iconbtn { width: 40px; height: 40px; border-radius: var(--pill); display: grid; place-items: center; color: var(--ink); flex: none; }
.iconbtn:hover { color: var(--secondary); }
.kseg { display: inline-flex; gap: 4px; height: 38px; padding: 4px; border-radius: var(--r36); background: var(--surface); }
.kseg > a, .kseg > button { flex: 1 1 0; display: flex; align-items: center; justify-content: center; padding: 0 12px; border-radius: var(--r24); color: var(--tertiary); font-weight: 500; font-size: 14px; line-height: 18px; white-space: nowrap; }
.kseg > a:hover, .kseg > button:hover { color: var(--secondary); }
.kseg > [aria-current], .kseg > [aria-pressed="true"] { background: #fff; color: var(--ink); }

/* ── поля (kb-field) ─────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field > span { padding: 0 12px; font-weight: 500; font-size: 14px; line-height: 20px; color: var(--secondary); }
.input, .select { width: 100%; height: 52px; padding: 0 16px; border: 0; border-radius: var(--r12); background: #fff; box-shadow: inset 0 0 0 1px var(--border-strong); font-weight: 500; font-size: 16px; line-height: 20px; color: var(--ink); outline: none; transition: box-shadow var(--motion); min-width: 0; }
.input:hover, .select:hover { box-shadow: inset 0 0 0 1px var(--secondary); }
.input:focus, .select:focus { box-shadow: var(--ring-field); }
.select { appearance: none; -webkit-appearance: none; padding-right: 40px; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 6l4.5 4.5L12.5 6' fill='none' stroke='%235a5a5a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; }
.select-s { height: 40px; width: auto; border-radius: var(--r36); background-color: var(--surface); box-shadow: none; font-size: 14px; line-height: 18px; padding: 0 36px 0 12px; }
.select-s:hover { box-shadow: none; color: var(--secondary); }

/* ── каркас ──────────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); height: 100dvh; overflow: hidden; }
.app.collapsed { --side-w: 112px; }
.side { background: var(--surface); padding: 36px 32px; display: flex; flex-direction: column; gap: 24px; min-height: 0; overflow: hidden; }
.brand { display: flex; align-items: center; justify-content: space-between; height: 22px; margin-bottom: 12px; }
.brand a { display: block; }
.logo { display: block; height: 22px; width: auto; }
.logo-mini { display: none; width: 24px; height: 14px; overflow: hidden; }
.logo-mini .logo { height: 14px; }
.side .kseg { width: 100%; }
.side .btn.new { align-self: flex-start; background: #fff; color: var(--ink); padding: 12px 16px 12px 8px; }
.side .btn.new:hover, .side .btn.new:focus-visible { color: var(--secondary); box-shadow: none; }
.side .btn.new[aria-current] { color: var(--ink); }
.navs { display: flex; flex-direction: column; gap: 4px; }
.nav { display: flex; align-items: center; gap: 8px; height: 44px; padding: 12px; border-radius: var(--r8); font-weight: 500; font-size: 16px; line-height: 20px; color: var(--tertiary); white-space: nowrap; }
.nav:hover { color: var(--secondary); }
.nav[aria-current] { color: var(--ink); background: #fff; }
.nav:focus-visible { box-shadow: var(--ring-ink); }
.nav .lbl { overflow: hidden; text-overflow: ellipsis; }
.side h3 { font-weight: 700; font-size: 14px; line-height: 18px; color: var(--secondary); margin-bottom: -12px; }
.recent { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; margin: 0 -12px; padding: 0 12px 0 12px; }
.rc { position: relative; display: flex; align-items: center; gap: 8px; height: 42px; flex: none; padding: 12px; border-radius: var(--r24); color: var(--secondary); }
.rc > a { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 100%; font-weight: 300; font-size: 14px; line-height: 18px; }
.rc > a > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc > a .ic { width: 16px; height: 16px; color: var(--secondary); }
.rc:hover > a { color: var(--ink); }
.rc.on { background: #fff; }
.rc.on > a { font-weight: 500; color: var(--ink); }
.rc .x { width: 16px; height: 16px; color: var(--tertiary); flex: none; display: grid; place-items: center; }
.rc .x:hover, .rc .x[aria-expanded="true"] { color: var(--ink); }
.rc .x .ic { width: 16px; height: 16px; }
.side-foot { display: flex; }
.side-foot .tog { width: 32px; height: 32px; border-radius: var(--pill); background: #fff; color: var(--secondary); display: grid; place-items: center; }
.side-foot .tog:hover { color: var(--ink); }
.side-foot .tog .ic { width: 20px; height: 20px; }
#btn-close-nav { display: none; }
.collapsed .side { padding: 36px 32px; align-items: center; }
.collapsed .brand .logo-full { display: none; }
.collapsed .logo-mini { display: block; }
.collapsed .brand { justify-content: center; }
.collapsed .side .kseg, .collapsed .side h3, .collapsed .recent, .collapsed .nav .lbl, .collapsed .btn.new .lbl { display: none; }
.collapsed .side .btn.new { padding: 12px; width: 44px; align-self: center; }
.collapsed .nav { width: 44px; padding: 12px; justify-content: center; }
.collapsed .side-foot { margin-top: auto; }
.backdrop { display: none; }

.main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100dvh; background: var(--page); }
.hdr { flex: none; position: relative; z-index: 3; height: 64px; padding: 12px 20px; display: flex; align-items: center; justify-content: center; gap: 20px; }
.hdr-title { position: absolute; left: var(--col-pad); top: 0; bottom: 0; max-width: calc(50% - 263px); display: flex; align-items: center; font-weight: 500; font-size: 16px; line-height: 20px; color: var(--ink); }
.hdr-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hdr-logo, #btn-open-nav { display: none; }
.hdr .grp { display: contents; }
.topup { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: var(--pill); background: var(--surface); font-weight: 500; font-size: 16px; line-height: 100%; color: var(--ink); white-space: nowrap; }
.topup:hover { color: var(--secondary); }
.topup b, #bal { font-weight: 700; }
.giftbtn { position: relative; width: 40px; height: 40px; border-radius: var(--pill); background: var(--accent-10); color: var(--accent); display: grid; place-items: center; }
.giftbtn .ic { width: 24px; height: 24px; }
.giftbtn::after { content: ""; position: absolute; top: 3px; right: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.giftbtn:hover { box-shadow: inset 0 0 0 2px var(--accent); }
.avatar { width: 40px; height: 40px; border-radius: var(--pill); background: var(--ink); color: #fff; display: grid; place-items: center; flex: none; }
.avatar .ic { width: 28px; height: 28px; }
.avatar:hover { background: #fff; color: var(--ink); box-shadow: var(--ring-ink); }
#stage { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }

/* ── экран чата ──────────────────────────────────────────────────────────── */
.chat { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.deco { position: absolute; z-index: 0; border-radius: 50%; background: var(--accent); filter: blur(70px); opacity: .32; pointer-events: none; left: 50%; display: none; }
.deco.top { width: 381px; height: 381px; top: -300px; margin-left: -190px; }
.deco.bot { width: 286px; height: 286px; bottom: -220px; margin-left: -143px; }
.chat.home .deco, .chat.blank .deco { display: block; }
.chat.blank .deco.top { display: none; }
.hero { position: relative; z-index: 1; margin: auto; width: 100%; box-sizing: border-box; padding: 0 var(--col-pad) 24px; display: none; flex-direction: column; align-items: center; }
.chat.home .hero { display: flex; }
.chat.home { overflow-y: auto; overflow-x: hidden; }
.hero h1, .blank-t { font-size: 36px; line-height: 46px; text-align: center; }
.hero h1 { margin-bottom: 32px; }
.tiles { display: flex; gap: 16px; justify-content: center; width: 100%; max-width: 736px; }  /* плитки резиновые: 360×360 по макету, но сжимаются, если колонка уже */
.tile { position: relative; flex: 1 1 0; min-width: 0; max-width: 360px; aspect-ratio: 1; border-radius: var(--r24); background: var(--surface); padding: 24px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; text-align: center; font-weight: 500; font-size: 16px; line-height: 20px; color: var(--ink); overflow: hidden; }
.tile:hover { color: var(--secondary); }
.tile > img { position: absolute; left: 50%; bottom: 6.7%; width: 75%; height: 75%; transform: translateX(-50%); object-fit: contain; pointer-events: none; }
.tile .mini { position: absolute; left: 9.5%; bottom: 14%; width: 59%; min-width: 150px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 10px 10px 14px; background: #fff; border: 1px solid var(--border); border-radius: var(--r24); transform: rotate(-5deg); font-weight: 500; font-size: 11px; line-height: 14px; text-align: left; pointer-events: none; }
.tile .mini i { width: 27px; height: 27px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.tile .mini i .ic { width: 16px; height: 16px; }
.cmds { margin-top: 24px; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 736px; }
.feed { position: relative; z-index: 1; flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.feed-in { padding: 32px var(--col-pad) 56px; display: flex; flex-direction: column; gap: 20px; }
.chat.home .feed, .chat.blank .feed { display: none; }
.chat.blank { justify-content: center; }
.cw { position: relative; z-index: 2; width: 100%; max-width: calc(728px + var(--col-pad) * 2); margin: 0 auto; padding: 0 var(--col-pad) 16px; flex: none; }
.chat.home .cw { display: none; }
.chat.blank .cw { padding-bottom: 0; margin-bottom: auto; margin-top: auto; }
.chat.blank .hint { display: none; }
.cw::before { content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 100px; background: linear-gradient(rgba(255, 255, 255, 0), #fff); pointer-events: none; }
.chat.blank .cw::before { display: none; }
.blank-t { display: none; margin-bottom: 32px; }
.chat.blank .blank-t { display: block; }
.hint { margin-top: 8px; text-align: center; font-weight: 300; font-size: 12px; line-height: 16px; color: var(--tertiary); }

/* композер */
.help { display: none; align-items: center; justify-content: space-between; gap: 12px; min-height: 42px; padding: 8px 20px; margin-bottom: 8px; background: #fff; border: 1px solid var(--border); border-radius: var(--r36); }
.help.on { display: flex; }
.help-t { font-weight: 300; font-size: 14px; line-height: 18px; color: var(--secondary); white-space: nowrap; }
.help-chips { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.hchip { height: 26px; padding: 4px 8px; border-radius: var(--r16); background: var(--surface); color: var(--secondary); font-weight: 300; font-size: 14px; line-height: 18px; white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; display: block; }
.hchip:hover { color: var(--ink); }
.hchip.has, .hchip[aria-expanded="true"] { background: var(--accent-10); color: var(--ink); }
.panel { background: #fff; border: 1px solid var(--border); border-radius: var(--r36); padding: 20px; display: flex; flex-direction: column; gap: 20px; transition: box-shadow var(--motion); }

.atts { display: flex; flex-wrap: wrap; gap: 8px; }
.att { position: relative; height: 48px; border-radius: var(--r8); border: 1px solid var(--border); background: var(--surface); }
.att img { width: 46px; height: 46px; object-fit: cover; border-radius: 7px; display: block; }
.att .rm { position: absolute; top: -6px; right: -6px; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; }
.att .rm .ic { width: 10px; height: 10px; }
.inp { display: flex; align-items: flex-start; gap: 16px; }
.inp textarea { flex: 1; min-width: 0; resize: none; border: 0; outline: none; background: none; padding: 0; font-weight: 500; font-size: 16px; line-height: 20px; color: var(--ink); max-height: 200px; display: block; }
.inp textarea:focus-visible { box-shadow: none; }
.inp textarea:disabled { color: var(--tertiary); }
.help-link { display: inline-flex; align-items: center; gap: 4px; flex: none; font-weight: 300; font-size: 14px; line-height: 18px; color: var(--accent); white-space: nowrap; }
.help-link:hover { color: var(--ink); }
.help-link .ic { width: 16px; height: 16px; transition: transform var(--motion); }
.help-link[aria-expanded="true"] .ic { transform: rotate(180deg); }
.tools { display: flex; align-items: flex-end; gap: 16px; min-height: 40px; }
/* левая группа переносится на вторую строку, отправка всегда справа внизу и не вылезает за рамку панели */
.tools-l { flex: 1 1 auto; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tools-r { flex: none; display: flex; align-items: center; gap: 8px; }
.pill.io { padding: 8px 8px 8px 8px; gap: 2px; }
.dd { position: relative; flex: none; }
.pill { height: 40px; display: inline-flex; align-items: center; gap: 4px; padding: 8px 12px 8px 8px; border-radius: var(--r36); background: var(--surface); color: var(--ink); font-weight: 500; font-size: 14px; line-height: 18px; white-space: nowrap; }
.pill .ic { width: 24px; height: 24px; }
.pill .ic.caret { width: 16px; height: 16px; color: var(--secondary); }
.pill:hover:not(:disabled) { color: var(--secondary); }
.pill.sq { width: 40px; padding: 0; justify-content: center; flex: none; }
.pill:disabled { color: var(--border-strong); }
.pill.on { box-shadow: inset 0 0 0 1px var(--border-strong); }
.segn { display: inline-flex; height: 40px; padding: 4px; gap: 2px; border-radius: var(--r36); background: var(--surface); flex: none; }
.segn button { width: 32px; border-radius: var(--r24); font-weight: 500; font-size: 14px; color: var(--tertiary); }
.segn button:hover:not(:disabled) { color: var(--secondary); }
.segn button[aria-pressed="true"] { background: #fff; color: var(--ink); }
.cost { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; font-size: 14px; line-height: 18px; color: var(--ink); white-space: nowrap; }
.cost:empty { display: none; }
.cost .ic { width: 24px; height: 24px; color: var(--secondary); }
.send { width: 40px; height: 40px; border-radius: var(--r36); background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.send .ic { width: 24px; height: 24px; }
.send:hover:not(:disabled), .send:focus-visible { background: #fff; color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.send.stop { background: var(--ink); }
.send.stop:hover, .send.stop:focus-visible { background: #fff; color: var(--ink); box-shadow: var(--ring-ink); }

/* всплывающие меню */
.dd-menu { display: none; position: absolute; z-index: 40; left: 0; bottom: calc(100% + 8px); min-width: 190px; max-height: min(60vh, 420px); overflow: auto; padding: 8px 16px; background: #fff; border-radius: var(--r12); box-shadow: var(--shadow-menu); }
.dd.open > .dd-menu { display: block; }
.chat.blank .tools .dd-menu.m-model, .chat.blank .tools .dd-menu.m-q { bottom: auto; top: calc(100% + 8px); }
.help-chips .dd-menu { left: auto; right: 0; bottom: calc(100% + 8px); top: auto; }
.dd-menu h4 { margin: 0; padding: 4px 0 8px; font-weight: 500; font-size: 14px; line-height: 18px; color: var(--ink); }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 32px; text-align: left; font-weight: 500; font-size: 14px; line-height: 18px; color: var(--secondary); padding: 7px 0; white-space: nowrap; }
.opt:hover { color: var(--ink); }
.opt[aria-checked="true"], .opt[aria-pressed="true"] { color: var(--ink); }
.opt .ic { width: 16px; height: 16px; color: var(--accent); }
.opt small { font-weight: 300; font-size: 12px; line-height: 16px; color: var(--tertiary); }
.opt[aria-disabled="true"] { color: var(--border-strong); cursor: default; }
.opt[aria-disabled="true"]:hover { color: var(--border-strong); }
.opt.rd { justify-content: flex-start; gap: 12px; min-height: 30px; padding: 6px 0; color: var(--ink); }
.opt.rd::before { content: ""; width: 16px; height: 16px; flex: none; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--border-strong); }
.opt.rd[aria-checked="true"]::before { box-shadow: inset 0 0 0 1px var(--accent); background: radial-gradient(circle, var(--accent) 0 3px, transparent 3.5px); }
.opt.rd small { margin-left: auto; }
.opt.rd[aria-disabled="true"] { color: var(--tertiary); }
.dd-menu.m-model, .dd-menu.m-q { min-width: 168px; }
.dd-menu.m-ar { width: 420px; max-width: calc(100vw - 32px); padding: 16px; }
.ar-top { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; padding-top: 4px; }
.ar-grid { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 12px; flex: 1; }
.ar { display: grid; place-items: center; border-radius: var(--r4); box-shadow: inset 0 0 0 1px var(--secondary); font-weight: 500; font-size: 11px; line-height: 14px; color: var(--ink); flex: none; }
.ar:hover { box-shadow: inset 0 0 0 1px var(--ink); }
.ar[aria-checked="true"] { box-shadow: inset 0 0 0 2px var(--accent); }
.ar-prev { width: 90px; height: 90px; flex: none; display: grid; place-items: center; }
.ar-prev i { display: block; background: var(--surface); box-shadow: inset 0 0 0 1px var(--border-strong); border-radius: 2px; }
.presets { margin-top: 16px; }
.presets .row { display: flex; flex-wrap: wrap; gap: 8px; }
.presets .chip { height: 30px; padding: 6px 12px; }
.presets .chip small { font-weight: 300; font-size: 12px; color: var(--tertiary); }
.presets .chip[aria-checked="true"] { background: var(--accent-10); color: var(--ink); }
.rowmenu { position: fixed; z-index: 80; min-width: 150px; padding: 8px 16px; background: #fff; border-radius: var(--r12); box-shadow: var(--shadow-menu); }

/* ── лента ───────────────────────────────────────────────────────────────── */
.msg { display: flex; width: 100%; max-width: 728px; margin: 0 auto; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--surface); border-radius: var(--r16); padding: 12px; max-width: 476px; font-weight: 500; font-size: 16px; line-height: 20px; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.bot .bubble { padding: 12px; max-width: 600px; width: 100%; display: flex; flex-direction: column; gap: 12px; font-weight: 300; font-size: 16px; line-height: 20px; color: var(--ink); min-width: 0; }
.feed-in.wide .msg.has-img { max-width: none; }  /* широкая только сама галерея, реплики остаются в колонке 728 */
.msg.bot.has-img .bubble { max-width: none; }
.msg.bot.has-img .bubble > :not(.imggrid) { max-width: 728px; width: 100%; margin-left: auto; margin-right: auto; }
.msg.bot.has-img .bubble > .tool, .msg.bot.has-img .bubble > .meta { width: 100%; }
.typing { display: inline-flex; gap: 4px; align-items: center; height: 20px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--tertiary); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; overflow-wrap: anywhere; }
.md h3, .md h4, .md h5, .md h6 { margin: 16px 0 8px; font-weight: 700; font-size: 16px; line-height: 20px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 2px 0; overflow-wrap: anywhere; }
.md code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9em; background: var(--surface); padding: 1px 5px; border-radius: var(--r4); }
.md pre { margin: 0 0 12px; background: var(--surface); border-radius: var(--r12); padding: 12px 16px; overflow: auto; }
.md pre code { background: none; padding: 0; font-size: 13px; line-height: 20px; }
.md blockquote { margin: 0 0 12px; padding-left: 12px; border-left: 2px solid var(--border-strong); color: var(--secondary); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.md a { color: var(--accent); }
.md a:hover { color: var(--ink); }
.md .tw { overflow: auto; margin: 0 0 12px; max-width: 100%; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; line-height: 18px; font-variant-numeric: tabular-nums; }
.md th { text-align: left; font-weight: 500; color: var(--secondary); padding: 0 12px; height: 40px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.md td { padding: 0 12px; height: 40px; border-bottom: 1px solid var(--border); }
.md th[align="right"], .md td[align="right"] { text-align: right; }
.md th[align="center"], .md td[align="center"] { text-align: center; }
.md tr:last-child td { border-bottom: 0; }
.tool { display: flex; align-items: center; gap: 8px; font-weight: 300; font-size: 14px; line-height: 18px; color: var(--secondary); }
.tool .st { width: 16px; height: 16px; flex: none; display: grid; place-items: center; }
.tool .st .ic { width: 16px; height: 16px; }
.tool.ok .st { color: var(--accent); }
.tool.bad .st { color: var(--error); }
.tool em { font-style: normal; color: var(--tertiary); }
.spin { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.errbox { display: flex; align-items: flex-start; gap: 8px; padding: 12px 16px; border-radius: var(--r16); background: var(--error-10); color: var(--error); font-weight: 500; font-size: 14px; line-height: 18px; }
.errbox .ic { width: 16px; height: 16px; margin-top: 1px; }
.variants { display: flex; flex-direction: column; gap: 8px; }
.variants > b { font-weight: 700; font-size: 14px; line-height: 18px; color: var(--secondary); }
.var { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; background: var(--surface); border-radius: var(--r16); }
.var p { font-weight: 500; font-size: 16px; line-height: 20px; overflow-wrap: anywhere; min-width: 0; }
.var .acts { display: flex; gap: 16px; flex: none; }
.confirm { display: flex; flex-direction: column; gap: 12px; padding: 20px; border-radius: var(--r16); background: var(--surface); }
.confirm.accent { background: var(--accent-10); }
.confirm .tt { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; line-height: 20px; }
.confirm .md { font-size: 14px; line-height: 18px; }
.confirm .acts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.confirm .res { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; line-height: 18px; color: var(--secondary); }
.confirm .res.ok { color: var(--success); }
.confirm .res.bad { color: var(--error); }
.confirm .res .ic { width: 16px; height: 16px; }
.chartbox { background: var(--surface); border-radius: var(--r16); padding: 16px 20px; }
.chartbox .ct { font-weight: 700; font-size: 16px; line-height: 20px; margin-bottom: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-weight: 300; font-size: 12px; line-height: 16px; color: var(--secondary); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 2px; border-radius: 1px; }
.chartbox .plot { position: relative; width: 100%; }
.chartbox svg { display: block; overflow: visible; }
.chartbox .axis text { fill: var(--tertiary); font-size: 12px; font-weight: 300; }
.chartbox .gl { stroke: var(--border); }
.tip { position: fixed; z-index: 85; pointer-events: none; background: #fff; border-radius: var(--r12); box-shadow: var(--shadow-menu); padding: 12px; font-weight: 300; font-size: 12px; line-height: 16px; min-width: 150px; opacity: 0; transition: opacity 80ms; }
.tip.on { opacity: 1; }
.tip b { display: block; margin-bottom: 4px; font-weight: 700; font-size: 12px; }
.tip .r { display: flex; gap: 12px; justify-content: space-between; }
.tip .r span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--secondary); }
.tip .r i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* ── картинки ────────────────────────────────────────────────────────────── */
.imggrid { display: flex; flex-wrap: wrap; gap: 16px; width: 100%; }
.imgcard { position: relative; flex: none; width: 240px; height: 240px; max-width: 100%; border-radius: var(--r12); background: var(--surface); }
.imgcard > img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: var(--r12); cursor: zoom-in; }
.imgcard .tb button { position: absolute; width: 32px; height: 32px; border-radius: var(--r8); background: #fff; color: var(--ink); display: grid; place-items: center; opacity: 0; box-shadow: 0 0 0 1px var(--border); }
.imgcard .tb button .ic { width: 16px; height: 16px; }
.imgcard:hover .tb button, .imgcard:focus-within .tb button { opacity: 1; }
.imgcard .tb button:hover { color: var(--secondary); }
.imgcard .tb button.del:hover { color: var(--error); }
.imgcard .tb [data-a="download"] { top: 8px; left: 8px; }
.imgcard .tb [data-a="quote"] { top: 8px; right: 8px; }
.imgcard .tb [data-a="retry"] { top: 8px; right: 48px; }
.imgcard .tb [data-a="delete"] { bottom: 8px; right: 8px; }
.imgcard .tb button::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 6px 10px; border-radius: var(--r8); font-weight: 500; font-size: 12px; line-height: 16px; white-space: nowrap; opacity: 0; pointer-events: none; z-index: 5; }
.imgcard .tb button::before { content: ""; position: absolute; bottom: calc(100% + 3px); left: 50%; margin-left: -5px; border: 5px solid transparent; border-top-color: var(--ink); border-bottom: 0; opacity: 0; pointer-events: none; z-index: 5; }
.imgcard .tb button:hover::after, .imgcard .tb button:hover::before, .imgcard .tb button:focus-visible::after, .imgcard .tb button:focus-visible::before { opacity: 1; }
.imgcard .tb [data-a="download"]::after { left: 0; transform: none; }
.imgcard .tb [data-a="download"]::before { left: 16px; }
.imgcard .tb [data-a="quote"]::after, .imgcard .tb [data-a="delete"]::after { left: auto; right: 0; transform: none; }
.imgcard .tb [data-a="quote"]::before, .imgcard .tb [data-a="delete"]::before { left: auto; right: 11px; margin: 0; }
@media (hover: none) { .imgcard .tb button { opacity: 1; } }
.imgcard.pending { overflow: hidden; display: grid; place-items: center; align-content: center; gap: 4px; padding: 12px; text-align: center; color: #fff; background: #98a0b8; }
.imgcard.pending::before { content: ""; position: absolute; inset: -30%; background: radial-gradient(circle at 25% 30%, #cfd5ea 0 22%, transparent 45%), radial-gradient(circle at 75% 70%, #5e77fd 0 20%, transparent 46%), radial-gradient(circle at 70% 20%, #e6e8f2 0 14%, transparent 40%); filter: blur(28px); opacity: .9; }
.imgcard.pending > * { position: relative; }
.imgcard.pending b { font-weight: 700; font-size: 32px; line-height: 36px; font-variant-numeric: tabular-nums; }
.imgcard.pending span { font-weight: 700; font-size: 16px; line-height: 20px; }
.imgcard.gone { opacity: 0; transition: opacity 200ms; }
.imgcard .cap { display: none; }

/* ── страницы: рутины, галерея ───────────────────────────────────────────── */
.view { flex: 1; min-height: 0; overflow: auto; padding: 24px var(--col-pad) 56px; display: flex; flex-direction: column; gap: 24px; }
.view .head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.view h1 { font-size: 24px; line-height: 100%; }
.card { background: var(--surface); border-radius: var(--r16); padding: 24px; min-width: 0; }
.card h2 { font-weight: 700; font-size: 16px; line-height: 20px; margin-bottom: 16px; }
.rform { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; align-items: end; }
.tbl-wrap { overflow: auto; max-width: 100%; }
table.t { border-collapse: separate; border-spacing: 0; width: 100%; font-weight: 300; font-size: 14px; line-height: 18px; }
table.t th { text-align: left; font-weight: 500; font-size: 12px; line-height: 16px; color: var(--tertiary); padding: 0 12px 8px; white-space: nowrap; }
table.t td { height: 52px; padding: 0 12px; vertical-align: middle; transition: background-color var(--motion); }
table.t tbody tr:hover td { background: var(--surface); }
table.t td:first-child { border-radius: var(--r8) 0 0 var(--r8); font-weight: 500; }
table.t td:last-child { border-radius: 0 var(--r8) var(--r8) 0; }
table.t td b { font-weight: 500; }
table.t td.act { width: 1%; }
.aw { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: var(--pill); font-weight: 500; font-size: 12px; background: var(--surface); color: var(--secondary); white-space: nowrap; }
.badge.ok { background: var(--success-10); color: var(--success); }
.badge.crit { background: var(--error-10); color: var(--error); }
.switch { position: relative; width: 40px; height: 24px; border-radius: 12px; background: var(--border-strong); flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform var(--motion); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }
.note-empty { padding: 48px 16px; text-align: center; font-weight: 300; font-size: 14px; line-height: 18px; color: var(--tertiary); }

/* ── модалки, лайтбокс, тосты ───────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; z-index: 70; background: rgba(23, 23, 23, .3); display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: var(--r24); width: min(560px, 100%); max-height: min(80vh, 100%); display: flex; flex-direction: column; box-shadow: var(--shadow-menu); }
.modal-h { display: flex; align-items: center; gap: 12px; padding: 20px 20px 0 24px; }
.modal-h h2 { font-weight: 500; font-size: 14px; line-height: 18px; }
.modal-b { padding: 16px 24px 24px; overflow: auto; }
.attach { width: min(424px, 100%); }
.attach .modal-b { display: flex; flex-direction: column; gap: 16px; }
.pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-height: 232px; overflow: auto; padding: 2px; }
.pick button { position: relative; aspect-ratio: 1; border-radius: var(--r4); overflow: hidden; background: var(--surface); }
.pick img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pick button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent); }
.attach .acts { display: flex; gap: 16px; }
.attach .acts .btn { flex: 1; }
.lightbox { background: rgba(255, 255, 255, .92); }
.lightbox figure { margin: 0; max-width: 100%; max-height: 100%; display: grid; gap: 12px; justify-items: center; }
.lightbox img { max-width: 100%; max-height: calc(100dvh - 120px); border-radius: var(--r12); display: block; }
.lightbox figcaption { font-weight: 300; font-size: 14px; line-height: 18px; color: var(--secondary); max-width: 640px; text-align: center; }
.lightbox .close { position: absolute; top: 16px; right: 16px; background: var(--surface); }
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; justify-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: #fff; border-radius: var(--r12); padding: 10px 16px; font-weight: 500; font-size: 14px; line-height: 18px; box-shadow: var(--shadow-menu); }
.toast.bad { background: var(--error); }

/* ── вход ───────────────────────────────────────────────────────────────── */
body.center { display: grid; place-items: center; min-height: 100dvh; height: auto; padding: 16px; }
.login { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 358px; max-width: 100%; text-align: center; }
.login .logo { height: 28px; margin-bottom: 16px; }
.login .sub { font-size: 14px; line-height: 18px; color: var(--secondary); margin-bottom: 8px; }
.login .input, .login .btn { width: 100%; }
.login .err { color: var(--error); font-weight: 500; font-size: 14px; line-height: 18px; }

/* ── support ────────────────────────────────────────────────────────────── */
.sup-page { min-height: 100dvh; height: auto; background: var(--surface); display: flex; flex-direction: column; align-items: center; padding: 24px 16px; gap: 16px; }
.sup-top { width: min(960px, 100%); display: flex; align-items: center; gap: 16px; }
.sup-top .logo { height: 22px; }
.sup-top .sub { font-size: 14px; }
.sup-note { width: min(960px, 100%); font-weight: 300; font-size: 14px; line-height: 18px; color: var(--secondary); }
.win { width: min(960px, 100%); flex: 1; display: grid; place-items: center; background: #fff; border-radius: var(--r24); padding: 24px 16px; min-height: 620px; }
.win-bar { display: none; }
.widget { width: min(420px, 100%); height: min(620px, calc(100dvh - 190px)); min-height: 520px; background: #fff; border-radius: var(--r24); box-shadow: inset 0 0 0 1px var(--border); display: flex; flex-direction: column; overflow: hidden; }
.w-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; background: var(--surface); }
.w-head .ava { width: 40px; height: 40px; border-radius: var(--pill); background: var(--ink); color: #fff; display: grid; place-items: center; flex: none; }
.w-head .ava .ic { width: 28px; height: 28px; }
.w-head b { display: block; font-weight: 700; font-size: 16px; line-height: 20px; }
.w-head small { display: flex; align-items: center; gap: 6px; font-weight: 300; font-size: 12px; line-height: 16px; color: var(--secondary); }
.w-head small i { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.w-body { flex: 1; min-height: 0; overflow: auto; padding: 16px 12px; display: flex; flex-direction: column; gap: 12px; }
.w-body .msg { max-width: none; margin: 0; }
.w-body .msg.user .bubble { font-size: 14px; line-height: 18px; max-width: 88%; }
.w-body .msg.bot .bubble { font-size: 14px; line-height: 18px; max-width: 92%; width: auto; }
.w-quick { padding: 0 16px 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.w-form { display: flex; gap: 8px; padding: 12px 16px 16px; border-top: 1px solid var(--border); }
.w-form .input { height: 40px; border-radius: var(--r36); padding: 0 16px; font-size: 14px; }
.w-form .send { flex: none; }
.esc { display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; border-radius: var(--r16); background: var(--accent-10); }
.esc b { font-weight: 700; font-size: 14px; }
.esc span { font-weight: 300; font-size: 14px; line-height: 18px; color: var(--secondary); }

/* ── адаптив ────────────────────────────────────────────────────────────── */
@media (max-width: 1100px) { :root { --col-pad: 40px; } }
@media (max-width: 768px) {
  :root { --col-pad: 16px; }
  .app, .app.collapsed { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .nav-open .side { display: flex; position: fixed; z-index: 60; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); padding: 24px 20px; box-shadow: var(--shadow-menu); }
  .nav-open .backdrop { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(23, 23, 23, .3); }
  .app.collapsed .side { align-items: stretch; }
  .collapsed .brand .logo-full { display: block; }
  .collapsed .logo-mini { display: none; }
  .collapsed .brand { justify-content: space-between; }
  .collapsed .side .kseg { display: inline-flex; }
  .collapsed .side h3, .collapsed .nav .lbl, .collapsed .btn.new .lbl { display: revert; }
  .collapsed .recent { display: flex; }
  .collapsed .side .btn.new { width: auto; padding: 12px 16px 12px 8px; align-self: flex-start; }
  .collapsed .nav { width: auto; padding: 12px; justify-content: flex-start; }
  .side-foot { display: none; }
  #btn-close-nav { display: grid; }
  .hdr { height: 72px; padding: 16px; justify-content: space-between; gap: 12px; }
  #btn-open-nav { display: grid; }
  .hdr-logo { display: block; height: 12px; margin-right: auto; }
  .hdr-title, .topup { display: none; }
  .hdr .grp { display: flex; gap: 12px; }
  .hero { padding: 0 16px 16px; }
  .hero h1, .blank-t { font-size: 28px; line-height: 36px; }
  .tiles { flex-direction: column; width: 100%; gap: 12px; }
  .tile { width: 100%; max-width: none; flex: none; aspect-ratio: auto; height: 220px; padding: 16px; }
  .tile > img { width: 150px; height: 150px; bottom: 12px; }
  .tile .mini { left: 12px; bottom: 28px; width: 176px; }
  .cw { padding-bottom: 8px; }
  .panel { border-radius: var(--r24); padding: 16px; gap: 16px; }
  .help { border-radius: var(--r24); padding: 8px 12px; flex-direction: column; align-items: flex-start; }
  .help-chips { justify-content: flex-start; }
  .inp { flex-wrap: wrap; gap: 8px; }
  .inp textarea { flex: 1 1 100%; }
  .tools { gap: 8px; }
  .tools-l { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tools-l::-webkit-scrollbar { display: none; }
  .dd { position: static; }
  .cost { display: none; }  /* на телефоне цена прячется: в узкой строке она перекрывала пилюли */
  .dd-menu, .chat.blank .tools .dd-menu.m-model, .chat.blank .tools .dd-menu.m-q, .help-chips .dd-menu { position: fixed; left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; min-width: 0; max-height: 65vh; z-index: 75; }
  .dd-menu.m-ar { width: auto; }
  .help-chips .dd { position: static; }
  .feed-in { padding-top: 16px; }
  .msg.user .bubble { max-width: 92%; }
  .msg.bot .bubble { max-width: 100%; padding: 12px 4px; }
  .var { flex-direction: column; align-items: flex-start; gap: 8px; }
  .view { padding: 16px 16px 48px; }
  .imgcard { width: 100%; }
  table.t thead { display: none; }
  table.t, table.t tbody, table.t tr, table.t td { display: block; width: 100%; }
  table.t tr { background: var(--surface); border-radius: var(--r16); padding: 12px; margin-bottom: 8px; }
  table.t td { height: auto; padding: 4px 4px; display: flex; justify-content: space-between; gap: 12px; align-items: center; border-radius: 0 !important; }
  table.t td::before { content: attr(data-l); color: var(--tertiary); font-weight: 500; font-size: 12px; }
  table.t td.act { width: 100%; }
  table.t td.act::before { content: none; }
  table.t tbody tr:hover td { background: none; }
  .win { padding: 16px 8px; min-height: 0; }
  .widget { height: calc(100dvh - 210px); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Пока картинок мало (≤3), сетка стоит в колонке чата; от 4 — галерея на всю ширину, как в макете «результаты» */
.msg.bot.has-img .imggrid:not(:has(> :nth-child(4))) { max-width: 728px; margin-left: auto; margin-right: auto; }
