/**
 * SIDEBAR MODERNA - OCSEVIS v2.0
 * Diseño profesional, compacto y responsive
 */

/* ============================================
   VARIABLES
   ============================================ */
:root {
  /* Colores */
  --sidebar-bg: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  --sidebar-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --text-primary: #ffffff;
  --text-secondary: #e2e8f0;
  --border-color: rgba(255, 255, 255, 0.1);
  --hover-bg: rgba(59, 130, 246, 0.1);
  --active-bg: rgba(59, 130, 246, 0.2);
  --danger-color: #ef4444;
  
  /* Dimensiones */
  --sidebar-width: 200px;
  --sidebar-width-collapsed: 50px;
  
  /* Espaciado */
  --spacing-xs: 4px;
  --spacing-sm: 6px;
  --spacing-md: 8px;
  --spacing-lg: 12px;
  
  /* Otros */
  --border-radius: 6px;
  --transition-speed: 0.3s;
}

/* ============================================
   SIDEBAR CONTAINER
   ============================================ */
.ocsevis-sidebar {
  position: fixed;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: var(--sidebar-width);
  max-height: 95vh;
  background: var(--sidebar-bg);
  box-shadow: var(--sidebar-shadow);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: all var(--transition-speed) ease;
  border-radius: 0 12px 12px 0;
  overflow: hidden;
}

/* Ocultar scrollbar pero permitir scroll */
.ocsevis-sidebar::-webkit-scrollbar {
  width: 4px;
}

.ocsevis-sidebar::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}

.ocsevis-sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.ocsevis-sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.ocsevis-sidebar.collapsed {
  width: var(--sidebar-width-collapsed);
  transform: translateY(-50%);
}

.ocsevis-sidebar.collapsed .btn-text,
.ocsevis-sidebar.collapsed .brand-text,
.ocsevis-sidebar.collapsed .section-title {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

/* ============================================
   COLLAPSIBLE SECTIONS
   ============================================ */
.sidebar-section.collapsible .collapsible-header {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
  user-select: none;
}

.sidebar-section.collapsible .collapsible-header:hover {
  color: #60a5fa;
}

.sidebar-section.collapsible .collapse-icon {
  transition: transform 0.3s ease;
  flex-shrink: 0;
  margin-left: 4px;
}

.sidebar-section.collapsible.collapsed .collapse-icon {
  transform: rotate(-90deg);
}

.sidebar-section.collapsible .collapsible-content {
  display: block;
  transition: all 0.3s ease;
  overflow: hidden;
}

.sidebar-section.collapsible.collapsed .collapsible-content {
  display: none;
}

/* ============================================
   HEADER
   ============================================ */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-sm) var(--spacing-sm);
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.2);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  flex: 1;
  overflow: hidden;
}

.brand-logo {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.brand-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 var(--spacing-xs) 0;
  letter-spacing: 0.5px;
}

.sidebar-collapse-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: var(--spacing-sm);
  cursor: pointer;
  border-radius: var(--border-radius);
  transition: all var(--transition-speed) ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

.collapsed .sidebar-collapse-btn svg {
  transform: rotate(180deg);
}

/* ============================================
   CONTENT
   ============================================ */
.sidebar-content {
  flex: 1;
  padding: var(--spacing-sm);
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(95vh - 120px);
}

.sidebar-content::-webkit-scrollbar {
  width: 4px;
}

.sidebar-content::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

/* ============================================
   SECTIONS
   ============================================ */
.sidebar-section {
  margin-bottom: var(--spacing-md);
}

.sidebar-section:last-child {
  margin-bottom: 0;
}

.section-title {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--spacing-xs);
  padding-left: var(--spacing-xs);
  opacity: 0.8;
}

/* ============================================
   BUTTONS
   ============================================ */
.sidebar-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-md);
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: var(--spacing-xs);
  text-align: left;
}

.sidebar-btn:hover {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  transform: translateX(2px);
  border-left: 3px solid #3b82f6;
}

.sidebar-btn:active {
  transform: translateX(0);
}

.sidebar-btn.active {
  background: var(--active-bg);
  color: var(--primary-color);
}

.sidebar-btn.compact {
  flex: 1;
  margin-bottom: 0;
  padding: var(--spacing-sm) var(--spacing-md);
  font-weight: 600;
}

.btn-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.btn-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity var(--transition-speed) ease, width var(--transition-speed) ease;
}

