/* =====================================================
   SIDEBAR — drawer (mobile) | rail (tablet) | fixed (desktop)
   ===================================================== */

.sidebar {
  width: var(--sidebar-drawer-width);
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  height: 100dvh;
  z-index: var(--z-drawer);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-default) transparent;

  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              width 0.25s ease,
              box-shadow 0.3s ease;

  background-color: var(--color-bg-surface);
  background-image:
    linear-gradient(rgba(0, 229, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 229, 255, 0.025) 1px, transparent 1px);
  background-size: 28px 28px;

  border-right: 1px solid var(--color-border-default);
}

.sidebar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 220px;
  background: radial-gradient(ellipse at 50% -10%,
    rgba(0, 229, 255, 0.14) 0%,
    transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.sidebar > * { position: relative; z-index: 1; }

.sidebar.open {
  transform: translateX(0);
  box-shadow: 4px 0 40px rgba(0, 0, 0, 0.50), var(--shadow-neon-md);
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: var(--color-border-default);
  border-radius: 3px;
}

/* ── Brand ── */
.sidebar-brand {
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
  flex-shrink: 0;
}

.sidebar-brand-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sidebar-brand-link img {
  height: var(--logo-sidebar-height);
  width: auto;
  display: block;
}

/* ── Section labels ── */
.sidebar-section-label {
  padding: var(--space-4) var(--space-4) var(--space-1);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-text-muted);
}

.sidebar-nav > .sidebar-section-label ~ .sidebar-section-label {
  margin-top: var(--space-4);
}

/* ── Nav ── */
.sidebar-nav {
  flex: 1;
  padding: var(--space-3) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.6rem var(--space-3);
  border-radius: 10px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  text-decoration: none;
  border: 1px solid transparent;
  transition: color 0.2s ease, background 0.2s ease,
              border-color 0.2s ease, box-shadow 0.2s ease;
  min-height: 44px;
  position: relative;
  overflow: hidden;
}

.sidebar-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 25%;
  bottom: 25%;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--color-neon);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sidebar-link:hover {
  color: var(--color-text-primary);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--color-border-subtle);
}

.sidebar-link.active,
.sidebar-link[aria-current="page"] {
  color: var(--color-neon);
  background: rgba(0, 229, 255, 0.08);
  border-color: rgba(0, 229, 255, 0.18);
}

.sidebar-link.active::before,
.sidebar-link[aria-current="page"]::before {
  opacity: 1;
}

.sidebar-link:focus-visible {
  outline: 2px solid var(--color-neon);
  outline-offset: -2px;
}

.sidebar-link svg,
.sidebar-link i[data-lucide] svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  transition: filter 0.2s ease;
}

.sidebar-link.active svg,
.sidebar-link[aria-current="page"] svg {
  filter: drop-shadow(0 0 6px rgba(0, 229, 255, 0.5));
}

.sidebar-link-label { flex: 1; }

/* ── Footer ── */
.sidebar-footer {
  padding: var(--space-4) var(--space-3);
  border-top: 1px solid var(--color-border-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex-shrink: 0;
}

.sidebar-user-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: 10px;
  border: 1px solid var(--color-border-subtle);
  background: rgba(255, 255, 255, 0.02);
}

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

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

.sidebar-user-plan {
  font-size: var(--text-xs);
  color: var(--color-neon);
  margin-top: 1px;
}

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.55rem var(--space-3);
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--color-border-subtle);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  min-height: 40px;
  text-align: left;
}

.sidebar-logout:hover {
  color: var(--color-error);
  border-color: rgba(239, 68, 68, 0.30);
  background: rgba(239, 68, 68, 0.06);
}

.sidebar-logout:focus-visible {
  outline: 2px solid var(--color-neon);
  outline-offset: 2px;
}

.sidebar-logout svg,
.sidebar-logout i[data-lucide] svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* ── Sidebar overlay (mobile drawer / tablet expanded) ── */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.70);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: var(--z-overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.open {
  opacity: 1;
  pointer-events: all;
}

/* =====================================================
   TABLET (768px – 1023px) — RAIL COLAPSADO
   ===================================================== */
@media (min-width: 768px) and (max-width: 1023.98px) {
  .sidebar {
    width: var(--sidebar-rail-width);
    transform: translateX(0);
    z-index: var(--z-sidebar);
    box-shadow: none;
  }

  /* Esconde labels quando rail */
  .sidebar:not(.open) .sidebar-section-label,
  .sidebar:not(.open) .sidebar-link-label,
  .sidebar:not(.open) .sidebar-user-info,
  .sidebar:not(.open) .sidebar-logout-text {
    display: none;
  }

  /* Centraliza brand logo no rail */
  .sidebar:not(.open) .sidebar-brand {
    padding: var(--space-4) var(--space-2);
    display: flex;
    justify-content: center;
  }

  .sidebar:not(.open) .sidebar-brand-link img {
    height: var(--logo-sidebar-rail-height);
  }

  /* Nav padding compacto */
  .sidebar:not(.open) .sidebar-nav {
    padding: var(--space-3) var(--space-2);
    align-items: center;
  }

  /* Links centralizados no rail */
  .sidebar:not(.open) .sidebar-link {
    justify-content: center;
    padding: 0.6rem;
    width: 48px;
    gap: 0;
  }

  /* Active indicator vira pílula em volta do ícone */
  .sidebar:not(.open) .sidebar-link::before {
    display: none;
  }

  .sidebar:not(.open) .sidebar-link.active,
  .sidebar:not(.open) .sidebar-link[aria-current="page"] {
    box-shadow: 0 0 0 1px rgba(0, 229, 255, 0.30),
                inset 0 0 12px rgba(0, 229, 255, 0.08);
  }

  /* Footer compacto */
  .sidebar:not(.open) .sidebar-footer {
    padding: var(--space-3) var(--space-2);
    align-items: center;
  }

  .sidebar:not(.open) .sidebar-user-row {
    padding: var(--space-2);
    justify-content: center;
  }

  .sidebar:not(.open) .sidebar-logout {
    width: 48px;
    justify-content: center;
    padding: 0.5rem;
    gap: 0;
  }

  /* Quando hamburger aciona .open, rail vira drawer expandido */
  .sidebar.open {
    width: var(--sidebar-drawer-width);
  }
}

/* =====================================================
   DESKTOP (≥ 1024px) — SIDEBAR FIXA
   ===================================================== */
@media (min-width: 1024px) {
  .sidebar {
    width: var(--sidebar-width);
    transform: translateX(0);
    z-index: var(--z-sidebar);
    box-shadow: none;
  }

  .sidebar.open {
    box-shadow: none;
  }

  /* Overlay nunca aparece em desktop */
  .sidebar-overlay {
    display: none !important;
  }
}

/* =====================================================
   ESTADOS — esconder em no-sidebar e onboarding-mode
   ===================================================== */
#app-layout.no-sidebar .sidebar,
#app-layout.no-sidebar .sidebar-overlay,
#app-layout.onboarding-mode .sidebar,
#app-layout.onboarding-mode .sidebar-overlay {
  display: none !important;
}

/* =====================================================
   REDUCED MOTION
   ===================================================== */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar-overlay,
  .sidebar-link {
    transition: none;
  }
}
