/* ============================================================
   Panel de Accesos — UI mobile-first con animaciones y "luces"
   ============================================================ */
:root {
  --bg: #07080d;
  --bg-2: #0d0f17;
  --card: rgba(22, 25, 36, 0.72);
  --card-solid: #161924;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef1f8;
  --muted: #9aa3b8;
  --accent: #e50914;          /* rojo Netflix */
  --accent-2: #ff5b6a;
  --grad: linear-gradient(135deg, #e50914 0%, #ff5b6a 100%);
  --grad-cool: linear-gradient(135deg, #6a5cff 0%, #2bd4ff 100%);
  --ok: #2ee6a6;
  --warn: #ffc14d;
  --danger: #ff5b6a;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --tap: rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ---- Fondo con auroras / luces animadas ---- */
body::before, body::after {
  content: "";
  position: fixed;
  z-index: -2;
  width: 60vmax; height: 60vmax;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.40;
  pointer-events: none;
}
body::before {
  background: radial-gradient(circle, #e50914, transparent 60%);
  top: -20vmax; left: -15vmax;
  animation: aurora1 18s ease-in-out infinite alternate;
}
body::after {
  background: radial-gradient(circle, #6a5cff, transparent 60%);
  bottom: -25vmax; right: -20vmax;
  animation: aurora2 22s ease-in-out infinite alternate;
}
@keyframes aurora1 { from { transform: translate(0,0) scale(1); } to { transform: translate(12vmax,8vmax) scale(1.25); } }
@keyframes aurora2 { from { transform: translate(0,0) scale(1); } to { transform: translate(-10vmax,-6vmax) scale(1.15); } }

a { color: var(--accent-2); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; }
.center { text-align: center; }

/* ============================ LOGIN ============================ */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 22px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--card); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border); border-radius: 24px;
  padding: 30px 26px;
  box-shadow: var(--shadow);
  animation: pop .5s cubic-bezier(.2,.9,.3,1.2) both;
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
.brand-dot { display:inline-block; width:10px; height:10px; border-radius:50%; background:var(--grad); margin-right:8px; box-shadow:0 0 12px var(--accent); animation: pulseGlow 2s infinite; }
/* Wordmark NETFLIX (sin imagen externa: CSP-safe) */
.netflix-logo { font-weight: 900; font-size: 21px; letter-spacing: 1.5px; color: var(--accent); text-shadow: 0 1px 14px rgba(229,9,20,.5); line-height: 1; }
.login-card .netflix-logo { font-size: 30px; display: block; margin-bottom: 2px; }
.help-box { border-left: 3px solid var(--accent); background: rgba(229,9,20,.07); }
.help-box ol, .help-box ul { margin: 6px 0 0; padding-left: 18px; }
.help-box li { margin: 3px 0; }

/* ============================ APP ============================ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: rgba(10, 12, 18, 0.7); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 800; letter-spacing: -.3px; display:flex; align-items:center; }
.container { max-width: 760px; margin: 0 auto; padding: 18px 16px 60px; }
/* El owner aprovecha más ancho en PC (buscador + ficha en paralelo); el cliente se queda estrecho. */
.container.wide { max-width: 1180px; }
/* Owner · Usuarios: buscador (fijo) + ficha (resto). Apila en una columna en móvil.
   minmax(0,1fr) permite que la celda ENCOJA (si no, el contenido ancho la infla y desborda). */
.owner-split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
@media (min-width: 900px) { .owner-split { grid-template-columns: 320px minmax(0, 1fr); } }
#user-detail { min-width: 0; }
/* Cualquier tabla ancha dentro de la ficha scrollea en horizontal en vez de desbordar. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---- Tabs ---- */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 6px; margin-bottom: 18px; }
.tab {
  flex: 0 0 auto; padding: 9px 16px; border-radius: 999px; cursor: pointer;
  background: var(--card-solid); border: 1px solid var(--border); color: var(--muted);
  font-size: 13.5px; font-weight: 600; white-space: nowrap; transition: .25s;
}
.tab.active { color: #fff; border-color: transparent; background-image: var(--grad); box-shadow: 0 6px 20px rgba(229,9,20,.35); }
.tabpane { display: none; animation: fadeUp .4s ease both; }
.tabpane.active { display: block; }

/* ---- Cards ---- */
.card {
  background: var(--card); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
  animation: fadeUp .45s ease both;
}
.card h2 { margin: 0 0 12px; font-size: 16px; font-weight: 700; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.col { flex: 1; min-width: 240px; }

/* ---- Forms ---- */
label { display: block; margin: 12px 0 5px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
input, textarea, select {
  width: 100%; padding: 13px 14px; background: rgba(0,0,0,.28);
  border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text);
  font-size: 16px; font-family: inherit; transition: .2s; -webkit-appearance: none;
}
textarea { resize: vertical; min-height: 96px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 4px rgba(229,9,20,.18); }
input::placeholder { color: #5e667b; }
/* Los checkbox/radio NO deben heredar el estilo de los inputs de texto (si no, no se marcan) */
input[type="checkbox"], input[type="radio"] {
  width: auto; height: auto; padding: 0; margin: 0; border: 0; background: none; box-shadow: none;
  -webkit-appearance: auto; appearance: auto; accent-color: var(--accent); cursor: pointer; flex: none;
}
input[type="checkbox"]:focus, input[type="radio"]:focus { box-shadow: none; }

/* ---- Buttons ---- */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 20px; border: none; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 15px; font-weight: 700; color: #fff; background-image: var(--grad);
  box-shadow: 0 8px 24px rgba(229,9,20,.35); transition: transform .12s, box-shadow .2s, filter .2s;
  overflow: hidden; text-decoration: none;
}
.btn::after { /* brillo que cruza */
  content: ""; position: absolute; top: 0; left: -120%; width: 60%; height: 100%;
  background: linear-gradient(120deg, transparent, rgba(255,255,255,.45), transparent);
  transform: skewX(-20deg); transition: left .6s;
}
.btn:hover::after { left: 140%; }
.btn:active { transform: scale(.96); }
.btn.block { width: 100%; }
.btn.secondary { background: var(--card-solid); background-image: none; border: 1px solid var(--border-strong); color: var(--text); box-shadow: none; }
.btn.cool { background-image: var(--grad-cool); box-shadow: 0 8px 24px rgba(106,92,255,.35); }
.btn.danger { background-image: linear-gradient(135deg,#ff5b6a,#b3122b); box-shadow: 0 8px 24px rgba(255,91,106,.3); }
.btn.small { padding: 8px 13px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled::after { display: none; }

/* ---- Stats ---- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; animation: fadeUp .5s ease both; }
.stat .n { font-size: 26px; font-weight: 800; background-image: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat .l { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
#pool-list { overflow-x: auto; } /* la tabla de la pool no rompe el layout en móvil */
tbody tr:hover, table tr:hover { background: rgba(255,255,255,.02); }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid var(--border-strong); }
.badge.active, .badge.connected, .badge.available { color: var(--ok); border-color: rgba(46,230,166,.4); background: rgba(46,230,166,.1); }
.badge.assigned { color: var(--accent-2); border-color: rgba(255,91,106,.4); }
.badge.expired, .badge.replaced { color: var(--muted); }
.badge.deactivation_pending, .badge.error, .badge.disconnected { color: var(--danger); border-color: rgba(255,91,106,.4); background: rgba(255,91,106,.1); }

/* ---- Access card (cliente) ---- */
.access {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
  position: relative; overflow: hidden; animation: fadeUp .5s ease both;
}
.access::before { content:""; position:absolute; inset:0 0 auto 0; height:3px; background-image: var(--grad); }
.access .email { font-weight: 700; font-size: 15px; word-break: break-all; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px;
  background: rgba(0,0,0,.25); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.field .k { color: var(--muted); font-size: 12px; }
.field .v { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; word-break: break-all; }
.icon-btn { background: var(--tap); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 7px 10px; cursor: pointer; font-size: 12px; transition: .15s; }
.icon-btn:active { transform: scale(.9); }

/* ---- Code grande (resultado) ---- */
.code-box { margin-top: 14px; text-align: center; padding: 18px; border-radius: var(--radius-sm);
  background: radial-gradient(circle at 50% 0%, rgba(229,9,20,.18), rgba(0,0,0,.25)); border: 1px solid var(--border-strong); animation: pop .45s cubic-bezier(.2,.9,.3,1.2) both; }
.code-box .label { color: var(--muted); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.code-box .code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 38px; font-weight: 800; letter-spacing: 6px;
  background-image: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; margin: 4px 0; text-shadow: 0 0 30px rgba(229,9,20,.4); }

/* ---- Contador de días ---- */
.counter { display: flex; align-items: center; gap: 12px; margin-top: 14px; padding: 12px; border-radius: var(--radius-sm); background: rgba(0,0,0,.22); border: 1px solid var(--border); }
.ring { --p: 0; width: 52px; height: 52px; border-radius: 50%; flex: 0 0 auto;
  background: conic-gradient(var(--accent) calc(var(--p)*1%), rgba(255,255,255,.08) 0);
  display: grid; place-items: center; position: relative; }
.ring::before { content:""; position:absolute; inset:5px; border-radius:50%; background: var(--card-solid); }
.ring b { position: relative; font-size: 15px; font-weight: 800; }
.counter .c-txt { font-size: 13px; }
.counter.ready { border-color: rgba(46,230,166,.4); background: rgba(46,230,166,.08); }

/* ---- PIN inputs (código TV 8 dígitos) ---- */
.pin { display: flex; gap: 7px; justify-content: center; margin: 14px 0; }
.pin input { width: 38px; height: 50px; text-align: center; font-size: 20px; font-weight: 800; padding: 0;
  border-radius: 10px; background: rgba(0,0,0,.3); }
.pin input:focus { transform: translateY(-2px); }

/* ---- Instrucciones contextuales por cuenta ---- */
.instr { background: rgba(0,0,0,.22); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; margin-top: 12px; }
.instr p { margin: 0 0 6px; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 5px; line-height: 1.45; }
.steps li { padding-left: 2px; }
.steps b { color: var(--text); }

/* ---- Tarjeta de autocreación (activar cuenta nueva) ---- */
.access.self-create { border-color: rgba(46,230,166,.45); box-shadow: 0 0 0 1px rgba(46,230,166,.12), var(--shadow); }
.access.self-create::before { background-image: linear-gradient(90deg, var(--ok), #2bd4ff); }
.access.self-create .email { background-image: linear-gradient(90deg, var(--ok), #7fe9c6); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---- Instrucciones personalizadas (cliente) ---- */
.instr.custom { display: block; }
.instr.custom > strong { display: block; margin-bottom: 4px; }
.instr-text { white-space: pre-wrap; font-size: 13.5px; line-height: 1.5; }
.instr-shots { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.instr-shots .shot { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border-strong); cursor: zoom-in; transition: transform .15s; background: rgba(0,0,0,.3); }
.instr-shots .shot:active { transform: scale(.94); }

/* ---- Listas con scroll y secciones desplegables (owner) ---- */
.scroll-list { max-height: 300px; overflow-y: auto; padding-right: 4px; }
.scroll-list::-webkit-scrollbar { width: 8px; }
.scroll-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
details.accordion > summary { cursor: pointer; font-size: 17px; font-weight: 700; padding: 6px 0; list-style: none; display: flex; align-items: center; gap: 8px; user-select: none; }
details.accordion > summary::-webkit-details-marker { display: none; }
details.accordion > summary::before { content: "▸"; color: var(--accent); transition: transform .2s; }
details.accordion[open] > summary::before { transform: rotate(90deg); }

/* ---- Cabecera de ficha de usuario (owner) ---- */
.user-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.user-id { min-width: 0; }
.user-id h2 { word-break: break-all; }
.sc-status { margin-top: 6px; color: var(--accent-2); font-weight: 600; }
.user-actions { display: flex; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
.user-actions .btn { white-space: nowrap; }
/* En móvil la cabecera apila y los botones ocupan todo el ancho (envuelven sin desbordar). */
@media (max-width: 560px) {
  .user-head { flex-direction: column; }
  .user-actions { width: 100%; flex-shrink: 1; }
}

/* ---- Editor de instrucciones (owner) ---- */
.iz-images { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.iz-thumb { position: relative; width: 92px; height: 92px; }
.iz-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; border: 1px solid var(--border-strong); }
.iz-del { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%; border: none; background: var(--danger); color: #fff; font-weight: 800; cursor: pointer; line-height: 1; box-shadow: 0 2px 8px rgba(0,0,0,.4); }

/* ---- Lightbox (ampliar captura) ---- */
#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.86); display: none; align-items: center; justify-content: center; z-index: 80; padding: 20px; cursor: zoom-out; backdrop-filter: blur(4px); }
#lightbox.show { display: flex; animation: fadeUp .2s ease both; }
#lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: 0 12px 50px rgba(0,0,0,.6); }

/* ---- Toast ---- */
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: calc(100% - 32px); max-width: 420px; }
.toast { background: rgba(20,22,32,.95); backdrop-filter: blur(10px); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent); padding: 13px 16px; border-radius: 12px; box-shadow: var(--shadow);
  animation: toastIn .35s cubic-bezier(.2,.9,.3,1.2) both; }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }

/* ---- Misc ---- */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 13.5px; }
.alert.err { background: rgba(255,91,106,.12); border: 1px solid rgba(255,91,106,.4); }
.alert.ok { background: rgba(46,230,166,.12); border: 1px solid rgba(46,230,166,.4); }
.alert.info { background: rgba(43,212,255,.12); border: 1px solid rgba(43,212,255,.4); }
.alert.warn { background: rgba(255,193,77,.12); border: 1px solid rgba(255,193,77,.45); }
.alert-card { padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; background: var(--card-solid); animation: fadeUp .4s ease both; }
.alert-card.unread { border-left: 3px solid var(--danger); background: rgba(255,91,106,.06); }
.hidden { display: none !important; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.list-item { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; background: rgba(0,0,0,.2); }
.spinner { width: 26px; height: 26px; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 16px auto; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }

/* ---- Licencias (owner) ---- */
.pill { display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 700; border: 1px solid var(--border-strong); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: rgba(46,230,166,.45); background: rgba(46,230,166,.1); }
.pill.warn { color: var(--warn); border-color: rgba(255,193,77,.45); background: rgba(255,193,77,.12); }
.pill.danger { color: var(--danger); border-color: rgba(255,91,106,.45); background: rgba(255,91,106,.12); }
.lic-group { margin-bottom: 18px; }
.lic-group-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--border); margin-bottom: 8px; font-size: 13px; word-break: break-all; }
.lic-card { background: var(--card-solid); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; animation: fadeUp .4s ease both; }
.lic-user { font-weight: 700; font-size: 15px; }

/* ---- Soporte / chat ---- */
.tab-badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 800; margin-left: 6px; box-shadow: 0 0 10px var(--accent); animation: pulseGlow 2s infinite; }
.ticket-item { padding: 11px 13px; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; background: var(--card-solid); cursor: pointer; transition: .15s; }
.ticket-item:hover { border-color: var(--accent); }
.ticket-item.unread { border-left: 3px solid var(--accent); }
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 52vh; overflow-y: auto; padding: 6px 2px; }
.bubble { max-width: 82%; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.4; word-break: break-word; animation: fadeUp .3s ease both; }
.bubble.user { align-self: flex-end; background-image: var(--grad); color: #fff; border-bottom-right-radius: 4px; }
.bubble.owner { align-self: flex-start; background: var(--card-solid); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble .when { display: block; font-size: 10px; opacity: .7; margin-top: 3px; }
.chat-input { display: flex; gap: 8px; margin-top: 10px; }
.chat-input input { flex: 1; }

/* ---- Keyframes ---- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulseGlow { 0%,100% { box-shadow: 0 0 8px var(--accent); } 50% { box-shadow: 0 0 18px var(--accent), 0 0 28px var(--accent); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* stagger para listas */
.access:nth-child(2){animation-delay:.06s}.access:nth-child(3){animation-delay:.12s}.access:nth-child(4){animation-delay:.18s}
.stat:nth-child(2){animation-delay:.05s}.stat:nth-child(3){animation-delay:.1s}.stat:nth-child(4){animation-delay:.15s}

/* desktop */
@media (min-width: 620px) { .stats { grid-template-columns: repeat(4, 1fr); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } body::before, body::after { animation: none !important; } }
