/**
 * Sidebar Moderno para OpenRest
 * Version: 1.0
 * Diseño limpio y funcional
 */

/* Variables del tema OpenRest Naranja */
:root {
  --sidebar-width: 260px;
  --sidebar-collapsed: 70px;
  --sidebar-bg: #ffffff;
  --sidebar-border: #f0f0f0;
  --item-hover: #fff5f0;
  --item-active: #FF6B35;
  --item-active-bg: rgba(255, 107, 53, 0.08);
  --text-primary: #3A4752;
  --text-secondary: #8b95a7;
  --text-open: #3A4752;
  --text-rest: #F8285A;
  --icon-brand: #0074BA;
  --orange-primary: #FF6B35;
  --orange-secondary: #FF8C42;
  --orange-hover: #ff5722;
  --icon-size: 22px;
  --success: #10B981;
  --danger: #EF4444;
}

/* Sidebar Base */
.modern-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1050; /* Mayor que el navbar para que esté por encima */
  display: flex;
  flex-direction: column;
}

/* Sidebar Colapsado */
.modern-sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

/* Header del Sidebar con Perfil */
.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 80px;
  background: linear-gradient(135deg, var(--orange-primary) 0%, var(--orange-secondary) 100%);
  position: relative;
  overflow: visible;
  transition: all 0.3s ease;
}

.modern-sidebar.collapsed .sidebar-header {
  padding: 0.75rem 0;
  justify-content: center;
  align-items: center;
  min-height: 100px; /* Espacio para botón + foto en vertical */
  flex-direction: column;
  gap: 8px;
}

/* Perfil en header del sidebar */
.sidebar-profile-header {
  display: flex;
  align-items: center;
  gap: 12px;
  transition: transform 0.3s ease;
}

/* Cuando está colapsado, el perfil se mueve hacia abajo */
.modern-sidebar.collapsed .sidebar-profile-header {
  transform: translateY(10px);
  order: 2; /* El perfil va segundo (abajo) */
}

.modern-sidebar.collapsed .sidebar-profile-header .sidebar-profile-info {
  display: none;
}

.sidebar-header .sidebar-profile-img {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.3);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: all 0.3s ease;
}

.modern-sidebar.collapsed .sidebar-header .sidebar-profile-img {
  width: 40px;
  height: 40px;
  border-width: 2px;
}

.sidebar-header .sidebar-profile-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: white;
  line-height: 1.2;
}

.sidebar-header .sidebar-profile-role {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.8);
  margin-top: 2px;
}

/* Logo */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--icon-brand);
  font-size: 24px;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.sidebar-logo:hover .sidebar-logo-icon {
  transform: scale(1.1) rotate(-5deg);
}

.sidebar-logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modern-sidebar.collapsed .sidebar-logo-text {
  display: none;
}

/* Botón Toggle */
.sidebar-toggle {
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255,255,255,0.2);
  color: white;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.sidebar-toggle:hover {
  background: rgba(255,255,255,0.3);
  transform: scale(1.05);
}

.sidebar-toggle i {
  font-size: 20px;
  transition: transform 0.3s ease;
}

/* Badge del Restaurante */
.sidebar-restaurant-badge {
  padding: 8px 16px;
  margin: 0 12px;
  margin-top: 8px;
  background: rgba(255, 107, 53, 0.08);
  border-radius: 8px;
  border: 1px solid rgba(255, 107, 53, 0.15);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
}

.sidebar-restaurant-badge i {
  font-size: 16px;
  color: var(--orange-primary);
  flex-shrink: 0;
}

.sidebar-restaurant-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

/* Cuando el sidebar está colapsado */
.modern-sidebar.collapsed .sidebar-restaurant-badge {
  margin: 8px 8px;
  padding: 6px;
  justify-content: center;
  border-radius: 50%;
  width: 36px;
  height: 36px;
}

.modern-sidebar.collapsed .sidebar-restaurant-name {
  display: none;
}

.modern-sidebar.collapsed .sidebar-restaurant-badge i {
  font-size: 18px;
}

/* Animación: el botón se mueve de derecha a arriba cuando se colapsa */
.modern-sidebar.collapsed .sidebar-toggle {
  order: 1; /* El botón va primero (arriba) */
  background: rgba(255,255,255,0.9);
  color: var(--orange-primary);
  width: 32px;
  height: 32px;
  animation: slideToTop 0.3s ease forwards;
}

@keyframes slideToTop {
  from {
    transform: translateX(100px) translateY(0);
    opacity: 0.7;
  }
  to {
    transform: translateX(0) translateY(-5px);
    opacity: 1;
  }
}

