/**
 * global.css — Core (Módulo 0)
 * ─────────────────────────────────────────────────────────────────
 * Variables CSS globales, reset base y estilos de layout principal.
 * Cargado en index.html y login.html. NO sobreescribir en módulos.
 *
 * Doc: /docs/modules/module-0-core.md
 */

/* ── Variables CSS globales ──────────────────────────────────── */
:root {
  /* Colores principales */
  --color-primary:        #6c63ff;
  --color-primary-light:  #8b85ff;
  --color-primary-dark:   #554bbb;
  --color-accent:         #ff6b9d;
  --color-accent-dark:    #e05285;

  /* Semáforo (PE, urgencia) */
  --color-danger:         #e05c6e;
  --color-warning:        #ffb347;
  --color-success:        #4caf8a;
  --color-info:           #74c7ec;

  /* Versiones RGB (para rgba() con tintes) — mantener en sync con los hex de arriba */
  --color-primary-rgb:    108, 99, 255;   /* #6c63ff */
  --color-success-rgb:    76, 175, 138;   /* #4caf8a */
  --color-success-dark:   #1a5c38;        /* verde oscuro para texto de ingresos sobre tinte */

  /* Neutros */
  --color-text:           #1A1A2E;
  --color-text-muted:     #6B7280;
  --color-text-light:     #9CA3AF;
  --color-bg:             #F9FAFB;
  --color-surface:        #FFFFFF;
  --color-border:         #E5E7EB;
  --color-border-dark:    #D1D5DB;

  /* Tipografía */
  --font-family:          'Inter', system-ui, -apple-system, sans-serif;
  --font-size-xs:         0.75rem;     /* 12px */
  --font-size-sm:         0.875rem;    /* 14px */
  --font-size-base:       1rem;        /* 16px */
  --font-size-lg:         1.125rem;    /* 18px */
  --font-size-xl:         1.5rem;      /* 24px */
  --font-size-2xl:        2rem;        /* 32px */
  --font-weight-normal:   400;
  --font-weight-medium:   500;
  --font-weight-semibold: 600;
  --font-weight-bold:     700;

  /* Espaciado */
  --spacing-xs:  0.25rem;   /* 4px */
  --spacing-sm:  0.5rem;    /* 8px */
  --spacing-md:  1rem;      /* 16px */
  --spacing-lg:  1.5rem;    /* 24px */
  --spacing-xl:  2rem;      /* 32px */
  --spacing-2xl: 3rem;      /* 48px */

  /* Bordes */
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-full: 9999px;

  /* Sombras */
  --shadow-sm:   0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md:   0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg:   0 8px 24px rgba(0, 0, 0, 0.12);

  /* Layout */
  --sidebar-width: 240px;
  --header-height: 64px;
  --content-max-width: 1200px;

  /* Transiciones */
  --transition-fast:   150ms ease;
  --transition-normal: 250ms ease;

  /* Sidebar (valores que no pueden hardcodearse para soportar dark mode) */
  --sidebar-bg:          rgba(255, 255, 255, 0.75);
  --sidebar-border:      rgba(255, 255, 255, 0.8);
  --sidebar-shadow:      0 12px 40px rgba(0, 0, 0, 0.04);
  --sidebar-separator:   rgba(0, 0, 0, 0.05);
  --toggle-hover-bg:     rgba(0, 0, 0, 0.05);

  /* Skeleton */
  --skeleton-base:       #e5e7eb;
  --skeleton-shine:      #f3f4f6;
}

/* ── Reset base ──────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family:      var(--font-family);
  font-size:        var(--font-size-base);
  font-weight:      var(--font-weight-normal);
  color:            var(--color-text);
  background-color: var(--color-bg);
  line-height:      1.6;
  min-height:       100vh;
  -webkit-font-smoothing: antialiased;
}

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

img, svg {
  max-width: 100%;
  display:   block;
}

ul, ol {
  list-style: none;
}

button, input, select, textarea {
  font-family: inherit;
  font-size:   inherit;
}

/* Soporte estricto para ocultar elementos con el atributo HTML5 hidden */
[hidden] {
  display: none !important;
}

/* ── Layout principal (Sidebar + Contenido) ──────────────────── */
.app-layout {
  display:   flex;
  min-height: 100vh;
}

