/* OWNER CONTROL CENTER — MEGA UPD REGRESO PUERTO RICO OG
   Negro real, grises oscuros y el rojo de la bandera de Puerto Rico (#EF3340),
   reservado para lo que está en vivo, las alertas y la acción principal. */

:root {
  --bg: #000000;
  --surface: #141416;
  --surface-2: #1c1c20;
  --surface-3: #26262b;
  --line: #2c2c32;
  --text: #ededf0;
  --muted: #9b9ba5;
  --faint: #6b6b74;
  --red: #ef3340;
  --red-deep: #8c1520;
  --red-glow: rgba(239, 51, 64, 0.16);
  --ok: #38c172;
  --warn: #e8a23a;
  --info: #5b8cff;
  --radius-s: 6px;
  --radius-m: 10px;
  --sidebar: 248px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Estructura ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 18px 12px 24px; display: flex; flex-direction: column; gap: 18px;
}
.brand { padding: 4px 8px 10px; border-bottom: 1px solid var(--line); }
.brand-name { font: 800 17px/1.1 var(--font-display); letter-spacing: -0.01em; }
.brand-game { color: var(--muted); font-size: 12px; margin-top: 4px; }
.brand-flag { display: inline-block; width: 18px; height: 12px; margin-right: 8px; vertical-align: -1px; border-radius: 2px;
  background: linear-gradient(90deg, #0050f0 0 38%, transparent 38%),
              repeating-linear-gradient(180deg, var(--red) 0 2.4px, #fff 2.4px 4.8px); }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-title { color: var(--faint); font-size: 12px; padding: 0 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px 10px;
  border-radius: var(--radius-s); text-decoration: none; color: var(--muted);
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--surface-3); color: var(--text); box-shadow: inset 3px 0 0 var(--red); }
.nav-icon { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav-count { margin-left: auto; font-size: 12px; color: var(--text); background: var(--red-deep); border-radius: 999px; padding: 0 7px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px;
  padding: 10px 24px; background: rgba(0,0,0,.86); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .menu-btn { display: none; }
.signal { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.signal-label { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
td.nowrap, th.nowrap { white-space: nowrap; }
.signal-label strong { color: var(--text); font-weight: 600; }
.signal-ticks { display: flex; gap: 3px; align-items: flex-end; height: 18px; }
.signal-tick { width: 5px; border-radius: 1px; background: var(--red); }
.signal-tick.off { background: var(--surface-3); height: 6px; }
.signal-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
.signal-dot.live { background: var(--red); box-shadow: 0 0 0 0 var(--red-glow); animation: beat 2.4s infinite; }
@keyframes beat { 0% { box-shadow: 0 0 0 0 rgba(239,51,64,.55); } 70% { box-shadow: 0 0 0 9px rgba(239,51,64,0); } 100% { box-shadow: 0 0 0 0 rgba(239,51,64,0); } }
.who { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.who strong { color: var(--text); }
.role-pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--text); }
.role-pill.owner { border-color: var(--red); color: #fff; background: var(--red-deep); }

.content { padding: 24px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font: 800 28px/1.1 var(--font-display); letter-spacing: -0.02em; margin: 0; }
.page-head p { margin: 6px 0 0; color: var(--muted); max-width: 70ch; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Superficies ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px; min-width: 0; }
.panel h2 { font: 700 16px/1.3 var(--font-display); margin: 0 0 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.panel-sub { color: var(--muted); font-size: 13px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* Cifras principales: una franja continua, no tarjetas sueltas */
.stats { display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; margin-bottom: 16px; }
.stat { padding: 16px 18px; background: var(--surface); min-width: 0; }
.stat-value { font: 800 34px/1 var(--font-display); letter-spacing: -0.02em; }
.stat-value.na { color: var(--faint); font-size: 20px; font-weight: 600; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 8px; }
.stat.live .stat-value { color: #fff; }
.stat.live { box-shadow: inset 0 3px 0 var(--red); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.empty { color: var(--muted); padding: 22px 4px; text-align: center; }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

/* ---------- Estados ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--text); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.badge.live::before, .badge.active::before { background: var(--red); }
.badge.ok::before, .badge.applied::before, .badge.finished::before { background: var(--ok); }
.badge.warn::before, .badge.pending::before, .badge.queued::before, .badge.sent::before, .badge.picked::before,
.badge.waiting_player::before, .badge.stale::before, .badge.partial::before { background: var(--warn); }
.badge.bad::before, .badge.failed::before, .badge.unconfirmed::before, .badge.expired::before, .badge.lost::before { background: #ff5a5a; }
.badge.removed::before, .badge.closed::before, .badge.cancelled::before { background: var(--muted); }
.badge.denied { border-color: var(--red-deep); }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-s);
  background: var(--surface-2); border: 1px solid var(--line); border-left: 3px solid var(--warn); margin-bottom: 8px; font-size: 14px; }
.alert.critical { border-left-color: var(--red); background: linear-gradient(90deg, var(--red-glow), transparent 60%), var(--surface-2); }
.alert.info { border-left-color: var(--info); }
.notice { padding: 12px 14px; border-radius: var(--radius-s); border: 1px dashed var(--line); color: var(--muted); font-size: 14px; }
.notice strong { color: var(--text); }

/* ---------- Controles ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 14px;
  border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  cursor: pointer; text-decoration: none; font-weight: 600; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: #ff4552; }
.btn.danger { border-color: var(--red-deep); color: #ff8a92; }
.btn.danger:hover { background: var(--red-deep); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; color: var(--muted); }
.field .hint { font-size: 12.5px; color: var(--faint); }
input[type=text], input[type=number], input[type=search], input[type=datetime-local], select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: #0a0a0b; color: var(--text); font-size: 16px; /* 16px evita el zoom en iPhone */
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--red); outline: none; box-shadow: 0 0 0 3px var(--red-glow); }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--red); flex: none; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.toolbar .field { min-width: 160px; flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 8px 12px; min-height: 38px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); box-shadow: inset 0 -2px 0 var(--red); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; color: var(--muted); cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--red); }

/* ---------- Jugador ---------- */
.target-card { display: flex; gap: 14px; align-items: center; padding: 12px; border-radius: var(--radius-s); background: var(--surface-2); border: 1px solid var(--line); }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-weight: 800; flex: none; }
.target-card .name { font-weight: 700; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Gráficas ---------- */
.chart { width: 100%; height: 220px; display: block; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--faint); font-size: 11px; }
.chart .area { fill: url(#redFade); }
.chart .line { fill: none; stroke: var(--red); stroke-width: 2; stroke-linejoin: round; }
.chart .line-2 { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart .hover-dot { fill: var(--red); }
.chart-legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.chart-legend span::before { content: ""; display: inline-block; width: 14px; height: 2px; background: var(--red); vertical-align: middle; margin-right: 6px; }
.chart-legend span.alt::before { background: var(--muted); }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr max-content; gap: 10px; align-items: center; font-size: 13.5px; }
.bar-track { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--red); }
.delta-up { color: var(--ok); }
.delta-down { color: #ff7b84; }

/* ---------- Diálogos y avisos ---------- */
.modal-back { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.72); display: grid; place-items: center; padding: 16px; }
.modal { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 22px; box-shadow: 0 24px 80px rgba(0,0,0,.6); animation: rise .18s ease-out; }
.modal h2 { font: 800 20px/1.2 var(--font-display); margin: 0 0 6px; }
.modal .lead { color: var(--muted); margin: 0 0 16px; }
.modal.danger { border-color: var(--red-deep); box-shadow: 0 0 0 1px var(--red-deep), 0 24px 80px rgba(0,0,0,.6); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 120; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface-2); border: 1px solid var(--line); border-left: 3px solid var(--ok); border-radius: var(--radius-s); padding: 12px 14px; font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.toast.error { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--warn); }

.progress { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.step { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--faint); }
.step::before { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.step.done { color: var(--text); }
.step.done::before { background: var(--ok); border-color: var(--ok); }
.step.now { color: var(--text); }
.step.now::before { border-color: var(--warn); animation: blink 1s infinite; }
.step.bad { color: #ff8a92; }
.step.bad::before { background: var(--red); border-color: var(--red); }
@keyframes blink { 50% { opacity: .3; } }

.spinner { width: 18px; height: 18px; border: 2px solid var(--surface-3); border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; gap: 10px; align-items: center; color: var(--muted); padding: 24px 4px; }

/* ---------- Inicio de sesión ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { position: relative; overflow: hidden; background: #050505; border-right: 1px solid var(--line); padding: 48px; display: flex; flex-direction: column; justify-content: flex-end; }
.login-art::before { content: ""; position: absolute; inset: -20% -40% auto auto; width: 90%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, rgba(239,51,64,.28), transparent 62%); }
.login-art h1 { position: relative; font: 900 clamp(40px, 6vw, 78px)/.92 var(--font-display); letter-spacing: -0.035em; margin: 0; }
.login-art p { position: relative; color: var(--muted); max-width: 46ch; margin: 18px 0 0; }
.login-form { display: flex; flex-direction: column; justify-content: center; padding: 48px; gap: 16px; max-width: 520px; }
.login-form h2 { font: 800 24px/1.2 var(--font-display); margin: 0; }
.login-form .btn { min-height: 52px; font-size: 16px; }

/* ---------- Móvil y tableta ---------- */
@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 60; transform: translateX(-102%); transition: transform .2s ease; padding-top: calc(18px + env(safe-area-inset-top)); }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.6); }
  .topbar .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .content { padding: 16px 14px calc(28px + env(safe-area-inset-bottom)); }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .page-head h1 { font-size: 24px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { grid-column: auto !important; }
  .stats > .stat:last-child:nth-child(odd) { grid-column: span 2 !important; }
  .stat-value { font-size: 28px; }
  .who .who-name { display: none; }
  .login { grid-template-columns: 1fr; }
  .login-art { min-height: 42vh; padding: 28px; padding-top: calc(28px + env(safe-area-inset-top)); }
  .login-form { padding: 28px; }
  .hide-mobile { display: none; }
  .modal-actions .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
