/* Seedream Studio — нейтральный серый, как в фоторедакторах: цвета снимков не искажаются */
:root {
  --bg: #2b2b2b;
  --panel: #333333;
  --raise: #3d3d3d;
  --raise-2: #474747;
  --line: #4b4b4b;
  --text: #ececec;
  --muted: #a0a0a0;
  --faint: #767676;
  --accent: #f2c14e;
  --accent-hover: #f7cf6c;
  --accent-ink: #232017;
  --danger: #ff7d6e;
  --ok: #93d29a;
  --viewer: #000;
  --row: 220px;
  --radius-s: 6px;
  --radius-m: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.filled { fill: currentColor; }

/* ── кнопки ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 14px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--raise); color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: var(--raise-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
a.btn { text-decoration: none; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--raise); }
.btn.danger { color: var(--danger); }
.btn.icon-only { width: 40px; padding: 0; }
.btn.small { height: 32px; padding: 0 10px; font-size: 13px; }
.btn.small.icon-only { width: 32px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }
.input {
  width: 100%; height: 42px; padding: 0 12px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: #262626; outline: none;
}
.input:focus { border-color: var(--accent); }

/* ── вход и настройка ── */
.auth-page { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; display: grid; gap: 18px; }
.auth-card.wide { max-width: 520px; }
.auth-card h1 { margin: 0; font-size: 26px; line-height: 1.15; font-weight: 650; letter-spacing: -.01em; }
.auth-card p { margin: 0; color: var(--muted); }
.auth-card form { display: grid; gap: 14px; }
.code-input { font-size: 22px; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }
.form-error { color: var(--danger); min-height: 1.45em; margin: 0; }
.steps { display: grid; gap: 22px; margin: 0; padding: 0; list-style: none; counter-reset: step; }
.steps > li { display: grid; grid-template-columns: 28px 1fr; gap: 4px 12px; counter-increment: step; }
.steps > li::before {
  content: counter(step); grid-row: span 3; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--raise); color: var(--accent); font-weight: 650; font-size: 14px;
}
.steps h2 { margin: 2px 0 4px; font-size: 16px; font-weight: 600; }
.steps .stack { display: grid; gap: 10px; }
.qr { width: 196px; height: 196px; border-radius: var(--radius-s); background: #fff; }
.secret { font: 13px/1.4 ui-monospace, Menlo, Consolas, monospace; color: var(--muted); word-break: break-all; user-select: all; }

/* ── приложение ── */
.app { display: grid; grid-template-columns: 384px 1fr; min-height: 100%; }
.composer {
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 18px; padding: 18px 18px 22px;
}
.brand { display: flex; align-items: center; justify-content: space-between; }
.brand-name { font-weight: 650; font-size: 17px; letter-spacing: -.01em; }

.prompt-box { position: relative; }
.prompt {
  width: 100%; min-height: 132px; max-height: 46vh; resize: none;
  padding: 12px 44px 12px 12px; border-radius: var(--radius-m);
  border: 1px solid var(--line); background: #262626; outline: none; line-height: 1.45;
}
.prompt:focus { border-color: var(--accent); }
.prompt-tools { position: absolute; top: 6px; right: 6px; display: grid; gap: 2px; }

.history {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px);
  max-height: 340px; overflow-y: auto; padding: 6px; border-radius: var(--radius-m);
  background: var(--raise); border: 1px solid var(--line); box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
.history button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: var(--radius-s);
  background: none; color: var(--text); font-size: 14px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.history button:hover { background: var(--raise-2); }
.history .empty { padding: 10px; color: var(--muted); font-size: 14px; }

.block { display: grid; gap: 8px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.block-head b { color: var(--text); font-weight: 600; }

.refs { display: flex; flex-wrap: wrap; gap: 8px; }
.ref, .ref-add {
  position: relative; width: 64px; height: 64px; border-radius: var(--radius-s); overflow: hidden; flex: none;
}
.ref img { width: 100%; height: 100%; object-fit: cover; }
.ref.loading::after {
  content: ""; position: absolute; inset: 0; background: rgba(0, 0, 0, .45);
}
.ref-remove {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0, 0, 0, .65); color: #fff;
}
.ref-remove .icon { width: 14px; height: 14px; }
.ref-add {
  display: grid; place-items: center; border: 1px dashed var(--faint); background: transparent; color: var(--muted);
}
.ref-add:hover { color: var(--text); border-color: var(--muted); }

.seg { display: flex; padding: 3px; gap: 3px; border-radius: var(--radius-s); background: #262626; border: 1px solid var(--line); }
.seg button {
  flex: 1; height: 32px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 14px;
}
.seg button[aria-pressed="true"] { background: var(--raise-2); color: var(--text); }

.aspects { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.aspect {
  height: 54px; border: 1px solid var(--line); border-radius: var(--radius-s); background: #262626;
  display: grid; grid-template-rows: 1fr auto; justify-items: center; align-items: center; padding: 6px 0 4px;
  color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums;
}
.aspect i { display: block; border: 1.5px solid currentColor; border-radius: 2px; }
.aspect[aria-pressed="true"] { border-color: var(--accent); color: var(--text); }
.aspect[aria-pressed="true"] i { border-color: var(--accent); }

.counter { display: flex; align-items: center; gap: 8px; }
.counter output { min-width: 28px; text-align: center; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }

.generate { height: 48px; font-size: 16px; }
.cost { font-size: 13px; color: var(--muted); text-align: center; margin-top: -8px; }
.extra { display: grid; gap: 18px; }
.composer-foot { margin-top: auto; display: grid; gap: 14px; }

/* ── правая часть ── */
.main { min-width: 0; padding: 0 18px 40px; }
.toolbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: 12px 0; background: var(--bg);
}
.search { position: relative; flex: 1; max-width: 420px; }
.search .icon { position: absolute; left: 11px; top: 11px; color: var(--faint); }
.search .input { padding-left: 38px; height: 42px; }
.toolbar .spacer { flex: 1; }
.toggle[aria-pressed="true"] { color: var(--accent); }
.select-bar { display: flex; align-items: center; gap: 8px; }
.select-bar .count { color: var(--muted); font-size: 14px; margin-right: 4px; font-variant-numeric: tabular-nums; }

.jobs { display: grid; gap: 14px; margin-bottom: 18px; }
.job { display: grid; gap: 8px; }
.job-head { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); min-width: 0; }
.job-head .job-prompt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }

