/* =============================================
   EASYSUITE - SIDEBAR CSS COMÚN
   Color oscuro fijo (no cambia con tema)
   ============================================= */

:root {
  --sidebar-width: 280px;
  --sidebar-collapsed-width: 70px;
  --sidebar-bg: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  --sidebar-text: rgba(255, 255, 255, 0.9);
  --sidebar-text-muted: rgba(255, 255, 255, 0.6);
  --sidebar-hover: rgba(255, 255, 255, 0.05);
  --sidebar-border: rgba(255, 255, 255, 0.05);
  --accent: #7c3aed;
  --accent-light: #8b5cf6;
}

[data-system="EASYFAC"] {
  --accent: #f59e0b;
  --accent-light: #fbbf24;
}

[data-system="EASYSTOCK"] {
  --accent: #10b981;
  --accent-light: #34d399;
}

[data-system="EASYPOS"] {
  --accent: #ec4899;
  --accent-light: #f472b6;
}

[data-system="EASYCOMPRAS"] {
  --accent: #0ea5e9;
  --accent-light: #38bdf8;
}

[data-system="EASYCRM"] {
  --accent: #8b5cf6;
  --accent-light: #a78bfa;

}

[data-system="EASYCONTAB"] {
  --accent: #0D9488;
  --accent-light: #14b8a6;
}

* { box-sizing: border-box; }

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease;
  z-index: 1000;
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

/* Header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  overflow: hidden;
}

.sidebar-logo-icon {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  white-space: nowrap;
}

.sidebar-logo-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--sidebar-text);
}

.sidebar-logo-name .name {
  color: var(--accent);
}

.sidebar-logo-subtitle {
  font-size: 0.7rem;
  color: var(--sidebar-text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.sidebar.collapsed .sidebar-logo-text {
  display: none;
}

.btn-collapse {
  width: 32px;
  height: 32px;
  background: var(--sidebar-hover);
  border: none;
  border-radius: 8px;
  color: var(--sidebar-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-collapse:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--sidebar-text);
}

.btn-collapse svg {
  transition: transform 0.3s;
}

.sidebar.collapsed .btn-collapse svg {
  transform: rotate(180deg);
}

.sidebar.collapsed .btn-collapse {
  margin: 0 auto;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--sidebar-hover);
  border-radius: 4px;
}

.nav-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--sidebar-text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 12px 12px 8px;
  white-space: nowrap;
}

.sidebar.collapsed .nav-title {
  text-align: center;
  padding: 12px 0 8px;
}

/* Módulos */
.module-group {
  margin-bottom: 4px;
  position: relative;
}

.module-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  color: var(--sidebar-text);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  user-select: none;
}

.module-header:hover {
  background: var(--sidebar-hover);
}

.module-header.active {
  background: var(--sidebar-hover);
}

.module-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: var(--sidebar-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.module-header:hover .module-icon,
.module-header.active .module-icon {
  color: var(--accent);
}

.module-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar.collapsed .module-name,
.sidebar.collapsed .module-arrow {
  display: none;
}

.module-arrow {
  width: 16px;
  height: 16px;
  color: var(--sidebar-text-muted);
  transition: transform 0.2s;
}

.module-group.open .module-arrow {
  transform: rotate(90deg);
}

/* Popup flotante - ahora controlado por clase .open */
.module-windows {
  position: fixed;
  min-width: 220px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.25);
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-10px);
  transition: all 0.2s ease;
  z-index: 99999;
  pointer-events: none;
}

/* Mostrar popup cuando el módulo tiene clase .open */
.module-group.open .module-windows {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
  pointer-events: auto;
}

.module-windows::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 16px;
  width: 12px;
  height: 12px;
  background: white;
  transform: rotate(45deg);
  box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.05);
}

.popup-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 12px 6px;
}

.window-item {
  margin: 2px 0;
}

.window-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: #475569;
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.2s;
  font-size: 0.875rem;
}

.window-link:hover {
  background: #f1f5f9;
}

.window-link.active {
  background: rgba(124, 58, 237, 0.1);
  font-weight: 500;
}

[data-system="EASYFAC"] .window-link:hover,
[data-system="EASYFAC"] .window-link.active {
  color: #f59e0b;
}

[data-system="EASYSTOCK"] .window-link:hover,
[data-system="EASYSTOCK"] .window-link.active {
  color: #10b981;
}

[data-system="EASYCONTAB"] .window-link:hover,
[data-system="EASYCONTAB"] .window-link.active {
  color: #0D9488;
}

