/* ═══════════════════════════════════════
   SIDEBAR — Premium SaaS Sidebar
   ═══════════════════════════════════════ */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  transition: width var(--duration-normal) var(--ease-out),
              transform var(--duration-normal) var(--ease-out);
  overflow: hidden;
}

/* ─── Brand Area ────────────────────── */
.sidebar-brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  transition: padding var(--duration-normal) var(--ease-out);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  overflow: hidden;
}

.brand-logo {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2563EB, #6366F1);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
  font-weight: 900;
  color: #fff;
  font-size: 19px;
  letter-spacing: -0.02em;
}

.brand-text {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.brand-text strong {
  display: block;
  font-size: 16px;
  color: var(--ink);
  letter-spacing: -0.03em;
  font-weight: 700;
}

.brand-text strong span {
  color: var(--brand);
}

.brand-text small {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-top: 2px;
  font-weight: 600;
}

.sidebar-close {
  display: none;
  margin-left: auto;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-light);
  font-size: 18px;
  flex-shrink: 0;
}

/* ─── Collapse Toggle ───────────────── */
.sidebar-toggle {
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all var(--duration-fast) var(--ease-out);
  z-index: 2;
}

.sidebar-toggle:hover {
  color: var(--brand);
  border-color: var(--brand);
  box-shadow: var(--shadow-md);
}

.sidebar-toggle svg {
  width: 10px;
  height: 10px;
  transition: transform var(--duration-normal) var(--ease-out);
}

/* ─── Nav Area ──────────────────────── */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 14px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

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

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 4px;
}

/* ─── Nav Group ─────────────────────── */
.nav-group {
  margin-bottom: 24px;
}

.nav-group-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 10px 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
}

.nav-group-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
  margin-top: 1px;
}

/* ─── Nav Item ──────────────────────── */
.nav-item {
  position: relative;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  margin: 2px 0;
  border-radius: var(--radius-md);
  color: var(--ink-light);
  transition: all var(--duration-fast) var(--ease-out);
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
}

.nav-item strong {
  font-size: 13px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  color: var(--muted);
  flex-shrink: 0;
  transition: color var(--duration-fast) var(--ease-out);
}

.nav-icon svg {
  width: 19px;
  height: 19px;
}

/* Hover */
.nav-item:hover {
  background: var(--bg-alt);
  color: var(--ink);
}

.nav-item:hover .nav-icon {
  color: var(--ink-light);
}

/* Active */
.nav-item.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--brand);
}

.nav-item.active .nav-icon {
  color: var(--brand);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
}

/* AI dot */
.nav-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 700;
  background: linear-gradient(135deg, #8B5CF6, #6366F1);
  color: #fff;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.nav-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: #8B5CF6;
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}

/* ─── Sidebar CTA Card ──────────────── */
.sidebar-upgrade {
  margin: 8px 14px 12px;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--brand-soft), #F5F3FF);
  border: 1px solid #E0E7FF;
  position: relative;
  overflow: hidden;
}

.sidebar-upgrade::after {
  content: '';
  position: absolute;
  right: -24px;
  bottom: -24px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.06);
}

.upgrade-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #6366F1, #8B5CF6);
  color: #fff;
  margin-bottom: 10px;
  position: relative;
  z-index: 1;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.upgrade-icon svg {
  width: 17px;
  height: 17px;
}

.sidebar-upgrade strong {
  display: block;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  position: relative;
  z-index: 1;
}

.sidebar-upgrade p {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
  position: relative;
  z-index: 1;
}

.sidebar-upgrade a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--brand);
  position: relative;
  z-index: 1;
  transition: gap var(--duration-fast) var(--ease-out);
}

.sidebar-upgrade a:hover {
  gap: 7px;
}

.sidebar-upgrade a::after {
  content: '→';
  font-size: 11px;
}

/* ─── Sidebar Footer ────────────────── */
.sidebar-footer {
  padding: 12px 14px 18px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.nav-item.logout {
  color: var(--danger);
}

.nav-item.logout .nav-icon {
  color: var(--danger);
}

.nav-item.logout:hover {
  background: var(--danger-soft);
}

/* ─── Collapsed state ───────────────── */
.app-shell.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed-w);
}

.app-shell.sidebar-collapsed .sidebar-brand {
  padding: 0 18px;
  justify-content: center;
}

.app-shell.sidebar-collapsed .brand-text,
.app-shell.sidebar-collapsed .sidebar-close,
.app-shell.sidebar-collapsed .nav-group-label,
.app-shell.sidebar-collapsed .nav-item strong,
.app-shell.sidebar-collapsed .nav-badge,
.app-shell.sidebar-collapsed .nav-dot,
.app-shell.sidebar-collapsed .sidebar-upgrade strong,
.app-shell.sidebar-collapsed .sidebar-upgrade p,
.app-shell.sidebar-collapsed .sidebar-upgrade a,
.app-shell.sidebar-collapsed .sidebar-upgrade::after,
.app-shell.sidebar-collapsed .upgrade-icon {
  display: none;
}

.app-shell.sidebar-collapsed .sidebar-upgrade {
  padding: 12px 8px;
  margin: 8px 10px 12px;
  text-align: center;
}

.app-shell.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 10px;
}

.app-shell.sidebar-collapsed .nav-group {
  margin-bottom: 16px;
}

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

/* ─── Responsive ────────────────────── */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
  }

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

  .sidebar-close {
    display: grid;
  }

  .app-shell.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
  }

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