/* ── Variables ─────────────────────────────────────────────── */
:root {
  --sidebar-bg: #1a1f2e;
  --sidebar-hover: #252c3f;
  --sidebar-active: #4361ee;
  --sidebar-text: #a8b2d8;
  --sidebar-text-active: #fff;
  --sidebar-width: 240px;

  --bg: #f0f2f8;
  --card-bg: #ffffff;
  --text: #1e2a45;
  --text-muted: #6b7a99;
  --border: #e2e8f0;

  --accent: #4361ee;
  --accent-hover: #3451d1;
  --success: #2ec4b6;
  --warning: #f77f00;
  --danger: #e63946;
  --info: #4895ef;

  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
       font-size: 14px; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; }

/* ── Layout ────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-logo {
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-logo h1 { font-size: 15px; color: #fff; font-weight: 700; letter-spacing: .02em; }
.sidebar-logo span { font-size: 11px; color: var(--sidebar-text); }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  cursor: pointer;
  border-radius: 0;
  transition: background .15s, color .15s;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-text-active); }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-footer {
  padding: 12px 18px;
  border-top: 1px solid rgba(255,255,255,.06);
  font-size: 12px;
  color: var(--sidebar-text);
}
.sidebar-footer .user { color: #fff; font-weight: 600; font-size: 13px; }
.btn-logout {
  margin-top: 8px;
  background: none; border: 1px solid rgba(255,255,255,.15);
  color: var(--sidebar-text);
  padding: 6px 12px; border-radius: var(--radius);
  font-size: 12px; width: 100%; text-align: center;
  transition: background .15s;
}
.btn-logout:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ── Main content ──────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky; top: 0; z-index: 50;
}
.topbar h2 { font-size: 17px; font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.content { padding: 24px 28px; flex: 1; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-header h3 { font-size: 14px; font-weight: 600; }
.card-body { padding: 20px; }

/* ── Stat cards ────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-card .sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.stat-card .progress { margin-top: 10px; }

/* ── Two-column grid ───────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
     color: var(--text-muted); background: #f8fafc; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; border: none;
  transition: opacity .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { opacity: .88; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-info    { background: var(--info); color: #fff; }
.btn-ghost   { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); background: #f8fafc; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 9px; border-radius: 99px;
  font-size: 11px; font-weight: 600; letter-spacing: .03em;
}
/* Roles admin */
.badge-superadmin { background: #ede9fe; color: #5b21b6; }
.badge-operador   { background: #e0f2fe; color: #075985; }
/* Estado contenedor */
.badge-running    { background: #dcfce7; color: #15803d; }
.badge-exited     { background: #f1f5f9; color: #64748b; }
.badge-restarting { background: #fef3c7; color: #92400e; }
.badge-created    { background: #e0f2fe; color: #075985; }
.badge-paused     { background: #f1f5f9; color: #64748b; }
/* Salud contenedor */
.badge-healthy    { background: #dcfce7; color: #15803d; }
.badge-unhealthy  { background: #fee2e2; color: #991b1b; }
.badge-starting   { background: #fef3c7; color: #92400e; }
.badge-none       { background: #f1f5f9; color: #94a3b8; }
/* Certs TLS */
.badge-ok         { background: #dcfce7; color: #15803d; }
.badge-advertencia{ background: #fef3c7; color: #92400e; }
.badge-critico    { background: #fee2e2; color: #991b1b; }
.badge-expirado   { background: #fee2e2; color: #991b1b; }
.badge-no-encontrado { background: #f1f5f9; color: #94a3b8; }
.badge-error      { background: #fee2e2; color: #991b1b; }
/* Estado activo/inactivo */
.badge-active     { background: #dcfce7; color: #15803d; }
.badge-inactive   { background: #f1f5f9; color: #64748b; }

/* ── Progress bar ──────────────────────────────────────────── */
.progress { background: #e2e8f0; border-radius: 99px; height: 6px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 99px; background: var(--accent);
                transition: width .4s; }
.progress-bar.warn   { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }

/* ── Metric row (label + bar + value) ─────────────────────── */
.metric-row { margin-bottom: 14px; }
.metric-row:last-child { margin-bottom: 0; }
.metric-label { display: flex; justify-content: space-between; margin-bottom: 5px; font-size: 12px; }
.metric-label span:first-child { font-weight: 600; color: var(--text); }
.metric-label span:last-child  { color: var(--text-muted); }

/* ── Cert cards ────────────────────────────────────────────── */
.certs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.cert-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.cert-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.cert-domain { font-size: 14px; font-weight: 700; }
.cert-days-big {
  font-size: 32px; font-weight: 800;
  line-height: 1; margin: 8px 0 4px;
}
.cert-days-big.ok       { color: var(--success); }
.cert-days-big.advertencia { color: var(--warning); }
.cert-days-big.critico  { color: var(--danger); }
.cert-days-big.expirado { color: var(--danger); }
.cert-meta { font-size: 11px; color: var(--text-muted); margin-top: 6px; }
.cert-sans { font-size: 11px; color: var(--text-muted); margin-top: 4px;
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Health indicators ─────────────────────────────────────── */
.health-dot {
  display: inline-block; width: 9px; height: 9px;
  border-radius: 50%; margin-right: 5px;
  flex-shrink: 0;
}
.health-dot.ok   { background: var(--success); }
.health-dot.error { background: var(--danger); }
.health-dot.unknown { background: var(--text-muted); }

/* ── Log viewer ────────────────────────────────────────────── */
.log-controls {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-bottom: 16px;
}
.log-controls select { flex: 1; min-width: 200px; }
.log-viewer {
  background: #0d1117;
  color: #e6edf3;
  font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 16px;
  border-radius: var(--radius);
  height: 520px;
  overflow-y: auto;
  overflow-x: auto;
  white-space: pre;
  resize: vertical;
  border: 1px solid #30363d;
}
.log-viewer:empty::before {
  content: "Selecciona un contenedor y haz clic en Cargar o Iniciar streaming.";
  color: #484f58;
}
.log-streaming-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: #dcfce7; color: #15803d;
  padding: 3px 10px; border-radius: 99px; font-size: 11px; font-weight: 600;
}
.log-streaming-badge::before {
  content: ''; display: inline-block;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--success);
  animation: pulse 1.2s ease infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; } 50% { opacity: 0.3; }
}

/* ── Section groups ────────────────────────────────────────── */
.section { display: none; }
.section.active { display: block; }

/* ── Section header ────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.section-header h2 { font-size: 18px; font-weight: 700; }

/* ── Forms / Modals ────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--card-bg);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  width: 480px; max-width: 96vw;
  max-height: 90vh; overflow-y: auto;
}
.modal-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--text-muted);
               line-height: 1; padding: 2px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border);
                display: flex; gap: 8px; justify-content: flex-end; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600;
                    color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; }
.form-control {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; color: var(--text); background: #fff;
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--accent);
                      box-shadow: 0 0 0 3px rgba(67,97,238,.12); }
select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7a99'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 28px; appearance: none;
}

/* ── Stats en modal ────────────────────────────────────────── */
.stats-dl { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stats-dl dt { font-size: 11px; color: var(--text-muted); text-transform: uppercase;
               font-weight: 700; margin-bottom: 2px; }
.stats-dl dd { font-size: 20px; font-weight: 700; }

/* ── Toast ─────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 999;
}
.toast {
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn .2s ease;
  max-width: 340px;
}
.toast-success { background: #dcfce7; color: #15803d; border-left: 4px solid var(--success); }
.toast-error   { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--danger); }
.toast-info    { background: #e0f2fe; color: #075985; border-left: 4px solid var(--info); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; }
                     to   { transform: translateX(0);    opacity: 1; } }

/* ── Loading / Empty states ────────────────────────────────── */
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-msg { text-align: center; padding: 32px; color: var(--text-muted); }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 36px; margin-bottom: 12px; }

/* ── Login page ────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--sidebar-bg) 0%, #2d3561 100%);
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: #fff; border-radius: 12px;
  padding: 40px; width: 380px; max-width: 95vw;
  box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 22px; font-weight: 800; color: var(--text); }
.login-logo p  { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.login-error { background: #fee2e2; color: #991b1b; padding: 10px 14px;
               border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }

/* ── Auto-refresh label ────────────────────────────────────── */
.refresh-label {
  font-size: 11px; color: var(--text-muted);
  display: flex; align-items: center; gap: 4px;
}

/* ── Barra de carga en segundo plano ────────────────────────── */
#refresh-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  opacity: 0;
  z-index: 9999;
  transition: opacity 0.3s;
}
#refresh-bar.active {
  opacity: 1;
  animation: refresh-slide 1.6s ease-in-out infinite;
}
@keyframes refresh-slide {
  0%   { transform: scaleX(0);    transform-origin: left;  }
  48%  { transform: scaleX(0.85); transform-origin: left;  }
  52%  { transform: scaleX(0.85); transform-origin: right; }
  100% { transform: scaleX(0);    transform-origin: right; }
}

/* Transición suave al actualizar contenido en segundo plano */
.stats-grid,
#resumen-charts,
#contenedores-table,
#red-ports,
#red-health,
#certs-grid,
#auditoria-table,
#admins-table {
  transition: opacity 0.25s ease;
}
.content-updating {
  opacity: 0.45;
  pointer-events: none;
}