.sidebar {
  width:            var(--sidebar-width);
  background:       var(--sidebar-bg);
  backdrop-filter:  blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border:           1px solid var(--sidebar-border);
  box-shadow:       var(--sidebar-shadow);
  color:            var(--color-text);
  display:          flex;
  flex-direction:   column;
  position:         fixed;
  top:              var(--spacing-md);
  left:             var(--spacing-md);
  height:           calc(100vh - (var(--spacing-md) * 2));
  border-radius:    var(--radius-xl);
  z-index:          100;
  overflow-x:       hidden;
  overflow-y:       auto;
  -ms-overflow-style: none;
  scrollbar-width:  none;
  transition:       width 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}
.sidebar::-webkit-scrollbar { display: none; }
.sidebar.collapsed {
  width: 80px;
}

.sidebar__logo {
  padding:     var(--spacing-lg) var(--spacing-md);
  font-size:   var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  border-bottom: 1px solid var(--sidebar-separator);
  display:     flex;
  align-items: center;
  justify-content: space-between;
  white-space: nowrap;
}
.sidebar__logo .logo-wrapper {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

/* Toggle button */
.sidebar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 1.2rem;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1), background 0.2s ease, color 0.2s ease;
}
.sidebar-toggle:hover {
  background: var(--toggle-hover-bg);
  color: var(--color-primary);
}
.sidebar.collapsed .sidebar-toggle {
  transform: rotate(180deg);
}
.sidebar__logo .logo-text {
  overflow:    hidden;
  white-space: nowrap;
  max-width:   160px;
  opacity:     1;
  transition:  opacity  0.22s ease 0.22s,
               max-width 0.4s  cubic-bezier(0.25, 1, 0.5, 1) 0s;
}
.sidebar.collapsed .sidebar__logo .logo-text {
  opacity:    0;
  max-width:  0;
  transition: opacity  0.14s ease 0s,
              max-width 0.4s  cubic-bezier(0.25, 1, 0.5, 1) 0s;
}

.sidebar__nav {
  flex:        1;
  padding:     var(--spacing-md) 0;
  display:     flex;
  flex-direction: column;
}

.sidebar__nav a {
  display:       flex;
  align-items:   center;
  gap:           var(--spacing-sm);
  padding:       var(--spacing-sm) var(--spacing-md);
  color:         var(--color-text-muted);
  border-radius: var(--radius-sm);
  margin:        2px var(--spacing-sm);
  transition:    all var(--transition-fast);
  cursor:        pointer;
  white-space:   nowrap;
  overflow:      hidden;
  position:      relative;
}

.sidebar.collapsed .sidebar__nav a {
  justify-content: center;
  padding: var(--spacing-sm);
}
.sidebar__nav a .icon,
.sidebar__nav a svg.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform var(--transition-fast), color var(--transition-fast), stroke var(--transition-fast);
}

.sidebar__logo .logo-img {
  width: 26px;
  height: auto;
  flex-shrink: 0;
}

.sidebar__logo .icon,
.sidebar__logo svg.icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  stroke: var(--color-primary);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sidebar__nav a span.label {
  /* Al expandir: max-width crece de inmediato, texto aparece con delay */
  overflow:        hidden;
  white-space:     nowrap;
  max-width:       180px;
  opacity:         1;
  transition:      opacity  0.22s ease 0.22s,
                   max-width 0.4s  cubic-bezier(0.25, 1, 0.5, 1) 0s;
}
.sidebar.collapsed .sidebar__nav a span.label {
  /* Al colapsar: texto desaparece rápido, max-width sigue al sidebar */
  opacity:         0;
  max-width:       0;
  transition:      opacity  0.14s ease 0s,
                   max-width 0.4s  cubic-bezier(0.25, 1, 0.5, 1) 0s;
}

.sidebar__nav a:hover,
.sidebar__nav a.nav-item--active {
  background-color: var(--color-surface);
  color:            var(--color-primary);
  box-shadow:       var(--shadow-sm);
  text-decoration:  none;
}

.sidebar__nav a:hover .icon,
.sidebar__nav a:hover svg.icon,
.sidebar__nav a.nav-item--active .icon,
.sidebar__nav a.nav-item--active svg.icon {
  transform: scale(1.15);
  color: var(--color-primary);
  stroke: var(--color-primary);
}

.sidebar__footer {
  padding:       var(--spacing-md);
  border-top:    1px solid var(--sidebar-separator);
  display:       flex;
  justify-content: center;
}
.sidebar__footer .label {
  overflow:    hidden;
  white-space: nowrap;
  max-width:   120px;
  opacity:     1;
  transition:  opacity  0.22s ease 0.22s,
               max-width 0.4s  cubic-bezier(0.25, 1, 0.5, 1) 0s;
}
.sidebar.collapsed .sidebar__footer .label {
  opacity:    0;
  max-width:  0;
  transition: opacity  0.14s ease 0s,
              max-width 0.4s  cubic-bezier(0.25, 1, 0.5, 1) 0s;
}
.sidebar__footer .btn .icon,
.sidebar__footer .btn svg.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform var(--transition-fast);
}
.sidebar__footer .btn:hover .icon,
.sidebar__footer .btn:hover svg.icon {
  transform: scale(1.15) translateX(2px);
}

