/* ============================================================
   SISTEMA MUNICIPAL — DESIGN SYSTEM GLOBAL
   Tipografía: Plus Jakarta Sans (títulos) + DM Sans (cuerpo)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=DM+Sans:wght@300;400;500;600&display=swap');

/* ============================================================
   1. VARIABLES GLOBALES
   ============================================================ */
:root {
  /* Tema claro — contraste mejorado para WCAG AA (4.5:1+) */
  --ui-heading:            #3d4f54;
  --ui-text:               #445559;
  --ui-accent:             #0d9488;
  --ui-accent-hover:       #0f766e;
  --ui-accent-soft:        #ccfbf1;
  --ui-warm:               #d4a574;
  --ui-warm-bg:            #faf6f0;
  --ui-coral:              #e07a5f;
  --ui-coral-soft:         #fde8e4;

  /* Compatibilidad (mapeo a nuevo tema) */
  --municipal-blue:        #0f766e;
  --municipal-blue-mid:    #115e59;
  --municipal-light-blue:  #14b8a6;
  --municipal-cyan:        #c9a84c;
  --municipal-cyan-light:  #f5ede0;

  --municipal-green:       #0d9488;
  --municipal-green-light: #ccfbf1;
  --municipal-red:         #c53030;
  --municipal-red-light:   #fed7d7;
  --municipal-warning:     #c27803;
  --municipal-warning-light: #fff7d6;
  --municipal-success:     #0d9488;
  --municipal-danger:      #c53030;

  --municipal-dark:        #3d4f54;
  --municipal-gray:        #445559;
  --municipal-gray-light:  #7a8f94;
  --municipal-border:      #e5e0d8;
  --municipal-white:       #ffffff;
  --municipal-bg:          #f3f1ec;
  --municipal-light-gray:  #ebe6df;

  --municipal-gradient:    #0f766e;
  --municipal-gradient-h:  #0d9488;

  /* Sombras */
  --municipal-shadow-xs:   0 1px 2px rgba(0,0,0,0.05);
  --municipal-shadow:      0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --municipal-shadow-md:   0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.06);
  --municipal-shadow-lg:   0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
  --municipal-shadow-xl:   0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);

  /* Bordes */
  --municipal-radius-sm:   6px;
  --municipal-radius:      8px;
  --municipal-radius-md:   12px;
  --municipal-radius-lg:   16px;
  --municipal-radius-xl:   24px;

  /* Espaciado */
  --space-1:  0.25rem;   /* 4px */
  --space-2:  0.5rem;    /* 8px */
  --space-3:  0.75rem;   /* 12px */
  --space-4:  1rem;      /* 16px */
  --space-5:  1.25rem;   /* 20px */
  --space-6:  1.5rem;    /* 24px */
  --space-8:  2rem;      /* 32px */
  --space-10: 2.5rem;    /* 40px */
  --space-12: 3rem;      /* 48px */

  /* Transiciones */
  --municipal-transition:  all 0.2s ease;
  --transition-fast:       all 0.15s ease;
  --transition-normal:     all 0.25s ease;
  --transition-slow:       all 0.35s ease;
}

/* ============================================================
   2. RESET Y BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

@media (min-width: 768px) {
  html { font-size: 16px; }
}

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--ui-text);
  background-color: var(--municipal-bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ui-heading);
  letter-spacing: -0.02em;
}

/* ============================================================
   3. FOCUS STATES ACCESIBLES
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--municipal-cyan);
  outline-offset: 2px;
  border-radius: var(--municipal-radius-sm);
}

.btn:focus-visible,
.form-control:focus-visible,
.form-check-input:focus-visible {
  outline: 2px solid var(--municipal-cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.2);
}

/* Legacy focus (Bootstrap override) */
.btn:focus, .btn:active:focus,
.form-control:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.2);
  border-color: var(--municipal-cyan);
  outline: none;
}

/* ============================================================
   4. TIPOGRAFÍA UTILITARIA
   ============================================================ */
.font-jakarta { font-family: 'Plus Jakarta Sans', sans-serif; }
.font-dm      { font-family: 'DM Sans', sans-serif; }

