@use 'variables' as v;
@use 'mixins' as m;

// ─────────────────────────────────────────────
// Sidebar shell
// ─────────────────────────────────────────────
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: v.$sidebar-width;
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: v.$z-sidebar;
  overflow: hidden;
  direction: ltr;           // prevent PrimeVue RTL inheritance
  transition: width v.$transition-slow, transform v.$transition-slow, background-color 150ms ease, border-color 150ms ease;

  @include m.max-lg {
    transform: translateX(-100%);
    width: v.$sidebar-width;
    z-index: 10050;

    &.is-open {
      transform: translateX(0);
      box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    }
  }

  .sidebar-collapsed & {
    width: v.$sidebar-collapsed;
    overflow: visible;

    .sidebar-brand-name,
    .nav-group-label,
    .nav-item span,
    .sidebar-user-info { display: none; }

    .nav-item {
      justify-content: center;
      padding: 10px;

      svg { flex-shrink: 0; }
    }
  }
}

// ─────────────────────────────────────────────
// Sidebar edge toggle
// ─────────────────────────────────────────────
.sidebar-edge-toggle {
  position: absolute;
  top: 16px;
  right: -8px;
  width: 20px;
  height: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  @include m.flex-center;
  color: var(--text-secondary);
  cursor: pointer;
  z-index: 10000;
  box-shadow: v.$shadow-sm;
  transition: background v.$transition-base, color v.$transition-base;
  outline: none;

  &:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
  }
  
  &:focus-visible {
    @include m.focus-ring;
  }

  svg { width: 12px; height: 12px; transition: transform v.$transition-base; }
}

.sidebar-collapsed .sidebar-edge-toggle svg {
  transform: rotate(180deg);
}

// ─────────────────────────────────────────────
// Brand / Logo area
// ─────────────────────────────────────────────
.sidebar-brand {
  @include m.flex-start;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  min-height: v.$topbar-height;
  text-decoration: none;

  &:hover { text-decoration: none; }
}

.sidebar-brand-icon {
  width: 32px;
  height: 32px;
  background: transparent;
  border-radius: v.$radius-md;
  @include m.flex-center;
  flex-shrink: 0;

  svg { width: 28px; height: 28px; }
}

.sidebar-brand-name {
  font-size: v.$font-size-lg;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

// ─────────────────────────────────────────────
// Scrollable nav area
// ─────────────────────────────────────────────
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  @include m.scrollbar-thin;
}

// ─────────────────────────────────────────────
// Navigation group
// ─────────────────────────────────────────────
.nav-group {
  margin-bottom: 4px;

  & + & { margin-top: 8px; }
}

.nav-group-label {
  display: block;
  font-size: v.$font-size-2xs;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 18px 4px;
  white-space: nowrap;
  direction: ltr;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
}

// ─────────────────────────────────────────────
// Nav item
// ─────────────────────────────────────────────
.nav-item {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  justify-content: flex-start !important;
  gap: 9px;
  padding: 8px 18px;
  border-radius: 0;
  font-size: v.$font-size-sm;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none !important;
  transition: background v.$transition-base, color v.$transition-base;
  position: relative;
  white-space: nowrap;
  direction: ltr;
  text-align: left;
  width: 100%;
  box-sizing: border-box;

  svg {
    width: 16px !important;
    height: 16px !important;
    min-width: 16px;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: color v.$transition-base;
  }

  span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  &:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;

    svg { color: var(--text-secondary); }
  }

  &.is-active,
  &[aria-current="page"] {
    background: var(--active-bg);
    color: var(--active-text);
    font-weight: 600;

    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      width: 3px;
      background: var(--active-text);
      border-radius: 0 v.$radius-sm v.$radius-sm 0;
    }

    svg { color: var(--active-text); }
  }

  // Single top-level item (Home)
  &.nav-item--top {
    padding: 9px 18px;
    font-size: v.$font-size-base;
  }
}

// Nav badge (e.g. count)
.nav-badge {
  margin-left: auto;
  background: v.$primary-light;
  color: v.$primary;
  font-size: v.$font-size-2xs;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: v.$radius-full;
  border: 1px solid v.$primary-border;
}

// ─────────────────────────────────────────────
// Sidebar footer (user info)
// ─────────────────────────────────────────────
.sidebar-footer {
  border-top: 1px solid var(--border-color);
  padding: 12px;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: v.$radius;
  cursor: pointer;
  transition: background v.$transition-base;

  &:hover { background: var(--bg-hover); }
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: v.$radius-full;
  background: var(--active-bg);
  border: 2px solid v.$primary-border;
  @include m.flex-center;
  flex-shrink: 0;
  overflow: hidden;
  font-size: v.$font-size-sm;
  font-weight: 600;
  color: var(--active-text);

  img { width: 100%; height: 100%; object-fit: cover; }
}

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

.sidebar-user-name {
  font-size: v.$font-size-sm;
  font-weight: 600;
  color: var(--text-primary);
  @include m.truncate;
}

.sidebar-user-email {
  font-size: v.$font-size-xs;
  color: var(--text-muted);
  @include m.truncate;
}

// ─────────────────────────────────────────────
// Mobile overlay
// ─────────────────────────────────────────────
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(v.$gray-900, 0.4);
  z-index: v.$z-sidebar - 1;

  @include m.max-lg {
    .sidebar-open & { display: block; }
  }
}

// ─────────────────────────────────────────────
// Sidebar hover tooltip
// ─────────────────────────────────────────────
.sidebar-tooltip {
  position: fixed;
  transform: translateY(-50%);
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 10px 12px;
  width: 240px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  z-index: 999999;
  pointer-events: none;
  font-family: inherit;
  line-height: 1.4;

  &::after {
    content: '';
    position: absolute;
    top: 50%;
    left: -5px;
    transform: translateY(-50%);
    border-width: 5px 5px 5px 0;
    border-style: solid;
    border-color: transparent #1e293b transparent transparent;
  }
}

.sidebar-tooltip-title {
  font-size: 12px;
  font-weight: 700;
  color: #38bdf8;
  margin-bottom: 4px;
}

.sidebar-tooltip-desc {
  font-size: 11px;
  font-weight: 500;
  color: #cbd5e1;
}
