/* =========================================================
   1. VARIABLES & TOKENS (TEMA PROFESIONAL)
========================================================= */
:root {
  /* Dimensiones Compactas */
  --radius: 10px;
  --radius-lg: 16px;
  --radius-pill: 50px;
  
  --sidebar-width: 260px;
  --panel-width: 400px; 
  --header-height: 64px;

  /* --- TEMA CLARO (Rojo Perú) --- */
  --bg-app: #f4f6f9;       /* Gris muy suave */
  --bg-panel: #ffffff;     /* Blanco */
  --border-color: #e2e8f0; 
  
  --input-bg: #f8fafc;
  --input-border: #cbd5e1;
  
  --text-main: #1e293b;
  --text-muted: #64748b;
  
  --brand-color: #dc2626;  /* Rojo Intenso */
  --brand-glow: rgba(220, 38, 38, 0.15); 
  
  /* Sombras Suaves */
  --shadow-card: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
  --shadow-float: 0 10px 25px -5px rgba(0,0,0,0.1);
  --shadow-panel: -5px 0 25px rgba(0,0,0,0.05);
}

/* --- TEMA OSCURO (GRIS PROFUNDO / CHARCOAL) --- */
body[data-theme="dark"] {
  --bg-app: #121212;       /* Negro Mate */
  --bg-panel: #1e1e1e;     /* Gris Oscuro */
  --border-color: #333333; /* Bordes sutiles */
  
  --input-bg: #252525;
  --input-border: #404040;
  
  --text-main: #e5e7eb;    /* Blanco Humo */
  --text-muted: #a1a1aa;

  /* Rojo suave para contraste en oscuro */
  --brand-color: #f87171;  
  --brand-glow: rgba(248, 113, 113, 0.2);
  
  --shadow-card: 0 4px 6px -1px rgba(0,0,0,0.5);
  --shadow-float: 0 10px 20px -5px rgba(0,0,0,0.7);
  --shadow-panel: -5px 0 25px rgba(0,0,0,0.8);
}

/* =========================================================
   2. PANTALLA DE CARGA (LOADER ANIMADO)
========================================================= */
#global-loader {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background-color: var(--bg-app); z-index: 99999;
  display: flex; justify-content: center; align-items: center;
  
  /* Transición suave para coincidir con el JS */
  transition: opacity 0.2s ease-out, visibility 0.2s;
  
  opacity: 1; visibility: visible;
}
#global-loader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

/* Animación pulsante del logo */
.loader-logo {
  width: 70px; height: 70px; object-fit: contain;
  animation: pulse-logo 1.5s infinite ease-in-out;
}
@keyframes pulse-logo { 
  0% { transform: scale(1); opacity: 1; } 
  50% { transform: scale(1.1); opacity: 0.8; } 
  100% { transform: scale(1); opacity: 1; } 
}

/* =========================================================
   3. ESTRUCTURA GLOBAL
========================================================= */
* { box-sizing: border-box; }

