/* ================================================================
   design-tokens.css — EGE Unified Design System
   Style: Corporate ERSCE — Navy + Yellow
   ================================================================ */

/* ── Design Tokens ── */
:root {
  /* Backgrounds */
  --bg-page: #eef1f7;
  --bg-surface: #FFFFFF;
  --bg-surface-alt: #f0f2f8;
  --bg-surface-hover: #f7f8fc;
  --bg-header: #0b0b5e;
  --bg-header-end: #151595;
  --bg-header-hover: rgba(255,255,255,0.10);
  --bg-sidebar: #0e0e52;
  --bg-sidebar-end: #090940;
  --bg-sidebar-hover: rgba(255,255,255,0.07);
  --bg-sidebar-active: rgba(255, 210, 0, 0.12);

  /* Text */
  --text-primary: #1F2328;
  --text-secondary: #5C6670;
  --text-muted: #9AA0AC;
  --text-inverse: #FFFFFF;
  --text-link: #1d4ed8;
  --text-link-hover: #1e3a8a;

  /* Borders */
  --border-default: #dce1ea;
  --border-light: #e9ecf3;
  --border-focus: #3b82f6;

  /* Brand accent (corporate yellow — headers, badges, highlights) */
  --accent: #ffd200;
  --accent-hover: #ffe033;
  --accent-soft: rgba(255, 210, 0, 0.10);
  --accent-ring: rgba(255, 210, 0, 0.30);
  --accent-text: #0b0b5e;

  /* Functional green (actions, success, CTAs) */
  --fn-accent: #10b981;
  --fn-accent-hover: #0ea672;
  --fn-accent-soft: rgba(16, 185, 129, 0.10);
  --fn-accent-ring: rgba(16, 185, 129, 0.25);

  /* Corporate blue (links, info, secondary CTA) */
  --corp-blue: #3b82f6;
  --corp-blue-hover: #2563eb;
  --corp-blue-soft: rgba(59, 130, 246, 0.10);
  --corp-blue-ring: rgba(59, 130, 246, 0.25);

  /* Semantic colors */
  --color-success: #1F7A4D;
  --color-success-bg: #ecfdf5;
  --color-warning: #B25E00;
  --color-warning-bg: #fffbeb;
  --color-danger: #B42318;
  --color-danger-bg: #fef2f2;
  --color-info: #155EEF;
  --color-info-bg: #eff6ff;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.07), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10), 0 2px 8px rgba(0,0,0,0.04);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.06);

  /* Border radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-pill: 999px;

  /* Typography */
  --font-body: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, 'Liberation Mono', monospace;
  --font-size-xs: 0.8rem;
  --font-size-sm: 0.9rem;
  --font-size-base: 1rem;
  --font-size-md: 1.075rem;
  --font-size-lg: 1.25rem;
  --font-size-xl: 1.5rem;
  --font-size-2xl: 1.85rem;
  --font-size-3xl: 2.25rem;
  --line-height: 1.6;

  /* Spacing (8pt base) — Toni 2026-05-14: convertidos a clamp() para
     que escalen proporcionalmente con el viewport.
     Baseline: 1920×1080 (monitor del user). Vw aporta el escalado,
     min/max protegen los extremos para que no se rompa en pantallas
     pequeñas (1366) ni se hinchen en 4K. */
  --space-1: clamp(3px, 0.21vw, 6px);    /* base 4px @ 1920 */
  --space-2: clamp(6px, 0.42vw, 12px);   /* base 8px */
  --space-3: clamp(8px, 0.63vw, 18px);   /* base 12px */
  --space-4: clamp(12px, 0.83vw, 22px);  /* base 16px */
  --space-5: clamp(14px, 1.04vw, 28px);  /* base 20px */
  --space-6: clamp(18px, 1.25vw, 34px);  /* base 24px */
  --space-8: clamp(22px, 1.67vw, 44px);  /* base 32px */
  --space-10: clamp(28px, 2.08vw, 56px); /* base 40px */

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;

  /* Header height */
  --header-height: 60px;
  --sidebar-width: 62px;
  --sidebar-width-expanded: 230px;
}

/* ── Global Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
}

/* ── Toni 2026-05-14: Fluid root font-size ──
   El "santo grial" del responsive proporcional. Baseline: 1920×1080
   = 16px root. clamp() protege monitores chicos (1366) y 4K (3840).
   Fórmula: y = ax + b donde a=0.45vw aporta la pendiente y el rem fijo
   marca el punto base. En 1920 → ~16px; en 1366 → ~13.4px; en 2560
   → ~18.9px; en 3840 → ~22.5px (capado por max 1.4rem si se llegara).
   Como ~92% de las font-size del proyecto están en rem, este cambio
   ESCALA TODA LA TIPOGRAFÍA automáticamente sin tocar otras reglas. */