.text-muted   { color: var(--municipal-gray) !important; }
.text-primary { color: var(--ui-accent) !important; }

/* ============================================================
   5. COMPONENTES GLOBALES
   ============================================================ */

/* Cards */
.card {
  border: 1px solid var(--municipal-border);
  border-radius: var(--municipal-radius-md);
  box-shadow: var(--municipal-shadow);
  background: var(--municipal-white);
  transition: var(--municipal-transition);
}

.card-header {
  background: #f8fafc;
  border-bottom: 1px solid var(--municipal-border);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--municipal-dark);
  padding: 0.875rem 1.25rem;
  border-radius: var(--municipal-radius-md) var(--municipal-radius-md) 0 0 !important;
}

/* Tablas */
.table {
  border-collapse: separate;
  border-spacing: 0;
}

.table thead th {
  background: var(--municipal-light-gray);
  color: var(--municipal-gray);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--municipal-border);
  border-top: none;
  white-space: nowrap;
}

.table tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--municipal-border);
  border-top: none;
  vertical-align: middle;
  font-size: 0.9rem;
  color: var(--municipal-dark);
}

.table tbody tr:last-child td { border-bottom: none; }

.table-hover tbody tr {
  transition: background 0.15s ease;
}

.table-hover tbody tr:hover td {
  background-color: #EBF8FF;
}

/* Badges */
.badge {
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  font-size: 0.75rem;
  padding: 0.35em 0.75em;
  border-radius: 99px;
  letter-spacing: 0.01em;
}

.bg-success { background-color: var(--municipal-green-light) !important; color: var(--municipal-green) !important; }
.bg-danger  { background-color: var(--municipal-red-light) !important;   color: var(--municipal-red) !important; }
.bg-warning { background-color: var(--municipal-warning-light) !important; color: var(--municipal-warning) !important; }
.bg-info    { background-color: var(--municipal-cyan-light) !important;  color: var(--municipal-cyan) !important; }
.bg-secondary { background-color: var(--municipal-light-gray) !important; color: var(--municipal-gray) !important; }

/* Alertas con borde izquierdo */
.alert {
  border: none;
  border-left: 4px solid;
  border-radius: var(--municipal-radius-md);
  padding: 0.875rem 1.25rem;
  font-size: 0.92rem;
}

.alert-success {
  background: var(--municipal-green-light);
  border-left-color: var(--municipal-green);
  color: #22543D;
}

.alert-danger {
  background: var(--municipal-red-light);
  border-left-color: var(--municipal-red);
  color: #742A2A;
}

.alert-info {
  background: var(--municipal-cyan-light);
  border-left-color: var(--municipal-cyan);
  color: #2A4365;
}

.alert-warning {
  background: var(--municipal-warning-light);
  border-left-color: var(--municipal-warning);
  color: #744210;
}

/* Botones globales */
.btn {
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  border-radius: var(--municipal-radius);
  transition: var(--municipal-transition);
  font-size: 0.9rem;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--municipal-shadow-md);
}

.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);
  border: none;
  color: white;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
  color: white;
  box-shadow: 0 6px 18px rgba(13, 148, 136, 0.35);
}

.btn-outline-primary {
  color: var(--municipal-blue);
  border-color: var(--municipal-blue);
}

.btn-outline-primary:hover {
  background: var(--municipal-blue);
  border-color: var(--municipal-blue);
  color: white;
}

.btn-outline-secondary {
  color: var(--municipal-gray);
  border-color: var(--municipal-border);
  background: white;
}

.btn-outline-secondary:hover {
  background: var(--municipal-light-gray);
  color: var(--municipal-dark);
  border-color: var(--municipal-border);
}

/* Form controls */
.form-control, .form-select {
  border: 1px solid var(--municipal-border);
  border-radius: var(--municipal-radius);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  padding: 0.6rem 0.875rem;
  color: var(--municipal-dark);
  background: white;
  transition: var(--municipal-transition);
}

.form-control:focus, .form-select:focus {
  border-color: var(--municipal-cyan);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.15);
  outline: none;
}