body { 
  margin: 0; font-family: 'Inter', system-ui, -apple-system, sans-serif; 
  background-color: var(--bg-app); color: var(--text-main); 
  height: 100vh; overflow: hidden; font-size: 13px;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.app {
  display: grid;
  /* Sidebar | Contenido | Panel Derecho (Empieza cerrado 0px) */
  grid-template-columns: var(--sidebar-width) 1fr 0px; 
  grid-template-rows: 100vh;
  
  /* Animación de apertura del panel */
  transition: grid-template-columns 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
  width: 100%;
}

/* Estado: Panel Abierto */
.app.panel-open {
  grid-template-columns: var(--sidebar-width) 1fr var(--panel-width);
}

/* =========================================================
   4. SIDEBAR & LOGO ANIMADO
========================================================= */
.sidebar {
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex; flex-direction: column; padding: 20px; z-index: 20;
  overflow: hidden; 
}

/* Caja de la Marca */
.brand { 
  display: flex; align-items: center; gap: 12px; 
  padding-bottom: 20px; margin-bottom: 20px; 
  border-bottom: 1px solid var(--border-color);
  
  /* Preparar animación */
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: default;
  border-radius: var(--radius);
  padding: 12px; margin-left: -12px; margin-right: -12px;
  border: 1px solid transparent;
}

.brand img { 
  width: 36px; height: 36px; object-fit: contain; 
  transition: transform 0.4s ease;
}

/* Efecto Hover: Logo salta y gira */
.brand:hover {
  background-color: var(--bg-app);
  border-color: var(--border-color);
  transform: translateX(5px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.brand:hover img { transform: scale(1.2) rotate(-10deg); filter: drop-shadow(0 0 5px var(--brand-glow)); }
.brand:hover .brand-name { color: var(--brand-color); }

.brand-name { font-weight: 800; font-size: 14px; text-transform: uppercase; transition: color 0.3s; }

/* Navegación */
.nav { flex: 1; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav-item { 
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; 
  border-radius: 6px; color: var(--text-muted); text-decoration: none; 
  font-weight: 600; transition: .2s; border: 1px solid transparent;
}
.nav-item:hover { background-color: var(--bg-app); color: var(--text-main); }
.nav-item.active { 
  background-color: var(--brand-glow); 
  color: var(--brand-color); 
  border-color: var(--brand-color); 
}

.theme-wrap-bottom { margin-top: auto; padding-top: 15px; border-top: 1px solid var(--border-color); }
.theme-toggle { 
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; 
  padding: 8px; border: 1px solid var(--border-color); background: var(--bg-app); 
  border-radius: 6px; cursor: pointer; color: var(--text-main); font-weight: 700; transition: .2s;
}
.theme-toggle:hover { border-color: var(--brand-color); color: var(--brand-color); }

/* =========================================================
   5. MAIN CONTENT
========================================================= */
.main {
  display: flex; flex-direction: column;
  background-color: var(--bg-app);
  height: 100vh; overflow: hidden;
  border-right: 1px solid var(--border-color);
  min-width: 0; 
}

.top-bar {
  height: var(--header-height); background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 25px; flex-shrink: 0;
}
.page-title { font-size: 20px; font-weight: 800; margin: 0; }

.content-area { flex: 1; padding: 25px; overflow: hidden; display: flex; flex-direction: column; }

.compact-view { max-width: 850px; margin: 0 auto; width: 100%; overflow-y: auto; padding-bottom: 50px; }

.card {
  background: var(--bg-panel); border: 1px solid var(--border-color);
  border-radius: var(--radius); box-shadow: var(--shadow-card);
  padding: 30px; margin-bottom: 20px; overflow: hidden;
}

/* =========================================================
   6. TABLA COMPACTA (LISTA DE ALUMNOS)
========================================================= */
.table-container {
  flex: 1; background: var(--bg-panel);
  border: 1px solid var(--border-color); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
  box-shadow: var(--shadow-card);
}
.table-scroll { overflow: auto; flex: 1; }

table { width: 100%; border-collapse: collapse; white-space: nowrap; }

thead th { 
  position: sticky; top: 0; z-index: 10; 
  background-color: var(--bg-app); color: var(--text-muted); 
  font-size: 10px; font-weight: 800; text-transform: uppercase; 
  padding: 12px 20px; text-align: left; border-bottom: 1px solid var(--border-color); 
}

tbody td { 
  padding: 10px 20px; /* Filas delgadas */
  border-bottom: 1px solid var(--border-color); 
  color: var(--text-main); font-size: 13px; vertical-align: middle; 
}
tbody td img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border-color); display: block; }

/* Animación de filas */
tbody tr { transition: transform 0.2s, background-color 0.2s; cursor: pointer; }
tbody tr:hover { 
  background-color: var(--bg-app); 
  transform: scale(1.005) translateX(4px); /* Se mueve un poco */
  box-shadow: var(--shadow-float); z-index: 5; position: relative; border-radius: 4px;
}
tbody tr.selected { background-color: var(--brand-glow); border-left: 4px solid var(--brand-color); }

.table-frame { 
  background: var(--bg-panel); border: 1px solid var(--border-color); 
  border-radius: var(--radius); box-shadow: var(--shadow-card); 
  padding: 5px; overflow: hidden; 
}

/* =========================================================
   7. RIGHT PANEL (PANEL DESLIZANTE)
========================================================= */
.right-panel {
  background-color: var(--bg-panel);
  display: flex; flex-direction: column;
  height: 100vh; 
  
  /* Oculto por defecto */
  width: 0; min-width: 0; overflow: hidden; opacity: 0; visibility: hidden;
  
  transition: width 0.4s ease, opacity 0.3s ease, visibility 0.3s;
  box-shadow: -5px 0 20px rgba(0,0,0,0.05);
  position: relative; z-index: 30; border-left: 1px solid var(--border-color);
}
.app.panel-open .right-panel { width: 400px; opacity: 1; visibility: visible; }

.panel-header {
  height: var(--header-height); border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; flex-shrink: 0; background: var(--bg-panel);
}
.btn-close { cursor: pointer; font-size: 24px; color: var(--text-muted); background: none; border: none; }
.btn-close:hover { color: var(--brand-color); }
.panel-content { flex: 1; overflow-y: auto; padding: 25px; width: 400px; }

/* =========================================================
   8. COMPONENTES UI
========================================================= */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.field-full { grid-column: 1 / -1; }

label { display: block; font-size: 10px; font-weight: 800; margin-bottom: 5px; color: var(--text-muted); text-transform: uppercase; }
input:not([type="file"]), select {
  width: 100%; padding: 10px 14px; border-radius: var(--radius);
  background: var(--input-bg); border: 1px solid var(--input-border);
  color: var(--text-main); font-weight: 500; outline: none; transition: .2s; font-size: 13px;
}
input:focus, select:focus { border-color: var(--brand-color); box-shadow: 0 0 0 3px var(--brand-glow); }

.search-input { width: 100%; max-width: 350px; padding: 10px 18px; border-radius: var(--radius-pill); box-shadow: var(--shadow-card); }

/* Botones */
.btn { 
  display: inline-flex; align-items: center; justify-content: center; 
  padding: 10px 20px; border-radius: 6px; font-weight: 700; 
  text-decoration: none; border: none; cursor: pointer; transition: .2s; font-size: 12px; 
}
.btn:hover { transform: translateY(-2px); }
.btn-primary { background: var(--brand-color); color: #fff !important; }
.btn-dark { background: var(--bg-app); border: 1px solid var(--border-color); color: var(--text-main); }
.btn-secondary { background: var(--bg-panel); border: 1px solid var(--brand-color); color: var(--brand-color); }
.btn-danger { background: #ef4444; color: #fff; }
.btn-success { background: #22c55e; color: #fff; }

.status-pill { padding: 3px 12px; border-radius: 50px; font-size: 10px; font-weight: 800; text-transform: uppercase; border: 1px solid transparent; display: inline-block; }
.status-pill.active { background: rgba(34, 197, 94, 0.1); color: #16a34a; border-color: #16a34a; }
.status-pill.inactive { background: rgba(239, 68, 68, 0.1); color: #ef4444; border-color: #ef4444; }
.code-badge { background: var(--brand-glow); color: var(--brand-color); padding: 4px 8px; border-radius: 6px; font-weight: 800; font-size: 11px; }

/* Dashboard Cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 30px; }
.stat-card { background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 20px; display: flex; align-items: center; gap: 15px; box-shadow: var(--shadow-card); transition: transform 0.2s; }
.stat-card:hover { transform: translateY(-3px); }
.stat-icon { width: 48px; height: 48px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.stat-info h3 { margin: 0; font-size: 22px; font-weight: 900; color: var(--text-main); }
.stat-info p { margin: 0; font-size: 10px; text-transform: uppercase; font-weight: 700; color: var(--text-muted); }
.s-green { background: rgba(16, 185, 129, 0.1); color: #10b981; }
.s-blue  { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }
.s-orange{ background: rgba(249, 115, 22, 0.1); color: #f97316; }
.s-red   { background: rgba(239, 68, 68, 0.1); color: #ef4444; }

/* Detalles */
.details-header-flex { display: flex; gap: 25px; align-items: flex-start; }
.img-container { width: 120px; height: 120px; flex-shrink: 0; border-radius: var(--radius-lg); border: 3px solid var(--border-color); background: var(--bg-app); overflow: hidden; }
.img-container img { width: 100%; height: 100%; object-fit: cover; }
.info-container { flex: 1; width: 100%; }
.detail-card { background: var(--bg-app); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 15px; margin-bottom: 15px; }
.detail-label { font-size: 10px; color: var(--text-muted); font-weight: 800; text-transform: uppercase; display: block; margin-bottom: 4px; }
.detail-value { font-size: 13px; color: var(--text-main); font-weight: 600; }

@media (max-width: 1024px) { .app.panel-open { grid-template-columns: 60px 1fr 350px; } }
@media (max-width: 768px) {
  body { overflow: auto !important; height: auto !important; }
  .app { display: block !important; height: auto !important; overflow: visible !important; }
  .sidebar { width: 100%; height: auto; position: relative; }
  .main { height: auto; overflow: visible; display: block !important; }
  .content-area { overflow: visible !important; height: auto !important; padding-bottom: 80px; }
  .right-panel { display: none !important; }
  .stats-grid, .form-grid { grid-template-columns: 1fr !important; }
  .details-header-flex { flex-direction: column; text-align: center; }
}