:root {
  --bg: #f5f5f8;
  --surface: #ffffff;
  --surface-2: #f0f0f5;
  --border: #e4e4ec;
  --text: #16161f;
  --muted: #6c6c80;
  --brand: #5b3df5;
  --brand-2: #ff4d8d;
  --brand-soft: #eeeaff;
  --ok: #12a150;
  --ok-soft: #e3f6ea;
  --warn: #b45309;
  --warn-soft: #fdf1dc;
  --danger: #e5484d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 6px 20px rgba(20, 20, 40, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d13;
    --surface: #16161f;
    --surface-2: #1e1e2a;
    --border: #2a2a38;
    --text: #f1f1f6;
    --muted: #9b9bb0;
    --brand: #7c63ff;
    --brand-soft: #241e4a;
    --ok-soft: #0f2d1c;
    --warn: #f0a33a;
    --warn-soft: #33250f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; letter-spacing: -.02em; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
a { color: var(--brand); }
code, pre { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- botones e inputs */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 10px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); }
.icon-btn {
  border: 0; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer;
  width: 36px; height: 36px; border-radius: 8px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 0; border-color: var(--brand); }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--brand); }
input[type="range"] { padding: 0; border: 0; accent-color: var(--brand); background: transparent; }

.form-error { color: var(--danger); font-weight: 600; margin: 0; min-height: 1px; flex: 1; }

/* ---------- login */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow);
  display: grid; gap: 14px; text-align: center;
}
.login-card .brand { justify-content: center; }

/* ---------- marca y barra superior */

