/* 
  ======================================================
  DESIGN SYSTEM (SaaS 2026) - VARIABLES GLOBALES
  ======================================================
*/
:root {
  /* Paleta Principal (Linear/Notion Vibe) */
  --bg-body: #f8fafc; /* Gris hiper sutil para el fondo general */
  --bg-surface: #ffffff; /* Blanco puro para cards y paneles */
  --bg-sidebar: #0f172a; /* Slate 900 para sidebar corporativo */
  --bg-sidebar-hover: #1e293b;
  
  --primary: #4f46e5; /* Indigo 600 */
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  
  --secondary: #64748b; /* Slate 500 */
  --secondary-hover: #475569;
  
  /* Textos */
  --text-main: #0f172a; /* Casi negro para máximo contraste */
  --text-muted: #64748b;
  --text-sidebar: #94a3b8;
  --text-sidebar-active: #ffffff;
  
  /* Estados */
  --success: #10b981;
  --success-bg: #d1fae5;
  --error: #ef4444;
  --error-bg: #fee2e2;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  
  /* Bordes y Divisores */
  --border-light: #e2e8f0;
  --border-medium: #cbd5e1;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  
  /* Sombras Modernas (Sutiles y profundas) */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.05);
  
  /* Tipografía */
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  
  /* Espaciados (Sistema de 8px) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-8: 48px;
  
  /* Layout Dimensions */
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 68px;
  --header-height: 64px;
}

[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-surface: #1e293b;
  --bg-sidebar: #020617;
  --bg-sidebar-hover: #1e293b;
  
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-light: rgba(99, 102, 241, 0.2);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --border-light: #334155;
  --border-medium: #475569;
}

/* ======================================================
   RESET & TIPOGRAFÍA BASE
   ====================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden; /* Prevent body scroll, layout handles it */
}

/* ======================================================
   SaaS LAYOUT BASE (CSS Grid)
   ====================================================== */
.saas-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  height: 100vh;
  width: 100vw;
  transition: grid-template-columns 0.3s ease;
}

.saas-layout.collapsed {
  grid-template-columns: var(--sidebar-collapsed-width) 1fr;
}

/* SIDEBAR */
.saas-sidebar {
  grid-row: 1 / -1;
  background-color: var(--bg-sidebar);
  border-right: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  color: var(--text-sidebar);
  transition: transform 0.3s ease;
  z-index: 200;
  overflow: hidden;
}

/* Logo area: fondo ligeramente diferenciado con borde inferior */
.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-4);
  gap: var(--sp-3);
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

/* Contenedor del logo con fondo blanco suave y redondeado */
.sidebar-logo-img-wrapper {
  background: rgba(255,255,255,0.12);
  border-radius: var(--radius-md);
  padding: 4px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  letter-spacing: -0.01em;
}

/* NAV: items alineados a la izquierda */
.sidebar-nav {
  padding: var(--sp-3) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

/* Separador visual opcional */
.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(148,163,184,0.5);
  padding: var(--sp-3) var(--sp-4) var(--sp-1);
}

.sidebar-nav .tab-btn {
  /* Anular todos los estilos agresivos del style.css viejo */
  flex: unset !important;
  min-width: unset !important;
  border: none !important;
  border-radius: var(--radius-md) !important;
  background: transparent !important;
  color: var(--text-sidebar) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: var(--sp-3) !important;
  padding: 10px var(--sp-4) !important;
  cursor: pointer !important;
  font-family: var(--font-family) !important;
  font-size: 0.9rem !important;
  font-weight: 500 !important;
  text-align: left !important;
  width: 100% !important;
  transition: all 0.15s ease !important;
  white-space: nowrap !important;
  box-shadow: none !important;
}

.sidebar-nav .tab-btn span {
  font-size: 1rem;
  flex-shrink: 0;
}

.sidebar-nav .tab-btn:hover {
  background-color: rgba(255,255,255,0.07) !important;
  color: #fff !important;
  border-color: transparent !important;
}

.sidebar-nav .tab-btn.active {
  background-color: var(--primary) !important;
  color: #fff !important;
  font-weight: 600 !important;
  border-color: transparent !important;
  box-shadow: 0 2px 8px rgba(79,70,229,0.4) !important;
}


/* HEADER TOP */
.saas-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-6);
  z-index: 90;
}

.header-search input {
  background: var(--bg-body);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-4);
  font-family: inherit;
  font-size: 0.9rem;
  width: 300px;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s;
}

.header-search input:focus {
  border-color: var(--primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: var(--bg-body);
}

/* MAIN CONTENT AREA */
.saas-main {
  background-color: var(--bg-body);
  overflow-y: auto;
  padding: var(--sp-6);
}

.tab-panel {
  display: none;
  max-width: 1400px; /* Ancho máximo para pantallas enormes */
  margin: 0 auto;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ======================================================
   COMPONENTES (Cards, Forms, Buttons)
   ====================================================== */

/* Cards */
.saas-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-6);
  margin-bottom: var(--sp-6);
}

