/* ===== Reset básico ===== */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', Arial, sans-serif;
  background-color: #f8f9f9;
  color: #222;
}
img { display: block; max-width: 100%; height: auto; }

/* ===== Barra lateral ===== */
.sidebar {
  width: 250px;
  background-color: #1B365D;
  color: #fff;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  padding: 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar h2 {
  text-align: center;
  margin: 10px 0 16px;
  font-size: 18px;
}
.sidebar .logo {
  text-align: center;
  margin-bottom: 16px;
}
.sidebar .logo img {
  max-width: 180px;
  height: auto;
  margin: 0 auto;
}
.sidebar a {
  display: block;
  color: #fff;
  padding: 10px;
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.2s;
}
.sidebar a:hover { background-color: #0f2442; }
.sidebar .logout { margin-top: auto; }
.sidebar .logout a {
  background-color: #419a4b;
  text-align: center;
  font-weight: bold;
  padding: 12px;
}
.sidebar .logout a:hover { background-color: #1B365D; }

/* 1. Ajuste para pantallas grandes (Escritorio) */
.main-content {
    margin-left: 260px; /* Ancho de tu menú */
    transition: 0.3s;
}

/* ===== Sidebar Móvil (drawer deslizable) ===== */
.sidebar-movil {
    position: fixed;
    top: 0;
    left: -290px;
    width: 280px;
    height: 100vh;
    background-color: #1B365D;
    z-index: 9999;
    overflow-y: auto;
    overflow-x: hidden;
    transition: left 0.3s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}
.sidebar-movil.active {
    left: 0;
}

/* Overlay oscuro detrás del drawer */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active {
    display: block;
}

/* Links del menú móvil */
.nav-movil {
    display: flex;
    flex-direction: column;
    padding: 8px 0 24px;
    flex: 1;
}
.nav-movil a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    padding: 12px 20px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
    border-left: 3px solid transparent;
}
.nav-movil a:hover,
.nav-movil a:active {
    background-color: rgba(255, 255, 255, 0.12);
    border-left-color: #4da3ff;
}
.nav-movil a i {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    font-size: 15px;
}
.menu-separator {
    font-size: 10px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.45);
    margin: 16px 20px 4px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}
.nav-movil .menu-resaltado {
    background: rgba(52, 152, 219, 0.15);
    border-left: 3px solid #3498db !important;
}
.nav-movil .card-salir {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 16px;
    padding: 12px 16px;
    background: rgba(231, 76, 60, 0.15);
    border: 1px solid rgba(231, 76, 60, 0.4);
    border-radius: 8px;
    color: #e74c3c !important;
    font-weight: 600;
    text-decoration: none;
    font-size: 14px;
    transition: background 0.2s;
}
.nav-movil .card-salir:hover {
    background: rgba(231, 76, 60, 0.3);
    border-left-color: #e74c3c !important;
}

/* Header fijo en móvil */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: #1B365D;
    z-index: 9997;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.menu-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 6px;
    line-height: 1;
    flex-shrink: 0;
    transition: background 0.2s;
}
.menu-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* 2. Ajustes para Móviles y Tablets */
@media (max-width: 768px) {
    .sidebar {
        display: none !important;
    }
    .mobile-header {
        display: flex !important;
    }
    .main-content {
        margin-left: 0 !important;
        margin-top: 56px;
        padding: 16px;
    }
}

@media (min-width: 769px) {
    .mobile-header,
    .sidebar-movil,
    .sidebar-overlay {
        display: none !important;
    }
    .menu-btn {
        display: none;
    }
}

/* ===== Colapso del sidebar en escritorio (aprovechar la pantalla) ===== */
.sidebar { transition: transform 0.25s ease; }
.main-content { transition: margin-left 0.25s ease; }
.sidebar-collapse-btn {
    display: none;
    position: fixed;
    top: 18px;
    left: 234px;
    z-index: 1001;
    width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--sidebar-bg, #1B365D);
    color: #fff;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    font-size: 12px;
    padding: 0;
    transition: left 0.25s ease, filter 0.2s;
}
.sidebar-collapse-btn:hover { filter: brightness(1.2); }
.sidebar-collapse-btn i { transition: transform 0.25s ease; }
body.sidebar-collapsed .sidebar { transform: translateX(-250px); }
body.sidebar-collapsed .main-content { margin-left: 0 !important; }
body.sidebar-collapsed .sidebar-collapse-btn { left: 14px; }
body.sidebar-collapsed .sidebar-collapse-btn i { transform: rotate(180deg); }

