:root {
  --bg: #F5F6F8; --surface: #FFFFFF; --border: #E3E6EB; --border-strong: #D5DAE1;
  --ink: #15181D; --muted: #4A505C; --accent: #2453D6; --accent-ink: #1A3FA8; --accent-soft: #EEF3FE;
  --ok: #1F6B45; --ok-soft: #E6F4EC; --warn: #8A4B00; --warn-soft: #FFF4E0; --err: #B42318; --err-soft: #FDECEA;
  --radius: 12px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink); border-radius: 10px; font: inherit; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #AEB5C0; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
.btn.dark:hover { background: #2B3038; }
.btn.wide { width: 100%; justify-content: flex-start; padding: 0 16px; min-height: 46px; border-radius: 12px; }
.btn.icon { width: 36px; min-height: 36px; padding: 0; font-size: 18px; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled, button:disabled, [aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
a[aria-disabled="true"], summary[aria-disabled="true"] { pointer-events: none; }
:focus-visible { outline: 3px solid #8FB0FF; outline-offset: 2px; }

/* ---------- старт: боковая панель + главная колонка ---------- */
.studio { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 20px 14px; display: flex; flex-direction: column; gap: 10px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 800; font-size: 18px; color: var(--ink); text-decoration: none; padding: 0 6px 8px; }
.tag { font-size: 12px; font-weight: 500; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; margin-left: 4px; }
.side-title { font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 8px 0; }
.plist { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; min-height: 0; }
.plist-empty { margin: 8px; font-size: 13px; color: var(--muted); }
.pitem { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; text-align: left; border: 0; background: transparent; border-radius: 10px; padding: 9px 10px; font: inherit; font-size: 14px; color: var(--ink); cursor: pointer; }
.pitem:hover { background: var(--bg); }
.pitem[aria-current="true"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.pitem small { font-size: 12px; font-weight: 400; color: var(--muted); }
.usage { background: var(--bg); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.usage-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.usage-row strong { color: var(--ink); }
.meter { height: 6px; border-radius: 999px; background: #E3E6EB; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .3s; }
.usage-note { margin: 0; font-size: 12px; line-height: 1.4; color: var(--muted); }

.stage { min-width: 0; padding: 56px 32px 40px; }
.start { width: 100%; max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.start h1 { margin: 0; font-size: clamp(30px, 5vw, 44px); line-height: 1.12; font-weight: 800; letter-spacing: -.01em; }
.start h2.sub { margin: 14px 0 0; font-size: 15px; font-weight: 600; color: var(--muted); }
.lead { margin: 0; font-size: 17px; line-height: 1.55; color: var(--muted); }
.note { margin: 0; font-size: 13px; line-height: 1.5; color: var(--muted); }

.composer { background: var(--surface); border: 1px solid var(--border-strong); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 1px 2px rgba(21, 24, 29, .04); }
.composer textarea { border: none; resize: vertical; outline: none; font: inherit; font-size: 17px; line-height: 1.5; padding: 0; min-height: 4.2em; color: var(--ink); background: transparent; }
.composer.small { border-radius: 16px; padding: 12px; gap: 8px; }
.composer.small textarea { font-size: 14px; min-height: 2.6em; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; border-top: 1px solid #EEF0F3; padding-top: 12px; }
.composer.small .composer-bar { border-top: none; padding-top: 0; }
.send { width: 38px; height: 38px; border-radius: 10px; border: 0; background: var(--accent); color: #fff; font-size: 18px; font-weight: 700; cursor: pointer; }
.send:hover { background: var(--accent-ink); }

.types-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.types { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.types button { min-height: 38px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); font: inherit; font-size: 14px; cursor: pointer; color: var(--ink); }
.types button:hover { border-color: #AEB5C0; }
.types button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

.examples { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.example { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 10px 10px 14px; font: inherit; color: var(--ink); cursor: pointer; }
.example:hover { border-color: var(--border-strong); box-shadow: 0 6px 18px rgba(21, 24, 29, .07); }
.example strong { font-size: 15px; padding: 6px 4px 0; }
.example .muted { font-size: 13px; padding: 0 4px; }
.thumb { align-self: stretch; height: 110px; border-radius: 10px; padding: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; }
.thumb i { flex: 0 0 46%; height: 8px; border-radius: 4px; }
.thumb b { flex: 1 1 100%; height: 66px; border-radius: 8px; }
.thumb.coffee { background: #F4EADF; } .thumb.coffee i { background: #7A4B2B; } .thumb.coffee b { background: #E7D6C3; }
.thumb.yoga { background: #E6F0EA; } .thumb.yoga i { background: #2F5D3A; } .thumb.yoga b { background: #CFE3D6; }
.thumb.clothes { background: #EEF0F3; } .thumb.clothes i { background: #20242B; flex-basis: 100%; } .thumb.clothes b { flex: 1 1 28%; background: #DADDE3; }

/* ---------- выбор модели ---------- */
.model-picker { position: relative; }
.picker-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border: 1px solid var(--border); background: var(--bg); border-radius: 10px; font: inherit; font-size: 14px; cursor: pointer; color: var(--ink); }
.model-picker[data-compact] .picker-btn { min-height: 34px; padding: 0 10px; font-size: 13px; }
.picker-btn .muted { color: var(--muted); }
.picker-list { position: absolute; z-index: 30; bottom: calc(100% + 6px); left: 0; width: min(440px, 90vw); margin: 0; padding: 6px; list-style: none; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: 0 12px 32px rgba(21, 24, 29, .16); }
.studio .picker-list { top: calc(100% + 6px); bottom: auto; }
.picker-list[hidden] { display: none; }
.picker-option { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border-radius: 10px; cursor: pointer; }
.picker-option:hover, .picker-option:focus-visible { background: var(--bg); }
.picker-option[aria-selected="true"] { background: var(--accent-soft); }
.picker-option .po-main { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.picker-option .po-title { font-size: 14px; font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.picker-option .po-sub { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.picker-option .po-price { font-size: 13px; color: var(--muted); white-space: nowrap; }
.badge { font-size: 11.5px; font-weight: 500; padding: 1px 8px; border-radius: 999px; background: #EEF0F3; color: var(--muted); }
.badge.ru { background: var(--ok-soft); color: var(--ok); }

/* ---------- рабочий экран ---------- */
.work { display: flex; flex-direction: column; height: 100vh; }
.wbar { display: flex; align-items: center; gap: 14px; padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--border); min-height: 60px; flex-wrap: wrap; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; font-size: 24px; line-height: 1; cursor: pointer; color: var(--ink); }
.icon-btn:hover { background: var(--bg); }
.ptitle { font-size: 18px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; min-width: 0; }
.tab { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; font: inherit; font-size: 14px; color: var(--ink); cursor: pointer; }
.tab:hover { background: var(--bg); }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.tab:disabled { opacity: .5; cursor: default; }
.tab .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; }
.tab.err .dot { background: var(--err); animation: none; }
@keyframes pulse { 50% { opacity: .3; } }
.wbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.versions { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; z-index: 40; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: 0 12px 32px rgba(21, 24, 29, .16); padding: 6px; display: flex; flex-direction: column; }
.menu-pop a { padding: 10px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-size: 14px; }
.menu-pop a:hover { background: var(--bg); }

.wbody { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(320px, 380px) minmax(0, 1fr); }
.chat { background: var(--surface); border-right: 1px solid var(--border); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding-right: 4px; min-height: 0; }
.msg { font-size: 14px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: stretch; background: #E7EEFD; border-radius: 14px; padding: 12px 14px; }
.msg.assistant { color: var(--ink); }
.msg.error { color: var(--err); }
.msg.warn { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 12px; }
.msg .meta { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.hint-card { display: flex; gap: 10px; background: var(--bg); border-radius: 14px; padding: 12px 14px; font-size: 13px; line-height: 1.5; color: var(--muted); }

.checklist { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.checklist li { display: flex; align-items: center; gap: 10px; padding: 11px 14px; font-size: 14px; border-top: 1px solid var(--border); }
.checklist li:first-child { border-top: 0; }
.checklist .st { color: var(--muted); }
.checklist li.err .st { color: var(--err); }
.checklist .btn { min-height: 30px; padding: 0 10px; font-size: 13px; margin-left: auto; }
.ck { width: 18px; height: 18px; flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; }
.ck.ok { color: var(--ok); }
.ck.pending { border: 2px solid var(--border-strong); border-radius: 50%; }
.ck.err { color: var(--err); }
.ck.spin { border: 2px solid #C9D6F8; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.checklist-note { font-size: 12.5px; color: var(--muted); margin: 6px 2px 0; }

.preview { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 12px; padding: 14px 20px 20px; }
.preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; background: #E9ECF0; border-radius: 10px; padding: 3px; }
.seg button { min-height: 34px; padding: 0 14px; border: none; border-radius: 8px; background: transparent; font: inherit; font-size: 13px; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(21, 24, 29, .08); }
.browser { position: relative; flex: 1; min-height: 320px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; }
.frame-wrap { flex: 1; min-height: 0; display: flex; justify-content: center; background: var(--surface); }
.frame-wrap.tablet, .frame-wrap.mobile { background: #E9EBEF; padding: 16px 0; }
#frame { width: 100%; height: 100%; border: 0; background: #fff; transition: width .25s ease; }
.frame-wrap.tablet #frame { width: 820px; max-width: 100%; border-radius: 14px; box-shadow: 0 0 0 1px var(--border-strong); }
.frame-wrap.mobile #frame { width: 390px; max-width: 100%; border-radius: 18px; box-shadow: 0 0 0 1px var(--border-strong); }
.frame-status { position: absolute; left: 12px; bottom: 12px; background: rgba(21, 24, 29, .86); color: #fff; font-size: 13px; padding: 6px 10px; border-radius: 8px; z-index: 5; }
.frame-help { position: absolute; z-index: 4; left: 50%; top: 18px; transform: translateX(-50%); background: var(--warn-soft); color: var(--warn); border: 1px solid #F1D9A8; border-radius: 10px; padding: 8px 14px; font-size: 13px; box-shadow: 0 6px 18px rgba(21, 24, 29, .1); }
.code-panel { position: absolute; inset: 0; background: #11151B; color: #E6EAF0; display: flex; flex-direction: column; z-index: 6; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: #1A2029; font-size: 13px; }
.code-head .btn { min-height: 30px; background: transparent; color: #E6EAF0; border-color: #3A4452; }
.code-panel pre { margin: 0; padding: 14px 16px; overflow: auto; flex: 1; font: 12.5px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; tab-size: 2; }

.block-edit { position: absolute; z-index: 8; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(560px, calc(100% - 32px)); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 16px; box-shadow: 0 16px 44px rgba(21, 24, 29, .22); padding: 16px; }
.block-edit form { display: flex; flex-direction: column; gap: 10px; }
.block-edit label { font-size: 14px; font-weight: 600; color: var(--muted); }
.block-edit textarea { border: 1px solid var(--border); background: var(--bg); border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 14px; resize: vertical; min-height: 64px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row .spacer { flex: 1; }

dialog { border: none; border-radius: 16px; padding: 0; max-width: 480px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(21, 24, 29, .5); }
dialog form { display: flex; flex-direction: column; gap: 12px; padding: 22px; }
dialog h2 { margin: 0; font-size: 20px; }
dialog p { margin: 0; font-size: 14px; line-height: 1.5; color: var(--muted); }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
dialog input, dialog textarea { min-height: 40px; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px; font: inherit; font-size: 14px; color: var(--ink); }
dialog label.check { flex-direction: row; align-items: flex-start; gap: 8px; }
dialog label.check input { min-height: auto; margin-top: 2px; }
dialog .row { justify-content: flex-end; }

@media (max-width: 1100px) {
  .wbar-right .versions { order: 5; }
}
@media (max-width: 900px) {
  .studio { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--border); }
  .side .btn.wide { width: auto; }
  .side-title, .usage { display: none; }
  .plist { flex-direction: row; overflow-x: auto; flex: 1 1 100%; }
  .pitem { width: auto; white-space: nowrap; }
  .plist-empty { display: none; }
  .stage { padding: 28px 16px; }
  .work { height: auto; min-height: 100vh; }
  .wbody { grid-template-columns: 1fr; }
  .chat { border-right: 0; border-bottom: 1px solid var(--border); max-height: 60vh; }
  .log { max-height: 36vh; }
  .browser { min-height: 72vh; }
  .wbar-right { margin-left: 0; width: 100%; }
  .block-edit { bottom: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
