:root {
  --bg: #070509;
  --bg2: #09070c;
  --card: rgba(13, 8, 17, .92);
  --text: #f3edf5;
  --hint: #b5a8ba;
  --accent: #7537ac;
  --accent-text: #fff;
  --link: #d495ef;
  --danger: #ff5963;
  --line: rgba(150, 46, 130, .42);
  --r: 10px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: env(safe-area-inset-bottom); background:
  radial-gradient(ellipse at 50% -12%, rgba(117,55,172,.34), transparent 56%),
  radial-gradient(ellipse at 100% 62%, rgba(150,46,130,.13), transparent 48%), #070509; background-attachment: fixed; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; }
[hidden] { display: none !important; }

.tabs { position: sticky; top: 0; z-index: 5; display: flex; gap: 5px; padding: 9px;
  background: linear-gradient(180deg, rgba(47,19,63,.96), rgba(10,7,13,.96)); border-bottom: 1px solid rgba(150,46,130,.55);
  box-shadow: 0 5px 24px rgba(117,55,172,.18); backdrop-filter: blur(14px); }
.tabs button { flex: 1; padding: 8px 4px; border: 0; border-radius: 10px; background: transparent; color: var(--hint); font-weight: 600; }
.tabs button.active { background: linear-gradient(135deg, rgba(117,55,172,.72), rgba(150,46,130,.52)); color: #fff; box-shadow: inset 0 0 0 1px rgba(212,149,239,.35); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent);
  color: var(--accent-text); font-size: 12px; }

main { padding: 10px 10px 90px; }
.tab { display: none; }
.tab.active { display: block; }
.card { background: radial-gradient(ellipse at 50% 0%, rgba(117,55,172,.22), transparent 78%), rgba(9,7,12,.94);
  border: 1px solid rgba(117,55,172,.62); border-radius: var(--r); padding: 13px; margin-bottom: 11px;
  box-shadow: 0 0 15px rgba(117,55,172,.13), inset 0 1px rgba(255,255,255,.035); }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin-bottom: 6px; font-weight: 600; }
