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

/* =========================================================
   DESIGN TOKENS
   ========================================================= */
:root {
  --bg-deep:        #0b0f19;
  --bg-color:       #111827;
  --card-bg:        #1f2937;
  --card-bg-hover:  #374151;
  --text-main:      #f9fafb;
  --text-muted:     #9ca3af;
  --text-dim:       #6b7280;
  --accent:         #fbbf24;
  --accent-glow:    rgba(251, 191, 36, 0.1);
  --blue:           #3b82f6;
  --blue-glow:      rgba(59, 130, 246, 0.1);
  --green:          #10b981;
  --green-glow:     rgba(16, 185, 129, 0.1);
  --red:            #ef4444;
  --red-glow:       rgba(239, 68, 68, 0.1);
  --purple:         #8b5cf6;
  --purple-glow:    rgba(139, 92, 246, 0.1);
  --orange:         #f59e0b;
  --orange-glow:    rgba(245, 158, 11, 0.1);
  --border:         rgba(255, 255, 255, 0.05);
  --border-light:   rgba(255, 255, 255, 0.1);
  --sidebar-w:      260px;
  --radius:         16px;
  --radius-sm:      8px;
  --transition:     all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --glass:          rgba(255, 255, 255, 0.03);
  --glass-border:   rgba(255, 255, 255, 0.08);
}

/* =========================================================
   RESET & BASE — Mobile-First
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background:   var(--bg-deep);
  color:        var(--text-main);
  font-family:  'Inter', sans-serif;
  font-size:    clamp(0.875rem, 1.5vw, 1rem);
  min-height:   100vh;
  overflow-x:   hidden;
  -webkit-tap-highlight-color: transparent;
}

img, svg { max-width: 100%; height: auto; }

/* =========================================================
   SCROLLBAR
   ========================================================= */
::-webkit-scrollbar          { width: 6px; }
::-webkit-scrollbar-track    { background: transparent; }
::-webkit-scrollbar-thumb    { background: var(--border-light); border-radius: 10px; }

/* =========================================================
   LAYOUT — Mobile first (sidebar oculto por defecto)
   ========================================================= */
.layout {
  display:    flex;
  width:      100vw;
  min-height: 100vh;
  overflow:   hidden;
}

/* Main ocupa todo en móvil */
.main-content {
  flex:            1;
  min-width:       0;          /* evita overflow en flex */
  margin-left:     0;
  overflow-y:      auto;
  padding:         1rem;
  background:      var(--bg-deep);
  display:         flex;
  flex-direction:  column;
  transition:      var(--transition);
}

.main-container {
  width:     100%;
  max-width: 100%;
}

/* =========================================================
   SIDEBAR
   ========================================================= */
.sidebar {
  width:      var(--sidebar-w);
  background: #0f172a;
  border-right: 1px solid var(--border);
  position:   fixed;
  top:        0;
  left:       0;
  bottom:     0;
  display:    flex;
  flex-direction: column;
  z-index:    200;
  transform:  translateX(-100%);
  transition: var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar.mobile-open {
  transform: translateX(0);
}

#sidebar-overlay {
  display:    none;
  position:   fixed;
  inset:      0;
  background: rgba(0, 0, 0, 0.65);
  z-index:    150;
  backdrop-filter: blur(2px);
}

#sidebar-overlay.active { display: block; }

#app-shell[style*="display: none"] .sidebar,
#app-shell[style*="display:none"]  .sidebar { display: none !important; }

.sidebar-brand {
  padding:       1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink:   0;
}