.main-content {
  margin-left: calc(var(--sidebar-width) + var(--spacing-md));
  flex:         1;
  padding:      var(--spacing-xl);
  max-width:    calc(100% - var(--sidebar-width) - var(--spacing-md));
  min-height:   100vh;
  transition:   margin-left 0.4s cubic-bezier(0.25, 1, 0.5, 1), max-width 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}
.app-layout.sidebar-collapsed .main-content {
  margin-left: calc(80px + var(--spacing-md));
  max-width:   calc(100% - 80px - var(--spacing-md));
}

/* ── Contenedor de toasts ────────────────────────────────────── */
.toast-container {
  position:       fixed;
  bottom:         var(--spacing-xl);
  right:          var(--spacing-xl);
  z-index:        1000;
  display:        flex;
  flex-direction: column;
  gap:            var(--spacing-sm);
}

/* ── Responsividad mobile ────────────────────────────────────── */
@media (max-width: 768px) {
  /* Ocultar el sidebar lateral — reemplazado por el bottom nav */
  .sidebar { display: none !important; }

  /* El contenido ocupa el ancho total */
  .main-content {
    margin-left: 0 !important;
    max-width:   100% !important;
    padding:     16px 16px 88px;   /* 88px = bottom nav (64px) + margen */
    min-height:  100svh;
  }

  /* Guest banner: el app-layout baja, el padding-top es suficiente */
  body.has-guest-banner .main-content { padding-top: 60px; }

  /* Toasts: flotan sobre el bottom nav */
  .toast-container {
    bottom: 76px;
    right:  var(--spacing-md);
    left:   var(--spacing-md);
    right:  var(--spacing-md);
  }
}

/* ═══════════════════════════════════════════════════════════
   MODO OSCURO — sobreescribe variables del :root
   Todas las clases del sistema se adaptan automáticamente.
═══════════════════════════════════════════════════════════ */
[data-theme="dark"] {
  /* Neutros */
  --color-text:           #e2e8f0;
  --color-text-muted:     #94a3b8;
  --color-text-light:     #64748b;
  --color-bg:             #0f0f1a;
  --color-surface:        #1a1a2e;
  --color-border:         #2a2a40;
  --color-border-dark:    #3a3a58;

  /* Primario — un poco más claro para mantener contraste en fondo oscuro */
  --color-primary:        #9b94ff;
  --color-primary-light:  #b8b3ff;
  --color-primary-dark:   #7b72ee;
  --color-primary-rgb:    155, 148, 255;  /* #9b94ff */

  /* Sombras más pronunciadas */
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md:  0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg:  0 8px 24px rgba(0, 0, 0, 0.6);

  /* Sidebar oscuro — frosted glass dark */
  --sidebar-bg:         rgba(18, 18, 32, 0.88);
  --sidebar-border:     rgba(255, 255, 255, 0.07);
  --sidebar-shadow:     0 12px 40px rgba(0, 0, 0, 0.45);
  --sidebar-separator:  rgba(255, 255, 255, 0.07);
  --toggle-hover-bg:    rgba(255, 255, 255, 0.06);

  /* Skeleton */
  --skeleton-base:  #2a2a40;
  --skeleton-shine: #363656;

  /* Controles nativos del navegador (select, input, scrollbar…) */
  color-scheme: dark;
}

/* ═══════════════════════════════════════════════════════════════
   ACCESIBILIDAD (Fase 3)
   ═══════════════════════════════════════════════════════════════ */

/* Foco visible por teclado en TODO elemento interactivo (WCAG 2.4.7).
   Usa :focus-visible, así el anillo aparece al navegar con teclado pero
   no molesta al hacer clic con el mouse. No pisa los inputs que ya
   definen su propio indicador (border/box-shadow) en :focus. */
:focus-visible {
  outline:        2px solid var(--color-primary, #6c63ff);
  outline-offset: 2px;
}

/* Respeta la preferencia del sistema de reducir el movimiento (WCAG 2.3.3):
   desactiva animaciones y transiciones para quienes marean o distraen. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration:        0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration:       0.001ms !important;
    scroll-behavior:           auto !important;
  }
}