html {
  font-size: clamp(13px, 0.55rem + 0.45vw, 22px);
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

/* Use dynamic viewport height where supported so mobile browser chrome
   (URL bar showing/hiding) doesn't leave residual scroll. Falls back to
   100% on browsers without dvh support. */
@supports (height: 100dvh) {
  html, body {
    height: 100dvh;
  }
}

body {
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--text-primary);
  background-color: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Pages that use the standard app shell (base.html → base_sidebar.html)
   delegate scrolling to the interior wrapper (.base_sidebar-content-wrapper).
   Hiding body overflow eliminates the residual page-level scroll caused
   by the fixed header + padding-top combo and any inner content using
   calc(100vh - X) that doesn't perfectly account for nested padding.
   Standalone pages (partes, invoice_classifier, login) opt out by not
   adding the .app-shell class. */
body.app-shell {
  overflow: hidden;
}

/* ── Focus Styles — kill all browser focus rings on click ── */
*:focus,
*:focus-visible,
*:focus-within,
*:-moz-focusring {
  outline: none !important;
  -webkit-tap-highlight-color: transparent;
}
button:focus,
button:focus-visible,
[type="button"]:focus,
[type="button"]:focus-visible,
[role="button"]:focus,
[role="button"]:focus-visible {
  outline: none !important;
  box-shadow: none;
}

/* ── Selection ── */
::selection {
  background: var(--corp-blue-soft);
  color: var(--text-primary);
}

/* ── Custom Scrollbar ── */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}

/* ── Links ── */
a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  color: var(--text-link-hover);
}

/* ── Flash Messages (Toast style) ── */
.flash-messages {
  position: fixed;
  bottom: var(--space-8);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  width: 90%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.flash-messages .alert {
  border: none;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-sm);
  font-weight: 500;
  padding: var(--space-3) var(--space-4);
}
.flash-messages .alert-success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-left: 3px solid var(--color-success);
}
.flash-messages .alert-danger,
.flash-messages .alert-error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-left: 3px solid var(--color-danger);
}
.flash-messages .alert-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border-left: 3px solid var(--color-warning);
}
.flash-messages .alert-info {
  background: var(--color-info-bg);
  color: var(--color-info);
  border-left: 3px solid var(--color-info);
}

/* ── Animations & Keyframes ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(11, 11, 94, 0.3); }
  50%      { box-shadow: 0 0 0 8px transparent; }
}

/* ── Glassmorphism Utility ── */
.glass {
  background: rgba(255,255,255,0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.3);
}

/* ── Enhanced Button Base ── */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(255,255,255,0.15), transparent);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.btn:hover::after {
  opacity: 1;
}

/* ── Smooth Page Transitions ── */
.base_sidebar-content-wrapper,
.base-container-fluid {
  animation: fadeIn 0.3s ease-out;
}

/* ── Enhanced Card Hover Effects ── */
.hover-lift {
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}
.hover-lift:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

/* ── Gradient Text Utility ── */
.text-gradient {
  background: linear-gradient(135deg, var(--bg-header), var(--corp-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Enhanced Table Styles ── */
.table thead th {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 0.72rem;
  background: #f9fafb;
  color: #6b7280;
  border-bottom: 1px solid #e5e7eb;
  padding: 12px 14px;
}
.table tbody tr {
  transition: background-color 0.15s ease;
}
.table tbody td {
  padding: 10px 14px;
  border: 1px solid #e5e7eb;
  color: #374151;
}
.table {
  font-size: 0.82rem;
}

/* ── Unified Export / Download Button ── */
.export-btn-unified,
#exportButton,
#downloadPdfBtn,
.download-icon,
.export-container .btn,
.export-dropdown > .btn,
.form-and-export-container .export-dropdown .btn {
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  background: white !important;
  border: 1px solid #e5e7eb !important;
  border-radius: 8px !important;
  cursor: pointer !important;
  font-size: 0.78rem !important;
  font-weight: 500 !important;
  color: #6b7280 !important;
  padding: 6px 14px !important;
  font-family: inherit !important;
  letter-spacing: 0.2px !important;
  text-decoration: none !important;
  transition: all 0.15s ease !important;
  box-shadow: none !important;
  line-height: 1.4 !important;
}

.export-btn-unified:hover,
#exportButton:hover,
#downloadPdfBtn:hover,
.download-icon:hover,
.export-container .btn:hover,
.export-dropdown > .btn:hover,
.form-and-export-container .export-dropdown .btn:hover {
  color: var(--corp-blue) !important;
  border-color: var(--corp-blue) !important;
  background: rgba(59, 130, 246, 0.04) !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1) !important;
  text-decoration: none !important;
}

/* Unified dropdown menus */
#exportDropdown,
.export-dropdown .dropdown-menu,
.form-and-export-container .export-dropdown .dropdown-menu {
  border-radius: 12px !important;
  border: 1px solid #e5e7eb !important;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12) !important;
  padding: 4px 0 !important;
  min-width: 180px !important;
  overflow: hidden !important;
  background: white !important;
}

#exportDropdown a,
.export-dropdown .dropdown-item,
.form-and-export-container .export-dropdown .dropdown-item {
  padding: 10px 16px !important;
  font-size: 0.82rem !important;
  color: #374151 !important;
  font-weight: 500 !important;
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  transition: all 0.15s ease !important;
  text-decoration: none !important;
}

#exportDropdown a:hover,
.export-dropdown .dropdown-item:hover,
.form-and-export-container .export-dropdown .dropdown-item:hover {
  background: rgba(59, 130, 246, 0.06) !important;
  color: var(--corp-blue) !important;
}

/* ── Flash Message Animation ── */
.flash-messages .alert {
  animation: fadeInUp 0.4s ease-out;
}
