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

/* ========== RESET & BASE ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-card-hover: rgba(30, 41, 59, 0.8);
  --bg-input: rgba(30, 41, 59, 0.6);
  --border: rgba(99, 102, 241, 0.15);
  --border-hover: rgba(99, 102, 241, 0.4);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.3);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-w: 260px;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: rgba(255, 255, 255, 1);
  --bg-input: rgba(241, 245, 249, 0.8);
  --border: rgba(99, 102, 241, 0.25);
  --border-hover: rgba(99, 102, 241, 0.5);
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --accent: #4f46e5;
  --accent-light: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.15);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}

html { font-size: 15px; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 20% 0%, rgba(99,102,241,0.08) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 100%, rgba(6,182,212,0.06) 0%, transparent 60%);
  pointer-events: none; z-index: 0;
}

a { color: var(--accent-light); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }

/* ========== LOGIN SCREEN ========== */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; position: relative; z-index: 1;
}

.login-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow), 0 0 60px rgba(99,102,241,0.08);
  animation: fadeUp 0.5s ease;
}

.login-card .logo { text-align: center; margin-bottom: 32px; }
.login-card .logo h1 {
  font-size: 1.8rem; font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--info));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.login-card .logo p { color: var(--text-secondary); font-size: 0.9rem; margin-top: 6px; }

.login-error {
  background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3);
  color: var(--danger); padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 0.85rem; margin-bottom: 16px; display: none;
}

/* ========== FORMS ========== */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block; font-size: 0.8rem; font-weight: 500;
  color: var(--text-secondary); margin-bottom: 6px; text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%; padding: 12px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-size: 0.95rem; transition: var(--transition); outline: none;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-input::placeholder { color: var(--text-muted); }

select.form-input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-check { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.form-check input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 500;
  border: 1px solid transparent; transition: var(--transition);
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: white; border: none;
}
.btn-primary:hover { box-shadow: 0 4px 20px var(--accent-glow); transform: translateY(-1px); }
.btn-secondary { background: var(--bg-input); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--border-hover); background: var(--bg-card-hover); }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--danger); border-color: rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-success { background: rgba(16,185,129,0.15); color: var(--success); border-color: rgba(16,185,129,0.3); }
.btn-success:hover { background: rgba(16,185,129,0.25); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.btn-icon { padding: 8px; min-width: 36px; }

/* ========== APP LAYOUT ========== */
#app { display: none; position: relative; z-index: 1; }
#app.active { display: flex; min-height: 100vh; }

/* ========== SIDEBAR ========== */
#sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 24px 0; z-index: 100;
  transition: var(--transition);
}

.sidebar-logo {
  padding: 0 24px 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sidebar-logo h2 {
  font-size: 1.25rem; font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--info));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.sidebar-logo span { font-size: 0.75rem; color: var(--text-muted); }

.nav-section { padding: 8px 12px; }
.nav-section-title {
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text-muted);
  padding: 8px 12px 6px;
}

.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; margin: 2px 0;
  border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 0.9rem; font-weight: 400;
  transition: var(--transition); cursor: pointer; border: none;
  background: none; width: 100%; text-align: left;
}
.nav-link:hover { color: var(--text-primary); background: rgba(99,102,241,0.08); }
.nav-link.active { color: var(--accent-light); background: rgba(99,102,241,0.12); font-weight: 500; }
.nav-link .icon { font-size: 1.15rem; width: 24px; text-align: center; }

.sidebar-footer {
  margin-top: auto; padding: 16px 12px;
  border-top: 1px solid var(--border);
}
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 8px;
}
.sidebar-user .avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--info));
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 0.9rem; color: white; flex-shrink: 0;
}
.sidebar-user .user-info { overflow: hidden; }
.sidebar-user .user-name { font-size: 0.85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role { font-size: 0.7rem; color: var(--text-muted); }

/* ========== MAIN CONTENT ========== */
#content {
  margin-left: var(--sidebar-w); flex: 1;
  padding: 32px 36px; min-height: 100vh;
}

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px; flex-wrap: wrap; gap: 16px;
}
.page-header h1 { font-size: 1.6rem; font-weight: 700; }
.page-header p { color: var(--text-secondary); font-size: 0.9rem; margin-top: 4px; }
.page-actions { display: flex; gap: 10px; }