/* ============================================
   ITEM ROWS (Button + Toggle)
   ============================================ */
.sidebar-item-row {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  margin-bottom: var(--spacing-xs);
}

/* ============================================
   TOGGLE SWITCH
   ============================================ */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 22px;
  transition: all 0.3s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary-color);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(14px);
}

.toggle-switch:hover .toggle-slider {
  background: rgba(255, 255, 255, 0.25);
}

.toggle-switch input:checked:hover + .toggle-slider {
  background: var(--primary-hover);
}

/* ============================================
   ZONES
   ============================================ */
.sidebar-zones {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-xs);
  margin-bottom: var(--spacing-sm);
}

.zone-btn {
  padding: var(--spacing-xs);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--border-radius);
  transition: all var(--transition-speed) ease;
  text-align: center;
}

.zone-btn:hover {
  background: var(--hover-bg);
  border-color: var(--primary-color);
  color: var(--text-primary);
}

.zone-btn.active {
  background: var(--active-bg);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* ============================================
   STORES COUNTER
   ============================================ */
.stores-counter {
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--border-radius);
  padding: var(--spacing-md);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.counter-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-secondary);
}

.counter-item.total {
  padding-top: var(--spacing-sm);
  border-top: 1px solid var(--border-color);
  font-size: 14px;
  font-weight: 600;
}

.counter-label {
  color: var(--text-muted);
}

.counter-value {
  color: var(--text-primary);
  font-weight: 700;
  font-size: 16px;
}

/* ============================================
   FOOTER
   ============================================ */
.sidebar-footer {
  padding: var(--spacing-md);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: auto;
}

/* Selector de Idioma en Sidebar */
.lang-selector {
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 8px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.lang-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 36px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lang-btn:hover {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.1);
  transform: scale(1.05);
}

.lang-btn.active {
  background: #3b82f6;
  border-color: #3b82f6;
}

.logout-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-md);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--border-radius);
  transition: all var(--transition-speed) ease;
  text-align: left;
}

.logout-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--danger-color);
  color: var(--danger-color);
  transform: translateX(2px);
}

/* ============================================
   LANGUAGE SELECTOR
   ============================================ */
.language-selector {
  width: 100%;
}

.language-select {
  width: 100%;
  padding: var(--spacing-sm);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition-speed) ease;
  outline: none;
}

.language-select:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--primary-color);
}

.language-select:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.language-select option {
  background: #1e293b;
  color: var(--text-primary);
  padding: var(--spacing-sm);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 600px) {
  .ocsevis-sidebar {
    top: 0;
    transform: translateX(-100%);
    max-height: 100vh;
    border-radius: 0;
  }
  
  .ocsevis-sidebar.mobile-open {
    transform: translateX(0);
  }
  
  /* Overlay para móvil */
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-speed) ease;
  }
  
  .sidebar-overlay.active {
    opacity: 1;
    pointer-events: all;
  }
}

/* Tablets y pantallas medianas (600px - 1024px) */
@media (max-width: 1024px) and (min-width: 601px) {
  .ocsevis-sidebar {
    width: 180px; /* Sidebar más estrecha en tablets */
  }
  
  .btn-text {
    font-size: 10px;
  }
  
  .sidebar-btn {
    padding: var(--spacing-xs) var(--spacing-xs);
    gap: 4px;
  }
  
  .zone-btn {
    padding: 4px;
    font-size: 9px;
  }
  
  .btn-icon {
    width: 12px;
    height: 12px;
  }
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.sidebar-btn,
.zone-btn {
  animation: slideIn 0.3s ease backwards;
}

.sidebar-btn:nth-child(1) { animation-delay: 0.05s; }
.sidebar-btn:nth-child(2) { animation-delay: 0.1s; }
.sidebar-btn:nth-child(3) { animation-delay: 0.15s; }
.sidebar-btn:nth-child(4) { animation-delay: 0.2s; }
.sidebar-btn:nth-child(5) { animation-delay: 0.25s; }

/* ============================================
   DARK MODE ADJUSTMENTS
   ============================================ */
@media (prefers-color-scheme: light) {
  :root {
    --sidebar-bg: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    --sidebar-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border-color: rgba(0, 0, 0, 0.1);
    --hover-bg: rgba(0, 0, 0, 0.05);
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.sidebar-divider {
  height: 1px;
  background: var(--border-color);
  margin: var(--spacing-md) 0;
}

.sidebar-spacer {
  height: var(--spacing-md);
}
