/**
 * ============================================================================
 * MIDE — Paleta y tema global
 * AccessNHS · Sistema de indicadores ejecutivos
 *
 * Uso: enlazar en todas las pantallas via mide_render_head() (config.app.php).
 * No duplicar variables :root en paginas PHP individuales.
 * ============================================================================
 */

/* --- Paleta oficial MIDE --------------------------------------------------- */
:root {
  /* Marca — paleta corporativa oficial */
  --mide-gold: #5b9bd5;
  --mide-gold-light: #fff8e1;
  --mide-gold-dark: #e6ac00;
  --mide-navy: #10131b;
  --mide-navy-soft: #181c25;
  --mide-surface-dark: #2a2f3a;
  --mide-white: #ffffff;

  /* Alias legacy (compatibilidad con codigo existente) */
  --gold: var(--mide-gold);
  --gold-light: var(--mide-gold-light);
  --gold-dark: var(--mide-gold-dark);
  --primary: var(--mide-navy);
  --secondary: var(--mide-navy-soft);

  /* Texto y superficies */
  --text: #10131b;
  --muted: #525968;
  --line: #e8eaed;
  --card: #ffffff;
  --surface: #ffffff;
  --border: #e2e4e8;
  --bg-page: linear-gradient(135deg, #f5f6f8 0%, #e8eaed 100%);

  /* Semáforo — tonos derivados de la paleta corporativa */
  --ok: #10131b;
  --ok-bg: #fff8e1;
  --warn: #b8860b;
  --warn-bg: #fff8e1;
  --err: #181c25;
  --err-bg: #f0f1f3;
  --info: #2a2f3a;
  --info-bg: #f5f6f8;

  /* Gradientes */
  --grad-gold: linear-gradient(135deg, #5b9bd5, #e6ac00);
  --grad-dark: linear-gradient(135deg, #10131b, #181c25);
  --grad-muted: linear-gradient(135deg, #181c25, #2a2f3a);

  /* Sombras y transiciones */
  --sh-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --sh-md: 0 4px 16px rgba(0, 0, 0, 0.1);
  --sh-lg: 0 8px 28px rgba(26, 35, 50, 0.12);
  --t-fast: 0.15s ease;
  --t-base: 0.25s ease;

  /* Tipografia */
  --font-ui: "Inter", "Segoe UI", system-ui, sans-serif;

  /* Layout */
  --topbar-h: 64px;
  --footer-h: 48px;
  --wrap-max: 1600px;
  --wrap-narrow: 760px;

  /* Sistema de diseño — espaciado (escala 4px) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Radios */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 999px;

  /* Colores semánticos (alias) */
  --color-success: var(--ok);
  --color-success-bg: var(--ok-bg);
  --color-warning: var(--warn);
  --color-warning-bg: var(--warn-bg);
  --color-danger: var(--err);
  --color-danger-bg: var(--err-bg);
  --color-info: var(--info);
  --color-info-bg: var(--info-bg);

  /* Gradientes extendidos — alias corporativos (sin colores aleatorios) */
  --grad-blue: var(--grad-muted);
  --grad-green: var(--grad-gold);
  --grad-red: var(--grad-dark);
  --grad-purple: var(--grad-muted);
  --grad-teal: var(--grad-gold);

  /* Z-index */
  --z-nav: 1000;
  --z-modal: 1100;
  --z-toast: 1200;
}

/* --- Reset minimo ---------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body.mide-body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
}

body.mide-body.mide-body-dashboard {
  padding-top: 85px;
  min-height: 100vh;
}

/* --- Barra superior -------------------------------------------------------- */
.mide-topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  min-height: var(--topbar-h);
  padding: 12px 24px;
  background: var(--card);
  color: var(--primary);
  border-bottom: 4px solid var(--gold);
  box-shadow: var(--sh-md);
}

.mide-topbar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--primary);
  text-decoration: none;
}

.mide-topbar .brand i {
  background: var(--grad-gold);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-size: 1.45rem;
}

.mide-topbar .brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.mide-topbar .brand-text span:first-child {
  font-size: 1.2rem;
  letter-spacing: 0.06em;
}

.mide-topbar .brand-text small {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.mide-topbar .nav-title {
  font-weight: 700;
  color: var(--muted);
  font-size: 0.95rem;
  padding-left: 14px;
  border-left: 2px solid var(--line);
}

.mide-topbar .spacer {
  flex: 1;
}

/* --- Botones --------------------------------------------------------------- */
.mide-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border: 2px solid transparent;
  border-radius: 11px;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  background: var(--grad-dark);
  color: #fff !important;
  transition: transform var(--t-fast), box-shadow var(--t-base);
}

.mide-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(26, 35, 50, 0.25);
  color: #fff !important;
}

.mide-btn.sec {
  background: var(--card);
  color: var(--primary) !important;
  border-color: var(--gold);
}

