:root {
  --bg: #0b0d10;
  --surface: #14181d;
  --surface-2: #1c2128;
  --line: #272e37;
  --text: #e8ecf1;
  --muted: #8a94a3;
  --accent: #0aa5a8;
  --accent-ink: #04201f;
  --danger: #ef5b5b;
  --fav: #ff5c8a;
  --warn: #f0b429;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.viewing { overflow: hidden; }
[hidden] { display: none !important; }
h2 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
h3 { margin: 0 0 8px; font-size: 16px; }
p { margin: 0; }
small, .small { font-size: 12.5px; }
.muted, small { color: var(--muted); }
.error-text { color: var(--danger); font-size: 13px; min-height: 1.2em; overflow-wrap: anywhere; }

.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.filled { fill: currentColor; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type='text'], input[type='password'], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
textarea { resize: vertical; min-height: 44px; line-height: 1.5; }
textarea.prompt { font-size: 16px; min-height: 110px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
input[type='range'] { width: 100%; accent-color: var(--accent); height: 28px; margin: 0; }

.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; border-radius: 12px; padding: 13px 22px; }
.primary:hover:not(:disabled) { filter: brightness(1.1); }
.ghost, .button { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; color: var(--text); text-decoration: none; background: var(--surface); }
.ghost:hover { border-color: var(--muted); }
.ghost.small { padding: 6px 10px; font-size: 13px; }
.ghost.small .icon { width: 16px; height: 16px; }
.ghost.on { border-color: var(--accent); color: var(--accent); }
.danger { color: var(--danger); }

/* ── Entrada ── */
.login { min-height: 100dvh; display: grid; place-content: center; gap: 14px; width: min(280px, 86vw); margin: auto; text-align: center; }
.login input { text-align: center; font-size: 22px; letter-spacing: 0.3em; padding: 14px; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: radial-gradient(circle at 50% 50%, var(--bg) 0 32%, transparent 34%), var(--accent); }
.login .logo { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 10px; }

/* ── Cabecera ── */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 10px max(14px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.online { background: #35c46b; }
.dot.busy { background: var(--warn); animation: pulse 1.2s infinite; }
.dot.offline { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.35; } }
.tabs { display: flex; gap: 4px; }
.main-tabs { margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.tab { display: inline-flex; align-items: center; gap: 7px; padding: 8px 16px; border-radius: 9px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tab.on { background: var(--surface-2); color: var(--text); }
.count { font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--line); color: var(--text); }
.main-tabs .count { background: var(--accent); color: var(--accent-ink); }

/* ── Vistas ── */
.view { padding: 16px max(14px, env(safe-area-inset-left)) 120px; }
.view.create, .view.queue { max-width: 860px; margin: 0 auto; display: grid; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; min-width: 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.models { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.model { text-align: left; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); display: grid; gap: 2px; }
.model span { font-size: 12.5px; color: var(--muted); }
.model.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.model.off { opacity: 0.45; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.chip { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 99px; background: var(--bg); white-space: nowrap; font-size: 13.5px; }
button.chip, .chip > button { padding: 6px 12px; }
.chip.on { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--bg)); }
.chip.saved { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.chip .x { padding: 6px 10px 6px 2px; color: var(--muted); }

details summary { cursor: pointer; color: var(--muted); font-size: 13.5px; padding: 4px 0; }
details label { display: block; margin: 10px 0 4px; font-size: 12.5px; color: var(--muted); }
.source { display: flex; align-items: center; gap: 12px; }
.source img { width: 64px; height: 84px; object-fit: cover; border-radius: 8px; }
.source div { display: grid; gap: 6px; justify-items: start; }

.params { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 22px; }
.param { display: grid; gap: 4px; align-content: start; min-width: 0; }
.param-head { display: flex; align-items: center; justify-content: space-between; min-height: 30px; }
.param label { font-weight: 600; }
.param small { line-height: 1.35; }
.dice { padding: 4px; border-radius: 8px; color: var(--muted); }
.dice.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }
.slider { display: flex; align-items: center; gap: 10px; }
.slider output { min-width: 3.2ch; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.range { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 8px; }
.tag { font-size: 11.5px; color: var(--muted); }
.param.random { background: color-mix(in srgb, var(--accent) 6%, transparent); border-radius: 10px; padding: 6px 10px; margin: -6px -10px; }

.submit { position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 35%); }
.go { width: 100%; font-size: 16px; padding: 15px; }

/* ── Cola ── */
.status { grid-template-columns: auto 1fr; align-items: center; }
.status .dot { width: 11px; height: 11px; }
.status.online .dot { background: #35c46b; }
.status.offline .dot { background: var(--danger); }
.running .bar { height: 3px; border-radius: 3px; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 50% 100%; background-repeat: no-repeat; animation: slide 1.4s linear infinite; }
@keyframes slide { from { background-position: -50% 0; } to { background-position: 150% 0; } }
.elapsed { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; }
.prompt-text { overflow-wrap: anywhere; white-space: pre-wrap; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 13.5px; }
.job { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.job .n { font-weight: 700; color: var(--accent); text-align: center; font-variant-numeric: tabular-nums; }
.job.error .n { color: var(--danger); }
.job.cancelled { opacity: 0.6; }

/* ── Galería ── */
.view.gallery { padding-left: 8px; padding-right: 8px; }
.gallery-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 0 6px 12px; }
.gallery-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.density { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.density input { width: 96px; }
.density span { min-width: 4.5ch; }
.bulk { display: inline-flex; align-items: center; gap: 6px; padding-left: 6px; }
.grid { display: grid; gap: 6px; grid-template-columns: repeat(var(--columns), 1fr); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(min(46vw, 190px), 1fr)); }
.tile { position: relative; aspect-ratio: 3 / 4 !important; border-radius: 8px; overflow: hidden; background: var(--surface); display: block; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile:hover img { filter: brightness(1.12); }
.tile.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.badge { position: absolute; top: 6px; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: rgb(0 0 0 / 0.55); }
.badge .icon { width: 13px; height: 13px; }
.badge.fav { right: 6px; color: var(--fav); }
.badge.video { left: 6px; }
.check { position: absolute; left: 6px; bottom: 6px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: rgb(0 0 0 / 0.4); display: grid; place-items: center; }
.selected .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check .icon { width: 15px; height: 15px; stroke-width: 3; }
.empty { text-align: center; padding: 70px 0; }
.sentinel { height: 1px; }

/* ── Visor ── */
.viewer { position: fixed; inset: 0; z-index: 20; background: #000; display: grid; grid-template-columns: 1fr; }
.viewer.with-info { grid-template-columns: 1fr min(360px, 34vw); }
.stage { position: relative; grid-column: 1; grid-row: 1; display: grid; place-items: center; min-height: 0; min-width: 0; height: 100dvh; }
.stage img, .stage video { max-width: 100%; max-height: 100dvh; object-fit: contain; display: block; background-size: contain; background-position: center; background-repeat: no-repeat; user-select: none; -webkit-user-drag: none; }
.nav { position: absolute; top: 50%; translate: 0 -50%; width: 54px; height: 96px; display: grid; place-items: center; color: #fff; opacity: 0.55; }
.nav:hover { opacity: 1; }
.nav .icon { width: 30px; height: 30px; filter: drop-shadow(0 0 4px #000); }
.prev { left: 0; }
.next { right: 0; }
.viewer-top { grid-column: 1; grid-row: 1; align-self: start; display: flex; justify-content: space-between; align-items: center; padding: max(10px, env(safe-area-inset-top)) 12px 0; pointer-events: none; z-index: 1; }
.viewer-top > * { pointer-events: auto; }
.position { font-size: 13px; font-variant-numeric: tabular-nums; background: rgb(0 0 0 / 0.5); padding: 4px 10px; border-radius: 99px; }
.toolbar { grid-column: 1; grid-row: 1; align-self: end; justify-self: center; display: flex; gap: 6px; padding: 6px; margin-bottom: max(14px, env(safe-area-inset-bottom)); background: rgb(20 24 29 / 0.82); backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 99px; z-index: 1; }
.tool { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; color: var(--text); }
.viewer-top .tool { background: rgb(0 0 0 / 0.5); }
.tool:hover { background: var(--surface-2); }
.tool.on { color: var(--accent); }
.tool.fav { color: var(--fav); }
.tool.danger { color: var(--danger); }
.info { grid-column: 2; grid-row: 1; background: var(--surface); border-left: 1px solid var(--line); padding: 18px; overflow-y: auto; display: grid; gap: 12px; align-content: start; height: 100dvh; }
.kvs { display: grid; gap: 1px; background: var(--line); border-radius: 10px; overflow: hidden; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; background: var(--bg); font-size: 13.5px; }
.kv span { color: var(--muted); }
.kv b { font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.info-actions { display: flex; flex-wrap: wrap; gap: 6px; }

#toasts { position: fixed; left: 50%; translate: -50% 0; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 40; display: grid; gap: 6px; justify-items: center; pointer-events: none; width: min(92vw, 440px); }
.toast { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; box-shadow: 0 8px 30px rgb(0 0 0 / 0.5); animation: rise 0.18s ease-out; }
.toast.ok { border-color: var(--accent); }
.toast.error { border-color: var(--danger); }
@keyframes rise { from { opacity: 0; translate: 0 8px; } }

@media (max-width: 720px) {
  .top { flex-wrap: wrap; row-gap: 8px; }
  .main-tabs { order: 3; width: 100%; margin: 0; }
  .main-tabs .tab { flex: 1; justify-content: center; }
  .top > .ghost { margin-left: auto; }
  .viewer.with-info { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .viewer.with-info .stage { height: 58dvh; }
  .viewer.with-info .stage img, .viewer.with-info .stage video { max-height: 58dvh; }
  .info { grid-column: 1; grid-row: 2; height: 42dvh; border-left: 0; border-top: 1px solid var(--line); }
  .nav { width: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
}