.nav-section-title {
  padding:        1.5rem 1.5rem 0.5rem;
  font-size:      0.6875rem;
  font-weight:    700;
  color:          var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Touch target ≥ 48px */
.nav-item {
  display:     flex;
  align-items: center;
  gap:         0.75rem;
  padding:     0.875rem 1.5rem;
  min-height:  48px;
  cursor:      pointer;
  color:       var(--text-muted);
  transition:  var(--transition);
  position:    relative;
  margin:      0 0.5rem 0.25rem;
  border-radius: 8px;
}

.nav-item:hover  { color: var(--text-main); background: rgba(255,255,255,0.05); }
.nav-item.active { color: var(--blue);      background: var(--blue-glow); }
.nav-item.active .nav-icon { filter: none; opacity: 1; }

.nav-item.active::before {
  content:       '';
  position:      absolute;
  left:          0;
  top:           8px;
  bottom:        8px;
  width:         4px;
  background:    var(--blue);
  border-radius: 0 4px 4px 0;
}

.nav-icon  { font-size: 1.125rem; opacity: 1; color: #fff; filter: none; }
.nav-label { font-size: 0.8125rem; font-weight: 500; }

/* =========================================================
   HEADER
   ========================================================= */
.header {
  display:         flex;
  justify-content: space-between;
  align-items:     center;
  margin-bottom:   1.5rem;
  flex-wrap:       wrap;
  gap:             0.75rem;
}

.header-left .breadcrumb {
  font-size:   0.75rem;
  color:       var(--text-dim);
  margin-bottom: 0.25rem;
}

.header-left h2 {
  font-size:   clamp(1rem, 3vw, 1.25rem);
  font-weight: 700;
}

.header-right {
  display:     flex;
  align-items: center;
  gap:         0.75rem;
  flex-wrap:   wrap;
}

/* En móvil ocultar controles de rol y búsqueda */
.header-right > div:not(.hamburger-wrap),
.header-right > div[style*="background:rgba"] {
  display: none;
}

.search-box {
  background:    rgba(255,255,255,0.05);
  border:        1px solid var(--border);
  padding:       0.625rem 1rem;
  border-radius: 12px;
  color:         #fff;
  font-size:     0.875rem;
  width:         min(280px, 100%);
  outline:       none;
  transition:    var(--transition);
}

.search-box:focus {
  border-color: var(--accent);
  background:   rgba(255,255,255,0.08);
}

/* =========================================================
   HAMBURGER — visible en móvil
   ========================================================= */
.hamburger {
  display:         flex !important;
  align-items:     center;
  justify-content: center;
  min-width:       48px;
  min-height:      48px;
  background:      rgba(255,255,255,0.05);
  border:          1px solid var(--border);
  border-radius:   10px;
  color:           #fff;
  font-size:       1.25rem;
  cursor:          pointer;
  transition:      var(--transition);
  flex-shrink:     0;
}

.hamburger:hover { background: rgba(255,255,255,0.1); }

/* =========================================================
   KPI GRID — 1 col móvil → auto-fit desktop
   ========================================================= */
.kpi-grid {
  display:               grid;
  grid-template-columns: 1fr;
  gap:                   1rem;
  margin-bottom:         1.5rem;
}

.kpi-card {
  background:    var(--card-bg);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       1.25rem;
  transition:    var(--transition);
}

.kpi-card:hover {
  transform:    translateY(-4px);
  background:   var(--card-bg-hover);
  border-color: var(--border-light);
}

.kpi-label {
  font-size:      clamp(0.6875rem, 1.5vw, 0.75rem);
  font-weight:    600;
  color:          var(--text-dim);
  text-transform: uppercase;
  margin-bottom:  0.75rem;
}

.kpi-value {
  font-size:     clamp(1.25rem, 4vw, 1.5rem);
  font-weight:   700;
  margin-bottom: 0.5rem;
}

.kpi-progress       { height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden; }
.kpi-progress-bar   { height: 100%; background: var(--accent); }
.kpi-sub            { font-size: clamp(0.6875rem, 1.5vw, 0.75rem); color: var(--text-dim); margin-top: 0.5rem; }

/* =========================================================
   QUICK ACTIONS
   ========================================================= */
.quick-actions {
  display:   flex;
  gap:       0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.action-btn {
  padding:       0.75rem 1.25rem;
  min-height:    48px;
  border-radius: 12px;
  border:        1px solid var(--border);
  background:    rgba(255,255,255,0.03);
  color:         var(--text-main);
  font-size:     clamp(0.75rem, 1.5vw, 0.8125rem);
  font-weight:   600;
  cursor:        pointer;
  display:       flex;
  align-items:   center;
  gap:           0.5rem;
  transition:    var(--transition);
}

.action-btn:hover { background: rgba(255,255,255,0.08); border-color: var(--border-light); }
.action-btn.primary { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #60a5fa; }

/* =========================================================
   PAGE HEADERS — fluid typography
   ========================================================= */
.page-h1 {
  font-size:   clamp(1.375rem, 5vw, 2rem);
  font-weight: 900;
  margin-bottom: 0.75rem;
  letter-spacing: -0.5px;
}

/* Aplicar a los h1 generados dinámicamente */
#page-content h1 {
  font-size:   clamp(1.375rem, 5vw, 2rem) !important;
  font-weight: 900 !important;
  letter-spacing: -0.5px;
}

/* =========================================================
   LOGIN SCREEN
   ========================================================= */
#login-screen {
  display:         flex;
  min-height:      100vh;
  align-items:     center;
  justify-content: center;
  background:      #020617;
  position:        relative;
  overflow:        hidden;
  padding:         1rem;
}

#login-screen::before {
  content:  '';
  position: absolute;
  width:    min(600px, 80vw);
  height:   min(600px, 80vw);
  background: radial-gradient(circle, rgba(59,130,246,0.1) 0%, transparent 70%);
  top:   -200px;
  right: -200px;
}

#login-screen::after {
  content:  '';
  position: absolute;
  width:    min(400px, 60vw);
  height:   min(400px, 60vw);
  background: radial-gradient(circle, rgba(251,191,36,0.05) 0%, transparent 70%);
  bottom: -100px;
  left:   -100px;
}