@media (min-width: 769px) {
    .sidebar-collapse-btn { display: flex; }
}

/* ===== Contenido principal ===== */
.main-content {
  margin-left: 250px;
  padding: 30px;
}
.main-content h1 {
  margin-bottom: 20px;
  color: #1B365D;
}

/* ===== Tarjetas unificadas ===== */
.card {
  background: #fff;
  padding: 22px;
  border-radius: 12px;
  text-align: left;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transition: transform 0.2s, box-shadow 0.2s;
}
.card h2 {
  margin: 0 0 14px 0;
  color: #003366;
  font-size: 20px;
}
.card h3 {
  margin: 10px 0;
  color: #003366;
}
.card p {
  font-size: 14px;
  color: #555;
  margin-bottom: 15px;
}

/* ===== Campos unificados ===== */
.field {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
}

.field label {
  display: block;
  font-weight: bold;
  margin-bottom: 6px;
}

/* Campos de texto y spans */
.field input,
.field select,
.field textarea,
.field span {
  width: 100%;
  padding: 12px;
  border: 1px solid #ccd3da;
  border-radius: 8px;
  background: #fff;
  display: block;
  box-sizing: border-box;
}

/* Inputs readonly */
.field input[readonly] {
  background: #f1f1f1;
  cursor: default;
}

/* Campos de carga de documentos */
.field input[type="file"] {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccd3da;
  border-radius: 6px;
  background: #f9f9f9;
  box-sizing: border-box;
}

/* Enlaces de documentos */
.field a {
  display: block;
  width: 100%;
  padding: 12px;
  border: 1px solid #ccd3da;
  border-radius: 8px;
  background: #f9f9f9;
  text-align: center;
  text-decoration: none;
  color: #005baa;
  box-sizing: border-box;
}

/* ===== Grids unificados ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 25px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
}

.docs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

/* ===== Botones unificados ===== */
.btn,
.save-btn {
  /* 1. Mantenemos tus bases */
  background: #003366;
  color: #fff !important; /* Fuerza el texto a blanco */
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  text-decoration: none;

  /* 2. EL COMANDO DE ALINEACIÓN (Flexbox) */
  display: inline-flex;    /* Alinea el botón con otros elementos */
  align-items: center;     /* Centra el icono y el texto verticalmente */
  justify-content: center; /* Centra el contenido horizontalmente */
  gap: 10px;               /* Espacio exacto entre el icono y el texto */
}

/* 3. ARREGLO PARA EL ICONO (Si se ve azul o pequeño) */
.btn i,
.save-btn i {
  color: #fff !important;  /* Obliga al icono a ser blanco */
  margin-top: 12px;          /* Ajusta la posición vertical del icono */   
  font-size: 1.2em;          /* Ajusta un poco el tamaño para que luzca PRO */
  display: flex;             /* Quita espacios fantasmas debajo del icono */
}

/* ===== Alertas ===== */
.alert {
  background: #eef;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
}

/* ===== Dashboard ===== */
.dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 25px;
}
.card a {
  color: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}
.card a:hover i,
.card a:hover h3 {
  color: #005599;
}
.card i {
  margin-bottom: 15px;
  color: #003366;
}

/* ===== Responsivo ===== */
@media (max-width: 1100px) {
  .dashboard { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 680px) {
  .dashboard { grid-template-columns: 1fr; }
  .main-content { padding: 20px; }
}

/* ===== Tarjeta del buscador ===== */
.search-card {
  width: 100%;
  background: #ffffff;
  padding: 25px;
  margin: 25px 0;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  border-left: 4px solid #007bff;
}
.search-card h2 {
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 22px;
  color: #333;
}

/* ===== Formulario de búsqueda ===== */
.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  align-items: center;
}
.search-form input[type="text"],
.search-form select {
  padding: 10px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 15px;
  flex: 1;
  min-width: 200px;
}
.search-form button {
  padding: 10px 20px;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
}
.search-form button:hover {
  background: #005fcc;
}

