@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700;800;900&display=swap');

:root {
  --bg: #e0e5ec;
  --card-bg: #e6eaf1;
  --text: #262b38;
  --text-muted: #5b6478;
  --accent: #4d7cfe;
  --accent-2: #7c5cfc;
  --navy: #323b4d;
  --verde: #24a262;
  --rojo: #e5484d;
  --amarillo: #d9a422;
  --sh-light: #ffffff;
  --sh-dark: #a9b6c9;
  --border: #ccd5e3;
  --radius: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--sh-dark); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: var(--bg);
  box-shadow: 0 4px 14px rgba(163, 177, 198, 0.4);
  position: relative;
  z-index: 5;
}
.topbar::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity: 0.7;
}

.topbar h1 {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--navy);
  margin: 0;
  letter-spacing: -0.01em;
}

.topbar .subtitulo {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  background: var(--bg);
  color: var(--navy);
  box-shadow: 5px 5px 10px var(--sh-dark), -5px -5px 10px var(--sh-light);
  transition: transform 0.15s ease, box-shadow 0.2s ease, color 0.2s ease;
}
.btn:hover { color: var(--accent); box-shadow: 6px 6px 12px var(--sh-dark), -6px -6px 12px var(--sh-light); }
.btn:active { transform: scale(0.97); }
.btn-primario {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 16px rgba(77, 124, 254, 0.4);
}
.btn-primario:hover { color: #fff; box-shadow: 0 8px 20px rgba(77, 124, 254, 0.5); filter: brightness(1.05); }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.resumen-nodo {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 8px 8px 18px var(--sh-dark), -8px -8px 18px var(--sh-light);
  padding: 22px 26px;
  margin-bottom: 26px;
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  align-items: center;
}

.resumen-nodo h2 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--navy);
  flex-basis: 100%;
}

.metrica-mini {
  min-width: 140px;
}

.metrica-mini .etiqueta {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.metrica-mini .valor {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--navy);
  margin-top: 2px;
}

.grid-instancias {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 20px;
}

.tarjeta {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 6px 6px 14px var(--sh-dark), -6px -6px 14px var(--sh-light);
  padding: 20px 22px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: aparecer 0.35s ease both;
}
.tarjeta:hover {
  transform: translateY(-3px);
  box-shadow: 9px 9px 18px var(--sh-dark), -9px -9px 18px var(--sh-light);
}

@keyframes aparecer {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.tarjeta-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  gap: 10px;
}

.tarjeta-header .nombre {
  font-weight: 800;
  font-size: 1.02rem;
  color: var(--navy);
  line-height: 1.25;
}

.tarjeta-header .vmid {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

.badge-estado {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 4px 11px;
  border-radius: 999px;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}
.badge-estado.running { background: rgba(36, 162, 98, 0.15); color: var(--verde); }
.badge-estado.stopped { background: rgba(229, 72, 77, 0.15); color: var(--rojo); }
.badge-estado .punto {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
}
.badge-estado.running .punto { animation: pulso 2s ease-in-out infinite; }
@keyframes pulso {
  0%, 100% { box-shadow: 0 0 0 0 rgba(36, 162, 98, 0.4); }
  50% { box-shadow: 0 0 0 4px rgba(36, 162, 98, 0); }
}

.tipo-tag {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.barra-metrica { margin-bottom: 10px; }

.barra-metrica .fila-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.barra-fondo {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.barra-relleno {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.5s ease;
}
.barra-relleno.alto { background: var(--amarillo); }
.barra-relleno.critico { background: var(--rojo); }

.tarjeta .uptime {
  margin-top: 10px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

.tarjeta-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  gap: 8px;
}
.tarjeta-footer .uptime { margin-top: 0; }

.btn-historial {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 14px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  background: rgba(77, 124, 254, 0.08);
  box-shadow: inset 0 0 0 1px rgba(77, 124, 254, 0.12);
  transition: background 0.2s ease, transform 0.15s ease;
}
.btn-historial:hover { background: rgba(77, 124, 254, 0.14); }
.btn-historial:active { transform: scale(0.98); }

.btn-historial-icono {
  font-size: 1.05rem;
  flex-shrink: 0;
}

.btn-historial-texto {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.btn-historial-label {
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--accent);
}

.btn-historial-detalle {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 34, 45, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fondoAparecer 0.15s ease both;
}
@keyframes fondoAparecer { from { opacity: 0; } to { opacity: 1; } }
.oculto { display: none !important; }

.modal-caja {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 14px 14px 28px rgba(20, 24, 33, 0.35);
  max-width: 640px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: modalAparecer 0.2s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}
@keyframes modalAparecer {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 1.02rem; font-weight: 800; color: var(--navy); }

.btn-cerrar-modal {
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px;
  width: 30px; height: 30px;
  transition: background 0.15s ease, color 0.15s ease;
}
.btn-cerrar-modal:hover { background: rgba(229, 72, 77, 0.12); color: var(--rojo); }

.modal-contenido {
  padding: 18px 22px;
  overflow-y: auto;
}

.tabla-historial {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.tabla-historial th {
  text-align: left;
  color: var(--text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.tabla-historial td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.tabla-historial tbody tr { transition: background 0.15s ease; }
.tabla-historial tbody tr:hover { background: rgba(77, 124, 254, 0.06); }
.tabla-historial td.ok { color: var(--verde); font-weight: 700; }
.tabla-historial td.error { color: var(--rojo); font-weight: 700; }

.campo-form { margin-bottom: 14px; }
.campo-form label { display: block; font-size: 0.78rem; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.campo-form input, .campo-form select {
  width: 100%; padding: 10px 14px; border-radius: var(--radius-sm); border: none;
  background: var(--bg); box-shadow: inset 3px 3px 6px var(--sh-dark), inset -3px -3px 6px var(--sh-light);
  font-family: inherit; font-size: 0.9rem; color: var(--text);
  transition: box-shadow 0.15s ease;
}
.campo-form input:focus, .campo-form select:focus { outline: 2px solid var(--accent); }

.mensaje-error { color: var(--rojo); font-size: 0.8rem; margin-top: 4px; min-height: 1em; }

.badge-rol {
  font-size: 0.68rem; font-weight: 800; padding: 4px 10px; border-radius: 999px;
  background: rgba(77, 124, 254, 0.15); color: var(--accent);
  letter-spacing: 0.02em;
}
.badge-rol.admin { background: rgba(217, 164, 34, 0.18); color: var(--amarillo); }

.btn-accion-tabla {
  border: none; background: none; color: var(--accent); font-weight: 700;
  font-size: 0.78rem; cursor: pointer; margin-right: 10px; font-family: inherit;
  transition: opacity 0.15s ease;
}
.btn-accion-tabla:hover { opacity: 0.7; }
.btn-accion-tabla.peligro { color: var(--rojo); }

.estado-carga, .estado-error {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.estado-error { color: var(--rojo); }

@media (max-width: 600px) {
  main { padding: 16px 12px 40px; }
  .grid-instancias { grid-template-columns: 1fr; }
}
