:root {
  --bg: #f6f2fb; --card: #fff; --ink: #231a36; --muted: #6d6482; --line: #e4dcf0;
  --brand: #5b3fa0; --brand-ink: #fff; --ok: #1f8a5b; --warn: #b4630a; --bad: #b3263e;
  --focus: #ffb703;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #150f24; --card: #1f1733; --ink: #f1ebfa; --muted: #a79cc0; --line: #34294f; --brand: #a98cf0; --brand-ink: #1a1030; --ok: #53d6a0; --warn: #ffb454; --bad: #ff7a90; }
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.45 system-ui, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
.muted { color: var(--muted); } .small { font-size: .85rem; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.btn { border: 1px solid var(--line); background: var(--card); padding: .6rem 1rem; border-radius: .7rem; cursor: pointer; min-height: 44px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: default; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(100%, 380px); background: var(--card); border: 1px solid var(--line); border-radius: 1.2rem; padding: 28px 24px; display: grid; gap: 14px; }
.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-card p { margin: 0; }
.mark { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(140deg, #ff8fb1, #b79ae0); color: #fff; font-weight: 700; font-size: 1.3rem; }
label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
input[type=email], input[type=password], input[type=text], input[type=number], select { width: 100%; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: .6rem; background: var(--bg); min-height: 44px; }
.error { color: var(--bad); min-height: 1.2em; font-size: .9rem; }
.hint { font-size: .8rem; color: var(--muted); }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }

/* Shell */
.top { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top strong { font-size: 1.1rem; margin-right: 8px; }
.tabs { display: flex; gap: 4px; padding: 10px 16px 0; overflow-x: auto; }
.tab { border: 0; background: transparent; padding: .65rem 1rem; border-radius: .7rem .7rem 0 0; cursor: pointer; color: var(--muted); min-height: 44px; border-bottom: 3px solid transparent; }
.tab.on { color: var(--ink); font-weight: 600; border-bottom-color: var(--brand); }
.layout { display: grid; gap: 16px; padding: 16px; max-width: 1200px; margin: 0 auto; }
@media (min-width: 960px) { .layout { grid-template-columns: minmax(0, 1fr) 460px; align-items: start; } .preview { position: sticky; top: 76px; } }

.pane { display: grid; gap: 16px; }
.group { background: var(--card); border: 1px solid var(--line); border-radius: 1rem; overflow: hidden; }
.group h2 { margin: 0; padding: 12px 16px; font-size: .85rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); background: color-mix(in srgb, var(--line) 35%, transparent); }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.group h2 + .row { border-top: 0; }
.row .nm { font-weight: 600; overflow-wrap: anywhere; }
.row .meta { font-size: .8rem; color: var(--muted); }
.row.dirty { background: color-mix(in srgb, var(--focus) 14%, transparent); }
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.price-in { display: flex; align-items: center; border: 1px solid var(--line); border-radius: .6rem; background: var(--bg); }
.price-in span { padding-left: .7rem; color: var(--muted); }
.price-in input { border: 0; background: transparent; width: 5.5rem; min-height: 42px; padding: .4rem .5rem; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.price-in input:focus { outline: none; }
.price-in:focus-within { outline: 3px solid var(--focus); outline-offset: 1px; }
.saved { color: var(--ok); font-size: .85rem; min-width: 4.5rem; text-align: right; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .85rem; color: var(--muted); user-select: none; min-height: 44px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 42px; height: 24px; border-radius: 12px; background: var(--line); position: relative; transition: background .2s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 3px solid var(--focus); outline-offset: 2px; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.tag.on { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.tag.off { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }

.edit-grid { display: grid; gap: 8px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .edit-grid { grid-template-columns: 1fr 1fr; } }

/* Preview */
.preview { background: var(--card); border: 1px solid var(--line); border-radius: 1rem; padding: 14px; display: grid; gap: 10px; }
.preview-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.preview-head select { width: auto; max-width: 60%; }
.frame { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #0c0720; border-radius: .6rem; overflow: hidden; }
.frame iframe { position: absolute; top: 0; left: 0; width: 1920px; height: 1080px; border: 0; transform-origin: top left; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 30px); opacity: 0; background: #231a36; color: #fff; padding: .7rem 1.1rem; border-radius: .7rem; transition: all .25s; pointer-events: none; z-index: 20; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--bad); }

/* Móvil: el nombre arriba y los controles debajo (evita que el nombre se parta letra a letra) */
.saved:empty { display: none; }
@media (max-width: 560px) {
  .row { grid-template-columns: 1fr; }
  .row .controls { justify-content: space-between; }
  .price-in { flex: 1; max-width: 11rem; }
  .price-in input { width: 100%; }
  .btn.primary[data-save] { flex: 1; }
  .layout { padding: 12px; }
  .preview-head { flex-wrap: wrap; }
  .preview-head select { max-width: 100%; }
}