.mide-btn.sec:hover {
  background: var(--gold-light);
  color: var(--primary) !important;
}

.mide-btn.gold,
.mide-submit {
  background: var(--grad-gold) !important;
  color: #000 !important;
  border: none;
  box-shadow: 0 4px 14px rgba(255, 215, 0, 0.35);
}

.mide-btn.is-loading,
.mide-submit.is-loading {
  pointer-events: none;
  opacity: 0.85;
}

.mide-btn.is-loading .mide-btn-label,
.mide-submit.is-loading .mide-btn-label {
  opacity: 0.7;
}

.mide-btn-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 0, 0, 0.15);
  border-top-color: #000;
  border-radius: 50%;
  animation: mide-spin 0.7s linear infinite;
}

.is-loading .mide-btn-spinner {
  display: inline-block;
}

@keyframes mide-spin {
  to { transform: rotate(360deg); }
}

/* --- Contenedores ---------------------------------------------------------- */
.mide-main {
  flex: 1;
  width: 100%;
}

.mide-wrap {
  max-width: var(--wrap-narrow);
  margin: 0 auto;
  padding: 24px;
}

.mide-wrap.wide {
  max-width: var(--wrap-max);
}

.mide-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--sh-md);
  border-top: 4px solid var(--gold);
}

.mide-card h1,
.mide-card h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 8px;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary);
}

.mide-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.mide-card h1 i,
.mide-card h2 i {
  background: var(--grad-gold);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* --- Alertas en pagina ----------------------------------------------------- */
.mide-alert {
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 0.92rem;
  line-height: 1.5;
}

.mide-alert.err { background: var(--err-bg); color: var(--err); }
.mide-alert.ok  { background: var(--ok-bg);  color: var(--ok);  }
.mide-alert.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid rgba(255, 193, 7, 0.45); }
.mide-alert.info { background: var(--info-bg); color: var(--info); }

.mide-flash {
  border-radius: 12px;
  padding: 12px 16px;
  margin: 0 0 16px;
  font-weight: 600;
  font-size: 0.9rem;
}

.mide-flash.err { background: var(--err-bg); color: var(--err); }
.mide-flash.ok  { background: var(--ok-bg);  color: var(--ok);  }

/* --- Formularios de carga -------------------------------------------------- */
.mide-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.mide-cols li {
  padding: 10px 12px;
  border: 1px solid rgba(255, 215, 0, 0.35);
  border-radius: 10px;
  background: var(--gold-light);
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--primary);
}

.mide-upload {
  position: relative;
  padding: 28px;
  border: 2px dashed var(--gold);
  border-radius: 14px;
  text-align: center;
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.08), rgba(255, 165, 0, 0.04));
  transition: border-color var(--t-base), box-shadow var(--t-base);
}

.mide-upload:hover {
  border-color: var(--gold-dark);
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.15);
}

.mide-upload input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.mide-upload i {
  font-size: 2rem;
  background: var(--grad-gold);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.mide-upload.has-file {
  border-style: solid;
  background: var(--ok-bg);
}

.mide-progress {
  display: none;
  height: 8px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}

.mide-progress.is-active {
  display: block;
}

.mide-progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--grad-gold);
  transition: width 0.2s ease;
}

.mide-year-sel {
  padding: 8px 12px;
  border: 2px solid var(--gold);
  border-radius: 10px;
  background: var(--card);
  color: var(--primary);
  font-size: 0.86rem;
  font-weight: 800;
  cursor: pointer;
}

.mide-note {
  margin-top: 12px;
  font-size: 0.84rem;
  color: var(--muted);
}

.mide-note i {
  color: var(--gold-dark);
}

/* --- Pie de pagina --------------------------------------------------------- */
.mide-footer {
  margin-top: auto;
  padding: 14px 24px;
  border-top: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.mide-footer i {
  color: var(--gold);
  margin-right: 4px;
}

/* --- Utilidades globales --------------------------------------------------- */
.mide-db-error {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-danger-bg);
  color: var(--color-danger);
  font-weight: 700;
  border: 1px solid rgba(185, 28, 28, 0.2);
}

.u-text-success { color: var(--color-success) !important; }
.u-text-danger  { color: var(--color-danger) !important; }
.u-text-muted   { color: var(--muted) !important; }

.u-mt-16 { margin-top: var(--space-4) !important; }
.u-mb-16 { margin-bottom: var(--space-4) !important; }
.u-mb-24 { margin-bottom: var(--space-6) !important; }

.mide-progress-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--grad-gold);
  width: var(--fill-width, 0%);
  transition: width 0.4s ease;
}

/* Loader de página */
.mide-page-loader {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.mide-page-loader.on {
  opacity: 1;
  visibility: visible;
}

.mide-page-loader-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: mide-spin 0.8s linear infinite;
}

@keyframes mide-spin {
  to { transform: rotate(360deg); }
}

/* Focus visible accesible */
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
