:root {
  --bg: #0e0f13;
  --panel: #16181f;
  --panel2: #1c1f28;
  --line: #272b36;
  --text: #e9eaf0;
  --muted: #8b90a0;
  --accent: #7c5cff;
  --accent2: #9b86ff;
  --ok: #35c48a;
  --warn: #e5b53a;
  --err: #ff5c6c;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, "SF Pro Text", "Golos Text", "Inter", system-ui, sans-serif;
}

body { overflow: hidden; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.sep { margin: 14px 0 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

/* кнопки */
.btn {
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 14px;
  cursor: pointer;
  font: inherit;
  transition: .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #3a3f4d; background: #232733; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: #5a2a31; color: #ff8d99; }
.btn.sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.xs { padding: 3px 7px; font-size: 11.5px; border-radius: 6px; }
.btn.apply { width: 100%; margin-top: 10px; font-size: 12.5px; padding: 7px; }
.btn.apply.ok { border-color: #2a5544; color: var(--ok); }
.btn.apply.warn { border-color: #5c4a1e; color: var(--warn); }

/* вход */
.login-screen { display: flex; align-items: center; justify-content: center; height: 100%; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 34px; width: 340px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.brand { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.login-card input, .login-card button { height: 42px; }
.login-error { color: var(--err); font-size: 12.5px; min-height: 16px; }

input, select, textarea {
  width: 100%;
  background: #101219;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #444a5c; }
textarea { resize: vertical; min-height: 60px; }
input[type="color"] { padding: 2px; height: 34px; cursor: pointer; }
input[type="range"] { padding: 0; accent-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 9px; }
label > input, label > select, label > textarea { margin-top: 4px; }
label.check, label.radio { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* каркас */
.screen { height: 100%; display: flex; flex-direction: column; }

.topbar {
  height: 52px; flex: 0 0 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.logo { font-weight: 700; letter-spacing: -.02em; font-size: 16px; }
.topbar-right { display: flex; gap: 6px; align-items: center; }

.tabsbar {
  height: 42px; flex: 0 0 42px; display: flex; align-items: center; gap: 6px;
  padding: 0 12px; border-bottom: 1px solid var(--line); overflow-x: auto; background: #12141a;
}
.tab {
  display: flex; align-items: center; gap: 7px; padding: 5px 10px; border-radius: 8px;
  border: 1px solid transparent; cursor: pointer; font-size: 13px; white-space: nowrap; color: var(--muted);
}
.tab:hover { background: #1a1d25; }
.tab.active { background: var(--panel2); border-color: var(--line); color: var(--text); }
.tab .dot { width: 7px; height: 7px; border-radius: 50%; background: #41465a; }
.tab .dot.running { background: #5b8cff; animation: pulse 1.1s infinite; }
.tab .dot.done { background: var(--ok); }
.tab .dot.error { background: var(--err); }
.tab .dot.warn { background: var(--warn); }
.tab .x { opacity: 0; font-size: 14px; }
.tab:hover .x { opacity: .6; }
@keyframes pulse { 50% { opacity: .35; } }

.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 330px minmax(0, 1fr) 300px;
}

/* настройки */
.settings {
  border-right: 1px solid var(--line); overflow-y: auto; background: #12141a;
  padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.block { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.block > summary {
  padding: 10px 12px; cursor: pointer; display: flex; justify-content: space-between;
  align-items: center; font-weight: 600; font-size: 13px; list-style: none;
}
.block > summary::-webkit-details-marker { display: none; }
.status { width: 8px; height: 8px; border-radius: 50%; background: #3a3f4d; }
.status.saved { background: var(--ok); }
.status.dirty { background: var(--warn); }
.status.error { background: var(--err); }
.block-body { padding: 4px 12px 12px; border-top: 1px solid var(--line); }
.chosen { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chosen img { width: 44px; height: 55px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.tpl-preview img { max-width: 100%; margin-top: 8px; border-radius: 8px; }

.runbox {
  position: sticky; bottom: -10px; margin-top: auto; display: flex; flex-direction: column; gap: 8px;
  padding: 14px 2px 10px; background: linear-gradient(to top, #12141a 72%, rgba(18,20,26,0));
}
.estimate { font-size: 12px; color: var(--muted); text-align: center; }
.runrow { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }

/* рабочая область */
.work { display: flex; flex-direction: column; min-width: 0; background: #0c0d12; }
.stepper { display: flex; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.stepper button {
  flex: 1; padding: 7px; border-radius: 8px; border: 1px solid transparent; background: transparent;
  color: var(--muted); cursor: pointer; font: inherit; font-size: 12.5px;
}
.stepper button.active { background: var(--panel2); border-color: var(--line); color: var(--text); }
.stage { flex: 1; overflow-y: auto; padding: 18px; }
.empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }

/* шаг 1: текст */
.slides { display: flex; flex-direction: column; gap: 10px; max-width: 720px; margin: 0 auto; }
.slidecard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.slidecard .head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.slidecard textarea { min-height: 74px; }
.counter { font-variant-numeric: tabular-nums; }
.counter.over { color: var(--err); }

/* шаг 2: картинки */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; max-width: 900px; margin: 0 auto; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tile img { width: 100%; aspect-ratio: 4/5; object-fit: cover; display: block; background: #101219; }
.tile .cap { padding: 7px 9px; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.skeleton {
  aspect-ratio: 4/5; background: linear-gradient(100deg, #171a22 30%, #22262f 50%, #171a22 70%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* шаг 3-4 */
.preview-wrap { display: flex; gap: 18px; max-width: 1100px; margin: 0 auto; }
.thumbs { display: flex; flex-direction: column; gap: 8px; width: 74px; flex: 0 0 74px; }
.thumbs img { width: 74px; aspect-ratio: 4/5; object-fit: cover; border-radius: 6px; border: 2px solid transparent; cursor: pointer; }
.thumbs img.active { border-color: var(--accent); }
.bigpreview { flex: 1; display: flex; justify-content: center; }
.bigpreview img { max-height: 62vh; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }

.result-caption { max-width: 900px; margin: 18px auto 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.result-caption textarea { min-height: 120px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* лог */
.logpanel { border-left: 1px solid var(--line); display: flex; flex-direction: column; background: #101219; min-height: 0; }
.loghead { display: flex; justify-content: space-between; align-items: center; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.loglist { flex: 1; overflow-y: auto; padding: 8px 10px; font: 12px/1.5 ui-monospace, "SF Mono", Menlo, monospace; }
.logline { padding: 3px 0; border-bottom: 1px dashed #1b1e27; word-break: break-word; }
.logline .t { color: #565d70; margin-right: 6px; }
.logline.ok { color: #9fe3c4; }
.logline.warn { color: var(--warn); }
.logline.error { color: #ff9aa4; }
.logline .detail { color: #737b90; font-size: 11px; }
.logsum { padding: 8px 12px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }

/* модалки */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; z-index: 50; backdrop-filter: blur(3px); }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: min(980px, 94vw); max-height: 88vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }

.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.asset { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; }
.asset img { width: 100%; aspect-ratio: 1/1; object-fit: cover; display: block; }
.asset.sel { outline: 2px solid var(--accent); }
.asset .meta { padding: 5px 7px; font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset .fav { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.55); border: none; color: #ffd166; border-radius: 6px; cursor: pointer; font-size: 13px; padding: 2px 6px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.setbar {
  display: flex; align-items: center; gap: 8px; margin: 0 0 8px; padding: 8px 10px;
  border: 1px dashed var(--line); border-radius: 9px; background: #141720;
  font-size: 12.5px; color: var(--muted);
}
.setbar #setCount { flex: 1; }
.hint { font-size: 12px; color: var(--muted); margin: 0 0 12px; }
.seth { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.setacts { display: flex; gap: 4px; }
.toolbar input[type="text"], .toolbar input:not([type]) { max-width: 240px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.librow { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 6px; background: var(--panel2); }
.librow .txt { flex: 1; white-space: pre-wrap; }
.setcard { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: var(--panel2); }
.setcard .imgs { display: flex; gap: 6px; margin: 8px 0; }
.setcard .imgs img { width: 62px; aspect-ratio: 4/5; object-fit: cover; border-radius: 6px; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
.toast { position: fixed; right: 18px; bottom: 18px; background: var(--panel2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 10px; z-index: 90; font-size: 13px; max-width: 380px; }
.toast.err { border-color: #5a2a31; color: #ff9aa4; }
.toast.ok { border-color: #2a5544; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 300px 1fr; }
  .logpanel { display: none; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; overflow-y: auto; }
  .settings { border-right: none; border-bottom: 1px solid var(--line); max-height: 46vh; }
  .result-caption { grid-template-columns: 1fr; }
  .preview-wrap { flex-direction: column; }
}