/* Icono del botón rota cuando se colapsa */
.modern-sidebar.collapsed .sidebar-toggle i {
  transform: rotate(180deg);
}

.modern-sidebar.collapsed .sidebar-toggle:hover {
  background: white;
  transform: scale(1.1) translateY(-5px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Contenido del Sidebar */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 0;
}

/* Scrollbar personalizado */
.sidebar-content::-webkit-scrollbar {
  width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: var(--text-secondary);
  border-radius: 3px;
  opacity: 0.5;
}

/* Items del Menú */
.sidebar-menu {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-item {
  margin-bottom: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  color: var(--text-primary);
  text-decoration: none;
  transition: all 0.2s;
  position: relative;
  gap: 12px;
}

.modern-sidebar.collapsed .sidebar-link {
  padding: 12px 0;
  justify-content: center;
}

.sidebar-link:hover {
  background: var(--item-hover);
  color: var(--item-active);
}

/* Item Activo */
.sidebar-item.active > .sidebar-link {
  background: var(--item-active-bg);
  color: var(--orange-primary);
  font-weight: 600;
}

.sidebar-item.active > .sidebar-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 70%;
  background: var(--orange-primary);
  border-radius: 0 2px 2px 0;
}

/* Hover mejorado */
.sidebar-link:hover {
  background: var(--item-hover);
  color: var(--orange-primary);
}

.sidebar-link:hover .sidebar-icon {
  transform: translateX(2px);
}

/* Iconos */
.sidebar-icon {
  width: var(--icon-size);
  height: var(--icon-size);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Texto del menú */
.sidebar-text {
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
}

.modern-sidebar.collapsed .sidebar-text {
  display: none;
}

/* Indicador de Submenú */
.sidebar-arrow {
  margin-left: auto;
  transition: transform 0.2s;
  font-size: 12px;
  color: var(--text-secondary);
}

.modern-sidebar.collapsed .sidebar-arrow {
  display: none;
}

.sidebar-item.open > .sidebar-link .sidebar-arrow {
  transform: rotate(90deg);
}

/* Submenú */
.sidebar-submenu {
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--item-hover);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.sidebar-item.open > .sidebar-submenu {
  max-height: 500px;
}

.sidebar-submenu .sidebar-link {
  padding-left: 52px;
  font-size: 0.8125rem;
}

.modern-sidebar.collapsed .sidebar-submenu {
  display: none;
}

/* Tooltip para items colapsados */
.modern-sidebar.collapsed .sidebar-item {
  position: relative;
}

.modern-sidebar.collapsed .sidebar-link:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 10px;
  padding: 6px 12px;
  background: var(--text-primary);
  color: white;
  font-size: 0.75rem;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 1000;
  pointer-events: none;
}

/* Perfil de Usuario */
.sidebar-profile {
  padding: 1rem;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-profile-img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--sidebar-border);
}

.sidebar-profile-info {
  flex: 1;
  min-width: 0;
}

.sidebar-profile-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-profile-role {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.modern-sidebar.collapsed .sidebar-profile-info {
  display: none;
}

.modern-sidebar.collapsed .sidebar-profile {
  justify-content: center;
  padding: 1rem 0;
}

/* Separador */
.sidebar-divider {
  height: 1px;
  background: var(--sidebar-border);
  margin: 1rem 20px;
}

.modern-sidebar.collapsed .sidebar-divider {
  margin: 1rem 10px;
}

/* Badge para notificaciones */
.sidebar-badge {
  background: var(--item-active);
  color: white;
  font-size: 0.625rem;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: auto;
}

.modern-sidebar.collapsed .sidebar-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 4px;
  min-width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.sidebar-link {
  animation: slideIn 0.3s ease;
}

/* Responsive */
@media (max-width: 768px) {
  .modern-sidebar {
    transform: translateX(-100%);
  }
  
  .modern-sidebar.mobile-open {
    transform: translateX(0);
  }
  
  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    display: none;
  }
  
  .sidebar-overlay.show {
    display: block;
  }
}

/* Ajuste del contenido principal - se desplaza con el sidebar */
#main-wrapper {
  min-height: 100vh;
  position: relative;
}

.page-wrapper.main-content {
  margin-left: var(--sidebar-width) !important;
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 100vh;
  background: #f8f9fa;
  position: relative;
  width: calc(100% - var(--sidebar-width)) !important;
}

