/* === VARIABLES CSS === */
:root {
  --sidebar-width-open: 300px;
  --sidebar-width-collapsed: 80px;
  --topbar-height: 64px;
  --z-modal: 3000;
  --z-overlay: 2999;
  --z-topbar: 1000;
  --z-sidebar: 999;
  --z-sidebar-overlay: 998;
  --color-primary: #064e3b;
  --color-primary-light: #d1fae5;
  --color-primary-dark: #022c22;
  --color-gray-50: #f9fafb;
  --color-gray-100: #f3f4f6;
  --color-gray-200: #e5e7eb;
  --color-gray-300: #d1d5db;
  --color-gray-500: #6b7280;
  --color-gray-600: #4b5563;
  --color-gray-700: #374151;
  --color-gray-900: #111827;
}

/* === TOPBAR === */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: white;
  border-bottom: 1px solid var(--color-gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: var(--z-topbar);
  transition: background 0.3s ease, backdrop-filter 0.3s ease;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
  min-width: 0;
}

.topbar-hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  font-size: 1.5rem;
  color: var(--color-gray-700);
  border-radius: 0.375rem;
  flex-shrink: 0;
}

.topbar-hamburger:hover {
  background: var(--color-gray-100);
}

.topbar-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-gray-900);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* Botón de notificaciones */
.topbar-notification-button {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  transition: background 0.2s;
  color: var(--color-gray-700);
}

.topbar-notification-button:hover {
  background: var(--color-gray-100);
}

.topbar-right button {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  transition: background 0.2s;
  color: var(--color-gray-700);
}

.topbar-right button:hover {
  background: var(--color-gray-100);
}

/* Badge de notificaciones */
.notification-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: #ef4444;
  color: white;
  font-size: 0.625rem;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  box-shadow: 0 0 0 2px white;
}

/* === SCROLL COMPACT MODE === */
.topbar--compact {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
}

.topbar--compact .topbar-search,
.topbar--compact .topbar-user {
  display: none;
}

.topbar--compact .topbar-hamburger {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
}

/* === USER DROPDOWN === */
.topbar-user {
  position: relative;
}

.user-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  transition: background 0.2s;
}

.user-trigger:hover {
  background: var(--color-gray-100);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.875rem;
  color: var(--color-gray-700);
  font-weight: 500;
  white-space: nowrap;
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: white;
  border: 1px solid var(--color-gray-200);
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  min-width: 200px;
  z-index: 1001;
  overflow: hidden;
}

.user-dropdown-item {
  display: flex !important;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--color-gray-700);
  text-decoration: none;
  transition: background 0.2s;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
}

.user-dropdown-item:hover {
  background: var(--color-gray-50);
}

.user-dropdown-item--danger {
  color: #dc2626;
}

.user-dropdown-item--danger:hover {
  background: #fee2e2;
}

.user-dropdown-icon {
  font-size: 1.125rem;
  flex-shrink: 0;
  width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-dropdown-label {
  flex: 1;
  font-size: 0.875rem;
  white-space: nowrap;
}

.user-dropdown-divider {
  height: 1px;
  background: var(--color-gray-200);
  margin: 0.25rem 0;
}

.user-dropdown--open {
  animation: dropdownFadeIn 0.15s ease-out;
}

@keyframes dropdownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* === SIDEBAR === */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width-open);
  background: white;
  border-right: 1px solid var(--color-gray-200);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar);
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.3s ease, transform 0.3s ease;
}

/* === RESPONSIVE === */

/* Móvil (< 750px) */
@media (max-width: 749px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width-open);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  }
  
  /* Cuando el estado isOpen es true, quitar collapsed class y mostrar */
  .sidebar.sidebar--mobile-open {
    transform: translateX(0);
  }
  
  /* En móvil NO usar la clase collapsed para ocultar */
  .sidebar.sidebar--collapsed {
    width: var(--sidebar-width-open);
    transform: translateX(-100%);
  }
  
  .sidebar.sidebar--collapsed.sidebar--mobile-open {
    transform: translateX(0);
  }
  
  /* Forzar labels visibles en móvil */
  .sidebar .sidebar-item-label,
  .sidebar .sidebar-search-kbd {
    display: block !important;
  }
  
  .sidebar .sidebar-item {
    justify-content: flex-start !important;
    padding-left: 1rem !important;
  }
  
  .main-content {
    margin-left: 0 !important;
  }
  
  .user-name {
    display: none;
  }
  
  .user-dropdown {
    right: -0.5rem;
  }
  
  .search-modal-container {
    width: 95%;
    max-height: 80vh;
  }
}

