/* =========================================================
   Sidebar
   ========================================================= */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--md-surface-elevated);
  border-right: 1px solid var(--md-outline);
  display: flex;
  flex-direction: column;
  padding: var(--s-4) var(--s-3);
  z-index: 10;
  transition: background var(--d-med) var(--ease-standard),
              border-color var(--d-med) var(--ease-standard);
}

/* ---------- Profile (now in footer) ---------- */
.profile {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex: 1;
  min-width: 0;
  padding: var(--s-2);
  border-radius: var(--r-md);
  transition: background var(--d-short) var(--ease-standard);
}

.profile:hover { background: var(--md-hover-layer); }

.profile__avatar {
  width: 36px; height: 36px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--md-primary-strong), #8B6FE0);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 14px;
  flex-shrink: 0;
}

.profile__meta {
  display: flex;
  flex-direction: column;
  text-align: left;
  min-width: 0;
}

.profile__name {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 14px;
  color: var(--md-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile__role {
  font-size: 11px;
  color: var(--md-on-surface-muted);
}

/* ---------- Brand ---------- */
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  margin-bottom: var(--s-4);
}

.brand-mark {
  width: 24px;
  height: 24px;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
}

.brand-mark__dot {
  border-radius: var(--r-full);
  transition: transform var(--d-med) var(--ease-emphasized);
}

.brand-mark__dot--1 { background: var(--md-primary-strong); }
.brand-mark__dot--2 { background: var(--md-accent-peach); }
.brand-mark__dot--3 { background: var(--md-tertiary); }
.brand-mark__dot--4 { background: var(--md-secondary); }

.sidebar__brand:hover .brand-mark__dot--1 { transform: translate(-1px, -1px); }
.sidebar__brand:hover .brand-mark__dot--2 { transform: translate(1px, -1px); }
.sidebar__brand:hover .brand-mark__dot--3 { transform: translate(-1px, 1px); }
.sidebar__brand:hover .brand-mark__dot--4 { transform: translate(1px, 1px); }

.brand-mark__name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--md-on-surface);
}

/* ---------- Nav Rail ---------- */
.nav-rail {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  flex: 1;
  overflow-y: auto;
}

.nav-group { display: flex; flex-direction: column; }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: 10px var(--s-3);
  border-radius: var(--r-full);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--md-on-surface);
  text-align: left;
  transition: background var(--d-short) var(--ease-standard),
              color var(--d-short) var(--ease-standard);
  cursor: pointer;
}

.nav-item:hover { background: var(--md-hover-layer); }

.nav-item.is-active {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
}

.nav-item__icon { font-size: 20px; }

.nav-item__label { flex: 1; }

.nav-item__chevron {
  font-size: 18px;
  color: var(--md-on-surface-muted);
  transition: transform var(--d-med) var(--ease-standard);
}

.nav-item[aria-expanded="false"] .nav-item__chevron {
  transform: rotate(-90deg);
}

/* Sub items */
.nav-sub {
  display: flex;
  flex-direction: column;
  padding: var(--s-1) 0 var(--s-2) var(--s-8);
  gap: 2px;
  overflow: hidden;
  max-height: 200px;
  transition: max-height var(--d-med) var(--ease-standard);
}

.nav-group:has(.nav-item[aria-expanded="false"]) .nav-sub {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
}

.nav-sub__item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 8px var(--s-3);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 400;
  color: var(--md-on-surface-muted);
  border-radius: var(--r-full);
  transition: background var(--d-short) var(--ease-standard),
              color var(--d-short) var(--ease-standard);
}

.nav-sub__item:hover {
  background: var(--md-hover-layer);
  color: var(--md-on-surface);
}

.nav-sub__item.is-active {
  background: var(--md-selected-layer);
  color: var(--md-primary-strong);
  font-weight: 500;
}
[data-theme="dark"] .nav-sub__item.is-active {
  color: var(--md-primary);
}

.nav-sub__bullet {
  width: 6px; height: 6px;
  border-radius: var(--r-full);
  background: currentColor;
  opacity: 0.5;
  flex-shrink: 0;
}

.nav-sub__item.is-active .nav-sub__bullet { opacity: 1; }

/* ---------- Bottom: profile + settings inline ---------- */
.sidebar__bottom {
  padding-top: var(--s-3);
  margin-top: var(--s-2);
  border-top: 1px solid var(--md-outline);
  display: flex;
  align-items: center;
  gap: var(--s-2);
  position: relative;
}

/* ---------- Profile menu (popover above the profile button) ---------- */
.profile-menu {
  position: absolute;
  left: var(--s-3);
  right: var(--s-3);
  bottom: calc(100% + var(--s-2));
  background: var(--md-surface);
  border: 1px solid var(--md-outline);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: var(--s-2);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.profile-menu[hidden] { display: none; }
.profile-menu__item {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 10px 12px;
  border-radius: 8px;
  background: transparent;
  border: 0;
  cursor: pointer;
  font: inherit;
  color: var(--md-on-surface);
  text-align: left;
}
.profile-menu__item:hover { background: var(--md-hover-layer); }
.profile-menu__item .material-symbols-outlined { font-size: 20px; }

/* Responsive: collapse sidebar on mobile */
@media (max-width: 960px) {
  .sidebar {
    position: relative;
    height: auto;
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--md-outline);
  }
  .nav-rail { flex-direction: row; flex-wrap: wrap; }
  .nav-item__label { display: none; }
  .nav-item__chevron { display: none; }
  .nav-sub { display: none; }
  .sidebar__brand { display: none; }
  .sidebar__bottom {
    border-top: none;
    margin-top: 0;
    padding-top: 0;
  }
  .profile__meta { display: none; }
}
