/* --- CSS Reset & Variables --- */
:root {
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Color Palette - HSL tailored */
  --bg-main: #070913;
  --card-bg: rgba(15, 22, 42, 0.55);
  --card-bg-hover: rgba(22, 32, 60, 0.75);
  --card-border: rgba(255, 255, 255, 0.06);
  --card-border-active: rgba(129, 140, 248, 0.4);
  
  --primary: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.35);
  --primary-hover: #4f46e5;
  
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.3);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.2);
  --warning: #f59e0b;
  --warning-glow: rgba(245, 158, 11, 0.2);
  --info: #06b6d4;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --border-radius: 16px;
  --shadow-premium: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* --- Animated Background --- */
.bg-gradient {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  background: radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.05) 0%, transparent 40%),
              radial-gradient(circle at 90% 80%, rgba(6, 182, 212, 0.05) 0%, transparent 40%),
              #070913;
  overflow: hidden;
}

.bg-gradient::after {
  content: "";
  position: absolute;
  width: 300px;
  height: 300px;
  background: var(--primary);
  border-radius: 50%;
  filter: blur(150px);
  opacity: 0.15;
  top: -50px;
  left: -50px;
  animation: float-orb 20s infinite alternate ease-in-out;
}

@keyframes float-orb {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(100px, 80px) scale(1.2); }
}

/* --- App Container & Layout --- */
#app {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.view {
  width: 100%;
  animation: fadeIn 0.4s ease-out forwards;
}

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

/* --- Helper Classes --- */
.hidden {
  display: none !important;
}

/* --- Premium Cards (Glassmorphism) --- */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-premium);
  transition: var(--transition-smooth);
}

/* --- 1. LOGIN SCREEN --- */
#login-view.card {
  max-width: 420px;
  width: 100%;
  padding: 40px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.login-header {
  text-align: center;
}

.login-header .logo-icon {
  width: 48px;
  height: 48px;
  color: var(--primary);
  filter: drop-shadow(0 0 10px var(--primary-glow));
  margin-bottom: 16px;
}

.login-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.login-header p {
  font-size: 14px;
  color: var(--text-muted);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.input-group label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.input-group input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 16px;
  transition: var(--transition-smooth);
}

.input-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
  background: rgba(255, 255, 255, 0.08);
}

.error-text {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 12px;
  border-radius: 10px;
  font-size: 14px;
  text-align: center;
  margin-top: 16px;
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* --- 2. MAIN DASHBOARD SCREEN --- */
#dashboard-view {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
}

/* Header */
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 20px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon-small {
  width: 32px;
  height: 32px;
  color: var(--primary);
  filter: drop-shadow(0 0 5px var(--primary-glow));
}

.header-brand h2 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.host-path {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
}

.header-actions {
  display: flex;
  gap: 12px;
}

/* Stats Row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.stat-card {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.stat-icon.bg-blue { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.stat-icon.bg-green { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.stat-icon.bg-indigo { background: rgba(99, 102, 241, 0.15); color: #818cf8; }

.stat-icon svg {
  width: 24px;
  height: 24px;
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.stat-val {
  font-size: 24px;
  font-weight: 700;
}

/* VM Section */
.vm-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.section-title h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
  position: relative;
  padding-left: 12px;
}

.section-title h3::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 4px;
  background: var(--primary);
  border-radius: 2px;
}

.search-bar-container {
  max-width: 320px;
  width: 100%;
}

.search-bar-container input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px 16px;
  color: var(--text-main);
  font-size: 14px;
  transition: var(--transition-smooth);
}

.search-bar-container input:focus {
  outline: none;
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.08);
}

/* VM Grid & Cards */
.vm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 18px;
}

.vm-card {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: relative;
  overflow: hidden;
}

.vm-card:hover {
  background: var(--card-bg-hover);
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateY(-2px);
}

.vm-card.running {
  border-color: rgba(16, 185, 129, 0.2);
}

.vm-card.running:hover {
  border-color: rgba(16, 185, 129, 0.35);
  box-shadow: 0 10px 30px -10px rgba(16, 185, 129, 0.15);
}

/* VM Card Top (Status & Info) */
.vm-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.vm-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 80%;
}

