/* App shell: fixed left sidebar + offset content column. */

:root {
  --sidebar-width: 260px;
  --sidebar-width-collapsed: 72px;
}

.app-shell {
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  height: 100vh;
  background-color: #fff;
  border-right: 1px solid #e5e7eb;
  transform: translateX(-100%);
  transition: transform 0.2s ease, width 0.2s ease;
}

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

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background-color: rgb(17 24 39 / 0.5);
}

/* ---------- Brand ---------- */

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  height: 64px;
  padding: 0 0.75rem 0 1rem;
  border-bottom: 1px solid #f3f4f6;
  flex-shrink: 0;
}

.sidebar-brand-name {
  margin-left: 0.625rem;
  font-size: 1.0625rem;
  font-weight: 700;
  color: #1f2937;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.sidebar-collapse-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 0.5rem;
  color: #9ca3af;
  flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
  background-color: #f3f4f6;
  color: #4b5563;
}

/* ---------- Nav ---------- */

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

.sidebar-section + .sidebar-section {
  margin-top: 1.25rem;
}

.sidebar-section-title {
  padding: 0 0.75rem;
  margin-bottom: 0.375rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9ca3af;
  white-space: nowrap;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: #4b5563;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.sidebar-link + .sidebar-link {
  margin-top: 2px;
}

.sidebar-link:hover {
  background-color: #f9fafb;
  color: #111827;
}

.sidebar-link-active {
  background-color: #fff7ed;
  color: #c2410c;
}

.sidebar-link-active:hover {
  background-color: #ffedd5;
  color: #c2410c;
}

.sidebar-link-icon {
  display: flex;
  flex-shrink: 0;
  color: #9ca3af;
}

.sidebar-link:hover .sidebar-link-icon {
  color: #6b7280;
}

.sidebar-link-active .sidebar-link-icon {
  color: #f97316;
}

.sidebar-link-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
}

/* Troubleshooting links recede until they have something to report. */
.sidebar-link-muted {
  color: #9ca3af;
  font-weight: 400;
}

.sidebar-link-muted .sidebar-link-icon {
  color: #d1d5db;
}

.sidebar-link-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  padding: 0 0.375rem;
  border-radius: 9999px;
  background-color: #dc2626;
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1.25rem;
  flex-shrink: 0;
}

/* button_to renders a form; keep the sign-out row flush with the links. */
.sidebar-footer form {
  margin: 0;
}

/* ---------- Footer / user ---------- */

.sidebar-footer {
  flex-shrink: 0;
  padding: 0.625rem;
  border-top: 1px solid #f3f4f6;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem 0.75rem;
  min-width: 0;
}

.sidebar-user-meta {
  min-width: 0;
}

.sidebar-user-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: #111827;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-email {
  font-size: 0.75rem;
  color: #9ca3af;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Mobile top bar ---------- */

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 56px;
  padding: 0 1rem;
  background-color: #fff;
  border-bottom: 1px solid #e5e7eb;
}

/* ---------- Desktop ---------- */

@media (min-width: 1024px) {
  .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop,
  .app-topbar {
    display: none;
  }

  .sidebar-collapse-btn {
    display: flex;
  }

  .app-main {
    margin-left: var(--sidebar-width);
    transition: margin-left 0.2s ease;
  }

  /* Collapsed rail */
  .sidebar-collapsed .sidebar {
    width: var(--sidebar-width-collapsed);
  }

  .sidebar-collapsed .app-main {
    margin-left: var(--sidebar-width-collapsed);
  }

  .sidebar-collapsed .sidebar-brand {
    justify-content: center;
    padding: 0;
  }

  .sidebar-collapsed .sidebar-brand-name,
  .sidebar-collapsed .sidebar-link-label,
  .sidebar-collapsed .sidebar-user-meta {
    display: none;
  }

  /* Collapsed: the brand row becomes the expand toggle. */
  .sidebar-collapsed .sidebar-brand > a {
    display: none;
  }

  /* Collapsed: labels can't fit, so sections read as divider rules instead. */
  .sidebar-collapsed .sidebar-section-title {
    display: none;
  }

  .sidebar-collapsed .sidebar-section + .sidebar-section {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #f3f4f6;
  }

  .sidebar-collapsed .sidebar-link,
  .sidebar-collapsed .sidebar-user {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }

  .sidebar-collapsed .sidebar-link-badge {
    position: absolute;
    margin-left: 1.5rem;
    margin-bottom: 1.25rem;
    min-width: 0.5rem;
    height: 0.5rem;
    padding: 0;
    font-size: 0;
    line-height: 0;
  }
}

/* Keep the fixed audio player dock clear of the sidebar. */
@media (min-width: 1024px) {
  body.has-sidebar .audio-player-dock {
    left: var(--sidebar-width);
  }

  body.has-sidebar.sidebar-collapsed .audio-player-dock {
    left: var(--sidebar-width-collapsed);
  }
}
