:root {
  --bg: #07080c; --panel: #0e1016; --panel2: #141721; --line: #222634; --line2: #2d3244;
  --text: #eef0f7; --mute: #8a90a6; --dim: #5d6378;
  --accent: #8b5cf6; --accent2: #22d3ee;
  --live: #22c55e; --red: #ef4444; --warn: #f59e0b; --info: #60a5fa;
  --r: 18px; --r-sm: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  min-height: 100vh; overflow-x: hidden;
  background:
    radial-gradient(1200px 500px at 50% -200px, rgba(139,92,246,.16), transparent 70%),
    radial-gradient(800px 400px at 110% 10%, rgba(34,211,238,.06), transparent 70%), var(--bg);
  background-attachment: fixed;
}
button, input, select { font: inherit; color: inherit; }
b { font-weight: 650; }
.muted { color: var(--mute); }
small { display: block; color: var(--mute); font-size: 12.5px; }

/* ---------- marca ---------- */
.brand { display: flex; align-items: center; gap: 10px; letter-spacing: .14em; font-size: 13px; }
.brand b { letter-spacing: .14em; }
.brand.big { font-size: 16px; justify-content: center; margin-bottom: 18px; }
.logo {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: conic-gradient(from 210deg, var(--accent), var(--accent2), var(--accent));
  box-shadow: 0 0 18px rgba(139,92,246,.55); position: relative;
}
.logo::after { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: var(--bg); }

/* ---------- layout ---------- */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  padding: calc(12px + var(--safe-t)) 16px 12px; background: rgba(7,8,12,.78);
  backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.top-state { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 650; letter-spacing: .08em; color: var(--mute); }
main { max-width: 720px; margin: 0 auto; padding: 14px 16px calc(96px + var(--safe-b)); }
.view { display: flex; flex-direction: column; gap: 14px; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.view-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 2px; }
h1 { font-size: 26px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 18px; margin: 0; }

.card {
  background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid var(--line);
  border-radius: var(--r); padding: 16px;
}
.card.slim { padding: 12px 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }
.label { font-size: 11.5px; font-weight: 700; letter-spacing: .16em; color: var(--mute); }

/* ---------- estado ---------- */
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); flex: none; }
.s-live .dot, .dot.live { background: var(--live); box-shadow: 0 0 0 0 rgba(34,197,94,.6); animation: pulse 1.8s infinite; }
.s-grace .dot, .dot.grace, .dot.warn { background: var(--warn); }
.s-starting .dot, .dot.starting { background: var(--info); animation: blink 1s infinite; }
.dot.err { background: var(--red); }
.dot.wait { background: var(--info); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.55); } 70% { box-shadow: 0 0 0 9px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }
@keyframes blink { 50% { opacity: .35; } }
.s-live { color: var(--live); } .s-grace { color: var(--warn); } .s-starting { color: var(--info); }

.hero { position: relative; overflow: hidden; }
.hero.is-live { border-color: rgba(34,197,94,.35); box-shadow: 0 0 0 1px rgba(34,197,94,.08), 0 10px 40px -12px rgba(34,197,94,.25); }
.hero.is-live::before {
  content: ""; position: absolute; inset: -1px -1px auto; height: 3px;
  background: linear-gradient(90deg, transparent, var(--live), transparent);
}
.hero-head { display: flex; justify-content: space-between; gap: 8px; }
.method { font-size: 11.5px; color: var(--dim); text-align: right; }
.hero-status { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 10px; font-size: 30px; font-weight: 800; letter-spacing: .02em;
}
.pill .dot { width: 14px; height: 14px; }
.timer { font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 650; color: var(--text); }
.hero-channel { font-size: 17px; font-weight: 650; }
.hero-title { font-size: 13.5px; margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
  font-size: 12.5px; font-weight: 650; padding: 5px 10px; border-radius: 999px;
  background: rgba(255,255,255,.05); border: 1px solid var(--line2); font-variant-numeric: tabular-nums;
}
.hint { font-size: 12.5px; color: var(--mute); margin: 10px 0 0; }
.error { color: var(--red); font-size: 13.5px; min-height: 1em; margin: 10px 0 0; }

/* ---------- multistream ---------- */
.ms-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.ms-list li { display: flex; align-items: center; gap: 10px; padding: 8px 2px; border-bottom: 1px solid rgba(255,255,255,.04); }
.ms-list li:last-child { border-bottom: 0; }
.ms-list .nm { flex: 1; font-weight: 600; }
.ms-list .st { font-size: 12.5px; color: var(--mute); font-variant-numeric: tabular-nums; }
.empty { color: var(--mute); font-size: 13.5px; padding: 6px 2px; }

