:root {
  --azul: #1e3a8a;
  --azul-claro: #2563eb;
  --texto: #1f2937;
  --texto-muted: #6b7280;
  --borde: #e5e7eb;
  --fondo: #f8fafc;
  --verde: #16a34a;
  --rojo: #dc2626;
  --amarillo: #d97706;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  min-height: 100%;
}

a { color: var(--azul-claro); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===================== Menú lateral (sidebar) ===================== */

body.con-sidebar { margin: 0; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--azul) 0%, #16296b 100%);
  color: #dbeafe;
  display: flex;
  flex-direction: column;
  transition: width 0.18s ease;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 20;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.sidebar-brand-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  background: white;
  border-radius: 8px;
  padding: 3px;
  flex-shrink: 0;
}
.sidebar-brand-text {
  font-weight: 700;
  font-size: 14.5px;
  color: white;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--azul-claro);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.sidebar-user-avatar-foto {
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.35);
}
.sidebar-user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  white-space: nowrap;
}
.sidebar-user-info strong { color: white; font-size: 13.5px; }
.sidebar-user-info span { color: #93c5fd; font-size: 12px; }

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #dbeafe;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  border: none;
  background: transparent;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.sidebar-link:hover { background: rgba(255,255,255,0.08); text-decoration: none; }
.sidebar-link.activo { background: var(--azul-claro); color: white; }
.sidebar-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-label { overflow: hidden; text-overflow: ellipsis; }

.sidebar-section-label {
  margin: 12px 12px 2px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #7c9be0;
  white-space: nowrap;
  overflow: hidden;
}

/* Grupo desplegable del menú lateral (p.ej. "Catálogos") */
.sidebar-grupo-boton { position: relative; }
.sidebar-grupo-flecha {
  margin-left: auto;
  font-size: 10px;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.sidebar-grupo-boton.abierto .sidebar-grupo-flecha { transform: rotate(180deg); }
.sidebar-submenu {
  max-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: max-height 0.2s ease;
}
.sidebar-submenu.abierto { max-height: 220px; }
.sidebar-sublink { padding-left: 34px; font-size: 13px; }

.sidebar-footer { padding: 10px 8px 16px; border-top: 1px solid rgba(255,255,255,0.12); }
.sidebar-logout:hover { background: rgba(220,38,38,0.35); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  z-index: 15;
}

/* Colapsado: solo iconos */
.app-shell.sidebar-colapsado .sidebar { width: 68px; }
.app-shell.sidebar-colapsado .sidebar-brand-text,
.app-shell.sidebar-colapsado .sidebar-user-info,
.app-shell.sidebar-colapsado .sidebar-label,
.app-shell.sidebar-colapsado .sidebar-section-label { display: none; }
.app-shell.sidebar-colapsado .sidebar-link { justify-content: center; }
.app-shell.sidebar-colapsado .sidebar-grupo-flecha { display: none; }
.app-shell.sidebar-colapsado .sidebar-submenu { max-height: none; overflow: visible; }
.app-shell.sidebar-colapsado .sidebar-sublink { padding-left: 12px; }

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  background: white;
  border-bottom: 1px solid var(--borde);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-toggle {
  border: none;
  background: #f1f5f9;
  color: var(--texto);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.topbar-toggle:hover { background: var(--borde); }
.topbar-title { margin: 0; font-size: 18px; color: var(--texto); }

@media (max-width: 880px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,0.2);
  }
  .app-shell.sidebar-movil-abierto .sidebar { transform: translateX(0); width: 250px; }
  .app-shell.sidebar-movil-abierto .sidebar-brand-text,
  .app-shell.sidebar-movil-abierto .sidebar-user-info,
  .app-shell.sidebar-movil-abierto .sidebar-label,
  .app-shell.sidebar-movil-abierto .sidebar-section-label { display: flex; }
  .app-shell.sidebar-movil-abierto .sidebar-brand-text,
  .app-shell.sidebar-movil-abierto .sidebar-section-label { display: block; }
  .app-shell.sidebar-movil-abierto .sidebar-link { justify-content: flex-start; }
  .app-shell.sidebar-movil-abierto .sidebar-backdrop { display: block; }
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
  width: 100%;
}

.section { margin-bottom: 32px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 10px;
}
.section h2, .section h3, .page h1 { margin: 0 0 4px 0; }

.muted { color: var(--texto-muted); font-size: 14px; }

.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--borde);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
}
.table th, .table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--borde);
  font-size: 14px;
  vertical-align: middle;
}
.table th { background: #f1f5f9; font-weight: 600; }
.table tr:last-child td { border-bottom: none; }

.btn {
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  display: inline-block;
}
.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--azul-claro); color: white; }
.btn-success { background: var(--verde); color: white; }
.btn-danger { background: var(--rojo); color: white; }
.btn-warning { background: var(--amarillo); color: white; }
.btn-ghost { background: transparent; color: white; border: 1px solid rgba(255,255,255,0.4); }
.btn-small { background: #e5e7eb; color: var(--texto); padding: 4px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.inline-form { display: inline; }

.alert {
  padding: 10px 14px;
  border-radius: 6px;
  margin: 10px 0;
  font-size: 14px;
}
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #d1fae5; color: #065f46; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-super { background: #ede9fe; color: #5b21b6; }
.badge-admin { background: #dbeafe; color: #1e40af; }
.badge-revisor { background: #fef3c7; color: #92400e; }
.badge-ce { background: #d1fae5; color: #065f46; }
.badge-ei { background: #e0e7ff; color: #3730a3; }
.badge-activo { background: #d1fae5; color: #065f46; }
.badge-inactivo { background: #fee2e2; color: #991b1b; }
.badge-suspendido { background: #fef3c7; color: #92400e; }
.badge-baja { background: #e5e7eb; color: #374151; }
.badge-clave {
  font-size: 24px;
  font-weight: 700;
  padding: 6px 18px;
}

.login-wrap {
  min-height: calc(100vh - 40px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: white;
  border: 1px solid var(--borde);
  border-radius: 12px;
  padding: 32px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { margin: 0; font-size: 20px; color: var(--azul); }
.login-logo { width: 100%; max-width: 240px; margin: 0 auto 4px; display: block; }

.login-tipo-selector {
  display: flex;
  gap: 8px;
  background: #eef1f4;
  border-radius: 999px;
  padding: 4px;
}
.login-tipo-opcion {
  flex: 1;
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 8px 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--texto-muted);
  background: transparent;
  border-radius: 999px;
  margin: 0;
  transition: background 0.15s ease, color 0.15s ease;
  user-select: none;
}
/* El radio real sigue ahí (accesibilidad, teclado) pero invisible —
   toda la píldora es el control visual, no un círculo aparte. */
.login-tipo-opcion input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.login-tipo-opcion.login-tipo-activo {
  background: var(--azul);
  color: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--texto-muted);
  flex: 1;
}
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  color: var(--texto);
  font-weight: 400;
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.password-wrap input {
  width: 100%;
  padding-right: 36px;
}
.password-toggle {
  position: absolute;
  right: 4px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 4px 6px;
}
.password-toggle:hover { opacity: 0.7; }

/* ===================== Editor de plantillas de correo ===================== */

.editor-modo-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--texto-muted);
  margin-bottom: 4px;
}
.editor-modo-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}
.editor-modo-tab {
  border: 1px solid var(--borde);
  background: #f8fafc;
  color: var(--texto-muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.editor-modo-tab.activo { background: var(--azul-claro); color: white; border-color: var(--azul-claro); }

.editor-html-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  background: #f1f5f9;
  border: 1px solid var(--borde);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 6px;
}
.editor-html-toolbar button {
  border: 1px solid transparent;
  background: white;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  color: var(--texto);
  white-space: nowrap;
}
.editor-html-toolbar button:hover { border-color: var(--borde); }
.editor-html-toolbar select {
  font-size: 12.5px;
  padding: 5px 6px;
  border-radius: 5px;
  max-width: 130px;
}
.editor-html-toolbar input[type="color"] {
  width: 30px;
  height: 30px;
  padding: 2px;
  border-radius: 5px;
  cursor: pointer;
}

.editor-html {
  min-height: 160px;
  border: 1px solid var(--borde);
  border-radius: 0 0 8px 8px;
  padding: 12px;
  font-size: 14px;
  background: white;
  overflow-y: auto;
}
.editor-html:focus { outline: 2px solid var(--azul-claro); outline-offset: -1px; }

.editor-texto {
  width: 100%;
  font-family: monospace;
  font-size: 13px;
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 10px;
}

.card-form {
  background: white;
  border: 1px solid var(--borde);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 640px;
}
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row label { min-width: 200px; }

.validation-summary-errors ul { color: var(--rojo); font-size: 13px; margin: 0; padding-left: 18px; }
.field-validation-error { color: var(--rojo); font-size: 12px; }
.input-validation-error { border-color: var(--rojo) !important; }

.back-link { display: inline-block; margin-bottom: 12px; font-size: 14px; }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.menu-card {
  background: white;
  border: 1px solid var(--borde);
  border-radius: 12px;
  padding: 20px;
  display: block;
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.menu-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(15,23,42,0.08);
  border-color: var(--azul-claro);
  text-decoration: none;
}
.menu-card h3 { margin: 0 0 6px 0; color: var(--azul); }
.menu-card p { margin: 0; font-size: 13px; color: var(--texto-muted); }

/* Panel "comparativo anual" en Inicio — info promocional para ver qué tanto
   se va superando el año pasado (Centros de Evaluación y certificados). */
.comparativo-anual { margin: 18px 0 8px; }
.comparativo-titulo { margin: 0; font-size: 18px; color: var(--azul); }
.comparativo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 10px;
}
.comparativo-card {
  background: linear-gradient(135deg, #0b3d91 0%, #1e5fbf 100%);
  color: white;
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: 0 4px 14px rgba(11,61,145,0.25);
}
.comparativo-label { font-size: 13px; font-weight: 600; opacity: 0.9; }
.comparativo-cifras { display: flex; gap: 28px; margin-top: 14px; }
.comparativo-cifra { display: flex; flex-direction: column; }
.comparativo-anio { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.75; }
.comparativo-numero { font-size: 34px; font-weight: 800; line-height: 1.15; }
.comparativo-actual .comparativo-numero { color: #7ee787; }
.comparativo-delta {
  display: inline-block;
  margin-top: 14px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
}
.comparativo-delta.positivo { color: #7ee787; }
.comparativo-delta.negativo { color: #ffb4b4; }
.comparativo-card .muted { color: rgba(255,255,255,0.7); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin: 20px 0;
}
.stat-card {
  background: white;
  border: 1px solid var(--borde);
  border-left: 4px solid var(--azul-claro);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
}
.stat-number { font-size: 32px; font-weight: 700; color: var(--azul); line-height: 1.1; }
.stat-label { font-size: 13px; color: var(--texto); margin-top: 6px; }
.stat-sub { font-size: 12px; color: var(--texto-muted); margin-top: 2px; }

.detail-card {
  background: white;
  border: 1px solid var(--borde);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px 24px;
}
.detail-field { display: flex; flex-direction: column; gap: 2px; }
.detail-field-label { font-size: 12px; font-weight: 600; color: var(--texto-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.detail-field-value { font-size: 15px; color: var(--texto); }
.detail-field-value.empty { color: var(--texto-muted); font-style: italic; }

.ce-logo-mini {
  max-width: 56px;
  max-height: 36px;
  object-fit: contain;
  display: block;
}

.ce-logo-placeholder {
  width: 120px;
  height: 70px;
  border: 1px dashed var(--borde);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--texto-muted);
  font-size: 11px;
  text-align: center;
  flex-shrink: 0;
}

.user-photo-mini {
  width: 84px;
  height: 104px;
  border-radius: 10px;
  object-fit: cover;
  display: block;
  border: 2px solid var(--borde);
  box-shadow: 0 1px 3px rgba(15,23,42,0.12);
}
.user-photo-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--azul-claro);
  color: white;
  font-weight: 700;
  font-size: 30px;
}
.user-photo-input {
  width: 90px;
  font-size: 10px;
  padding: 2px 0;
  border: none;
  margin-top: 4px;
}
