/*
  server/static/admin.css
  Estilos propios (sin dependencias externas / CDN) para el panel admin web.
  v4.0: agregados estilos para indicadores de estado en tiempo real.
*/

:root {
  --primary:      #4f46e5;
  --primary-dark: #4338ca;
  --danger:       #dc2626;
  --success:      #16a34a;
  --warning:      #d97706;
  --live:         #10b981;
  --offline:      #9ca3af;
  --bg:           #f4f5f7;
  --card-bg:      #ffffff;
  --border:       #e2e4e9;
  --text:         #1f2430;
  --text-muted:   #6b7280;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ── Navbar ────────────────────────────────────────────────────────────────── */

.navbar {
  background: var(--primary);
  color: #fff;
  padding: 0.45rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.2rem;
}

/* ── Fila 1: marca + reloj + indicador WS ── */
.navbar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.navbar .brand {
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  text-decoration: none;
  flex-shrink: 0;
}

/* ── Fila 2: links de navegación, wrappean en 2 líneas si no caben ── */
.navbar nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.1rem 0;
  row-gap: 0.2rem;
}

.navbar nav a {
  color: #e0e0ff;
  text-decoration: none;
  margin-left: 0;
  padding: 0.18rem 0.55rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

.navbar nav a:hover, .navbar nav a.active {
  color: #fff;
  font-weight: 600;
}

/* Indicador de estado WS en la navbar */
.ws-indicator {
  font-size: 0.85rem;
  margin-left: 1rem;
  transition: color 0.3s;
}
.ws-connected    { color: var(--live); }
.ws-disconnected { color: #ef4444; }
.ws-connecting   { color: #fbbf24; }

/* ── Layout ────────────────────────────────────────────────────────────────── */

.container {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1.25rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.card h2, .card h3 { margin-top: 0; }

/* ── Stats grid ────────────────────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  text-align: center;
}

.stat-box .value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-box .label {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

/* Stat boxes para métricas en vivo */
.stat-box-live {
  border-color: var(--live);
}
.stat-box-live .live-value {
  color: var(--live);
}

/* ── Tablas ────────────────────────────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
}

tr:hover td { background: #fafafd; }

/* ── Badges ────────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
}

.badge-active   { background: var(--success); }
.badge-expired  { background: var(--warning); }
.badge-revoked  { background: var(--danger); }
.badge-admin    { background: var(--primary); }
.badge-blocked  { background: #4b5563; }
.badge-banned   { background: var(--danger); }
.badge-basic    { background: #3b82f6; }
.badge-pro      { background: #8b5cf6; }
.badge-premium  { background: #f59e0b; color: #1e1e2e; }

/* Badge numérico de sesiones en el nav */
.badge-live {
  display: inline-block;
  background: var(--live);
  color: #fff;
  border-radius: 999px;
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  font-weight: 700;
  vertical-align: middle;
}

/* Punto verde/gris de estado en vivo en tablas */
.dot-live {
  color: var(--live);
  font-size: 1rem;
  line-height: 1;
}
.dot-offline {
  color: var(--offline);
  font-size: 1rem;
  line-height: 1;
}

/* ── Botones ────────────────────────────────────────────────────────────────── */

.btn {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: #fff;
  background: var(--primary);
}

.btn:hover      { background: var(--primary-dark); }
.btn-sm         { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-danger     { background: var(--danger); }
.btn-danger:hover  { background: #b91c1c; }
.btn-success    { background: var(--success); }
.btn-success:hover { background: #15803d; }
.btn-secondary  { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }
.btn-delete     { background: #7c3aed; }
.btn-delete:hover { background: #6d28d9; }
.btn-disabled   { background: #9ca3af; color: #fff; cursor: not-allowed; opacity: 0.65; pointer-events: none; }

/* ── Formularios ────────────────────────────────────────────────────────────── */

.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

input, select {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.92rem;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}

.inline-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.inline-form .form-group {
  margin-bottom: 0;
  min-width: 110px;
}

/* ── Alertas ────────────────────────────────────────────────────────────────── */

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-danger {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

/* ── Login ──────────────────────────────────────────────────────────────────── */

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary), #312e81);
}

.login-box {
  background: #fff;
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.login-box h1 {
  margin-top: 0;
  font-size: 1.4rem;
  text-align: center;
  color: var(--primary);
}

/* ── Utilidades ─────────────────────────────────────────────────────────────── */

.text-muted  { color: var(--text-muted); font-size: 0.85rem; }
.text-danger { color: var(--danger); }
.mt-1        { margin-top: 1rem; }
.d-flex      { display: flex; gap: 0.5rem; }

/* ── Uptime badge ──────────────────────────────────────────────────────────── */

.badge-uptime {
  display: inline-block;
  background: #ede9fe;
  color: #5b21b6;
  border-radius: 6px;
  padding: 0.2rem 0.65rem;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: monospace;
}

/* ── Auditoría — etiquetas de acción ──────────────────────────────────────── */

.audit-action {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: monospace;
  background: #f3f4f6;
  color: var(--text);
}

.audit-admin_login        { background: #dbeafe; color: #1e40af; }
.audit-admin_logout       { background: #f3f4f6; color: #6b7280; }
.audit-client_login       { background: #d1fae5; color: #065f46; }
.audit-user_created       { background: #d1fae5; color: #065f46; }
.audit-user_deleted       { background: #fee2e2; color: #991b1b; }
.audit-user_blocked       { background: #fee2e2; color: #991b1b; }
.audit-user_unblocked     { background: #d1fae5; color: #065f46; }
.audit-license_renewed    { background: #dbeafe; color: #1e40af; }
.audit-license_revoked    { background: #fee2e2; color: #991b1b; }
.audit-session_limit_changed { background: #fef3c7; color: #92400e; }
.audit-session_kicked     { background: #fef3c7; color: #92400e; }
.audit-version_uploaded   { background: #ede9fe; color: #5b21b6; }
.audit-version_set_current{ background: #ede9fe; color: #5b21b6; }
.audit-version_set_min    { background: #ede9fe; color: #5b21b6; }
.audit-version_revoked    { background: #fee2e2; color: #991b1b; }
.audit-version_deleted    { background: #fee2e2; color: #991b1b; }
.audit-server_started     { background: #d1fae5; color: #065f46; }

/* ── Auditoría — formulario de filtros ────────────────────────────────────── */

.audit-filter-form { margin: 0; }

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  align-items: end;
}

.filter-grid .form-group { margin-bottom: 0; }

/* ── Paginación ─────────────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ── Botón primary ──────────────────────────────────────────────────────────── */

.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }

/* ── Estado del servidor ────────────────────────────────────────────────────── */

.status-indicator-ok  { color: var(--live); font-weight: 700; }
.status-indicator-err { color: var(--danger); font-weight: 700; }

/* ── Backups ─────────────────────────────────────────────────────────────────── */

.backup-file {
  font-family: monospace;
  font-size: 0.85rem;
  background: #f3f4f6;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

/* ── Historial de actualizaciones ───────────────────────────────────────────── */

.audit-update_started  { background: #dbeafe; color: #1e40af; }
.audit-update_success  { background: #d1fae5; color: #065f46; }
.audit-update_failed   { background: #fee2e2; color: #991b1b; }
.audit-device_blocked  { background: #fee2e2; color: #991b1b; }
.audit-device_deleted  { background: #fee2e2; color: #991b1b; }
.audit-device_unblocked { background: #d1fae5; color: #065f46; }
.audit-backup_created  { background: #ede9fe; color: #5b21b6; }
.audit-backup_restored { background: #fef3c7; color: #92400e; }
.audit-backup_deleted  { background: #fee2e2; color: #991b1b; }

/* ── Monitoreo de dispositivos ──────────────────────────────────────────────── */

.device-blocked-row td { opacity: 0.6; }
.device-blocked-badge {
  display: inline-block;
  background: #4b5563;
  color: #fff;
  border-radius: 999px;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  font-weight: 600;
}

/* ── Exportaciones ───────────────────────────────────────────────────────────── */

.export-card { margin-bottom: 1.25rem; }

/* ── Mensajes admin ──────────────────────────────────────────────────────────── */

.audit-message_global_sent    { background: #dbeafe; color: #1e40af; }
.audit-message_individual_sent { background: #ede9fe; color: #5b21b6; }
.audit-all_connections_closed  { background: #fef3c7; color: #92400e; }
.audit-admin_deleted           { background: #fee2e2; color: #991b1b; }

/* ── Progress / info bar ─────────────────────────────────────────────────────── */

.info-bar {
  background: #ede9fe;
  color: #5b21b6;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  margin-bottom: 1rem;
}

/* ── 4-row per user / license table ─────────────────────────────────────────── */

.rsd-row-head { background: #eef2f9; }
.rsd-row-head th { color: #374151; font-weight: 700; font-size: 0.72rem; text-transform: uppercase; padding: 0.32rem 0.6rem; }
.rsd-row-data { background: #ffffff; }
.rsd-row-sep td { border-bottom: 3px solid #c8cfe0 !important; }

.rsd-action-col {
  vertical-align: top;
  border-left: 3px solid #c8cfe0;
  border-bottom: 3px solid #c8cfe0 !important;
  padding: 0.55rem 0.7rem;
  min-width: 185px;
  max-width: 230px;
}

/* Flex column of buttons inside action cell */
.rsd-af { display: flex; flex-direction: column; gap: 0.3rem; }
.rsd-af form { margin: 0; }
.rsd-af > .btn-sm,
.rsd-af > a.btn-sm { display: block; width: 100%; text-align: center; box-sizing: border-box; }

/* Inline row for select+button combos */
.rsd-sf {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  flex-wrap: nowrap;
}
.rsd-sf select,
.rsd-sf input[type=number] {
  flex: 1;
  min-width: 0;
  font-size: 0.76rem;
  padding: 0.17rem 0.28rem;
}
.rsd-sf .btn-sm { flex: 0 0 auto; width: auto; white-space: nowrap; }

/* Small separator label between button groups */
.rsd-sep-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-top: 0.3rem;
  border-top: 1px solid #e2e4e9;
  padding-top: 0.25rem;
}
.rsd-sep-label:first-child { margin-top: 0; border-top: none; padding-top: 0; }

/* ── Flex record layout — info compacta, acciones independientes (forma L) ── */

/* Wrapper por registro: flex horizontal, items alineados al tope */
.rsd-record-flex {
  display: flex;
  align-items: flex-start;
  border-bottom: 3px solid #c8cfe0;
  margin-bottom: 0.25rem;
}

/* Bloque de información: tabla interna compacta */
.rsd-record-info {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

/* Quitar el borde del último rsd-row-sep dentro del bloque info
   (el borde lo da rsd-record-flex, evitar doble línea) */
.rsd-record-info .rsd-row-sep td {
  border-bottom: none !important;
}

/* Columna de acciones en contexto flex: siempre pegada al tope */
.rsd-record-flex > .rsd-action-col {
  align-self: flex-start;
}
