/* ============================================================
   SABER Analytics - Hoja de Estilos Principal
   Fuente: Montserrat | Diseño profesional responsive
   ============================================================ */

:root {
  --primary: #1A3C5E;
  --primary-light: #2a5280;
  --accent: #00C9A7;
  --accent-dark: #00a88c;
  --bg: #F0F4F8;
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --white: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --card-shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
  --radius: 14px;
  --radius-sm: 8px;

  /* Niveles */
  --ins: #E74C3C;
  --min: #E67E22;
  --sat: #F1C40F;
  --avz: #27AE60;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Montserrat', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

/* ============================================================ SIDEBAR */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--primary);
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  pointer-events: auto;
  -webkit-overflow-scrolling: touch;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 4px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
}
.brand-icon {
  width: 42px; height: 42px;
  background: linear-gradient(135deg, var(--accent), #00a88c);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.2rem;
  flex-shrink: 0;
}
.brand-logo { width: 42px; height: 42px; border-radius: 10px; object-fit: contain; flex-shrink: 0; }
.brand-name { display: block; color: #fff; font-size: .92rem; font-weight: 700; line-height: 1.2; }
.brand-sub { display: block; color: var(--accent); font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }

.sidebar-user {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px;
  background: rgba(255,255,255,.05);
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.user-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #0099ff);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: .85rem; font-weight: 700;
  flex-shrink: 0;
}
.user-name { display: block; color: #fff; font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; color: var(--accent); font-size: .65rem; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.user-info { overflow: hidden; }

.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-section { padding: 8px 0; }
.nav-section-label {
  display: block; padding: 4px 20px 6px;
  color: rgba(255,255,255,.4);
  font-size: .62rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1.5px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 20px;
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: .84rem; font-weight: 500;
  transition: all .2s;
  border-left: 3px solid transparent;
  position: relative;
  min-height: 44px;
  touch-action: manipulation;
}
.nav-item i { width: 18px; text-align: center; font-size: .9rem; flex-shrink: 0; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.08); border-left-color: rgba(255,255,255,.3); }
.nav-item.active { color: #fff; background: rgba(0,201,167,.15); border-left-color: var(--accent); font-weight: 600; }
.nav-item.active i { color: var(--accent); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
}
.btn-logout {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 14px;
  background: rgba(231,76,60,.15);
  color: #fc8a7d; border: 1px solid rgba(231,76,60,.2);
  border-radius: var(--radius-sm); text-decoration: none;
  font-size: .82rem; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: all .2s;
}
.btn-logout:hover { background: rgba(231,76,60,.25); color: #fff; }

/* ============================================================ MAIN */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1; min-height: 100vh;
  display: flex; flex-direction: column;
  transition: margin .3s;
}
.main-content.expanded {
  margin-left: 0;
}
.sidebar.collapsed {
  transform: translateX(-100%);
}
.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .sidebar-user,
.sidebar.collapsed .sidebar-nav,
.sidebar.collapsed .sidebar-footer {
  opacity: 0;
}

/* ============================================================ TOPBAR */
.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 28px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.menu-toggle {
  display: flex; align-items: center; justify-content: center;
  background: none; border: none;
  width: 40px; height: 40px;
  font-size: 1.2rem; color: var(--text-muted);
  cursor: pointer; padding: 8px;
  border-radius: var(--radius-sm);
  transition: .2s;
  flex-shrink: 0;
}
.menu-toggle:hover { background: var(--bg); color: var(--primary); }
.topbar-title { flex: 1; }
.topbar-title h1 { font-size: 1.1rem; font-weight: 700; color: var(--primary); }
.breadcrumb { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.breadcrumb a, .breadcrumb span { font-size: .72rem; color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb i { font-size: .55rem; color: var(--border); }
.topbar-org { font-size: .75rem; font-weight: 600; color: var(--text-muted); white-space: nowrap; }

/* ============================================================ PAGE CONTENT */
.page-content { padding: 28px; flex: 1; }

/* ============================================================ FLASH */
.flash {
  margin: 12px 28px 0;
  padding: 13px 18px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 10px;
  font-size: .85rem; font-weight: 500;
  position: relative;
}
.flash-success { background: #d1fae5; color: #065f46; border-left: 4px solid #10b981; }
.flash-error { background: #fee2e2; color: #dc2626; border-left: 4px solid #ef4444; }
.flash-warning { background: #fef9c3; color: #92400e; border-left: 4px solid #f59e0b; }
.flash-info { background: #dbeafe; color: #1e40af; border-left: 4px solid #3b82f6; }
.flash-close { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 1.2rem; cursor: pointer; color: inherit; opacity: .6; }
.flash-close:hover { opacity: 1; }

/* ============================================================ CARDS */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}
.card-header {
  padding: 20px 24px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 1rem; font-weight: 700; color: var(--primary); }
.card-subtitle { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }
.card-body { padding: 20px 24px; }

/* ============================================================ STAT CARDS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--card-shadow);
  display: flex; align-items: center; gap: 18px;
  position: relative; overflow: hidden;
  transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.1); }
.stat-card::after {
  content: ''; position: absolute;
  top: 0; right: 0;
  width: 80px; height: 100%;
  opacity: .06;
  background: var(--stat-color, var(--accent));
  clip-path: circle(60px at 80% 50%);
}
.stat-icon {
  width: 52px; height: 52px;
  background: var(--stat-color, var(--accent));
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.4rem;
  flex-shrink: 0;
}
.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--primary); line-height: 1; }
.stat-label { font-size: .76rem; color: var(--text-muted); font-weight: 500; margin-top: 4px; }
.stat-delta { font-size: .72rem; font-weight: 600; margin-top: 4px; }
.stat-delta.up { color: #10b981; }
.stat-delta.down { color: #ef4444; }

/* ============================================================ TABLES */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
thead th {
  background: var(--primary); color: #fff;
  padding: 13px 16px;
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px;
  white-space: nowrap;
}
thead th:first-child { border-radius: var(--radius-sm) 0 0 0; }
thead th:last-child { border-radius: 0 var(--radius-sm) 0 0; }
tbody tr { border-bottom: 1px solid var(--border); transition: background .15s; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 13px 16px; color: var(--text); vertical-align: middle; }
tbody tr:last-child { border-bottom: none; }

/* ============================================================ FORMS */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: .76rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 11px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Montserrat', sans-serif;
  font-size: .88rem; color: var(--text);
  transition: .2s; outline: none; background: #fff;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,201,167,.12); }
.form-group textarea { resize: vertical; min-height: 90px; }
.form-full { grid-column: 1 / -1; }

/* ============================================================ BUTTONS */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: 'Montserrat', sans-serif;
  font-size: .84rem; font-weight: 600;
  cursor: pointer; border: 2px solid transparent;
  text-decoration: none; transition: all .2s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-light); border-color: var(--primary-light); transform: translateY(-1px); }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-dark); border-color: var(--accent-dark); transform: translateY(-1px); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-danger { background: #ef4444; color: #fff; border-color: #ef4444; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: #10b981; color: #fff; border-color: #10b981; }
.btn-success:hover { background: #059669; }
.btn-sm { padding: 7px 14px; font-size: .78rem; }
.btn-lg { padding: 13px 28px; font-size: .95rem; }
.btn-icon { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 8px; }

/* ============================================================ BADGES */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 20px;
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #dc2626; }
.badge-warning { background: #fef9c3; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-primary { background: rgba(26,60,94,.1); color: var(--primary); }
.badge-ins { background: #fee2e2; color: #dc2626; }
.badge-min { background: #fff7ed; color: #c2410c; }
.badge-sat { background: #fefce8; color: #854d0e; }
.badge-avz { background: #f0fdf4; color: #15803d; }

/* ============================================================ NIVELES DESEMPEÑO */
.nivel-bar { height: 8px; border-radius: 4px; display: inline-block; }
.nivel-insuficiente { background: var(--ins); }
.nivel-minimo { background: var(--min); }
.nivel-satisfactorio { background: var(--sat); }
.nivel-avanzado { background: var(--avz); }

/* ============================================================ PROGRESS */
.progress { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 4px; transition: width .6s ease; }
.progress-bar.primary { background: var(--primary); }
.progress-bar.accent { background: var(--accent); }
.progress-bar.danger { background: var(--ins); }
.progress-bar.warning { background: var(--min); }
.progress-bar.success { background: var(--avz); }

/* ============================================================ FILTERS */
.filters-bar {
  background: var(--white);
  border-radius: var(--radius);
  padding: 18px 24px;
  box-shadow: var(--card-shadow);
  margin-bottom: 20px;
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.filter-group label { font-size: .7rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.filter-group select,
.filter-group input {
  padding: 9px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Montserrat', sans-serif;
  font-size: .84rem;
  outline: none; transition: .2s;
}
.filter-group select:focus,
.filter-group input:focus { border-color: var(--accent); }

/* ============================================================ PAGINATION */
.pagination {
  display: flex; align-items: center; gap: 4px;
  justify-content: center; padding: 20px 0 0;
  flex-wrap: wrap;
}
.page-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 2px solid var(--border);
  color: var(--text-muted); text-decoration: none;
  font-size: .82rem; font-weight: 600;
  transition: .2s;
}
.page-btn:hover, .page-btn.active {
  background: var(--primary); border-color: var(--primary); color: #fff;
}

/* ============================================================ MODAL */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; visibility: hidden;
  transition: .3s;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--white);
  border-radius: var(--radius);
  width: 100%; max-width: 600px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 25px 60px rgba(0,0,0,.25);
  transform: scale(.95); transition: transform .3s;
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-header {
  padding: 22px 26px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 1.05rem; font-weight: 700; color: var(--primary); }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); transition: .2s; }
.modal-close:hover { color: #ef4444; }
.modal-body { padding: 24px 26px; }
.modal-footer { padding: 16px 26px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ============================================================ CHART CONTAINERS */
.chart-container { position: relative; }
.chart-wrapper { padding: 20px; }

/* ============================================================ SIDEBAR OVERLAY MÓVIL */
.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 150;
  display: none;
  pointer-events: none;
}
.sidebar-overlay.show { pointer-events: auto; }
body.touch-sidebar-mode .sidebar { transform: translateX(-100%); }
body.touch-sidebar-mode .sidebar.open { transform: translateX(0); }
body.touch-sidebar-mode .sidebar-overlay.show { display: block; }
body.touch-sidebar-mode .main-content { margin-left: 0; }

/* ============================================================ RESPONSIVE */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .main-content { margin-left: 0; }
  .page-content { padding: 20px; }
}
@media (hover: none) and (pointer: coarse) and (max-width: 1366px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .main-content { margin-left: 0; }
  .page-content { padding: 20px; }
}
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .topbar { padding: 0 16px; }
  .page-content { padding: 16px; }
  .filters-bar { padding: 14px 16px; }
  .filter-group { min-width: 130px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .topbar-org { display: none; }
  .modal { max-width: 100%; }
}

/* ============================================================ UTILITIES */
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-5 { margin-bottom: 20px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .8rem; }
.fw-700 { font-weight: 700; }
.w-100 { width: 100%; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 900px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ============================================================ PÁGINA LOGIN */
body.login-page {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
  min-height: 100vh; padding: 20px;
}
.login-card {
  background: #fff; border-radius: 22px;
  width: 100%; max-width: 420px;
  box-shadow: 0 30px 80px rgba(0,0,0,.4);
  overflow: hidden;
}
.login-header {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  padding: 42px 36px; text-align: center; color: #fff;
}
.login-header .logo-icon { font-size: 3rem; margin-bottom: 10px; }
.login-header h1 { font-size: 1.6rem; font-weight: 800; }
.login-header p { opacity: .85; font-size: .88rem; margin-top: 4px; }
.login-body { padding: 36px; }
.login-body .form-group { margin-bottom: 18px; }
.login-body input {
  width: 100%; padding: 13px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: 'Montserrat',sans-serif;
  font-size: .9rem; transition: .2s; outline: none;
}
.login-body input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,201,167,.12); }
.btn-login {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; border: none; border-radius: 10px;
  font-family: 'Montserrat',sans-serif; font-size: .95rem; font-weight: 700;
  cursor: pointer; transition: .3s;
}
.btn-login:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(0,201,167,.3); }
