/* Navegación lateral compartida por el panel admin y el portal del cliente.
   Sustituye al navbar superior fijo: sidebar permanente en escritorio,
   sidebar solo-iconos en tablet, cajón (drawer) con overlay en móvil. */

:root {
  --sidebar-width: 260px;
  --sidebar-width-collapsed: 76px;
  --mobile-topbar-height: 60px;
}

.mobile-topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--mobile-topbar-height);
  padding-inline: 1rem;
  align-items: center;
  gap: 0.75rem;
  background: linear-gradient(135deg, var(--color-brand-primary) 0%, var(--color-brand-secondary) 100%);
  box-shadow: 0 2px 10px rgba(var(--color-shadow-rgb), 0.16);
  z-index: 1040;
}

.mobile-topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-text-inverse) !important;
  font-weight: 600;
  text-decoration: none;
  overflow: hidden;
}

.mobile-topbar-brand img {
  height: 28px;
}

.mobile-topbar-brand span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-toggle-btn {
  background: rgba(255, 255, 255, 0.16);
  border: none;
  color: var(--color-text-inverse);
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.sidebar-toggle-btn:hover,
.sidebar-toggle-btn:focus {
  background: rgba(255, 255, 255, 0.28);
  color: var(--color-text-inverse);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 24, 0.55);
  z-index: 1044;
}

.sidebar-backdrop.is-visible {
  display: block;
}

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  z-index: 1045;
  display: flex;
  flex-direction: column;
  background: var(--color-sidebar-bg, var(--color-brand-secondary));
  box-shadow: 2px 0 20px rgba(var(--color-shadow-rgb), 0.16);
  transition: width 0.25s ease, transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1.1rem 1.1rem;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--color-text-inverse) !important;
  font-weight: 600;
  font-size: 1.1rem;
  text-decoration: none;
  min-width: 0;
}

.sidebar-brand img {
  height: 36px;
  flex-shrink: 0;
}

.sidebar-brand-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-close-btn {
  display: none;
  background: rgba(255, 255, 255, 0.16);
  border: none;
  color: var(--color-text-inverse);
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.25rem 0.75rem;
}

.sidebar-nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.sidebar-nav-link,
.sidebar-nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.9) !important;
  background: none;
  border: none;
  text-decoration: none;
  font-size: 0.95rem;
  white-space: nowrap;
}

.sidebar-nav-link i,
.sidebar-nav-group-toggle i:first-child {
  font-size: 1.1rem;
  width: 1.4rem;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-nav-link:hover,
.sidebar-nav-group-toggle:hover {
  background: rgba(255, 255, 255, 0.14);
  color: var(--color-text-inverse) !important;
}

.sidebar-nav-link.active,
.sidebar-nav-group-toggle.active {
  background: var(--color-brand-secondary);
  color: var(--color-text-inverse) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  font-weight: 600;
}

.sidebar-nav-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav-group-toggle .sidebar-caret {
  margin-left: auto;
  font-size: 0.8rem;
  transition: transform 0.2s ease;
}

.sidebar-nav-group-toggle[aria-expanded="true"] .sidebar-caret {
  transform: rotate(180deg);
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 0.85rem 0.75rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.sidebar-footer .theme-toggle-button {
  width: 100%;
  justify-content: flex-start;
  gap: 0.75rem;
  min-width: 0;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
}

.sidebar-context {
  padding: 0 0.35rem 0.6rem;
  flex-shrink: 0;
}

.sidebar-context .dropdown-toggle {
  width: 100%;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: var(--color-text-inverse) !important;
  padding: 0.55rem 0.75rem;
}

.sidebar-context .dropdown-toggle:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Contenido: se desplaza para dejar hueco al sidebar.
   .app-shell también es un .container-fluid de Bootstrap (width: 100%),
   así que hay que restar el ancho del sidebar explícitamente en vez de
   confiar en que el margin-left "encoja" un ancho ya fijado al 100%. */
.app-shell,
.patient-shell {
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  transition: margin-left 0.25s ease, width 0.25s ease;
}

/* Tablet: sidebar solo-iconos */
@media (max-width: 1199.98px) and (min-width: 768px) {
  .app-sidebar {
    width: var(--sidebar-width-collapsed);
  }

  .sidebar-brand-text,
  .sidebar-nav-text,
  .sidebar-context .tenant-context-current-name,
  .sidebar-footer .theme-toggle-label {
    display: none;
  }

  .sidebar-nav-group-toggle .sidebar-caret {
    display: none;
  }

  .sidebar-nav-link,
  .sidebar-nav-group-toggle,
  .sidebar-footer .theme-toggle-button {
    justify-content: center;
    padding: 0.65rem;
  }

  .sidebar-context .dropdown-toggle {
    justify-content: center;
    display: flex;
  }

  .app-shell,
  .patient-shell {
    margin-left: var(--sidebar-width-collapsed);
    width: calc(100% - var(--sidebar-width-collapsed));
  }
}

/* Móvil: sidebar oculto por defecto, cajón con overlay */
@media (max-width: 767.98px) {
  .mobile-topbar {
    display: flex;
  }

  .sidebar-close-btn {
    display: inline-flex;
  }

  .app-sidebar {
    width: var(--sidebar-width);
    transform: translateX(-100%);
    top: 0;
  }

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

  .app-shell,
  .patient-shell {
    margin-left: 0;
    width: 100%;
    padding-top: calc(var(--mobile-topbar-height) + 1rem);
  }
}

body.sidebar-open-lock {
  overflow: hidden;
}