/* ===== Tabla de resultados ===== */
.resultados-usuarios {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.resultados-usuarios th {
  background: #f5f5f5;
  padding: 12px;
  text-align: left;
  font-weight: 600;
}
.resultados-usuarios td {
  padding: 12px;
  border-bottom: 1px solid #eee;
}
.resultados-usuarios tr:hover {
  background: #f0f8ff;
}
.resultados-usuarios td a {
  margin-right: 10px;
  color: #007bff;
  text-decoration: none;
  font-weight: bold;
}
.resultados-usuarios td a:hover {
  text-decoration: underline;
}

/* ===== Banner de edición global ===== */
.edit-banner {
  background: #fff3cd;
  border-left: 4px solid #ffca2c;
  padding: 15px 20px;
  margin-bottom: 25px;
  border-radius: 8px;
  font-size: 16px;

  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.edit-banner .edit-info {
  font-size: 16px;
  color: #664d03;
}
.edit-banner .edit-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.edit-banner .exit-edit {
  background: #dc3545;
  color: white;
  padding: 8px 14px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: bold;
}
.edit-banner .exit-edit:hover {
  background: #b02a37;
}

.menu-resaltado {
    border-left: 4px solid #00a859;
    padding-left: 10px;
    font-weight: bold;
    color: #ffffff !important;
}
.menu-resaltado:hover {
    border-left-color: #0055cc;
}

/* ===== Sección de descarga de apps móviles ===== */
.app-buttons {
    display: flex;
    gap: 20px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.app-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f5f5f5;
    padding: 12px 18px;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s ease;
    border: 1px solid #ddd;
}

.app-btn:hover {
    background: #e9e9e9;
}

.app-logo {
    height: 40px;
    width: auto;
}

/* ===== Botones de acción ===== */
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #005baa;
    color: #fff !important;
    padding: 10px 16px;
    border-radius: 6px;
    font-weight: 600;
    text-decoration: none;
    transition: 0.2s ease;
}

.action-btn i {
    color: #fff !important;
}

.action-btn:hover {
    background: #004a94;
}

/* ================================================= */
/* CONFIGURACIÓN DE TEMAS (UNIFICADO)               */
/* ================================================= */

:root {
    --bg-body: #f8f9f9;
    --bg-card: #ffffff;
    --text-main: #222222;
    --text-muted: #555555;
    --border-color: #ccd3da;
    --sidebar-bg: #1B365D;
    --accent-color: #003366;
    --input-bg: #ffffff;
    --input-readonly: #f1f1f1;
}

body.tema-oscuro {
    --bg-body: #121212;
    --bg-card: #1e1e1e;
    --text-main: #e0e0e0;
    --text-muted: #aaaaaa;
    --border-color: #333333;
    --sidebar-bg: #000000;
    --accent-color: #3498db;
    --input-bg: #2a2a2a;
    --input-readonly: #121212;
}

/* Redefinición de elementos para que usen las variables */
body {
    background-color: var(--bg-body);
    color: var(--text-main);
}

.main-content h1 { color: var(--sidebar-bg); }
body.tema-oscuro .main-content h1 { color: var(--accent-color); }

.card {
    background-color: var(--bg-card) !important;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.card h2, .card h3 { color: var(--accent-color); }

.card-salir {
    background-color: #06671c !important;
    color: #ffffff !important;
    margin-bottom: 10px;
}

/* Campos e Inputs */
.field input, .field select, .field textarea, .field span {
    background-color: var(--input-bg) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border-color);
}

.field input[readonly] {
    background-color: var(--input-readonly) !important;
}

.field label { color: var(--text-main); }

/* Barra Lateral */
.sidebar { background-color: var(--sidebar-bg); }

/* Tablas */
.resultados-usuarios {
    background-color: var(--bg-card);
    color: var(--text-main);
}
.resultados-usuarios th {
    background-color: var(--input-readonly);
    color: var(--text-main);
}
.resultados-usuarios td { border-bottom: 1px solid var(--border-color); }
body.tema-oscuro .resultados-usuarios tr:hover { background: #252525; }

/* Color base: Rojo (0% a 39%) */
.barra-progreso-dinamica {
    background-color: #ff4d4d !important;
}

/* Color Amarillo/Naranja (40% a 79%) */
/* Detecta si el estilo empieza con width: 4, 5, 6 o 7 */
.barra-progreso-dinamica[style*="width: 4"],
.barra-progreso-dinamica[style*="width: 5"],
.barra-progreso-dinamica[style*="width: 6"],
.barra-progreso-dinamica[style*="width: 7"] {
    background-color: #f39c12 !important;
}

/* Color Verde (80% a 100%) */
.barra-progreso-dinamica[style*="width: 8"],
.barra-progreso-dinamica[style*="width: 9"],
.barra-progreso-dinamica[style*="width: 100"] {
    background-color: #27ae60 !important;
}

/* ================================
   BOTONES FINANCIEROS
   ================================ */
.finance-btn {
    background: #2c7be5;
    color: white;
    padding: 10px 18px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
    border-radius: 40px !important;
    padding: 10px 24px;
}

.finance-btn:hover {
    background: #1a5fc4;
}

/* ================================================
   MODO OSCURO — COBERTURA GLOBAL AMPLIADA
   Aplica a todos los elementos que no usan vars
   ================================================ */

/* Inputs / selects / textareas sin clase .field */
body.tema-oscuro input,
body.tema-oscuro select,
body.tema-oscuro textarea {
    background-color: var(--input-bg) !important;
    color: var(--text-main) !important;
    border-color: var(--border-color) !important;
}

/* Código monoespaciado */
body.tema-oscuro code {
    background-color: #2a2a2a;
    color: #80cbc4;
    padding: 1px 5px;
    border-radius: 4px;
}

/* Tablas genéricas */
body.tema-oscuro th {
    background-color: var(--input-readonly) !important;
    color: var(--text-main) !important;
    border-color: var(--border-color) !important;
}
body.tema-oscuro td {
    color: var(--text-main);
    border-color: var(--border-color) !important;
}
body.tema-oscuro tr:hover td {
    background-color: #252525 !important;
}

/* Finance table */
body.tema-oscuro .finance-table {
    background-color: var(--bg-card);
    color: var(--text-main);
}
body.tema-oscuro .finance-table th,
body.tema-oscuro .finance-table td {
    border-color: var(--border-color) !important;
}

/* Tarjetas de dashboard (card-kpi, chart-box) */
body.tema-oscuro .card-kpi {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border-color);
}
body.tema-oscuro .chart-box {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border-color);
}

