:root {
  --bg: #eceff3; --panel: #ffffff; --ink: #1c2530; --muted: #68737f; --rule: #d2d9e1;
  --accent: #1f4fd8; --accent-ink: #ffffff; --ok: #1b7a4b;
  --err-bg: #fbecea; --err-ink: #8c2a1f; --code-bg: #f1f4f8;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --read: Charter, "Iowa Old Style", "Palatino Linotype", Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12171d; --panel: #1a2129; --ink: #e4e9ef; --muted: #8b97a4; --rule: #2b3541;
    --accent: #6b8cff; --accent-ink: #0d1220; --ok: #56c98d; --err-bg: #34201e; --err-ink: #ffb4a8; --code-bg: #232c36; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--ui); }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top { display: flex; align-items: center; gap: 14px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--rule); }
.brand { font-weight: 700; font-size: 20px; color: var(--ink); text-decoration: none; }
.grow { flex: 1; }
.btn { font: 600 15px var(--ui); padding: 9px 16px; border-radius: 6px; border: 1px solid var(--rule); background: var(--panel); color: var(--ink); cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.ghost { font: 600 14px var(--ui); color: var(--muted); background: none; border: 0; cursor: pointer; padding: 6px 4px; text-decoration: none; }
.ghost:hover { color: var(--ink); }
.pill { font: 600 14px var(--ui); padding: 6px 12px; border-radius: 999px; border: 1px solid var(--rule); background: var(--bg); color: var(--ink); cursor: pointer; }
input, textarea { font: 16px/1.4 var(--ui); color: var(--ink); background: var(--bg); border: 1px solid var(--rule); border-radius: 6px; padding: 10px 12px; width: 100%; }
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
.err { background: var(--err-bg); color: var(--err-ink); padding: 8px 12px; border-radius: 4px; font-size: 14px; margin-top: 12px; overflow-wrap: anywhere; }
.card { background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 20px; }
.muted { color: var(--muted); }

/* --- лендинг --- */
.landing { max-width: 1040px; margin: 0 auto; padding: 40px 16px 64px; display: grid; grid-template-columns: 1.3fr 1fr; gap: 40px; align-items: start; }
@media (max-width: 800px) { .landing { grid-template-columns: 1fr; gap: 28px; padding-top: 24px; } }
.landing h1 { font: 700 clamp(28px, 4.5vw, 44px)/1.12 var(--ui); margin: 0 0 14px; letter-spacing: -.01em; }
.landing .lead { font-size: 18px; color: var(--muted); max-width: 46ch; margin: 0 0 20px; }
.models { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 28px; }
.model-tag { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--rule); border-radius: 999px; background: var(--panel); font-weight: 600; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.plans { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.plans th, .plans td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--rule); }
.plans tr:last-child td { border-bottom: 0; }
.plans th { font-size: 13px; color: var(--muted); font-weight: 600; }
.tabs { display: flex; gap: 4px; margin-bottom: 4px; border-bottom: 1px solid var(--rule); }
.tab { font: 600 15px var(--ui); background: none; border: 0; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.auth .btn { width: 100%; margin-top: 16px; }
.fine { font-size: 13px; color: var(--muted); margin-top: 12px; }

/* --- приложение --- */
body.app { display: flex; flex-direction: column; }
.shell { flex: 1; min-height: 0; display: flex; }
.side { width: 240px; flex: none; background: var(--panel); border-right: 1px solid var(--rule); display: flex; flex-direction: column; padding: 12px; gap: 10px; min-height: 0; }
.convs { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.convs li { display: flex; align-items: center; border-radius: 6px; }
.convs li:hover, .convs li.active { background: var(--bg); }
.convs button.open { flex: 1; text-align: left; background: none; border: 0; color: var(--ink); font: 14px var(--ui); padding: 8px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convs button.del { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px 8px; font-size: 16px; opacity: 0; }
.convs li:hover .del, .convs .del:focus-visible { opacity: 1; }
.work { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
.bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--rule); }
.chip { display: inline-flex; align-items: center; gap: 8px; font: 600 14px var(--ui); color: var(--ink); padding: 6px 12px; border-radius: 999px; cursor: pointer; background: transparent; border: 1px solid var(--rule); }
.chip .dot { background: var(--c); }
.chip[aria-pressed="false"] { color: var(--muted); }
.chip[aria-pressed="false"] .dot { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }
.cols { flex: 1; min-height: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(320px, 1fr); overflow-x: auto; }
.col { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--rule); }
.col:last-child { border-right: 0; }
.col-head { padding: 8px 16px; border-bottom: 1px solid var(--rule); border-top: 3px solid var(--c); font-weight: 600; }
.col-body { flex: 1; overflow-y: auto; padding: 4px 16px 16px; }
.empty { color: var(--muted); font-size: 14px; padding: 16px 0; }
.msg { margin: 14px 0; }
.msg.user { font-weight: 600; padding-left: 10px; border-left: 3px solid var(--rule); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant { font: 400 17px/1.6 var(--read); max-width: 70ch; overflow-wrap: anywhere; }
.msg.assistant p { margin: 0 0 .8em; white-space: pre-line; }
.msg.assistant h4 { margin: 1em 0 .4em; font: 600 17px var(--ui); }
.msg.assistant ul, .msg.assistant ol { margin: 0 0 .8em; padding-left: 1.4em; }
.msg.assistant pre { background: var(--code-bg); padding: 10px 12px; border-radius: 4px; overflow-x: auto; font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; margin: 8px 0; }
.msg.assistant code { font: .9em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--code-bg); padding: 1px 4px; border-radius: 3px; }
.msg.assistant pre code { background: none; padding: 0; }
.meta { display: flex; gap: 12px; font: 13px var(--ui); color: var(--muted); margin-top: 2px; }
.meta button { font: inherit; color: inherit; background: none; border: 0; padding: 2px 0; cursor: pointer; }
.meta button:hover { color: var(--ink); }
.msg.pending { color: var(--muted); font-style: italic; }
.msg.error { background: var(--err-bg); color: var(--err-ink); padding: 8px 12px; border-radius: 4px; font-size: 14px; }
.composer-wrap { padding: 12px 16px; border-top: 1px solid var(--rule); }
.composer { display: flex; gap: 10px; align-items: flex-end; max-width: 1100px; margin: 0 auto; }
.composer textarea { resize: none; min-height: 48px; max-height: 200px; }
.composer .btn { height: 48px; white-space: nowrap; }
.hint { max-width: 1100px; margin: 6px auto 0; color: var(--muted); font-size: 13px; }
.only-mobile { display: none; }
@media (max-width: 760px) {
  .only-mobile { display: inline-block; }
  .side { position: fixed; z-index: 5; top: 53px; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .15s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .cols { grid-auto-columns: minmax(86vw, 1fr); }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }

dialog { border: 1px solid var(--rule); border-radius: 10px; background: var(--panel); color: var(--ink); padding: 22px; max-width: 520px; width: calc(100% - 24px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 4px; font-size: 20px; }
.offers { display: grid; gap: 8px; margin: 12px 0; }
.offer { display: flex; align-items: center; gap: 12px; border: 1px solid var(--rule); border-radius: 8px; padding: 10px 12px; }
.offer .grow b { display: block; }
.offer small { color: var(--muted); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 6px; font-size: 14px; z-index: 20; max-width: 90vw; }

/* --- админка --- */
.admin { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 16px 0 24px; }
.kpi { background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 12px 14px; }
.kpi b { display: block; font-size: 24px; }
.kpi span { color: var(--muted); font-size: 13px; }
.tbl { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--rule); font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--rule); }
.tbl th { color: var(--muted); font-weight: 600; font-size: 13px; }
.scroll-x { overflow-x: auto; margin-bottom: 24px; }
.neg { color: var(--err-ink); } .pos { color: var(--ok); }

.prov { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.prov-card { background: var(--panel); border: 1px solid var(--rule); border-top: 3px solid var(--c); border-radius: 8px; padding: 14px; }
.prov-card h3 { margin: 0 0 2px; font-size: 17px; }
.prov-card .status { font-size: 13px; margin-bottom: 6px; }
.prov-card label { margin: 10px 0 3px; font-size: 13px; }
.prov-card .two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.prov-card .acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.prov-card .acts .btn { padding: 7px 12px; font-size: 14px; }
.prov-card .result { font-size: 13px; margin-top: 8px; overflow-wrap: anywhere; min-height: 1.2em; }
.prov-card .hint { font-size: 12px; color: var(--muted); }