/* Cuando el sidebar está colapsado - IMPORTANTE: usar !important para override */
body.sidebar-collapsed .page-wrapper.main-content {
  margin-left: var(--sidebar-collapsed) !important;
  width: calc(100% - var(--sidebar-collapsed)) !important;
}

/* Asegurar que TODO el contenido se desplace */
body:not(.sidebar-collapsed) .page-wrapper {
  padding-left: 0 !important;
  margin-left: var(--sidebar-width) !important;
}

body.sidebar-collapsed .page-wrapper {
  padding-left: 0 !important;
  margin-left: var(--sidebar-collapsed) !important;
}

/* Header se ajusta al contenido */
.page-wrapper.main-content .topbar {
  position: sticky;
  top: 0;
  width: 100%;
  z-index: 999;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 70px;
  overflow: visible !important; /* No cortar contenido */
}

/* El navbar dentro del header debe ser flexible */
.topbar .navbar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 70px;
  padding: 10px 15px !important; /* Padding vertical adecuado */
  overflow: visible !important;
}

/* Asegurar que los elementos del navbar no se corten */
.topbar .navbar-nav {
  flex-wrap: nowrap;
  overflow: visible !important; /* Cambiar de auto a visible */
  align-items: center;
  gap: 10px;
}

/* Los botones del header no deben cortarse */
.topbar .nav-link,
.topbar .btn,
.topbar .dropdown-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 5px 0; /* Margen vertical */
}

/* Eliminar cualquier overflow y scrollbar en el topbar */
.topbar {
  overflow: visible !important;
}

.topbar::-webkit-scrollbar {
  display: none !important;
}

/* Prevenir scrollbar en focus */
.topbar:focus,
.topbar *:focus {
  overflow: visible !important;
  outline-offset: -2px; /* Mantener outline dentro del elemento */
}

/* Si hay dropdowns, que no se corten */
.topbar .dropdown-menu {
  position: absolute !important;
  z-index: 1050 !important;
}

/* Forzar que los dropdowns se abran hacia la izquierda si están muy a la derecha */
.topbar .navbar-nav:last-child .dropdown-menu,
.topbar .ms-auto .dropdown-menu {
  right: 0 !important;
  left: auto !important;
}

/* Asegurar que dropdown-menu-end funcione correctamente */
.dropdown-menu-end {
  right: 0 !important;
  left: auto !important;
}

/* En móviles, permitir scroll horizontal si es necesario */
@media (max-width: 768px) {
  .topbar .navbar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Ajustar el body-wrapper */
.body-wrapper {
  padding-bottom: 30px; /* Espacio inferior para que no se corten los botones */
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: calc(100vh - 100px); /* Altura mínima */
}

/* Asegurar que el contenido se mueva suavemente */
.container-fluid {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding-bottom: 30px; /* Espacio extra en la parte inferior */
}

/* Ajustar contenedores de botones circulares o grandes */
.card-body:has(.btn-circle),
.card-body:has(.rounded-circle),
.card-body:has(.btn-lg) {
  min-height: auto !important;
  padding-bottom: 20px !important;
  overflow: visible !important;
}

/* Asegurar que los botones grandes/circulares no se corten */
.btn-circle,
.btn-rounded-circle,
.rounded-circle.btn,
a.rounded-circle {
  margin-bottom: 10px !important;
  position: relative !important;
}

/* Si los botones están en un row/grid */
.row:has(.btn-circle),
.row:has(.rounded-circle) {
  margin-bottom: 20px !important;
  overflow: visible !important;
}

/* Cards con botones en la parte inferior */
.card:has(.btn-circle),
.card:has(.rounded-circle) {
  overflow: visible !important;
  margin-bottom: 20px !important;
}

/* Ajustar el card que contiene los 4 botones */
.card .row .col-3:has(.rounded-circle),
.card .row .col-md-3:has(.rounded-circle) {
  padding-bottom: 15px !important;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --sidebar-bg: #1f2937;
    --sidebar-border: #374151;
    --item-hover: #374151;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
  }
}

/* ========================================
   TOOLTIPS PARA SIDEBAR COLAPSADO
   ======================================== */
   
/* Los tooltips ahora usan Bootstrap's tooltip component */
/* Se activan solo cuando el sidebar está colapsado mediante JavaScript */

/* ========================================
   SUBMENUS EN SIDEBAR COLAPSADO
   ======================================== */

/* Cuando el sidebar está colapsado y se hace click en un submenu,
   el sidebar se expande automáticamente para mostrar las opciones.
   No se necesitan estilos especiales para submenús flotantes. */