.form-label {
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--municipal-dark);
  margin-bottom: 0.4rem;
}

/* Inputs de fecha (date pickers) */
input[type="date"].form-control {
  appearance: none;
  -webkit-appearance: none;
}

/* Spinner */
.spinner-border {
  color: var(--municipal-cyan);
}

/* Dropdown */
.dropdown-menu {
  border: 1px solid var(--municipal-border);
  border-radius: var(--municipal-radius-md);
  box-shadow: var(--municipal-shadow-lg);
  padding: 0.375rem;
  font-size: 0.9rem;
}

.dropdown-item {
  border-radius: var(--municipal-radius-sm);
  padding: 0.5rem 0.875rem;
  transition: var(--municipal-transition);
  font-weight: 400;
}

.dropdown-item:hover {
  background: var(--municipal-light-gray);
  color: var(--municipal-dark);
}

.dropdown-divider {
  border-color: var(--municipal-border);
  margin: 0.375rem 0;
}

/* ============================================================
   6. ACCESIBILIDAD — REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Visually hidden (accesibilidad: labels ocultos visualmente) */
.visually-hidden,
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip link (accesibilidad: saltar al contenido) */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--ui-accent);
  color: white;
  padding: 0.75rem 1.5rem;
  z-index: 9999;
  font-weight: 600;
  border-radius: 0 0 var(--municipal-radius) 0;
}

.skip-link:focus,
.skip-link:focus-visible {
  top: 0;
}

/* ============================================================
   7. ANIMACIONES GLOBALES
   ============================================================ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.6; transform: scale(0.85); }
}

/* Status pulse used by dispatcher.css */
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.45); }
  70%  { box-shadow: 0 0 0 6px rgba(5, 150, 105, 0); }
  100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); }
}

/* Slide-in used by waiting cards */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Animación de entrada en page load */
.page-enter {
  animation: fadeInUp 0.35s ease forwards;
}

/* Skeleton shimmer */
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 800px 100%;
  animation: shimmer 1.5s infinite linear;
  border-radius: var(--municipal-radius);
}

/* ============================================================
   7. UTILIDADES
   ============================================================ */
.flex-grow-1 { flex: 1 1 auto; }

main {
  flex: 1;
  background: var(--municipal-bg);
}

/* KPI number emphasis */
.kpi-number {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 800;
  font-size: 2rem;
  line-height: 1;
  color: var(--municipal-blue);
}

/* Code inline */
code {
  font-size: 0.85em;
  color: var(--municipal-blue-mid);
  background: var(--municipal-cyan-light);
  padding: 0.15em 0.45em;
  border-radius: 4px;
}

/* ============================================================
   8. KPI CARDS
   ============================================================ */
.kpi-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--municipal-shadow-md) !important;
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--municipal-radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  margin-bottom: 0.75rem;
  opacity: 0.9;
}

/* ============================================================
   9. SESSION TIMER / PROGRESS BAR
   ============================================================ */
.session-progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 0.5rem;
}

.session-progress-fill {
  height: 100%;
  background: rgba(255,255,255,0.7);
  border-radius: 2px;
  transition: width 1s linear;
}

/* ============================================================
   10. SCROLLBAR PERSONALIZADO (webkit)
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E0; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ============================================================
   11. CHART.JS OVERRIDE HELPERS
   ============================================================ */
.chart-municipal-wrapper {
  position: relative;
  border-radius: var(--municipal-radius-md);
  overflow: hidden;
}

/* ============================================================
   12. UTILIDADES DE ESPACIADO
   ============================================================ */
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

/* ============================================================
   13. MEJORAS DE MICRO-INTERACCIÓN
   ============================================================ */

/* Selección de texto con color institucional */
::selection {
  background: rgba(13, 148, 136, 0.15);
  color: var(--ui-heading);
}

/* Smooth images */
img {
  max-width: 100%;
  height: auto;
}

/* Links globales */
a {
  color: var(--ui-accent);
  transition: color 0.15s ease;
}

a:hover {
  color: var(--ui-accent-hover);
}