/* Desktop (>= 750px) */
@media (min-width: 750px) {
  .sidebar {
    transform: translateX(0) !important;
  }
  
  .sidebar--collapsed {
    width: var(--sidebar-width-collapsed);
  }
  
  .main-content {
    margin-left: var(--sidebar-width-open);
  }
  
  body:has(.sidebar--collapsed) .main-content {
    margin-left: var(--sidebar-width-collapsed);
  }
  
  .sidebar-overlay {
    display: none !important;
  }
}
/* === SIDEBAR ITEMS === */
.sidebar-item-container {
  position: relative;
  display: block;
  width: 100%;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--color-gray-700);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s;
  position: relative;
  width: 100%;
  box-sizing: border-box;
  border: none;
  background: none;
  text-align: left;
  font-size: 1rem;
  font-family: inherit;
}

.sidebar-item:hover {
  background: var(--color-gray-50);
}

.sidebar-item--active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 500;
  border-left: 3px solid var(--color-primary);
  padding-left: calc(1rem - 3px);
}

.sidebar-item-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
  width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-item-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9375rem;
}

.sidebar-item-arrow {
  font-size: 1rem;
  transition: transform 0.2s;
  margin-left: auto;
  color: #9ca3af;
  flex-shrink: 0;
}

.sidebar-item--expanded .sidebar-item-arrow {
  transform: rotate(90deg);
}

/* === SUBITEMS === */
.sidebar-subitems {
  background: var(--color-gray-50);
  width: 100%;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.sidebar-subitem {
  display: flex !important;
  padding-left: 3rem !important;
  font-size: 0.875rem;
  width: 100%;
  box-sizing: border-box;
}

.sidebar-subitem:hover {
  background: var(--color-gray-100);
}

.sidebar-subitem .sidebar-item-icon {
  font-size: 1rem;
  width: 20px;
}

/* Ocultar subitems en modo colapsado */
.sidebar--collapsed .sidebar-subitems {
  display: none !important;
}

/* En móvil, mantener comportamiento normal */
@media (max-width: 749px) {
  .sidebar .sidebar-subitems {
    background: var(--color-gray-50);
  }
}



/* === SEARCH BUTTON EN SIDEBAR === */
.sidebar-search-button {
  border-bottom: 1px solid var(--color-gray-200);
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.sidebar-search-kbd {
  margin-left: auto;
  background: var(--color-gray-100);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  color: var(--color-gray-600);
  font-family: monospace;
}

/* === MODO COLAPSADO === */
.sidebar--collapsed {
  width: var(--sidebar-width-collapsed);
}

.sidebar--collapsed .sidebar-item {
  justify-content: center;
  padding-left: 1rem;
  padding-right: 1rem;
}

.sidebar--collapsed .sidebar-item-label,
.sidebar--collapsed .sidebar-item-arrow,
.sidebar--collapsed .sidebar-search-kbd {
  display: none;
}

.sidebar--collapsed .sidebar-item-icon {
  margin: 0;
}

.sidebar--collapsed .sidebar-subitem {
  padding-left: 1rem !important;
  justify-content: center;
}

.sidebar--collapsed .sidebar-subitems {
  background: transparent;
}

/* === SUBITEMS TOOLTIP (Modo Colapsado) === */
.subitems-tooltip {
  animation: tooltipSlideIn 0.15s ease-out;
}

@keyframes tooltipSlideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.subitems-tooltip-header {
  padding: 0.5rem 1rem;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--color-gray-900);
  border-bottom: 1px solid var(--color-gray-200);
  margin-bottom: 0.25rem;
}

.subitems-tooltip-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  text-decoration: none;
  transition: background 0.2s;
  font-size: 0.875rem;
  cursor: pointer;
}

.subitems-tooltip-item:hover {
  background: var(--color-gray-50);
}

.subitems-tooltip-item--active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 500;
}



/* === SIDEBAR FOOTER === */
.sidebar-footer {
  border-top: 1px solid var(--color-gray-200);
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--color-gray-500);
  text-align: center;
}

.sidebar-footer-version {
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--color-gray-600);
}

.sidebar-footer-links {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.sidebar-footer-link {
  color: var(--color-gray-600);
  text-decoration: none;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  transition: color 0.2s;
}

.sidebar-footer-link:hover {
  color: var(--color-primary);
}

.sidebar--collapsed .sidebar-footer {
  display: none;
}

/* === SIDEBAR OVERLAY === */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-sidebar-overlay);
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay--visible {
  display: block;
  opacity: 1;
}

/* === MAIN CONTENT === */
.main-content {
  min-height: 100vh;
  background: var(--color-gray-50);
  padding: 1rem;
  transition: margin-left 0.3s ease;
  margin-top: var(--topbar-height);
}