/* ========== CARDS ========== */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: var(--transition);
}
.card:hover { border-color: var(--border-hover); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 1rem; font-weight: 600; }

/* ========== STATS GRID ========== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card {
  background: var(--bg-card); backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 24px; transition: var(--transition);
}
.stat-card:hover { border-color: var(--border-hover); transform: translateY(-2px); }
.stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 8px; }
.stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }
.stat-value.danger { color: var(--danger); }

/* ========== SERVER STATUS CARDS ========== */
.server-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

.server-card {
  background: var(--bg-card); backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; transition: var(--transition);
  position: relative; overflow: hidden;
  display: flex; flex-direction: column;
}
.server-card:hover { border-color: var(--border-hover); transform: translateY(-2px); box-shadow: var(--shadow); }
.server-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.server-card.encendido::before { background: linear-gradient(90deg, var(--success), #34d399); }
.server-card.encendiendo::before { background: linear-gradient(90deg, var(--warning), #fbbf24); }
.server-card.apagado::before { background: linear-gradient(90deg, var(--danger), #f87171); }
.server-card.apagando::before { background: linear-gradient(90deg, #f97316, #fb923c); }

.server-name { font-size: 1.1rem; font-weight: 600; margin-bottom: 6px; }
.server-host { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 16px; font-family: monospace; }

.server-status { display: flex; align-items: center; gap: 10px; }
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
}
.status-dot.encendido { background: var(--success); box-shadow: 0 0 8px var(--success); animation: pulse 2s infinite; }
.status-dot.encendiendo { background: var(--warning); box-shadow: 0 0 8px var(--warning); animation: pulse 1.5s infinite; }
.status-dot.apagado { background: var(--danger); box-shadow: 0 0 8px var(--danger); animation: pulse 2.5s infinite; }
.status-dot.apagando { background: #f97316; box-shadow: 0 0 8px #f97316; animation: pulse 1s infinite; }

.status-text { font-size: 0.85rem; font-weight: 500; text-transform: capitalize; }
.server-checked { font-size: 0.7rem; color: var(--text-muted); margin-top: 12px; }

/* ========== SERVER POWER CONTROLS ========== */
.server-power-controls {
  display: flex; gap: 6px; margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(99,102,241,0.1);
}
.btn-power {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 7px 10px; border-radius: 8px;
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.3px;
  border: 1px solid transparent; transition: var(--transition);
  position: relative; overflow: hidden; white-space: nowrap;
}
.btn-power svg { width: 13px; height: 13px; flex-shrink: 0; }
.btn-power:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; }

.btn-power-on {
  background: rgba(16,185,129,0.1);
  color: var(--success);
  border-color: rgba(16,185,129,0.25);
}
.btn-power-on:hover:not(:disabled) {
  background: rgba(16,185,129,0.2);
  border-color: rgba(16,185,129,0.5);
  box-shadow: 0 0 14px rgba(16,185,129,0.2);
  transform: translateY(-1px);
}
.btn-power-off {
  background: rgba(239,68,68,0.08);
  color: var(--danger);
  border-color: rgba(239,68,68,0.2);
}
.btn-power-off:hover:not(:disabled) {
  background: rgba(239,68,68,0.18);
  border-color: rgba(239,68,68,0.45);
  box-shadow: 0 0 14px rgba(239,68,68,0.18);
  transform: translateY(-1px);
}
.btn-power-restart {
  background: rgba(245,158,11,0.08);
  color: var(--warning);
  border-color: rgba(245,158,11,0.2);
}
.btn-power-restart:hover:not(:disabled) {
  background: rgba(245,158,11,0.18);
  border-color: rgba(245,158,11,0.45);
  box-shadow: 0 0 14px rgba(245,158,11,0.18);
  transform: translateY(-1px);
}
.btn-power.sending {
  pointer-events: none;
  opacity: 0.6;
}

/* ========== WOL SECTION ========== */
.wol-section { margin-top: 28px; }
.wol-card {
  background: linear-gradient(135deg, rgba(99,102,241,0.1), rgba(6,182,212,0.08));
  border: 1px solid rgba(99,102,241,0.2); border-radius: var(--radius);
  padding: 32px; text-align: center;
}
.wol-card h3 { font-size: 1.2rem; margin-bottom: 8px; }
.wol-card p { color: var(--text-secondary); margin-bottom: 24px; font-size: 0.9rem; }
.btn-wol {
  padding: 16px 48px; font-size: 1.05rem; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: white; border: none; border-radius: var(--radius);
  transition: var(--transition); position: relative; overflow: hidden;
}
.btn-wol:hover { box-shadow: 0 8px 32px var(--accent-glow); transform: translateY(-2px); }
.btn-wol:active { transform: translateY(0); }
.btn-wol.loading { pointer-events: none; opacity: 0.7; }

/* ========== TABLE ========== */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 14px 16px; text-align: left;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted);
  background: var(--bg-secondary); border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 14px 16px; font-size: 0.9rem;
  border-bottom: 1px solid rgba(99,102,241,0.06);
  vertical-align: middle;
}
tbody tr { transition: var(--transition); }
tbody tr:hover { background: rgba(99,102,241,0.04); }
tbody tr:last-child td { border-bottom: none; }

.badge {
  display: inline-flex; align-items: center; padding: 4px 10px;
  border-radius: 20px; font-size: 0.75rem; font-weight: 500;
}
.badge-success { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-info { background: rgba(99,102,241,0.15); color: var(--accent-light); }

.actions-cell { display: flex; gap: 6px; }

/* ========== PAGINATION ========== */
.pagination { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 20px; }
.pagination button {
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text-secondary); font-size: 0.85rem; transition: var(--transition);
}
.pagination button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-light); }
.pagination button.active { background: var(--accent); color: white; border-color: var(--accent); }
.pagination span { color: var(--text-muted); font-size: 0.85rem; }

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 16px; width: 100%; max-width: 500px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
  transform: translateY(20px) scale(0.97);
  transition: transform 0.25s ease;
  max-height: 90vh; overflow-y: auto;
}
.modal-overlay.active .modal { transform: translateY(0) scale(1); }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-close {
  width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: none; color: var(--text-muted);
  font-size: 1.3rem; display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.modal-close:hover { background: rgba(239,68,68,0.15); color: var(--danger); }

.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ========== TOAST ========== */
#toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 2000;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  padding: 14px 20px; border-radius: var(--radius-sm);
  font-size: 0.9rem; min-width: 280px; max-width: 420px;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  display: flex; align-items: center; gap: 10px;
  backdrop-filter: blur(12px);
}
.toast.success { background: rgba(16,185,129,0.2); border: 1px solid rgba(16,185,129,0.3); color: var(--success); }
.toast.error { background: rgba(239,68,68,0.2); border: 1px solid rgba(239,68,68,0.3); color: var(--danger); }
.toast.info { background: rgba(99,102,241,0.2); border: 1px solid rgba(99,102,241,0.3); color: var(--accent-light); }
.toast.fadeOut { animation: slideOut 0.3s ease forwards; }

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.95rem; }

.hidden { display: none !important; }

/* ========== TOOLBAR ========== */
.toolbar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.toolbar .form-input { max-width: 200px; padding: 8px 12px; font-size: 0.85rem; }

/* ========== SPINNER ========== */
.spinner { width: 20px; height: 20px; border: 2px solid rgba(255,255,255,0.3); border-top-color: white; border-radius: 50%; animation: spin 0.6s linear infinite; }

/* ========== ANIMATIONS ========== */
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(80px); } to { opacity: 1; transform: translateX(0); } }
@keyframes slideOut { to { opacity: 0; transform: translateX(80px); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.page-enter { animation: fadeUp 0.35s ease; }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  #sidebar { transform: translateX(-100%); width: 260px; box-shadow: 4px 0 24px rgba(0,0,0,0.5); }
  #sidebar.open { transform: translateX(0); }
  #content { padding: 72px 16px 20px; margin-left: 0; }
  .mobile-toggle { display: flex !important; }
  .form-row { grid-template-columns: 1fr; }
  .server-grid { grid-template-columns: 1fr; }
  .modal { width: 92%; margin: 0 4%; }
  .page-header h1 { font-size: 1.4rem; }
  .stat-card { padding: 16px; }
  .table-wrapper { font-size: 0.85rem; }
}

.mobile-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px); z-index: 99; opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.mobile-overlay.active { opacity: 1; pointer-events: auto; }

.mobile-toggle {
  display: none !important; position: fixed; top: 16px; left: 16px; z-index: 101;
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  background: var(--bg-secondary); border: 1px solid var(--border);
  color: var(--text-primary); font-size: 1.2rem;
  align-items: center; justify-content: center;
}