.muted { color: var(--hint); }
.small { font-size: 12.5px; }
.help { margin-top: 7px; line-height: 1.35; }
.center { text-align: center; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.link { background: none; border: 0; color: var(--link); padding: 0; font-size: 13px; }
.empty { text-align: center; color: var(--hint); padding: 40px 0; }

.btn { border: 1px solid rgba(212,149,239,.28); border-radius: 10px; padding: 11px 14px; font-weight: 600; }
.btn.primary { background: linear-gradient(115deg, #7537ac, #962e82 72%, #a62668); color: var(--accent-text);
  border-color: rgba(230,177,246,.5); box-shadow: 0 5px 20px rgba(150,46,130,.32); }
.btn.secondary { background: linear-gradient(110deg, rgba(117,55,172,.28), rgba(150,46,130,.14)); color: #e4b9f4; }
.btn.danger { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.btn.wide { width: 100%; }
.btn.sticky { position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); width: auto; z-index: 4;
  box-shadow: 0 6px 20px rgba(0,0,0,.35); }
.btn:disabled { opacity: .5; }
.icon { border: 1px solid var(--line); background: rgba(20,12,25,.9); border-radius: 10px; min-width: 40px; height: 40px; font-size: 17px; }
.footer-actions .btn { flex: 1; font-size: 13px; }

.model-card { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.thumb { width: 56px; height: 76px; border-radius: 10px; background: var(--bg2) center/cover no-repeat; flex: none; overflow: hidden; }
.thumb video { width: 100%; height: 100%; object-fit: cover; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.model-info { flex: 1; min-width: 0; }
.model-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chev { color: var(--hint); font-size: 26px; }

details.neg { margin-top: 8px; }
details summary { cursor: pointer; color: var(--hint); font-size: 13px; padding: 4px 0; }
details.neg textarea { margin-top: 6px; }
details.acc > summary { font-weight: 700; color: #f4e9fa; font-size: 15px; list-style: none; }
details.acc > summary::after { content: "⌄"; float: right; color: #d495ef; font-size: 19px; line-height: 1; }
details.acc:not([open]) > summary::after { content: "▸"; }
details.acc[open] > summary { color: #e9b5fa; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border: 1px solid rgba(150,46,130,.46); background: rgba(20,12,25,.88); border-radius: 8px; padding: 6px 11px; font-size: 13px; white-space: nowrap; }
.chips button.active { background: linear-gradient(110deg, #7537ac, #962e82); color: var(--accent-text); border-color: #ca75cb; box-shadow: 0 0 12px rgba(150,46,130,.24); }
.presets { padding-top: 10px; }

.num { display: flex; align-items: center; gap: 6px; flex: 1; }
.num span { color: var(--hint); font-size: 13px; }
.stepper { display: flex; align-items: center; background: var(--bg2); border-radius: 10px; height: 40px; }
.stepper button { border: 0; background: none; width: 38px; height: 40px; font-size: 18px; }
.stepper span { min-width: 22px; text-align: center; font-weight: 700; }

/* LoRA */
.lora { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.lora:last-child { border-bottom: 0; }
.lora .thumb { width: 48px; height: 64px; }
.lora.off { opacity: .45; }
.lora-body { flex: 1; min-width: 0; }
.lora-title { display: flex; align-items: center; gap: 8px; }
.lora-title .name { flex: 1; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.x { border: 0; background: none; color: var(--hint); font-size: 18px; padding: 0 2px; }
.triggers { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.triggers button { border: 0; border-radius: 8px; padding: 3px 7px; font-size: 12px; background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--link); }

/* слайдеры */
.field { margin: 10px 0; }
.field-help, .select-help { display: block; margin-top: 2px; line-height: 1.3; }
.field-top { display: flex; justify-content: space-between; align-items: center; font-size: 13.5px; margin-bottom: 2px; }
.field-top input { width: 72px; padding: 3px 6px; text-align: right; font-size: 13px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; padding: 0; border: 0; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9px; border-radius: 50%; background: var(--accent); border: 3px solid var(--card); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 3px solid var(--card); }
.mini .field { margin: 2px 0; }
.mini .field-top { font-size: 12px; color: var(--hint); }

.stage { border-top: 1px solid rgba(150,46,130,.32); padding: 10px 0 2px; }
.stage-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.stage-head .sub { font-weight: 400; color: var(--hint); font-size: 12px; display: block; }
.stage.off .stage-body { display: none; }
.selects { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.selects label { font-size: 12px; color: var(--hint); }
.opt-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; gap: 10px; }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 14px; background: var(--line); transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }

/* задания */
.job { background: var(--card); border-radius: var(--r); padding: 12px; margin-bottom: 10px; }
.job-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--hint); }
.bar { height: 8px; border-radius: 6px; background: rgba(255,255,255,.1); margin: 8px 0; overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,.65); }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #7537ac, #962e82 65%, #d01a4a); transition: width .5s; box-shadow: 0 0 10px rgba(208,26,74,.7); }
.progress-row { display: flex; align-items: center; gap: 9px; }
.progress-row .bar { flex: 1; }
.progress-value { min-width: 38px; text-align: right; color: #e9b5fa; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.job { background: radial-gradient(ellipse at 50% 0%, rgba(117,55,172,.25), transparent 75%), rgba(9,7,12,.95); border: 1px solid rgba(117,55,172,.65); border-radius: 10px; padding: 13px; margin-bottom: 11px; box-shadow: 0 0 14px rgba(117,55,172,.12); }
.job-head { color: #d5c6dc; }
.job .live { width: 100%; border-radius: 10px; margin-top: 6px; display: block; background: var(--bg2); }
.job .stages { display: flex; gap: 6px; overflow-x: auto; margin-top: 8px; }
.job .stages figure { margin: 0; flex: none; text-align: center; }
.job .stages img { height: 110px; border-radius: 8px; display: block; }
.job .stages figcaption { font-size: 11px; color: var(--hint); }
.job .err { color: var(--danger); white-space: pre-wrap; font-size: 13px; margin-top: 6px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 6px; }
.grid .cell { position: relative; aspect-ratio: 2/3; border-radius: 10px; background: var(--card) center/cover no-repeat; overflow: hidden; cursor: pointer; }
.grid .cell video { width: 100%; height: 100%; object-fit: cover; }
.grid .cell img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg2); overflow-y: auto; padding: 0 10px 20px; }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; gap: 8px; align-items: center; padding: 10px 0; background: var(--bg2); }
.sort { position: sticky; top: 60px; z-index: 2; background: var(--bg2); }
.pick { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.pcard { background: var(--card); border-radius: 12px; overflow: hidden; cursor: pointer; }
.pcard .img { aspect-ratio: 2/3; background: var(--bg) center/cover no-repeat; position: relative; }
.pcard .img video { width: 100%; height: 100%; object-fit: cover; }
.pcard .img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pcard .meta { padding: 6px 8px 8px; }
.pcard .t { font-size: 13px; font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pcard .b { font-size: 11px; color: var(--hint); }
.pcard.disabled { opacity: .35; pointer-events: none; }
.pcard .tag { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 10.5px; padding: 2px 6px; border-radius: 6px; }
.pcard.selected { outline: 2px solid var(--accent); }

.viewer img { width: 100%; border-radius: 12px; display: block; }
.viewer #viewerImg { cursor: zoom-in; }
.viewer-zoom-hint { margin-top: 6px; }
.viewer-info { font-size: 13px; color: var(--hint); margin: 10px 0; white-space: pre-wrap; word-break: break-word; }
.viewer-info b { color: var(--text); }
.viewer-actions .btn { flex: 1; }
#viewerActions .btn { flex: 1 1 45%; }

.image-fullscreen { position: fixed; inset: 0; z-index: 40; background: #030204; color: #fff; overflow: hidden;
  padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom)); }
.image-full-controls { position: absolute; z-index: 2; top: calc(8px + env(safe-area-inset-top)); left: 10px; right: 10px;
  display: flex; align-items: center; justify-content: space-between; pointer-events: none; }
.image-full-controls button, .zoom-tools { pointer-events: auto; }
.zoom-tools { display: flex; align-items: center; gap: 7px; padding: 5px 7px; border: 1px solid rgba(212,149,239,.35);
  border-radius: 12px; background: rgba(13,8,17,.88); box-shadow: 0 0 16px rgba(117,55,172,.25); }
.zoom-tools .icon { min-width: 36px; height: 36px; }
#zoomValue { min-width: 42px; text-align: center; color: #e9b5fa; font-size: 12px; font-variant-numeric: tabular-nums; }
.image-full-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
.image-full-stage img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain;
  transform-origin: center center; transition: none; user-select: none; -webkit-user-drag: none; }

.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); z-index: 30; background: rgba(20,20,20,.92);
  color: #fff; padding: 10px 14px; border-radius: 12px; font-size: 14px; max-width: 90vw; white-space: pre-wrap; }