.window-link .window-icon {
  width: 16px;
  height: 16px;
  color: #94a3b8;
}

.window-link:hover .window-icon,
.window-link.active .window-icon {
  color: inherit;
}

/* Footer */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--sidebar-hover);
  border-radius: 10px;
  margin-bottom: 8px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.user-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar.collapsed .user-info {
  display: none;
}

.sidebar.collapsed .sidebar-user {
  justify-content: center;
  padding: 8px;
}

.empresa-actual {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 8px;
  color: var(--accent-light);
  font-size: 0.8rem;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

[data-system="EASYFAC"] .empresa-actual {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.2);
}

[data-system="EASYSTOCK"] .empresa-actual {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.2);
}

[data-system="EASYCONTAB"] .empresa-actual {
  background: rgba(13, 148, 136, 0.1);
  border-color: rgba(13, 148, 136, 0.2);
}

.empresa-actual:hover {
  background: rgba(16, 185, 129, 0.15);
}

.empresa-actual svg {
  flex-shrink: 0;
}

.empresa-actual span {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar.collapsed .empresa-actual {
  justify-content: center;
}

.sidebar.collapsed .empresa-actual span {
  display: none;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--sidebar-text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.sidebar-btn:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

.sidebar-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-btn span {
  white-space: nowrap;
}

.sidebar.collapsed .sidebar-btn {
  justify-content: center;
  padding: 10px;
}

.sidebar.collapsed .sidebar-btn span {
  display: none;
}

.sidebar-btn.logout:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

/* Main content */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  background: #f8fafc;
  transition: margin-left 0.3s ease;
}

.sidebar.collapsed ~ .main-content {
  margin-left: var(--sidebar-collapsed-width);
}

/* Modales */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: white;
  border-radius: 16px;
  max-width: 450px;
  width: 100%;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.25);
  animation: modalSlide 0.3s ease;
}

@keyframes modalSlide {
  from { opacity: 0; transform: translateY(-20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid #e2e8f0;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: #64748b;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.2s;
}

.modal-close:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid #e2e8f0;
}

.modal-footer .btn {
  flex: 1;
  padding: 12px 20px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
  font-family: inherit;
}

.modal-footer .btn-outline {
  background: white;
  border: 2px solid #e2e8f0;
  color: #64748b;
}

.modal-footer .btn-outline:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.modal-footer .btn-primary {
  background: var(--accent);
  border: none;
  color: white;
}

.modal-footer .btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Lista empresas modal */
.empresas-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.empresa-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.empresa-option:hover {
  border-color: var(--accent);
  background: white;
}

.empresa-option.active {
  border-color: var(--accent);
  background: rgba(124, 58, 237, 0.05);
}

.empresa-option-logo {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
}

.empresa-option-info {
  flex: 1;
}

.empresa-option-name {
  font-weight: 600;
  color: #0f172a;
  font-size: 0.9rem;
}

.empresa-option-rut {
  color: #64748b;
  font-size: 0.8rem;
}

/* Modal logout */
.modal-logout-content {
  text-align: center;
}

.modal-logout-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: #fef2f2;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ef4444;
}

.modal-logout-content h4 {
  font-size: 1.1rem;
  color: #0f172a;
  margin-bottom: 8px;
}

.modal-logout-content p {
  color: #64748b;
  font-size: 0.9rem;
}

/* Nav loading */
.nav-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px;
  color: var(--sidebar-text-muted);
}

.nav-loading .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--sidebar-hover);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0;
  }
  
  .sidebar.collapsed ~ .main-content {
    margin-left: 0;
  }
}
/* ── Modal Sistemas (Cambiar Sistema) ── */
.modal-sistemas-box {
  max-width: 680px;
}

.sistemas-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 8px 0;
}

.sistema-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 12px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  position: relative;
}

.sistema-card:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
  transform: translateY(-2px);
}

.sistema-card.active {
  border-color: #8b5cf6;
  background: rgba(139, 92, 246, 0.05);
}

.sistema-card-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sistema-card-icon svg {
  width: 28px;
  height: 28px;
}

.sistema-card-nombre {
  font-size: 0.85rem;
  font-weight: 700;
  color: #1e293b;
}

.sistema-card-sub {
  font-size: 0.72rem;
  color: #64748b;
}

.sistema-card-actual {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 0.6rem;
  font-weight: 600;
  color: #8b5cf6;
  background: rgba(139, 92, 246, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
}

@media (max-width: 640px) {
  .sistemas-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}