.saas-card-header {
  margin-bottom: var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.saas-card-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Forms (Grid 3 columnas) */
.saas-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--sp-5);
  margin-bottom: var(--sp-5);
  align-items: end; /* Para alinear botones con inputs */
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.input-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.saas-input {
  background: var(--bg-body);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text-main);
  outline: none;
  transition: all 0.2s;
  width: 100%;
}

.saas-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  background: var(--bg-surface);
}

/* Botones Modernos */
.saas-btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 20px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  white-space: nowrap;
}

.saas-btn-primary:hover {
  background: var(--primary-hover);
}

.saas-btn-primary:active {
  transform: scale(0.98);
}

.saas-btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Utilidades visuales */
.hidden {
  display: none !important;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: var(--sp-1);
}

.flex-center {
  display: flex;
  align-items: center;
}

/* ======================================================
   SIDEBAR RESPONSIVE (Mobile)
   ====================================================== */

/* Botón hamburguesa — oculto en desktop */
.sidebar-toggle-btn {
  display: none;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.4rem;
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.sidebar-toggle-btn:hover { background: var(--bg-body); }

/* Overlay para cerrar el sidebar en móvil */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  opacity: 0;
  transition: opacity 0.3s;
  cursor: pointer;
  pointer-events: none; /* << NO bloquear clics cuando está invisible */
}
.sidebar-overlay.active {
  opacity: 1;
  pointer-events: all; /* << Solo interceptar clics cuando está visible */
}

/* ── Mobile breakpoint ─────────────────────────── */
@media (max-width: 768px) {
  .saas-layout {
    grid-template-columns: 1fr;
  }

  .saas-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    z-index: 200;
  }

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

  .sidebar-overlay {
    display: block;
    pointer-events: none; /* Asegurarse que no bloquea nada hasta activarse */
  }

  .sidebar-toggle-btn {
    display: flex;
  }

  .saas-main-wrapper {
    width: 100%;
  }

  .header-search input {
    width: 100%;
    max-width: 200px;
  }
}

/* ======================================================
   HOME DASHBOARD (Pantalla de Inicio)
   ====================================================== */

/* Hero Section */
.home-hero {
  text-align: center;
  padding: var(--sp-8) var(--sp-5) var(--sp-6);
  max-width: 700px;
  margin: 0 auto;
}

.home-hero-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 6px 16px;
  border-radius: 99px;
  margin-bottom: var(--sp-4);
}

.home-hero-title {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
  margin-bottom: var(--sp-3);
  letter-spacing: -0.03em;
}

.home-hero-sub {
  font-size: 1.05rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Módulos Grid */
.home-modules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--sp-5);
  max-width: 1300px;
  margin: 0 auto var(--sp-6);
}

/* Tarjeta de Módulo */
.home-module-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-5);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  position: relative;
  font-family: var(--font-family);
  overflow: hidden;
}

.home-module-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg), 0 0 0 3px var(--primary-light);
  transform: translateY(-3px);
}

.home-module-featured {
  border-color: rgba(220, 38, 38, 0.3);
  background: linear-gradient(160deg, var(--bg-surface) 60%, rgba(220, 38, 38, 0.04));
}

.home-module-featured:hover {
  border-color: #dc2626;
  box-shadow: var(--shadow-lg), 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.home-module-badge {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  background: linear-gradient(135deg, #dc2626, #f97316);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 99px;
}

.home-module-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  flex-shrink: 0;
}

.home-module-content {
  flex: 1;
}

.home-module-content h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: var(--sp-2);
}

.home-module-content p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: var(--sp-3);
}

.home-module-features {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.home-module-features li {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding-left: var(--sp-1);
}

.home-module-cta {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  margin-top: var(--sp-2);
}

.home-module-card:hover .home-module-cta {
  text-decoration: underline;
}

/* Tip de Configuración */
.home-tip {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: var(--radius-lg);
  padding: var(--sp-4) var(--sp-5);
  max-width: 1300px;
  margin: 0 auto;
  font-size: 0.9rem;
  color: #78350f;
}

[data-theme="dark"] .home-tip {
  background: rgba(245,158,11,0.1);
  border-color: rgba(245,158,11,0.3);
  color: #fbbf24;
}

.home-tip-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
  margin-top: 2px;
}

@media (max-width: 768px) {
  .home-modules-grid {
    grid-template-columns: 1fr;
  }
  .home-hero-title {
    font-size: 1.6rem;
  }
  .home-hero {
    padding: var(--sp-5) var(--sp-3) var(--sp-4);
  }
}

/* ======================================================
   HISTORIAL LOCAL
   ====================================================== */
.ap-history-item {
    background: var(--bg-body);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: var(--sp-3);
    cursor: pointer;
    transition: all 0.2s ease;
}

.ap-history-item:hover {
    border-color: var(--primary);
    background: var(--bg-surface);
    transform: translateX(4px);
}

.ap-history-title {
    font-size: 0.85rem;
    color: var(--text-main);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ap-history-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}