.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.brand img { width: 30px; height: 30px; }
.brand b {
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-lg { font-size: 28px; }
.brand-lg img { width: 44px; height: 44px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 24px;
  padding: 12px max(16px, calc((100vw - 1200px) / 2));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tab {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: 8px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.badge { font-size: 12px; color: var(--muted); font-weight: 600; margin-left: 2px; }

.page { max-width: 1200px; margin: 0 auto; padding: 28px 16px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head p { margin: 4px 0 0; }

/* ---------- vista previa de TV (compartida por tarjetas y editor) */

.tv {
  position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 10px;
  background: #0b0b12; isolation: isolate;
}
.tv-scene {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 25% 30%, rgba(255, 190, 110, .55), transparent 42%),
    radial-gradient(circle at 75% 65%, rgba(90, 120, 255, .55), transparent 45%),
    linear-gradient(160deg, #23234a, #3b2150 55%, #12122a);
}
.tv-scene-title {
  position: absolute; left: 6%; top: 40%; color: rgba(255, 255, 255, .75);
  font-weight: 700; font-size: clamp(9px, 2.2cqw, 16px); letter-spacing: .02em;
}
.tv-scene-bar {
  position: absolute; left: 6%; right: 6%; top: 52%; height: 3px; border-radius: 3px;
  background: linear-gradient(90deg, rgba(255, 255, 255, .8) 35%, rgba(255, 255, 255, .25) 35%);
}
.tv { container-type: inline-size; }
.pv { position: absolute; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.pv img, .pv video { width: 100%; height: 100%; object-fit: contain; display: block; }
.pv-full { inset: 0; background: #000; }
.pv-banner { background: rgba(0, 0, 0, .6); }
.pv-banner.pos-top { top: 0; left: 0; right: 0; }
.pv-banner.pos-bottom { bottom: 0; left: 0; right: 0; }
.pv-banner.pos-left { top: 0; bottom: 0; left: 0; }
.pv-banner.pos-right { top: 0; bottom: 0; right: 0; }
.pv-banner[class*="pos-top_"], .pv-banner[class*="pos-bottom_"] {
  background: transparent; border-radius: 6px; box-shadow: 0 4px 14px rgba(0, 0, 0, .45);
}
.pv-banner[class*="pos-top_"] img, .pv-banner[class*="pos-top_"] video,
.pv-banner[class*="pos-bottom_"] img, .pv-banner[class*="pos-bottom_"] video { height: auto; }
/* margen = 3% del alto en ambos ejes (igual que la app de TV): 3% * 9/16 del ancho */
.pv-banner.pos-top_left { top: 3%; left: 1.6875%; }
.pv-banner.pos-top_right { top: 3%; right: 1.6875%; }
.pv-banner.pos-bottom_left { bottom: 3%; left: 1.6875%; }
.pv-banner.pos-bottom_right { bottom: 3%; right: 1.6875%; }
.pv-placeholder {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  color: rgba(255, 255, 255, .8); font-size: 12px; font-weight: 600;
  background: repeating-linear-gradient(45deg, rgba(124, 99, 255, .5), rgba(124, 99, 255, .5) 8px, rgba(255, 77, 141, .45) 8px, rgba(255, 77, 141, .45) 16px);
}

/* ---------- tarjetas de anuncios */

.ad-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.ad-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 12px;
}
.ad-card.paused .tv { filter: grayscale(.85) brightness(.8); }
.ad-card .tv { cursor: pointer; }
.ad-body { display: grid; gap: 8px; padding: 0 4px; }
.ad-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.ad-title h3 { overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
}
.chip.brand { background: var(--brand-soft); color: var(--brand); }
.meta { margin: 0; font-size: 13px; color: var(--muted); }
.status { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.status.on { background: var(--ok-soft); color: var(--ok); }
.status.off { background: var(--surface-2); color: var(--muted); }
.status.wait { background: var(--warn-soft); color: var(--warn); }
.ad-actions {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  border-top: 1px solid var(--border); padding: 10px 4px 0; margin-top: auto;
}
.ad-actions .switch { margin-right: auto; }
.live-pill {
  position: absolute; top: 8px; left: 8px; z-index: 3;
  font-size: 11px; font-weight: 700; color: #fff; background: rgba(18, 161, 80, .92);
  padding: 2px 8px; border-radius: 999px;
}

.empty {
  grid-column: 1 / -1; text-align: center; padding: 56px 20px;
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty h3 { margin-bottom: 6px; }
.empty p { margin: 0 auto 18px; color: var(--muted); max-width: 440px; }

/* ---------- interruptor */

.switch { position: relative; display: inline-block; width: 40px; height: 23px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: background .2s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s;
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(17px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.switch-row { display: flex; align-items: center; gap: 10px; font-weight: 600; padding-top: 22px; }

/* ---------- pantallas */

.screen-list { display: grid; gap: 14px; }
.screen-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; display: grid; gap: 14px;
}
.screen-main { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.screen-main > div { flex: 1; min-width: 180px; }
.screen-main p { margin: 2px 0 0; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--border); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.code {
  font-size: 13px; color: var(--muted); background: var(--surface-2);
  padding: 5px 10px; border-radius: 8px;
}
.code b { color: var(--text); font: 700 14px ui-monospace, Menlo, monospace; letter-spacing: .08em; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 0; }
.facts div { background: var(--surface-2); border-radius: 10px; padding: 9px 12px; }
.facts dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.facts dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.note {
  margin: 0; font-size: 13px; padding: 10px 12px; border-radius: 10px;
  background: var(--warn-soft); color: var(--warn);
}
.note a { color: inherit; font-weight: 700; }
.screen-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- instalación */

.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; counter-reset: step; }
.steps > li {
  counter-increment: step; position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px 18px 66px;
}
.steps > li::before {
  content: counter(step); position: absolute; left: 18px; top: 17px;
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2));
}
.steps h3 { margin-bottom: 6px; }
.steps p { margin: 6px 0; }
.steps ol { margin: 8px 0; padding-left: 20px; }
.steps li li { margin: 4px 0; }
.copy {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--surface-2); border-radius: 10px; padding: 8px 8px 8px 14px; margin: 8px 0;
}
.copy code { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 14px; }
.copy.big code { font-size: 20px; font-weight: 700; color: var(--brand); }
.pill-ok, .pill-warn { display: inline-block; font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 8px; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- editor */

.editor {
  width: min(1040px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
  padding: 0; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
}
.editor::backdrop { background: rgba(10, 10, 20, .55); backdrop-filter: blur(2px); }
.editor form { display: flex; flex-direction: column; max-height: calc(100vh - 26px); }
.editor-head, .editor-foot {
  display: flex; align-items: center; gap: 10px; padding: 14px 20px; flex: none;
}
.editor-head { justify-content: space-between; border-bottom: 1px solid var(--border); }
.editor-foot { border-top: 1px solid var(--border); justify-content: flex-end; }
.editor-body {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px;
  padding: 20px; overflow-y: auto;
}
.editor-form { display: grid; gap: 16px; align-content: start; }
.editor-preview { position: sticky; top: 0; align-self: start; display: grid; gap: 10px; }
.editor-preview .tv { box-shadow: 0 0 0 6px #1c1c26, 0 12px 30px rgba(0, 0, 0, .3); margin: 6px; }

.field { display: grid; gap: 6px; }
.field > span:first-child { font-weight: 600; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.hint { color: var(--muted); font-size: 12.5px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.check, .radio { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check { padding-top: 6px; }
.row .check { padding-top: 30px; }
.input-suffix { position: relative; display: block; }
.input-suffix em { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-style: normal; font-size: 13px; pointer-events: none; }
.input-suffix input { padding-right: 46px; }
.freq { display: grid; gap: 8px; }
.freq input[type="number"] { width: 84px; padding: 6px 10px; }

.drop {
  display: grid; place-items: center; text-align: center; gap: 8px; cursor: pointer;
  border: 2px dashed var(--border); border-radius: 12px; padding: 18px; min-height: 92px;
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop small { color: var(--muted); }
.drop.has-file { border-style: solid; }
.progress { width: 100%; height: 6px; border-radius: 6px; background: var(--border); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .15s; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span {
  display: block; text-align: center; padding: 8px; border-radius: 9px; font-weight: 600; cursor: pointer; color: var(--muted);
}
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--brand); }

.banner-fields { display: grid; gap: 16px; padding: 14px; border-radius: 12px; background: var(--surface-2); }
.pos-picker {
  display: grid; grid-template-columns: 22% 1fr 22%; grid-template-rows: 26% 1fr 26%; gap: 4px;
  width: 200px; aspect-ratio: 16 / 9; padding: 5px; border-radius: 10px;
  background: #1c1c26;
}
.pos-picker button {
  border: 0; border-radius: 5px; background: rgba(255, 255, 255, .14); cursor: pointer; transition: background .15s;
}
.pos-picker button:hover { background: rgba(255, 255, 255, .3); }
.pos-picker button.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.pos-center { border-radius: 5px; background: rgba(255, 255, 255, .04); }

.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { position: relative; }
.days input { position: absolute; opacity: 0; }
.days span {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
  font-weight: 700; font-size: 13px; background: var(--surface); border: 1px solid var(--border); color: var(--muted);
}
.days input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.days input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

details.more { border: 1px solid var(--border); border-radius: 12px; padding: 0 14px; }
details.more[open] { padding-bottom: 14px; }
details.more > summary { cursor: pointer; font-weight: 600; padding: 12px 0; list-style-position: inside; }
details.more > *:not(summary) + * { margin-top: 12px; }
.screen-checks { display: grid; gap: 6px; padding-left: 24px; }

/* ---------- toast */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #16161f; color: #fff; padding: 11px 18px; border-radius: 12px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3); transition: opacity .2s, transform .2s; z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ---------- móvil */

@media (max-width: 760px) {
  .topbar { gap: 12px; flex-wrap: wrap; }
  .topbar .brand span { display: none; }
  .tabs { order: 3; flex-basis: 100%; }
  .page { padding-top: 20px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .editor-body { grid-template-columns: 1fr; }
  .editor-preview { position: static; order: -1; }
  .row { grid-template-columns: 1fr; }
  .row .check, .switch-row { padding-top: 0; }
  .steps > li { padding-left: 56px; }
  .steps > li::before { left: 14px; }
}
