/* ───────────────────────────── tokens ───────────────────────────── */
:root {
  color-scheme: dark;
  --bg: #0c0a12;
  --bg-elev: #130f1c;
  --bg-card: #181422;
  --bg-input: #1d1829;
  --bg-hover: #251e34;
  --line: #2b2439;
  --line-strong: #3b3152;
  --text: #f4f1fb;
  --muted: #9d95b3;
  --faint: #6e6685;
  --accent: #ff7a3d;
  --accent-2: #ff3d8b;
  --accent-3: #8b5cf6;
  --grad: linear-gradient(135deg, #ff9a3d 0%, #ff3d8b 55%, #8b5cf6 100%);
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar: 300px;
  --topbar: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body.no-scroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.55rem; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
img, video { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; border-radius: 6px; }
::selection { background: rgba(255, 61, 139, 0.35); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2f2742; border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #3f3559; }

.grow { flex: 1 1 auto; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { display: flex; justify-content: center; padding: 18px 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.is-on { color: var(--accent) !important; }

/* ───────────────────────────── primitives ───────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 11px; border: 1px solid var(--line-strong);
  background: var(--bg-input); font-weight: 600; font-size: 0.92rem; line-height: 1.2;
  transition: transform 0.12s ease, background 0.15s, border-color 0.15s, box-shadow 0.2s, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); border-color: #4b3f68; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 8px 24px rgba(255, 61, 139, 0.28); }
.btn--primary:hover:not(:disabled) { background: var(--grad); filter: brightness(1.08); box-shadow: 0 10px 30px rgba(255, 61, 139, 0.4); }
.btn--ghost { background: transparent; }
.btn--danger { background: #3b1620; border-color: #6d2433; color: #ffb4bf; }
.btn--danger-text { color: #ff9aa8; }
.btn--small { padding: 6px 11px; font-size: 0.82rem; border-radius: 9px; }
.btn--block { width: 100%; padding: 12px 16px; }
.btn--go { padding: 12px 22px; font-size: 1rem; border-radius: 13px; }
.btn.is-busy { opacity: 0.7; pointer-events: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex: 0 0 auto;
  border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn--go { background: var(--grad); color: #fff; }
.icon-btn--go:hover:not(:disabled) { background: var(--grad); color: #fff; filter: brightness(1.12); }
.icon-btn.is-busy { animation: pulse 1s infinite; pointer-events: none; }
.icon { flex: 0 0 auto; }

.input, .select {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg-input); color: var(--text); transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder { color: var(--faint); }
.input:focus, .select:focus { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(255, 61, 139, 0.18); }
.input--mono { font-family: var(--mono); font-size: 0.9rem; }
.input--search { padding: 8px 12px; border-radius: 10px; }
.select { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%239d95b3' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.select--compact { width: auto; min-width: 150px; max-width: 220px; padding: 7px 30px 7px 10px; font-size: 0.88rem; }
.input-row { display: flex; gap: 6px; align-items: center; }

.field { display: grid; gap: 6px; min-width: 0; }
.field--wide { grid-column: 1 / -1; }
.field__label { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.02em; color: var(--muted); text-transform: uppercase; }
.field__hint { font-size: 0.8rem; color: var(--faint); }
.form { display: grid; gap: 14px; }
.form-error { padding: 10px 12px; border-radius: 10px; background: rgba(248, 113, 113, 0.1); border: 1px solid rgba(248, 113, 113, 0.35); color: #ffb4b4; font-size: 0.9rem; }
.notice { padding: 10px 12px; border-radius: 10px; background: rgba(251, 191, 36, 0.1); border: 1px solid rgba(251, 191, 36, 0.35); color: #ffe08a; font-size: 0.9rem; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: 0.76rem; font-weight: 600; background: var(--bg-input); border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.chip--model { background: rgba(139, 92, 246, 0.14); border-color: rgba(139, 92, 246, 0.4); color: #cdb8ff; }
.chip--param { font-weight: 500; }
.chip--open { background: rgba(52, 211, 153, 0.1); border-color: rgba(52, 211, 153, 0.4); color: #7ee8c0; }
.chip--warn { background: rgba(251, 191, 36, 0.1); border-color: rgba(251, 191, 36, 0.4); color: #ffe08a; }
.chip--cost { color: #ffd29a; background: rgba(255, 154, 61, 0.1); border-color: rgba(255, 154, 61, 0.35); }
.chip--credits { cursor: pointer; font-variant-numeric: tabular-nums; color: #ffd29a; background: rgba(255, 154, 61, 0.09); border-color: rgba(255, 154, 61, 0.3); }
.chip--credits:hover { background: rgba(255, 154, 61, 0.18); }
.chip--credits.is-low { color: #ffb4b4; border-color: rgba(248, 113, 113, 0.5); background: rgba(248, 113, 113, 0.12); }

.tag { padding: 2px 7px; border-radius: 6px; font-size: 0.7rem; font-weight: 600; background: var(--bg-hover); color: var(--muted); }
.tag--open { background: rgba(52, 211, 153, 0.12); color: #7ee8c0; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--bg-input); border: 1px solid var(--line); border-radius: 12px; }
.seg__btn { display: inline-flex; align-items: center; gap: 7px; padding: 7px 14px; border: 0; background: transparent; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.seg__btn:hover { color: var(--text); }
.seg__btn.is-active { background: var(--bg-hover); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
.seg--small .seg__btn { padding: 5px 11px; font-size: 0.82rem; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__track { position: relative; width: 38px; height: 22px; flex: 0 0 auto; border-radius: 999px; background: var(--line-strong); transition: background 0.2s; }
.switch__track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch input:checked + .switch__track { background: var(--grad); }
.switch input:checked + .switch__track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.switch__label { display: grid; font-size: 0.9rem; }
.switch__label .field__hint { font-size: 0.75rem; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.check input { accent-color: var(--accent-2); }

.range { width: 100%; accent-color: var(--accent-2); }
.range-row { display: grid; grid-template-columns: minmax(80px, 1fr) auto auto; align-items: center; gap: 12px; }
.range__value { min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid rgba(255, 255, 255, 0.18); border-top-color: var(--accent-2); animation: spin 0.8s linear infinite; display: inline-block; }
.spinner--tiny { width: 10px; height: 10px; border-width: 2px; margin-right: 5px; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.45; } }
@keyframes shimmer { to { background-position: -200% 0; } }
.loading { display: grid; place-items: center; height: 40vh; }

.card { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; display: grid; gap: 14px; }
.card--table { padding: 0; overflow: auto; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.is-disabled td { opacity: 0.55; }
.table .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.usage { display: grid; gap: 4px; }
.usage__bar { height: 6px; border-radius: 6px; background: var(--bg-input); overflow: hidden; }
.usage__bar i { display: block; height: 100%; background: var(--grad); border-radius: 6px; transition: width 0.4s; }
.usage.is-high .usage__bar i { background: var(--bad); }
.usage__text { font-size: 0.76rem; color: var(--muted); }
.usage--wide .usage__bar { height: 8px; }

/* ───────────────────────────── toasts / dialogs ───────────────────────────── */
.toasts { position: fixed; z-index: 200; right: 16px; bottom: 16px; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 11px 14px; border-radius: 12px; background: #231d31; border: 1px solid var(--line-strong); box-shadow: var(--shadow); font-size: 0.9rem; cursor: pointer; animation: toast-in 0.22s ease; }
.toast--ok { border-color: rgba(52, 211, 153, 0.5); }
.toast--warn { border-color: rgba(251, 191, 36, 0.5); }
.toast--error { border-color: rgba(248, 113, 113, 0.6); background: #2b1822; }
.toast--out { opacity: 0; transform: translateY(6px); transition: all 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.overlay { position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; padding: 16px; background: rgba(6, 4, 10, 0.72); backdrop-filter: blur(4px); }
.dialog { width: min(460px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--bg-card); border: 1px solid var(--line-strong); border-radius: 18px; box-shadow: var(--shadow); }
.dialog--wide { width: min(860px, 100%); }
.dialog__head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px 20px; }
.dialog__body { padding: 8px 20px 12px; overflow: auto; }
.dialog__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.dialog__text { line-height: 1.55; }

.menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 120; min-width: 210px; padding: 6px; background: var(--bg-card); border: 1px solid var(--line-strong); border-radius: 14px; box-shadow: var(--shadow); }
.menu__head { display: grid; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu__head span { font-size: 0.8rem; color: var(--muted); }
.menu__item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: transparent; border-radius: 9px; text-align: left; }
.menu__item:hover { background: var(--bg-hover); }

/* ───────────────────────────── login ───────────────────────────── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; position: relative; overflow: hidden; }
.login__glow { position: absolute; inset: -20%; background: radial-gradient(40% 40% at 25% 20%, rgba(255, 122, 61, 0.22), transparent 70%), radial-gradient(40% 40% at 80% 25%, rgba(139, 92, 246, 0.25), transparent 70%), radial-gradient(45% 45% at 55% 90%, rgba(255, 61, 139, 0.18), transparent 70%); filter: blur(20px); pointer-events: none; }
.login__card { position: relative; width: min(430px, 100%); display: grid; gap: 18px; padding: 30px; background: rgba(24, 20, 34, 0.82); backdrop-filter: blur(14px); border: 1px solid var(--line-strong); border-radius: 22px; box-shadow: var(--shadow); }
.login__lead { color: var(--muted); }
.login__form { display: grid; gap: 14px; }
.login__legal { font-size: 0.76rem; color: var(--faint); line-height: 1.5; }

.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 800; letter-spacing: -0.02em; font-size: 1.15rem; }
.brand span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand--big { font-size: 1.7rem; }

/* ───────────────────────────── shell ───────────────────────────── */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); grid-template-rows: var(--topbar) minmax(0, 1fr); height: 100dvh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); background: rgba(12, 10, 18, 0.9); backdrop-filter: blur(10px); z-index: 40; }
.topbar__menu { display: none; }
.user { position: relative; }
.avatar { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--grad); color: #fff; font-weight: 800; }

.sidebar { grid-row: 2; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--bg-elev); }
.nav { display: grid; gap: 4px; padding: 12px 12px 6px; }
.nav__item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-weight: 600; text-align: left; }
.nav__item:hover { background: var(--bg-hover); color: var(--text); }
.nav__item.is-active { background: rgba(255, 61, 139, 0.12); color: #ffb3d1; box-shadow: inset 0 0 0 1px rgba(255, 61, 139, 0.3); }
.sidebar__tools { display: grid; gap: 8px; padding: 8px 12px; }
.threads { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 4px 8px 12px; display: grid; align-content: start; gap: 2px; }
.threads__empty { padding: 14px; color: var(--faint); font-size: 0.88rem; }
.thread { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 11px; }
.thread:hover { background: var(--bg-hover); }
.thread.is-active { background: var(--bg-hover); box-shadow: inset 0 0 0 1px var(--line-strong); }
.thread__thumb { position: relative; width: 44px; height: 44px; flex: 0 0 auto; border-radius: 9px; overflow: hidden; background: var(--bg-input); display: grid; place-items: center; }
.thread__thumb img, .thread__thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.threads__ph { color: var(--faint); }
.thread__badge { position: absolute; right: 3px; bottom: 3px; display: grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: rgba(0, 0, 0, 0.65); color: #fff; }
.thread__text { display: grid; min-width: 0; }
.thread__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 0.9rem; }
.thread__meta { font-size: 0.76rem; color: var(--faint); display: flex; align-items: center; }
.sidebar .usage { padding: 12px 16px 14px; border-top: 1px solid var(--line); }

.main { grid-row: 2; grid-column: 2; min-width: 0; min-height: 0; }
.outlet { height: 100%; overflow: auto; }
.scrim { display: none; }

.page { max-width: 1100px; margin: 0 auto; padding: 28px 24px 60px; display: grid; gap: 18px; }
.page--narrow { max-width: 720px; }
.page__head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.section-title { font-size: 1rem; color: var(--muted); font-weight: 600; margin-bottom: 12px; }

/* ───────────────────────────── studio + composer ───────────────────────────── */
.studio { max-width: 1040px; margin: 0 auto; padding: 30px 24px 70px; display: grid; gap: 22px; }
.studio__head { display: grid; gap: 6px; }
.studio__head h1 { font-size: 1.9rem; background: linear-gradient(90deg, #fff, #ffc6a0 40%, #ff9ac4 70%, #c3a8ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.composer { display: grid; gap: 16px; }
.composer--studio { padding: 18px; background: var(--bg-card); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); }
.composer__picker { display: grid; gap: 14px; }
.model-cards { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 8px; scroll-snap-type: x proximity; }
.model-card {
  flex: 0 0 auto; width: 220px; display: grid; align-content: start; gap: 4px; text-align: left; padding: 12px 14px;
  background: linear-gradient(var(--bg-input), var(--bg-input)) padding-box, linear-gradient(var(--line), var(--line)) border-box;
  border: 1.5px solid transparent; border-radius: 14px; scroll-snap-align: start; transition: transform 0.12s, box-shadow 0.2s;
}
.model-card:hover { transform: translateY(-1px); }
.model-card.is-selected { background: linear-gradient(var(--bg-hover), var(--bg-hover)) padding-box, var(--grad) border-box; box-shadow: 0 8px 28px rgba(255, 61, 139, 0.18); }
.model-card__name { font-weight: 700; }
.model-card__vendor { font-size: 0.74rem; color: var(--faint); }
.model-card__blurb { font-size: 0.8rem; color: var(--muted); line-height: 1.35; min-height: 2.7em; }
.model-card__tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 4px; }

.prompt { position: relative; background: var(--bg-input); border: 1px solid var(--line); border-radius: 16px; transition: border-color 0.15s, box-shadow 0.15s; }
.prompt:focus-within { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(255, 61, 139, 0.16); }
.prompt__input { display: block; width: 100%; resize: none; border: 0; background: transparent; padding: 14px 16px 6px; line-height: 1.55; min-height: 110px; }
.prompt__input:focus { outline: none; }
.prompt__bar { display: flex; align-items: center; gap: 10px; padding: 6px 10px 10px 16px; flex-wrap: wrap; }
.prompt__count { font-size: 0.76rem; color: var(--faint); font-variant-numeric: tabular-nums; margin-right: auto; }
.prompt__count.is-over { color: var(--bad); }
.prompt__tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.btn--enhance { background: linear-gradient(135deg, rgba(255, 154, 61, 0.14), rgba(139, 92, 246, 0.18)); border-color: rgba(255, 122, 61, 0.45); color: #ffd7b8; }
.btn--enhance.is-busy { animation: pulse 1s infinite; }
.hint-input { flex: 1 1 100%; }

.refs { display: grid; gap: 10px; padding: 14px; border: 1px dashed var(--line-strong); border-radius: 16px; }
.refs__title { display: flex; align-items: center; gap: 7px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; color: var(--muted); }
.refs__title small { font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--faint); }
.refs__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.slot { display: grid; gap: 8px; padding: 10px; border-radius: 12px; background: var(--bg-input); border: 1px solid var(--line); transition: border-color 0.15s, background 0.15s; }
.slot.is-drop { border-color: var(--accent-2); background: rgba(255, 61, 139, 0.08); }
.slot__head { display: flex; justify-content: space-between; font-size: 0.82rem; font-weight: 600; }
.slot__head small { color: var(--faint); font-weight: 500; }
.slot__items { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.slot__add, .slot__lib { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 11px; border: 1px dashed var(--line-strong); background: transparent; color: var(--muted); }
.slot__lib { width: 38px; height: 38px; }
.slot__add:hover, .slot__lib:hover { border-color: var(--accent-2); color: var(--text); background: rgba(255, 61, 139, 0.06); }
.thumb { position: relative; width: 54px; height: 54px; border-radius: 11px; overflow: hidden; background: #000; border: 1px solid var(--line-strong); }
.thumb__media { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb__media--pending, .thumb__media--audio { display: grid; place-items: center; color: var(--muted); background: var(--bg-hover); }
.thumb__x { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; display: grid; place-items: center; border: 0; border-radius: 50%; background: rgba(0, 0, 0, 0.75); color: #fff; opacity: 0; transition: opacity 0.15s; }
.thumb:hover .thumb__x, .thumb:focus-within .thumb__x { opacity: 1; }
@media (hover: none) { .thumb__x { opacity: 1; } }
.thumb__bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--grad); transition: width 0.2s; }

.params { display: grid; gap: 14px; }
.params__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px 16px; align-items: end; }
.nsfw { display: inline-flex; align-items: center; gap: 9px; justify-self: start; padding: 9px 14px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--bg-input); font-size: 0.88rem; font-weight: 600; }
.nsfw b { font-size: 0.74rem; letter-spacing: 0.05em; padding: 2px 8px; border-radius: 999px; }
.nsfw.is-open { border-color: rgba(52, 211, 153, 0.5); background: rgba(52, 211, 153, 0.09); color: #9ff0cf; }
.nsfw.is-open b { background: rgba(52, 211, 153, 0.22); color: #b7f7dd; }
.nsfw.is-filtered { border-color: rgba(251, 191, 36, 0.5); background: rgba(251, 191, 36, 0.08); color: #ffe08a; }
.nsfw.is-filtered b { background: rgba(251, 191, 36, 0.2); }
.nsfw.is-locked { cursor: help; color: var(--muted); }
.advanced { border-top: 1px solid var(--line); padding-top: 10px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; font-weight: 600; margin-bottom: 12px; }
.advanced[open] summary { color: var(--text); }

.foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.foot__info { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.foot__warn { font-size: 0.82rem; color: #ffb4a0; max-width: 520px; }

.recent__grid, .library__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { position: relative; padding: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; aspect-ratio: 1; background: var(--bg-card); transition: transform 0.15s, border-color 0.15s; }
.tile:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile__badge { position: absolute; right: 7px; bottom: 7px; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; background: rgba(0, 0, 0, 0.65); color: #fff; }
.library__grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; max-height: 60vh; overflow: auto; }
.picker-item { position: relative; padding: 0; aspect-ratio: 1; border: 2px solid transparent; border-radius: 10px; overflow: hidden; background: var(--bg-input); }
.picker-item:hover { border-color: var(--accent-2); }
.picker-item img, .picker-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.picker-item__badge { position: absolute; right: 5px; bottom: 5px; width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; background: rgba(0, 0, 0, 0.65); color: #fff; }

/* ───────────────────────────── thread (chat) ───────────────────────────── */
.thread-view { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: rgba(12, 10, 18, 0.6); }
.thread-head__title { font-size: 1.05rem; font-weight: 700; cursor: text; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: min(620px, 60vw); padding: 4px 6px; border-radius: 8px; }
.thread-head__title:hover { background: var(--bg-hover); }
.thread-head__back { display: none; }
.thread-view__scroll { overflow: auto; padding: 24px 20px 10px; scroll-behavior: auto; }
.turns { max-width: 1000px; margin: 0 auto; }
.turn { display: grid; gap: 14px; margin-bottom: 34px; }

.bubble { display: grid; gap: 8px; min-width: 0; }
.bubble--user { justify-self: end; max-width: min(760px, 100%); padding: 12px 14px 8px; background: linear-gradient(180deg, #241b36, #1b1529); border: 1px solid var(--line-strong); border-radius: 18px 18px 5px 18px; }
.bubble--assistant { width: 100%; }
.bubble__meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.bubble__text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.bubble__tools { display: flex; justify-content: flex-end; margin: 0 -6px -2px; }
.bubble__refs { display: flex; gap: 8px; flex-wrap: wrap; }
.bubble__foot { display: flex; align-items: center; gap: 5px; font-size: 0.76rem; color: var(--faint); }
.orig { font-size: 0.85rem; color: var(--muted); }
.orig summary { cursor: pointer; }
.orig p { margin-top: 6px; padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.03); white-space: pre-wrap; }
.ref-thumb { width: 52px; height: 52px; padding: 0; border-radius: 10px; overflow: hidden; border: 1px solid var(--line-strong); background: #000; }
.ref-thumb img, .ref-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.ref-audio { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); }

.progress { position: relative; width: min(100%, 560px); aspect-ratio: var(--ar, 1 / 1); max-height: 62vh; border-radius: 16px; overflow: hidden; border: 1px solid var(--line-strong); background: var(--bg-card); }
.progress__shimmer { position: absolute; inset: 0; background: linear-gradient(110deg, transparent 20%, rgba(255, 122, 61, 0.1) 40%, rgba(255, 61, 139, 0.14) 50%, rgba(139, 92, 246, 0.1) 60%, transparent 80%); background-size: 200% 100%; animation: shimmer 2.2s linear infinite; }
.progress__body { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; padding: 16px; text-align: center; }
.progress__body small { color: var(--faint); max-width: 36ch; }
.progress__time { font-variant-numeric: tabular-nums; color: var(--muted); }

.errorcard { display: grid; grid-template-columns: auto 1fr; gap: 10px 14px; padding: 14px 16px; border-radius: 14px; border: 1px solid rgba(248, 113, 113, 0.4); background: rgba(248, 113, 113, 0.07); max-width: 720px; }
.errorcard--muted { border-color: var(--line-strong); background: var(--bg-card); }
.errorcard__icon { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: rgba(248, 113, 113, 0.18); color: #ffb4b4; }
.errorcard__body p { color: #e6c3c8; margin-top: 2px; overflow-wrap: anywhere; }
.errorcard__actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }

.outputs { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.outputs--1 { grid-template-columns: minmax(0, 620px); }
.outputs--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 900px; }
.out { margin: 0; display: grid; gap: 6px; align-content: start; min-width: 0; padding: 8px; border-radius: 18px; border: 1px solid transparent; transition: border-color 0.2s, background 0.2s; }
.out.is-target { border-color: rgba(255, 61, 139, 0.55); background: rgba(255, 61, 139, 0.05); }
.out__frame { position: relative; border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: var(--ar, auto); max-height: 74vh; display: grid; }
.out__media { display: block; width: 100%; height: 100%; max-height: 74vh; object-fit: contain; cursor: zoom-in; }
video.out__media { cursor: default; height: auto; }
.out__actions { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: rgba(10, 8, 16, 0.72); backdrop-filter: blur(8px); opacity: 0; transition: opacity 0.15s; }
.out__actions .icon-btn { width: 30px; height: 30px; color: #e8e2f5; }
.out:hover .out__actions, .out:focus-within .out__actions { opacity: 1; }
@media (hover: none) { .out__actions { opacity: 1; } }
.out__cap { font-size: 0.74rem; color: var(--faint); padding: 0 4px; }
.inline-edit { display: flex; align-items: flex-end; gap: 4px; padding: 5px 5px 5px 12px; border-radius: 14px; background: var(--bg-input); border: 1px solid var(--line); transition: border-color 0.15s, box-shadow 0.15s; }
.inline-edit:focus-within { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(255, 61, 139, 0.14); }
.inline-edit.is-busy { opacity: 0.6; }
.inline-edit__input { flex: 1 1 auto; min-width: 0; resize: none; border: 0; background: transparent; padding: 7px 0; line-height: 1.4; max-height: 140px; }
.inline-edit__input:focus { outline: none; }
.inline-edit__input::placeholder { color: var(--faint); }

.dock { border-top: 1px solid var(--line); background: rgba(12, 10, 18, 0.94); backdrop-filter: blur(14px); padding: 10px 20px calc(12px + env(safe-area-inset-bottom)); }
.composer--dock { max-width: 1000px; margin: 0 auto; gap: 8px; }
.target { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 14px; background: var(--bg-card); border: 1px solid var(--line); }
.target--empty { color: var(--muted); font-size: 0.88rem; padding: 10px 12px; }
.target__thumb { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 9px; overflow: hidden; background: #000; }
.target__thumb img, .target__thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.target__text { display: grid; line-height: 1.25; min-width: 0; margin-right: auto; }
.target__text span { font-size: 0.78rem; color: var(--muted); }
.composer__params.is-hidden { display: none; }
.composer--dock .composer__params { padding: 12px 14px; border-radius: 14px; background: var(--bg-card); border: 1px solid var(--line); max-height: 40vh; overflow: auto; }
.prompt--dock { border-radius: 16px; }
.prompt__row { display: flex; align-items: flex-end; gap: 6px; padding: 6px 8px 6px 14px; }
.prompt--dock .prompt__input { padding: 8px 0; min-height: 40px; max-height: 160px; }
.prompt--dock .prompt__tools { flex-wrap: nowrap; padding-bottom: 2px; }
.dock-thumbs { display: flex; gap: 8px; padding: 10px 12px 0; flex-wrap: wrap; }
.composer__refs.is-empty { display: none; }
.composer--dock .foot { justify-content: flex-end; }
.composer--dock .foot__info { margin-right: auto; }
.composer--dock .btn--go { padding: 9px 18px; font-size: 0.92rem; }

/* ───────────────────────────── lightbox ───────────────────────────── */
.lightbox { position: fixed; inset: 0; z-index: 180; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: rgba(4, 3, 8, 0.94); }
.lightbox__bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.lightbox__counter { color: var(--muted); font-size: 0.85rem; }
.lightbox__stage { display: grid; place-items: center; min-height: 0; padding: 0 56px; }
.lightbox__media { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.lightbox__nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border: 0; background: transparent; color: #fff; font-size: 2.4rem; opacity: 0.7; }
.lightbox__nav:hover { opacity: 1; }
.lightbox__nav--prev { left: 6px; }
.lightbox__nav--next { right: 6px; }
.lightbox__caption { padding: 10px 20px 18px; text-align: center; color: var(--muted); font-size: 0.85rem; max-height: 5.5em; overflow: auto; }

/* ───────────────────────────── responsive ───────────────────────────── */
@media (max-width: 880px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .main { grid-column: 1; }
  .topbar__menu { display: inline-grid; }
  .sidebar { position: fixed; z-index: 90; top: var(--topbar); bottom: 0; left: 0; width: min(88vw, 340px); transform: translateX(-102%); transition: transform 0.25s ease; box-shadow: var(--shadow); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .scrim { display: block; position: fixed; z-index: 80; inset: var(--topbar) 0 0 0; background: rgba(0, 0, 0, 0.55); }
  .studio, .page { padding: 18px 14px 60px; }
  .composer--studio { padding: 12px; border-radius: 16px; }
  .studio__head h1 { font-size: 1.5rem; }
  .thread-view__scroll { padding: 16px 12px 6px; }
  .thread-head { padding: 8px 12px; }
  .thread-head__back { display: inline-grid; }
  .dock { padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
  .outputs--2 { grid-template-columns: minmax(0, 1fr); }
  .lightbox__stage { padding: 0 8px; }
  .model-card { width: 188px; }
  .target { flex-wrap: wrap; }
  .select--compact { min-width: 120px; max-width: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* ───────────────────────────── fixes: narrow screens ───────────────────────────── */
.prompt__input { min-width: 0; }
.prompt__row > .prompt__input { flex: 1 1 auto; }
.composer, .composer--dock, .thread-view, .thread-view__scroll, .turns, .turn, .bubble { min-width: 0; }
.dock { overflow: hidden; }
.thread-view__scroll { overflow-x: hidden; }

@media (max-width: 880px) {
  .target { flex-wrap: nowrap; gap: 8px; }
  .target__text span { display: none; }
  .target__text { min-width: 0; }
  .select--compact { min-width: 0; flex: 1 1 100px; max-width: none; }
  .composer--dock .foot { gap: 8px; }
  .composer--dock .foot__info { min-width: 0; }
  .composer--dock .btn--go { padding: 9px 14px; }
  .library__grid, .recent__grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .prompt--dock .prompt__tools { gap: 2px; }
  .prompt--dock .btn--enhance { padding: 7px 10px; }
  .dock-thumbs { padding: 8px 8px 0; }
  .out__actions { top: 6px; right: 6px; }
  .bubble--user { max-width: 100%; }
}
.thread-view { grid-template-columns: minmax(0, 1fr); }
.outlet { min-width: 0; }
