/* ============================================================
   PANEL IPTV — Control Room (tema Grupo AMIX HN: blanco y rojo)
   Paleta: fondo blanco, superficie tipo consola clara, acento rojo
   de marca (extraído del logo), ámbar de alerta, rojo oscuro de error.
   Tipografía: Space Grotesk (marca), Inter (UI), JetBrains Mono (datos).
   ============================================================ */

:root {
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --surface-alt: #F3F3F4;
  --border: #E4E4E7;
  --text: #17171A;
  --muted: #6B7076;
  --signal: #F70201;      /* rojo de marca (Grupo AMIX HN) */
  --signal-dim: #FDE4E3;
  --amber: #C97A0A;
  --danger: #B00020;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }

/* El atributo hidden SIEMPRE gana, aunque una clase (.dashboard,
   .modal-overlay, etc) también defina "display". Sin esto, el login,
   el dashboard y la ventana de Astra podían quedar todos visibles
   a la vez y tapándose entre sí. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  height: 100%;
}

body {
  background-image:
    radial-gradient(circle at 15% 0%, rgba(247,2,1,0.05), transparent 40%),
    repeating-linear-gradient(0deg, rgba(0,0,0,0.012) 0px, rgba(0,0,0,0.012) 1px, transparent 1px, transparent 3px);
}

button, input, select { font-family: inherit; }

/* ---------- Marca ---------- */
.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-logo {
  height: 34px;
  width: auto;
}
.brand-logo-sidebar {
  height: 26px;
}
.sidebar-brand {
  justify-content: flex-start;
  padding-left: 4px;
  margin-bottom: 10px;
}

.rec-indicator {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--signal);
  margin: 2px 0 24px 4px;
}

.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 0 0 rgba(247,2,1,0.55);
  animation: pulse 2s infinite;
  flex-shrink: 0;
}
.rec-dot.small { width: 7px; height: 7px; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(247,2,1,0.5); }
  70%  { box-shadow: 0 0 0 8px rgba(247,2,1,0); }
  100% { box-shadow: 0 0 0 0 rgba(247,2,1,0); }
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.login-bars {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
  opacity: 0.35;
  pointer-events: none;
}
.login-bars span {
  width: 18px;
  background: linear-gradient(to top, var(--signal-dim), var(--signal));
  border-radius: 3px 3px 0 0;
  animation: bar-wave 2.4s ease-in-out infinite;
  opacity: 0.5;
}
.login-bars span:nth-child(1) { height: 30%; animation-delay: 0s; }
.login-bars span:nth-child(2) { height: 55%; animation-delay: 0.15s; }
.login-bars span:nth-child(3) { height: 80%; animation-delay: 0.3s; }
.login-bars span:nth-child(4) { height: 40%; animation-delay: 0.45s; }
.login-bars span:nth-child(5) { height: 70%; animation-delay: 0.6s; }
.login-bars span:nth-child(6) { height: 35%; animation-delay: 0.75s; }
.login-bars span:nth-child(7) { height: 60%; animation-delay: 0.9s; }
.login-bars span:nth-child(8) { height: 25%; animation-delay: 1.05s; }

@keyframes bar-wave {
  0%, 100% { transform: scaleY(0.6); }
  50%      { transform: scaleY(1); }
}

@media (prefers-reduced-motion: reduce) {
  .rec-dot, .login-bars span { animation: none; }
}

.login-card {
  position: relative;
  z-index: 1;
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.12);
}

.login-sub {
  margin: 6px 0 24px;
  color: var(--muted);
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 0.8rem;
  color: var(--muted);
}
.field input {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus { border-color: var(--signal); }

.error-text {
  color: var(--danger);
  font-size: 0.82rem;
  margin-top: 12px;
  text-align: center;
}

/* ---------- Botones ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s;
}
.btn:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; }

.btn-primary {
  background: var(--signal);
  color: #FFFFFF;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-alt); }

.btn-danger-outline {
  background: transparent;
  border-color: rgba(176,0,32,0.35);
  color: var(--danger);
}
.btn-danger-outline:hover { background: rgba(176,0,32,0.08); }

.mobile-menu-btn {
  display: none; /* solo aparece en móvil, ver media query abajo */
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  flex-shrink: 0;
  padding: 0;
}
.mobile-menu-btn span {
  display: block;
  height: 2px;
  width: 18px;
  margin: 0 auto;
  background: var(--text);
  border-radius: 2px;
}

.sidebar-backdrop {
  display: none;
}

.topbar { gap: 12px; }

/* ============================================================
   DASHBOARD LAYOUT
   ============================================================ */