.vm-name {
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vm-folder {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.vm-folder svg {
  width: 14px;
  height: 14px;
  color: var(--text-dim);
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 20px;
}

.status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

/* Status States */
.status-badge.poweredon {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}
.status-badge.poweredon::before {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse-glow 2s infinite;
}

.status-badge.poweredoff {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}
.status-badge.poweredoff::before {
  background: var(--danger);
}

.status-badge.suspended {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}
.status-badge.suspended::before {
  background: var(--warning);
  animation: pulse-glow 2.5s infinite;
}

.status-badge.unknown {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-muted);
}
.status-badge.unknown::before {
  background: var(--text-muted);
}

@keyframes pulse-glow {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.5; }
  100% { transform: scale(1); opacity: 1; }
}

/* VM Card Middle (Specs & Path) */
.vm-card-mid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  padding-top: 12px;
}

.vm-spec {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.vm-spec-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.vm-spec-item svg {
  width: 14px;
  height: 14px;
  color: var(--text-dim);
}

.vm-path-text {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl; /* Hace que se vea el final de la ruta en vez de cortarse el nombre .vmx */
  text-align: left;
}

/* VM Card Controls (Footer) */
.vm-controls {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

/* --- Button Styling --- */
.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  border-radius: 10px;
  padding: 8px 16px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition-smooth);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Primary Button */
.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px var(--primary-glow);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 16px var(--primary-glow);
}

.btn-block {
  width: 100%;
  padding: 12px;
}

/* Secondary Button */
.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--card-border);
  color: var(--text-main);
}
.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.15);
}

/* Action Control Buttons (Dashboard Cards) */
.btn-control {
  padding: 10px;
  flex: 1;
}

.btn-control-play {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.2);
  color: #34d399;
}
.btn-control-play:hover:not(:disabled) {
  background: var(--success);
  color: #fff;
  box-shadow: 0 4px 12px var(--success-glow);
}

.btn-control-pause {
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
}
.btn-control-pause:hover:not(:disabled) {
  background: var(--warning);
  color: #fff;
  box-shadow: 0 4px 12px var(--warning-glow);
}

.btn-control-stop {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.2);
  color: #f87171;
}
.btn-control-stop:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 12px var(--danger-glow);
}

.btn-control-reset {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--card-border);
  color: var(--text-muted);
}
.btn-control-reset:hover:not(:disabled) {
  background: #64748b;
  color: #fff;
}

.btn-danger-outline {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}
.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 12px var(--danger-glow);
}

/* --- Spinner & Loading States --- */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 0;
  gap: 16px;
  color: var(--text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.08);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s infinite linear;
}

.card-loader {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 22, 42, 0.85);
  backdrop-filter: blur(4px);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  animation: fadeIn 0.2s ease-out;
}

.card-loader .spinner {
  width: 32px;
  height: 32px;
}

.card-loader span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* --- Error & Empty States --- */
.error-state, .empty-state {
  padding: 48px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  max-width: 500px;
  margin: 40px auto;
}

.error-icon {
  width: 48px;
  height: 48px;
  color: var(--danger);
  filter: drop-shadow(0 0 5px var(--danger-glow));
}

.empty-icon {
  width: 48px;
  height: 48px;
  color: var(--text-dim);
}

.error-state h4, .empty-state h4 {
  font-size: 18px;
  font-weight: 600;
}

.error-state p, .empty-state p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 9999;
  max-width: 380px;
  width: calc(100% - 48px);
}

.toast {
  background: rgba(30, 41, 59, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 16px;
  color: var(--text-main);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-info { border-left: 4px solid var(--info); }

.toast-content {
  flex-1: 1;
  font-size: 14px;
  line-height: 1.4;
}

.toast-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: var(--transition-smooth);
}

.toast-close:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

@keyframes slideIn {
  from { transform: translateX(100%) translateY(0); opacity: 0; }
  to { transform: translateX(0) translateY(0); opacity: 1; }
}

.toast.fade-out {
  animation: slideOut 0.3s ease-in forwards;
}

@keyframes slideOut {
  from { transform: translateX(0) scale(1); opacity: 1; }
  to { transform: translateX(100%) scale(0.9); opacity: 0; }
}

/* --- Responsive Layout Adjustments --- */
@media (max-width: 768px) {
  #app {
    padding: 16px;
  }
  
  .main-header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .header-actions {
    justify-content: space-between;
  }
  
  .section-title {
    flex-direction: column;
    align-items: stretch;
  }
  
  .search-bar-container {
    max-width: 100%;
  }
}