.grid { display: flex; flex-wrap: wrap; gap: 6px; }
.grid::after { content: ""; flex-grow: 1000000; }
.tile {
  position: relative; overflow: hidden; border-radius: 4px; background: var(--panel);
  border: 0; padding: 0; min-width: 0;
}
.tile img { width: 100%; height: 100%; object-fit: cover; }
.tile:hover img { filter: brightness(1.06); }
.tile .badge {
  position: absolute; left: 6px; bottom: 6px; display: flex; gap: 4px; pointer-events: none;
}
.tile .badge span {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 4px;
  background: rgba(0, 0, 0, .55); color: #fff;
}
.tile .badge .icon { width: 13px; height: 13px; }
.tile .check {
  position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0, 0, 0, .25); display: none; place-items: center; color: var(--accent-ink);
}
.selecting .tile .check { display: grid; }
.tile.selected .check { background: var(--accent); border-color: var(--accent); }
.tile.selected img { opacity: .72; }
.tile .check .icon { width: 14px; height: 14px; stroke-width: 3; }

/* проявка: пустая плитка медленно «светлеет», готовое фото проявляется из серого */
.tile.pending { background: #353535; }
.tile.pending::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, .07) 45%, transparent 70%);
  background-size: 250% 100%; animation: develop 2.4s linear infinite;
}
.tile.pending .state, .tile.failed .state {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 10px;
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1.3;
}
.tile.failed { background: #3a2f2e; }
.tile.failed .state { color: var(--danger); }
.tile.fresh img { animation: reveal 1.1s var(--ease) both; }
@keyframes develop { from { background-position: 125% 0; } to { background-position: -125% 0; } }
@keyframes reveal {
  from { filter: grayscale(1) brightness(1.9) contrast(.6); opacity: .25; }
  to { filter: none; opacity: 1; }
}

.empty-state { padding: 80px 16px; text-align: center; color: var(--muted); display: grid; gap: 6px; justify-items: center; }
.empty-state strong { color: var(--text); font-size: 17px; font-weight: 600; }
.sentinel { height: 40px; }
.gallery-meta { margin: 18px 0 0; color: var(--faint); font-size: 13px; text-align: center; }

/* ── перетаскивание файлов ── */
.dropzone {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; pointer-events: none;
  background: rgba(30, 30, 30, .82); border: 3px dashed var(--accent); font-size: 20px; font-weight: 600;
}

/* ── просмотр ── */
.viewer {
  position: fixed; inset: 0; z-index: 100; background: var(--viewer);
  display: grid; grid-template-columns: 1fr 340px; color: var(--text);
}
.stage { position: relative; overflow: hidden; display: grid; place-items: center; touch-action: pan-y; }
.stage img { max-width: 100%; max-height: 100dvh; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.stage.zoomed { overflow: auto; place-items: start; touch-action: auto; }
.stage.zoomed img { max-width: none; max-height: none; cursor: zoom-out; }
.stage:not(.zoomed) img { cursor: zoom-in; }
.nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 72px; border: 0;
  background: rgba(40, 40, 40, .55); color: #fff; display: grid; place-items: center; border-radius: var(--radius-s);
}
.nav.prev { left: 12px; }
.nav.next { right: 12px; }
.viewer-close { position: absolute; top: 12px; left: 12px; background: rgba(40, 40, 40, .55); color: #fff; border: 0; }
.info {
  background: #1e1e1e; border-left: 1px solid #333; padding: 18px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px;
}
.info .prompt-text { white-space: pre-wrap; word-break: break-word; margin: 0; max-height: 40vh; overflow-y: auto; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; margin: 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-variant-numeric: tabular-nums; }
.actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.actions .btn { justify-content: flex-start; min-width: 0; overflow: hidden; text-overflow: ellipsis; padding: 0 10px; }
.actions .btn.fav[aria-pressed="true"] { color: var(--accent); }
.info-refs { display: flex; flex-wrap: wrap; gap: 6px; }
.info-refs img { width: 56px; height: 56px; object-fit: cover; border-radius: 4px; }
.info-refs .gone { width: 56px; height: 56px; border-radius: 4px; background: #2a2a2a; display: grid; place-items: center; font-size: 11px; color: var(--faint); text-align: center; }

/* ── меню и уведомления ── */
.menu {
  position: absolute; z-index: 40; right: 0; top: calc(100% + 6px); min-width: 230px; padding: 6px;
  background: var(--raise); border: 1px solid var(--line); border-radius: var(--radius-m);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 9px 10px; border: 0; border-radius: var(--radius-s); background: none; text-align: left; }
.menu button:hover { background: var(--raise-2); }
.rel { position: relative; }
.toasts { position: fixed; z-index: 200; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100% - 32px)); }
.toast {
  padding: 11px 14px; border-radius: var(--radius-s); background: #f0f0f0; color: #1d1d1d;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45); font-size: 14px; animation: toast-in .2s var(--ease);
}
.toast.error { background: #ffd9d3; color: #4a1610; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── телефон ── */
.mobile-only { display: none; }
@media (max-width: 899px) {
  :root { --row: 112px; }
  .app { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none !important; }
  .main { padding: 0 8px calc(var(--dock, 150px) + 16px); }
  .grid { gap: 4px; }
  .composer {
    position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; top: auto; height: auto; max-height: 88dvh;
    border-right: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); gap: 12px;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .35);
  }
  .composer .brand { display: none; }
  .composer:not(.open) .extra { display: none; }
  .composer:not(.open) .prompt { min-height: 46px; max-height: 120px; }
  .composer.open .prompt { min-height: 96px; }
  .composer-foot { margin-top: 0; }
  .dock-row { display: flex; gap: 8px; }
  .dock-row .generate { flex: 1; }
  .cost { margin-top: -4px; }
  .toolbar { padding: 8px 0; gap: 6px; }
  .viewer { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .stage img { max-height: 100%; }
  .info { border-left: 0; border-top: 1px solid #333; max-height: 42dvh; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); }
  .nav { display: none; }
  .aspects { grid-template-columns: repeat(6, 1fr); }
}
@media (min-width: 900px) {
  .dock-row { display: grid; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 899px) {
  .composer:not(.open) .refs-block.empty { display: none; }
  .composer:not(.open) .refs-block .block-head { display: none; }
  .composer:not(.open) .ref, .composer:not(.open) .ref-add { width: 48px; height: 48px; }
}