.dashboard {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  min-height: 100dvh; /* respeta la barra de direcciones de Android/iOS */
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
}

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface-alt); color: var(--text); }
.nav-item.active {
  background: var(--signal-dim);
  color: var(--signal);
}
.nav-ico { font-size: 1rem; width: 18px; text-align: center; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.whoami {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-family: var(--font-mono);
  color: var(--text);
}
.role-pill {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.content { padding: 28px 36px; overflow-y: auto; }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
}
.topbar-title h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0 0 4px;
}
.topbar-title p { margin: 0; color: var(--muted); font-size: 0.88rem; }
.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 0.85rem;
  padding-top: 4px;
}

.view { display: none; }
.view.active { display: block; }

/* ---------- Tarjetas de estadísticas ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
}
.stat-sub { font-size: 0.78rem; color: var(--muted); font-family: var(--font-mono); }

.bar {
  height: 6px;
  background: var(--surface-alt);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 2px;
}
.bar-fill {
  height: 100%;
  width: 0%;
  background: var(--signal);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.bar-fill.warn { background: var(--amber); }
.bar-fill.danger { background: var(--danger); }

/* ---------- Tarjetas de panel / formularios ---------- */
.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  margin-bottom: 20px;
}
.panel-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.panel-card-head h2 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.fw-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.fw-status-dot.on { background: var(--signal); box-shadow: 0 0 0 3px var(--signal-dim); }
.fw-status-dot.off { background: var(--danger); box-shadow: 0 0 0 3px rgba(176,0,32,0.12); }

.fw-status-text {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.fw-port-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
}
.fw-port-row i { font-size: 16px; color: var(--muted); flex-shrink: 0; }
.fw-port-label { color: var(--text); flex: 1; }
.fw-port-num { font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); }
.fw-port-conn { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); white-space: nowrap; }

.inline-form {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
}
.inline-form.wrap { flex-wrap: wrap; }
.inline-form input, .inline-form select {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}
.inline-form input:focus, .inline-form select:focus { border-color: var(--signal); }

.hint-text { font-size: 0.82rem; color: var(--muted); margin: 10px 0 0; }
.hint-text.ok { color: var(--signal); }
.hint-text.err { color: var(--danger); }

.raw-output {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

/* ---------- Tabla ---------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}
.data-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
}
.data-table tr:last-child td { border-bottom: none; }
.muted { color: var(--muted); }

.status-tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-family: var(--font-body);
}
.status-tag.active { background: var(--signal-dim); color: var(--signal); }
.status-tag.expired { background: rgba(176,0,32,0.1); color: var(--danger); }

.section-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}
.section-label-spaced { margin-top: 28px; }

/* ---------- Ventana modal (agregar servidor Astra) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 13, 0.72);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-box {
  width: 380px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.16);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin: 0;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--surface-alt); color: var(--text); }

.modal-form { display: flex; flex-direction: column; gap: 14px; }
.modal-form .field input {
  width: 100%;
}

.field-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text);
}
.field-check input { accent-color: var(--signal); width: 15px; height: 15px; }

/* ============================================================
   RESPONSIVE — tablet y celular (cualquier tamaño, Android/iOS)
   ============================================================ */

/* Tablet: el sidebar se angosta un poco antes de convertirse en cajón */
@media (max-width: 1000px) {
  .dashboard { grid-template-columns: 200px 1fr; }
}

/* Celular / pantallas angostas: el sidebar se convierte en cajón
   deslizante que se abre con el botón hamburguesa, en vez de
   desaparecer sin dejar forma de navegar. */
@media (max-width: 860px) {
  .dashboard { grid-template-columns: 1fr; }

  .mobile-menu-btn { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 84vw);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    padding-top: max(22px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    overflow-y: auto;
    box-shadow: 0 0 0 1px var(--border);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 150;
  }
  .sidebar-backdrop[hidden] { display: none; }

  .content {
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .topbar { margin-bottom: 18px; flex-wrap: wrap; }
  .topbar-title h1 { font-size: 1.2rem; }
  .topbar-status { display: none; } /* el reloj no es crítico, libera espacio */

  /* Tarjetas de estadísticas: una o dos columnas según ancho real */
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .stat-value { font-size: 1.5rem; }

  /* Formularios: todo apilado, inputs a ancho completo, más fáciles de tocar */
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form input, .inline-form select, .inline-form button { width: 100%; }
  .inline-form button { margin-left: 0 !important; margin-top: 4px; }

  /* Tablas: scroll horizontal en vez de desbordar la pantalla.
     El envoltorio .table-scroll lo agrega app.js automáticamente
     alrededor de cada .data-table, así no depende de :has(). */
  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -16px;
    padding: 0 16px;
  }
  .table-scroll .data-table { min-width: 480px; }

  .panel-card { padding: 16px; }

  /* Ventanas modales: ocupan casi todo el ancho, no se salen de pantalla */
  .modal-box { width: 100% !important; max-width: 100%; margin: 0 12px; }

  /* Botones táctiles: altura mínima cómoda para dedo */
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }
}

/* Celulares chicos (iPhone SE y similares) */
@media (max-width: 380px) {
  .content { padding: 12px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .login-card { padding: 24px 18px; }
}