/* Formulario de búsqueda en header-flex */
body.tema-oscuro .header-flex form {
    background-color: var(--bg-card) !important;
    border: 1px solid var(--border-color);
}

/* Alertas de edición */
body.tema-oscuro .edit-banner {
    background-color: #2a2000 !important;
    color: #f5d77e !important;
    border-left-color: #f39c12 !important;
}

/* Alertas de Moodle / info */
body.tema-oscuro .moodle-alert {
    background: #1a0d00 !important;
    border-color: #6b3a00 !important;
    color: #f5a623 !important;
}

/* Alertas de éxito / error con fondo fijo */
body.tema-oscuro [style*="background:#d4edda"],
body.tema-oscuro [style*="background: #d4edda"] {
    background: #0d2e14 !important;
    color: #a3d9a5 !important;
}
body.tema-oscuro [style*="background:#f8d7da"],
body.tema-oscuro [style*="background: #f8d7da"] {
    background: #2e0d0d !important;
    color: #f5a5a5 !important;
}

/* Scroll de la sidebar en oscuro */
body.tema-oscuro .sidebar {
    scrollbar-color: #444 #121212;
}

/* h4 y small dentro de main-content */
body.tema-oscuro .main-content h4 { color: var(--accent-color); }
body.tema-oscuro .main-content small { color: var(--text-muted); }