/* ---------- botones ---------- */
.btn {
  border: 1px solid var(--line2); background: var(--panel2); border-radius: var(--r-sm); padding: 10px 14px;
  font-weight: 650; cursor: pointer; transition: transform .08s, background .15s, border-color .15s; text-align: center;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #6d4ae0); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(255,255,255,.04); }
.btn.dashed { background: transparent; border-style: dashed; color: var(--mute); padding: 14px; letter-spacing: .06em; font-size: 13px; }
.btn.danger { color: #fca5a5; border-color: rgba(239,68,68,.35); background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.huge {
  width: 100%; padding: 18px; font-size: 16px; letter-spacing: .12em; border-radius: var(--r);
  background: linear-gradient(135deg, var(--accent), var(--accent2)); border: 0; color: #fff;
  box-shadow: 0 12px 30px -12px rgba(139,92,246,.7);
}
.btn.huge.stop { background: linear-gradient(135deg, #ef4444, #b91c1c); box-shadow: 0 12px 30px -12px rgba(239,68,68,.6); }
.controls { display: flex; flex-direction: column; gap: 10px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.file { display: inline-block; }

/* ---------- interruptores ---------- */
.switch-row {
  display: flex; flex-direction: row; justify-content: space-between; align-items: center; gap: 14px; margin: 0;
  color: var(--text); font-weight: 400; font-size: 15px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px;
}
.switch {
  appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 999px; flex: none;
  background: #2a2f3f; position: relative; cursor: pointer; transition: background .2s; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.switch:checked { background: var(--live); }
.switch:checked::after { transform: translateX(20px); }
.mini-switch { font-size: 13px; color: var(--mute); display: flex; flex-direction: row; gap: 6px; align-items: center; margin: 0; }

/* ---------- recursos ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: rgba(255,255,255,.025); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px; min-width: 0; }
.stat .k { font-size: 11px; letter-spacing: .1em; color: var(--mute); font-weight: 700; }
.stat .v { font-size: 20px; font-weight: 750; font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; }
.stat .v small { display: inline; font-size: 12px; font-weight: 600; }
.estimate { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.estimate .stat .v { font-size: 18px; }
.estimate .full { grid-column: 1 / -1; font-size: 12.5px; color: var(--mute); }

/* ---------- destinos ---------- */
.badge {
  --c: var(--accent); width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center;
  font-weight: 800; font-size: 14px; color: #fff; background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.badge.tw { --c: #9146ff; }
.badge.dark { color: #0b0d12; }
.source-lock { display: flex; align-items: center; gap: 12px; }
.source-lock > div { flex: 1; min-width: 0; }
.state { font-size: 12.5px; font-weight: 650; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.dest-list { display: flex; flex-direction: column; gap: 10px; }
.dest { display: flex; flex-direction: column; gap: 12px; }
.dest-top { display: flex; align-items: center; gap: 12px; }
.dest-top .who { flex: 1; min-width: 0; }
.dest-top .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dest .field { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13px; min-width: 0; }
.dest .field span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.dest .field .k { flex: none; font-family: inherit; color: var(--mute); font-size: 11px; letter-spacing: .1em; font-weight: 700; width: 36px; }
.icon-btn { background: none; border: 0; color: var(--mute); padding: 2px 4px; cursor: pointer; font-size: 13px; font-weight: 650; }
.access { font-size: 12px; padding: 8px 10px; border-radius: 10px; background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.25); color: #fcd34d; }
.test-res { font-size: 12.5px; }
.test-res.ok { color: #86efac; } .test-res.bad { color: #fca5a5; }

/* ---------- historial ---------- */
.hist { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin-bottom: 10px; }
.hist .d { font-weight: 700; }
.hist .dur { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.hist .meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- logs ---------- */
.log { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.log li { display: flex; gap: 12px; padding: 9px 14px; border-bottom: 1px solid rgba(255,255,255,.035); font-size: 13.5px; }
.log li:last-child { border-bottom: 0; }
.log time { color: var(--dim); font-variant-numeric: tabular-nums; flex: none; }
.log .ok { color: #86efac; } .log .warn { color: #fcd34d; } .log .error { color: #fca5a5; }
.tech { background: #05060a; border: 1px solid var(--line); border-radius: var(--r); padding: 12px; font-size: 11.5px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; color: #aab; max-height: 70vh; }

/* ---------- formularios ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--mute); font-weight: 600; margin-bottom: 12px; }
input:not([type=checkbox]), select {
  background: var(--bg); border: 1px solid var(--line2); border-radius: 11px; padding: 12px; font-size: 16px;
  color: var(--text); outline: none; width: 100%;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139,92,246,.2); }
.check { flex-direction: row; align-items: center; justify-content: space-between; color: var(--text); }
.form .btn { margin-top: 4px; }
.upd { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.upd div { display: flex; justify-content: space-between; gap: 10px; }
.upd .new { color: var(--warn); font-weight: 650; }
.rules { margin: 0; padding-left: 18px; font-size: 13.5px; color: #c9cbe0; display: flex; flex-direction: column; gap: 8px; }
.foot { text-align: center; font-size: 12px; }

/* ---------- acceso ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.auth-card { width: 100%; max-width: 380px; background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid var(--line); border-radius: 22px; padding: 26px 20px; }
.auth-card p.muted { text-align: center; margin: 0 0 18px; }

/* ---------- navegación ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 6px calc(6px + var(--safe-b)); background: rgba(10,11,16,.9);
  backdrop-filter: saturate(160%) blur(16px); -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid rgba(255,255,255,.05);
}
.tabs button {
  background: none; border: 0; color: var(--dim); display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 650; padding: 6px 0; cursor: pointer; letter-spacing: .02em;
}
.tabs svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--text); }
.tabs button.on svg { stroke: var(--accent2); }

/* ---------- hoja ---------- */
.sheet-bg { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--panel2); border: 1px solid var(--line2);
  border-radius: 22px 22px 0 0; padding: 16px 16px calc(20px + var(--safe-b));
}
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 22px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.x { background: rgba(255,255,255,.06); border: 0; width: 32px; height: 32px; border-radius: 50%; font-size: 20px; cursor: pointer; color: var(--mute); }
.plat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.plat { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; cursor: pointer; font-size: 13px; font-weight: 650; }
.plat:hover { border-color: var(--line2); }
.plat.closed { opacity: .4; cursor: not-allowed; }
.plat small { font-size: 10.5px; text-align: center; }
.qr { background: #fff; border-radius: 12px; padding: 8px; width: fit-content; margin: 0 auto 12px; }
.qr svg { display: block; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; word-break: break-all; }

.toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%); z-index: 60;
  background: #1c2030; border: 1px solid var(--line2); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: calc(100vw - 32px);
}
.toast.bad { border-color: rgba(239,68,68,.5); }

@media (max-width: 380px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .pill { font-size: 26px; }
}
