:root {
  --bg: #0b0b10;
  --panel: #121218;
  --panel-2: #17171f;
  --line: #24242e;
  --text: #e8e8ee;
  --muted: #8b8b99;
  --accent: #7c5cff;
  --accent-2: #a28bff;
  --ok: #2fd27a;
  --warn: #f0b429;
  --bad: #ff5c6c;
  --radius: 10px;
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.error { color: var(--bad); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }

/* buttons, inputs, chips */
.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 8px;
  padding: 9px 14px; font: inherit; cursor: pointer; }
.btn:hover { border-color: #3a3a48; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #6a48ff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; margin: 0; }
input[type=text], input[type=password], input[type=date], input[type=number], select, textarea { background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 9px 12px; font: inherit; }
/* our own arrow, with room on the right */
select { appearance: none; -webkit-appearance: none; padding-right: 38px; background-repeat: no-repeat; background-position: right 14px center;
  background-size: 12px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%239a9ab0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
input:focus { outline: none; border-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; font-size: 13px; }
.chip.balance { display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.chip.balance::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 0 rgba(47, 210, 122, .6); animation: live 2s ease-out infinite; }
@keyframes live {
  0% { box-shadow: 0 0 0 0 rgba(47, 210, 122, .6); opacity: 1; }
  60% { box-shadow: 0 0 0 6px rgba(47, 210, 122, 0); opacity: .55; }
  100% { box-shadow: 0 0 0 0 rgba(47, 210, 122, 0); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .chip.balance::before { animation: none; } }
.chip.balance.off::before { background: var(--muted); animation: none; }
.chip.avatar { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; font: inherit;
  font-weight: 600; width: 34px; height: 34px; padding: 0; border-radius: 50%; cursor: pointer; }
.chip.avatar:hover, .chip.avatar[aria-expanded=true] { box-shadow: 0 0 0 3px rgba(124, 92, 255, .35); }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; box-shadow: 0 12px 32px rgba(0, 0, 0, .45); z-index: 5; }
.menu-who { display: grid; gap: 2px; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-who .muted { font-size: 12.5px; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; color: var(--text);
  font: inherit; padding: 8px 10px; border-radius: 6px; cursor: pointer; text-align: left; }
.menu-item:hover { background: var(--panel-2); }
.menu-item svg, .icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round; }
.badge { display: inline-block; border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
.badge.COMPLETED, .badge.DONE { background: rgba(47, 210, 122, .12); color: var(--ok); }
.badge.RUNNING, .badge.IN_PROGRESS, .badge.IN_QUEUE, .badge.PENDING { background: rgba(124, 92, 255, .15); color: var(--accent-2); }
.badge.FAILED { background: rgba(255, 92, 108, .12); color: var(--bad); }
.badge.tipo-final { background: rgba(124, 92, 255, .18); color: var(--accent-2); }
.badge.tipo-muestra { background: rgba(240, 180, 41, .14); color: var(--warn); }
.badge.tipo-previa { background: rgba(139, 139, 153, .15); color: #c9c9d3; }
.badge.tipo-ajuste { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.badge.devuelto { background: rgba(124, 92, 255, .18); color: var(--accent-2); margin-left: 6px; }
.badge.CANCELLED { background: rgba(139, 139, 153, .15); color: var(--muted); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px; display: grid; gap: 14px; }
.login-card h1 { margin: 6px 0 0; font-size: 22px; }
.login-card p { margin: 0; }

/* layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; transition: grid-template-columns .15s; }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.icon-btn { background: none; border: 0; color: var(--muted); padding: 6px; border-radius: 8px; cursor: pointer; display: grid; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.app.collapsed { grid-template-columns: 64px 1fr; }
.app.collapsed .nav-label { display: none; }
.app.collapsed .side-head { flex-direction: column; }
.app.collapsed .brand { display: none; }
.app.collapsed nav a { justify-content: center; padding: 9px 0; }
.app.collapsed #collapse svg { transform: scaleX(-1); }
.sidebar { border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh; }
.brand { font-size: 20px; letter-spacing: .3px; padding: 0 8px; white-space: nowrap; }
a.brand:hover .logo { color: var(--accent-2); }
.brand b { color: var(--accent-2); font-weight: 700; }
.logo { color: var(--accent); margin-right: 4px; }
nav { display: grid; gap: 4px; flex: 1; align-content: start; }
nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; color: #c9c9d3; }
nav a svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round; opacity: .8; }
nav a:hover { background: var(--panel-2); color: #fff; }
nav a.active { background: #22222b; color: #fff; }
nav a.active svg { opacity: 1; }
.subnav { display: grid; gap: 4px; }
/* the admin: a client's views hang under Clientes while that client is open */
.subnav.nested { margin: 0 0 4px 18px; padding-left: 10px; border-left: 1px solid var(--line); }
.subnav-title { font-size: 12px; color: var(--accent-2); font-weight: 600; padding: 4px 12px 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app.collapsed .subnav.nested { margin-left: 0; padding-left: 0; border-left: 0; border-top: 1px solid var(--line); padding-top: 4px; }
.app.collapsed .subnav-title { display: none; }
main { min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 28px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: rgba(11, 11, 16, .92);
  backdrop-filter: blur(6px); z-index: 2; }
.crumbs { font-weight: 600; }
.viewing { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 16px 28px 0; padding: 10px 14px; border: 1px solid var(--accent); border-radius: var(--radius);
  background: rgba(124, 92, 255, .08); }
.viewing .muted { font-size: 13px; }
.chips { display: flex; gap: 8px; align-items: center; }
.view { padding: 24px 28px 48px; display: grid; gap: 20px; }
.view h2 { margin: 0; font-size: 26px; font-weight: 600; }
.subtitle { margin: -12px 0 0; color: var(--muted); }

/* cards */
.grid { display: grid; gap: 14px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.two { grid-template-columns: 2fr 1fr; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.progress { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kv.four dd { white-space: normal; overflow-wrap: anywhere; }

/* charts */
.chart { width: 100%; height: auto; max-height: 260px; display: block; }
.chart .bar { fill: var(--accent); }
.chart .bar:hover { fill: var(--accent-2); }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--line); }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* tables */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.num, th.num { text-align: right; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
td .sub { color: var(--muted); font-size: 12px; }

.dot { display: inline-flex; align-items: center; gap: 8px; }
.dot::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 3px rgba(47, 210, 122, .15); }
.dot.bad::before { background: var(--bad); box-shadow: 0 0 0 3px rgba(255, 92, 108, .15); }
.stat .value .dot { font-size: 20px; }

.section { margin: 6px 0 -6px; font-size: 15px; }
.live .progress { margin: 4px 0 6px; }
.kv.four { grid-template-columns: auto 1fr; margin: 10px 0 12px; }
.kv.four dd { text-align: left; }
.inline-progress { display: inline-flex; align-items: center; gap: 10px; }
.inline-progress .progress { width: 90px; margin: 0; }
.chip.admin { border-color: var(--accent); color: var(--accent-2); font-weight: 600; }
.accent { color: var(--accent-2); font-weight: 600; }

/* home: price table */
.price-note { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
td.hl, th.hl { color: var(--accent-2); }

/* expandable rows */
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.card-head h3 { margin: 0; }
.card-head b { color: var(--text); }
/* a centered box, so turning it keeps the arrow in place */
.chev { display: inline-block; width: 14px; height: 14px; margin-right: 4px; vertical-align: middle; font-size: 0; overflow: hidden;
  background: var(--muted); transform-origin: 50% 50%; transition: transform .15s;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M5.5 3.5L9 7l-3.5 3.5' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M5.5 3.5L9 7l-3.5 3.5' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat; }
tr.open .chev { transform: rotate(90deg); background: var(--text); }
td:has(> .chev) { white-space: nowrap; }
tr.open td { background: var(--panel-2); }
tr.detail > td { padding: 0 0 12px 26px; background: var(--panel-2); white-space: normal; }
/* contain: inline-size -> the nested table never widens the outer one; it scrolls inside instead */
.nested { border-left: 1px solid var(--line); padding: 8px 0 0 14px; contain: inline-size; }
.nested table { font-size: 13px; }
.nested th, .nested td { padding: 7px 10px; }
.small { font-size: 12.5px; margin: 0 0 6px; }
.attempts { margin: 0; display: grid; gap: 4px; white-space: normal; min-width: 320px; }
.attempt { font-size: 12.5px; color: var(--muted); }
.attempt.failed { color: var(--bad); }
.parts td { vertical-align: top; }
.parts tr.retry td { border-top: 0; padding-top: 0; }
.parts .gpu { color: #c9c9d3; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; }
  nav { display: flex; flex-wrap: wrap; }
  .grid.two { grid-template-columns: 1fr; }
  .view, .topbar { padding-left: 16px; padding-right: 16px; }
  .viewing { margin: 12px 16px 0; }
  .app.collapsed { grid-template-columns: 1fr; }
  .app.collapsed .nav-label { display: inline; }
  #collapse { display: none; }
}

/* admin: refunds form */
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form label.wide { grid-column: 1 / -1; }
.form select, .form input, .form textarea { width: 100%; box-sizing: border-box; }
.form textarea { min-height: 60px; resize: vertical; }
.form .hint { font-size: 12px; color: var(--muted); }
.form-actions { display: flex; gap: 12px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.ok-msg { color: var(--ok, #3ecf8e); }
.version-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin: 14px 0 6px; font-size: 13px; }
.version-head b { color: var(--text); }
.version-head .muted { font-size: 12px; }
.for { font-size: 12px; color: var(--muted); display: block; }

/* refunds shown where they apply */
/* a refunded row is tinted end to end, so it shows without looking at the left edge */
tr.refunded > td { background: rgba(124, 92, 255, .13); }
tr.click.refunded:hover > td, tr.refunded.open > td { background: rgba(124, 92, 255, .2); }
.refund-note { border: 1px solid rgba(124, 92, 255, .35); background: rgba(124, 92, 255, .08); border-radius: 8px;
  padding: 8px 12px; margin: 8px 0; font-size: 13px; }
.refund-note b { color: var(--accent-2); }
details.refund-note > summary { cursor: pointer; list-style: none; }
details.refund-note > summary::-webkit-details-marker { display: none; }
details.refund-note > summary::before { content: "▸"; display: inline-block; width: 14px; color: var(--accent-2); }
details.refund-note[open] > summary::before { content: "▾"; }
details.refund-note > p { margin: 6px 0 0 14px; color: var(--muted); }
.note { font-size: 12px; color: var(--muted); max-width: 460px; display: block; font-weight: 400; margin-top: 4px;
  white-space: normal; line-height: 1.4; }
/* admin refunds: pick several */
.picks td input[type=number] { width: 110px; padding: 6px 8px; }
.picks tr.off { opacity: .45; }
.picks .toggle { background: none; border: 0; color: var(--accent-2); cursor: pointer; font: inherit; font-size: 12px; padding: 0; }
.picks tr.part td:nth-child(2) { padding-left: 52px; position: relative; }
.picks tr.part td:nth-child(2)::before { content: ""; position: absolute; left: 30px; top: 0; bottom: 0; border-left: 1px solid var(--line); }
.picks tr.part > td { background: rgba(255, 255, 255, .015); }
.picks .count { color: var(--muted); font-size: 12px; margin-left: 4px; }
.kv-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; margin: 6px 0; }
.kv-list dt { color: var(--muted); }
.kv-list dd { margin: 0; }
.clip { display: inline-block; max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
tr.note-row td { padding-top: 0; border-top: 0; }
tr.note-row .note { max-width: none; }
.player { margin: 10px 0 14px; display: grid; gap: 8px; max-width: 900px; position: sticky; left: 0; }
.player-media { display: grid; place-items: center; min-height: 64px; background: #000; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.player-media video, .player-media img { display: block; width: 100%; max-height: 60vh; object-fit: contain; background: #000; }
.player-media .btn { margin: 14px; }
.player-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.player-bar a.btn { text-decoration: none; margin-left: auto; }
button.play { border: 0; background: transparent; color: var(--accent); cursor: pointer; padding: 0 6px 0 0; font-size: 12px; }
button.play:hover { color: #fff; }
.player-media[hidden] { display: none; }
details.fold > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 12px; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary h3 { margin: 0; }
details.fold > summary::before { content: "›"; color: var(--muted); transition: transform .15s; display: inline-block; }
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold[open] > summary { margin-bottom: 12px; }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: start; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.tags .chip { font-size: 12px; padding: 4px 10px; }
.usage .progress { margin: 2px 0 4px; }
.usage p { margin: 0 0 12px; }
table.money tbody tr.house td { border-top: 1px dashed var(--line); }
table.money tfoot td { border-top: 2px solid var(--line); padding-top: 10px; }
table.money .sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; white-space: normal; max-width: 520px; }
.newkey { border-color: var(--accent); }
.keybox { display: flex; gap: 10px; align-items: center; margin: 10px 0 12px; }
.keybox code { flex: 1; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  overflow-wrap: anywhere; user-select: all; font-size: 13px; }
.actions { display: inline-flex; gap: 6px; }
.btn.danger { color: var(--bad); border-color: rgba(255, 92, 108, .35); }
.btn.danger:hover { border-color: var(--bad); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h3 { margin: 0; }
.card-head .dot { font-size: 13px; color: var(--muted); }