.login-card {
  background:     rgba(30, 41, 59, 0.4);
  backdrop-filter: blur(12px);
  border:         1px solid rgba(255,255,255,0.1);
  padding:        clamp(1.5rem, 5vw, 3rem);
  border-radius:  clamp(16px, 4vw, 32px);
  width:          100%;
  max-width:      440px;
  text-align:     center;
  box-shadow:     0 25px 50px -12px rgba(0,0,0,0.5);
  z-index:        1;
}

.login-logo { margin-bottom: 2rem; display: flex; justify-content: center; }

.btn-google {
  width:           100%;
  display:         flex;
  align-items:     center;
  justify-content: center;
  gap:             0.75rem;
  padding:         0.875rem;
  min-height:      48px;
  background:      #fff;
  color:           #1f2937;
  border:          none;
  border-radius:   12px;
  font-weight:     700;
  cursor:          pointer;
  transition:      var(--transition);
  margin-top:      1.5rem;
}

.btn-google:hover { background: #f3f4f6; transform: translateY(-2px); }

/* =========================================================
   DOCUMENTOS — Carpetas
   ========================================================= */
.folder {
  background:    var(--bg-deep);
  border:        1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 0.75rem;
  overflow:      hidden;
  transition:    all 0.3s ease;
}

.folder-header {
  padding:         1rem 1.5rem;
  display:         flex;
  justify-content: space-between;
  align-items:     center;
  cursor:          pointer;
  background:      rgba(255,255,255,0.02);
  font-weight:     600;
  min-height:      48px;
}

.folder-header:hover { background: rgba(255,255,255,0.05); }

.folder-content {
  padding:               1rem;
  display:               none;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap:                   0.75rem;
  border-top:            1px solid var(--border);
}

.folder.open .folder-content { display: grid; }

.doc-btn {
  background:    var(--card-bg);
  border:        1px solid var(--border);
  padding:       0.75rem;
  min-height:    48px;
  border-radius: 8px;
  display:       flex;
  align-items:   center;
  gap:           0.625rem;
  color:         var(--text-muted);
  font-size:     0.8125rem;
  cursor:        pointer;
  transition:    all 0.2s;
  width:         100%;
}

.doc-btn:hover { border-color: var(--blue); background: var(--blue-glow); color: #fff; }

/* =========================================================
   ALERTAS / BADGES
   ========================================================= */
.absent-card {
  border-left: 4px solid var(--red) !important;
  background:  rgba(239,68,68,0.08) !important;
  animation:   pulse-red 2s infinite;
}

@keyframes pulse-red {
  0%   { box-shadow: 0 0 0 0   rgba(239,68,68,0.4); }
  70%  { box-shadow: 0 0 0 10px rgba(239,68,68,0);   }
  100% { box-shadow: 0 0 0 0   rgba(239,68,68,0);   }
}

.nav-badge {
  padding:        0.25rem 0.75rem;
  min-height:     32px;
  border-radius:  6px;
  font-size:      clamp(0.625rem, 1.2vw, 0.6875rem);
  font-weight:    700;
  border:         1px solid var(--border-light);
  background:     rgba(255,255,255,0.05);
  color:          var(--text-main);
  cursor:         pointer;
  transition:     var(--transition);
  text-transform: uppercase;
  display:        inline-flex;
  align-items:    center;
}

.nav-badge:hover           { background: rgba(255,255,255,0.1); border-color: var(--text-muted); }
.nav-badge.primary         { background: var(--blue-glow); border-color: var(--blue); color: var(--blue); }
.nav-badge.primary:hover   { background: var(--blue); color: #fff; }
.nav-badge.wa              { background: #25d366 !important; color: #fff !important; border: none; }

/* =========================================================
   FILTROS PILL
   ========================================================= */
.filter-bar {
  display:       flex;
  flex-wrap:     wrap;
  gap:           0.625rem;
  margin-bottom: 1.5rem;
  padding:       0.25rem;
}

.pill {
  background:    var(--bg-color);
  border:        1px solid var(--border);
  padding:       0.5rem 1rem;
  min-height:    40px;
  border-radius: 20px;
  display:       flex;
  align-items:   center;
  gap:           0.5rem;
  font-size:     clamp(0.75rem, 1.5vw, 0.8125rem);
  font-weight:   600;
  color:         var(--text-muted);
  cursor:        pointer;
  transition:    all 0.2s;
}

.pill:hover  { background: var(--card-bg-hover); border-color: var(--border-light); }
.pill.active { background: var(--blue-glow); border-color: var(--blue); color: #fff; box-shadow: 0 0 15px rgba(56,189,248,0.2); }

.pill-badge             { font-size: 0.625rem; background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 10px; }
.pill.active .pill-badge{ background: var(--blue); color: #fff; }
.pill.red               { border-color: var(--red); color: var(--red); }
.pill.red:hover         { background: var(--red-glow); }
.pill.yellow            { border-color: var(--accent); color: var(--accent); }
.pill.yellow:hover      { background: var(--accent-glow); }

/* =========================================================
   PROGRESO CIRCULAR
   ========================================================= */
.progress-circle {
  width:         clamp(70px, 15vw, 110px);
  height:        clamp(70px, 15vw, 110px);
  border-radius: 50%;
  background:    conic-gradient(var(--accent) var(--p), rgba(255,255,255,0.05) 0);
  display:       flex;
  align-items:   center;
  justify-content: center;
  position:      relative;
  margin:        0 auto 0.75rem;
}

.progress-circle::before {
  content:       '';
  position:      absolute;
  width:         87%;
  height:        87%;
  border-radius: 50%;
  background:    var(--card-bg);
}

.progress-circle .inner-text {
  position:    relative;
  z-index:     1;
  font-size:   clamp(0.75rem, 2.5vw, 0.875rem);
  font-weight: 800;
  color:       var(--text-main);
}

/* =========================================================
   GLASSMORPHISM CARD
   ========================================================= */
.card {
  background:     var(--glass);
  backdrop-filter: blur(8px);
  border:         1px solid var(--glass-border);
  border-radius:  var(--radius);
  box-shadow:     0 8px 32px rgba(0,0,0,0.2);
}

.card:hover {
  border-color: rgba(255,255,255,0.2);
  background:   rgba(255,255,255,0.05);
}

/* =========================================================
   CONTEXT MENU
   ========================================================= */
.context-menu {
  position:  fixed;
  background: #1e293b;
  border:    1px solid var(--border-light);
  border-radius: 8px;
  padding:   0.5rem 0;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.5);
  z-index:   1000;
  display:   none;
}

.context-menu-item {
  padding:     0.5rem 1rem;
  font-size:   0.8125rem;
  min-height:  40px;
  cursor:      pointer;
  color:       var(--text-main);
  display:     flex;
  align-items: center;
  gap:         0.5rem;
}

.context-menu-item:hover { background: var(--blue-glow); color: var(--blue); }

/* =========================================================
   TABLAS — Responsive con scroll horizontal
   ========================================================= */
.table-responsive {
  width:      100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
}

.table-responsive table {
  min-width: 560px;  /* fuerza scroll antes de colapsar */
}

/* En móvil pequeño: ocultar columnas poco críticas */
@media (max-width: 639px) {
  .col-hide-mobile { display: none !important; }
}

/* =========================================================
   MODALES — Mobile-First
   ========================================================= */
.modal-overlay {
  position:        fixed;
  inset:           0;
  background:      rgba(0,0,0,0.85);
  backdrop-filter: blur(12px);
  z-index:         10000;
  display:         flex;
  align-items:     center;
  justify-content: center;
  padding:         1rem;
}

.modal-inner {
  width:         100%;
  max-width:     650px;
  padding:       clamp(1.25rem, 5vw, 2.5rem);
  position:      relative;
  border-radius: var(--radius);
  max-height:    90vh;
  overflow-y:    auto;
}

/* Grid del modal de canje — 1 col móvil, 2 col desktop */
.modal-grid-canje {
  display:               grid;
  grid-template-columns: 1fr;
  gap:                   1.5rem;
}

/* =========================================================
   TOAST CONTAINER — Safe area para iOS
   ========================================================= */
#toast-container {
  position:        fixed;
  bottom:          max(24px, env(safe-area-inset-bottom));
  right:           max(16px, env(safe-area-inset-right));
  z-index:         9999;
  display:         flex;
  flex-direction:  column;
  gap:             10px;
  max-width:       calc(100vw - 32px);
}

/* =========================================================
   TABLET — min-width: 640px
   ========================================================= */
@media (min-width: 640px) {
  .main-content { padding: 1.5rem; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }

  /* Mostrar controles de rol en header */
  .header-right > div { display: flex; }

  .folder-content {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  .modal-grid-canje {
    grid-template-columns: 1.2fr 1fr;
  }
}

/* =========================================================
   DESKTOP — min-width: 992px
   ========================================================= */
@media (min-width: 992px) {
  .sidebar        { transform: translateX(0) !important; }
  .main-content   { margin-left: var(--sidebar-w); padding: 2rem; }
  .hamburger      { display: none !important; }
  #sidebar-overlay{ display: none !important; }

  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

  .header-right > div { display: flex; }
}

/* =========================================================
   LARGE DESKTOP — min-width: 1280px
   ========================================================= */
@media (min-width: 1280px) {
  .main-content { padding: 2rem 2.5rem; }
}

/* =========================================================
   FICHAJE CLOCK — fluid en móvil
   ========================================================= */
#fichaje-clock {
  font-size: clamp(3rem, 15vw, 5rem) !important;
}

/* =========================================================
   ROLE SWITCHER HEADER — colapso en móvil
   ========================================================= */
@media (max-width: 639px) {
  .role-switcher-wrap {
    display: none !important;
  }
}

/* =========================================================
   BOTONES DE ACCIÓN EN FICHAJEENTRY — touch-friendly
   ========================================================= */
.fichaje-btn-group {
  display:         flex;
  justify-content: center;
  gap:             1rem;
  flex-wrap:       wrap;
}

.fichaje-btn-group button {
  flex:       1;
  min-width:  140px;
  max-width:  200px;
  min-height: 52px;
}

/* =========================================================
   ACCIONES RÁPIDAS — min-width en móvil
   ========================================================= */
.quick-action-grid {
  display:   flex;
  flex-wrap: wrap;
  gap:       0.75rem;
}

.quick-action-grid button,
.quick-action-grid .nav-badge {
  flex:      1 1 auto;
  min-width: clamp(140px, 40%, 200px);
  justify-content: center;
  padding:   0.875rem 1rem;
  min-height: 48px;
}

/* =========================================================
   GRIDS DE PÁGINAS — Ajuste de minmax para móvil
   ========================================================= */
/* Override inline styles via container queries (fallback con clamp) */
.grid-auto-300 {
  display:               grid;
  grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
  gap:                   1.5rem;
}

.grid-auto-450 {
  display:               grid;
  grid-template-columns: repeat(auto-fit, minmax(min(450px, 100%), 1fr));
  gap:                   2.5rem;
}

.grid-auto-280 {
  display:               grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap:                   1.5rem;
}

/* =========================================================
   TABS DE DOCUMENTOS — scroll horizontal en móvil
   ========================================================= */
.doc-tabs-wrap {
  display:                  flex;
  gap:                      0.75rem;
  margin-bottom:            2rem;
  overflow-x:               auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom:           0.25rem;
  scrollbar-width:          none;
}

.doc-tabs-wrap::-webkit-scrollbar { display: none; }

.doc-tabs-wrap button {
  flex-shrink: 0;
  min-height:  48px;
}

/* =========================================================
   DATE / DATETIME INPUTS — dark theme
   ========================================================= */
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"] {
  color-scheme: dark;
  color: #fff;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(1.5);
  cursor: pointer;
}