/* === TOOLTIPS === */
.tooltip {
  position: fixed;
  background: var(--color-gray-900);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  white-space: nowrap;
  z-index: 2000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.tooltip--visible {
  opacity: 1;
}

/* === LOADING SPINNER === */
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-gray-200);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === SEARCH MODAL === */
.search-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.search-modal-overlay--active {
  opacity: 1;
  pointer-events: auto;
}

.search-modal-container {
  background: white;
  border-radius: 0.75rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  width: 90%;
  max-width: 640px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.search-modal-overlay--active .search-modal-container {
  transform: scale(1);
}

.search-modal-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--color-gray-200);
}

.search-modal-icon {
  font-size: 1.25rem;
  color: #9ca3af;
  flex-shrink: 0;
}

.search-modal-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 1rem;
  color: var(--color-gray-900);
}

.search-modal-input::placeholder {
  color: #9ca3af;
}

.search-modal-kbd {
  background: var(--color-gray-100);
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  color: var(--color-gray-600);
  font-family: monospace;
  border: 1px solid var(--color-gray-300);
}

.search-modal-results {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.search-modal-empty,
.search-modal-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  text-align: center;
}

/* === SEARCH CATEGORIES === */
.search-category-section {
  margin-bottom: 1.5rem;
}

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

.search-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
}

.search-category-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--color-gray-900);
}

.search-category-icon {
  font-size: 1.125rem;
}

.search-category-label {
  font-size: 0.875rem;
}

.search-category-count {
  font-size: 0.75rem;
  color: var(--color-gray-600);
  font-weight: 400;
}

.search-category-show-all,
.search-category-collapse {
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: 0.875rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  transition: background 0.2s;
  font-weight: 500;
}

.search-category-show-all:hover,
.search-category-collapse:hover {
  background: var(--color-gray-100);
}

.search-category-collapse {
  width: 100%;
  text-align: center;
  margin-top: 0.5rem;
}

.search-category-items {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* === SEARCH RESULTS === */
.search-result-item {
  display: block;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  text-decoration: none;
  color: inherit;
  transition: background 0.2s;
  border: 1px solid transparent;
}

.search-result-item:hover {
  background: var(--color-gray-50);
  border-color: var(--color-gray-200);
}

.search-result-primary {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--color-gray-900);
  margin-bottom: 0.25rem;
}

.search-result-secondary {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.875rem;
  color: var(--color-gray-600);
}

.search-result-tertiary {
  color: #9ca3af;
  font-size: 0.8125rem;
}

/* === SEARCH CONTEXT DROPDOWN (legacy, por si acaso) === */
.search-context-dropdown {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  background: white;
  border: 1px solid var(--color-gray-200);
  border-radius: 0.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  min-width: 200px;
  display: none;
  z-index: 1001;
}

.search-context-dropdown--open {
  display: block;
}

.search-context-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background 0.2s;
}

.search-context-option:hover {
  background: var(--color-gray-50);
}

.search-context-option--active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 500;
}

/* === RESPONSIVE === */

/* Móvil (< 750px) */
@media (max-width: 749px) {
  .main-content {
    margin-left: 0 !important;
  }
  
  .user-name {
    display: none;
  }
  
  .user-dropdown {
    right: -0.5rem;
  }
  
  .search-modal-container {
    width: 95%;
    max-height: 80vh;
  }
}

/* Desktop (>= 750px) */
@media (min-width: 750px) {
  
  .main-content {
    margin-left: var(--sidebar-width-open);
  }
  
  body:has(.sidebar--collapsed) .main-content {
    margin-left: var(--sidebar-width-collapsed);
  }
  
  .sidebar-overlay {
    display: none !important;
  }
}

/* Tablet y pequeños desktops */
@media (max-width: 1024px) {
  .topbar-title {
    font-size: 1.125rem;
  }
}

/* === ACCESSIBILITY === */
.sidebar-item:focus-visible,
.topbar-hamburger:focus-visible,
.user-trigger:focus-visible,
.search-modal-input:focus-visible,
.search-result-item:focus-visible,
.search-category-show-all:focus-visible,
.search-category-collapse:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* === PRINT === */
@media print {
  .sidebar,
  .topbar,
  .sidebar-overlay,
  .search-modal-overlay {
    display: none !important;
  }
  
  .main-content {
    margin: 0 !important;
  }
}

/* === UTILIDADES GENERALES === */
.text-gray-500 {
  color: var(--color-gray-500);
}

.text-gray-600 {
  color: var(--color-gray-600);
}

.text-red-600 {
  color: #dc2626;
}

.mt-4 {
  margin-top: 1rem;
}

.flex {
  display: flex;
}

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

.justify-center {
  justify-content: center;
}

.p-8 {
  padding: 2rem;
}
