/* ===========================
   App Shell — Linear-inspired minimal chrome
   =========================== */

/* Boot Guard */
.no-animate *,
.no-animate *::before,
.no-animate *::after {
  transition: none !important;
  animation: none !important;
}

/* Chrome Base */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  color: var(--body-color);
  background: var(--body-bg);
  overflow-x: hidden;
}

/* ===========================
   Layout
   =========================== */

.layout-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#layoutSidenav {
  display: flex;
  width: 100%;
  position: relative;
  flex: 1;
  overflow: hidden;
}

/* ===========================
   Mobile Header
   =========================== */

.main-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1050;
  background: var(--color-surface);
  border-bottom: 1px solid var(--sidebar-border);
}

.mobile-navbar {
  padding: 0 12px;
  height: var(--navbar-height);
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-navbar-brand {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.mobile-navbar-brand img {
  height: 22px;
}

.sidebar-toggle-btn {
  background: transparent;
  color: var(--sidebar-text-muted);
  border: none;
  font-size: 18px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 100ms ease, color 100ms ease;
  padding: 0;
  cursor: pointer;
}

.sidebar-toggle-btn:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
}

.sidebar-toggle-btn:active {
  transform: scale(0.95);
}

.sidebar-toggle-btn:focus {
  outline: none;
}

/* ===========================
   Content Area
   =========================== */

#layoutSidenav_content {
  min-height: 100vh;
  width: 100%;
  overflow-y: auto;
  padding: 24px;
  position: relative;
  background: var(--body-bg);
  transition: margin-left 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

#layoutSidenav_nav {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  z-index: 1040;
  overflow: hidden;
  transition: width 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.sb-sidenav {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sb-sidenav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 8px;
  flex-shrink: 0;
  min-height: 46px;
}

.sidebar-logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  overflow: hidden;
  flex-shrink: 1;
  min-width: 0;
}

.sidebar-logo {
  height: 22px;
  width: auto;
  flex-shrink: 0;
}

.sidebar-collapse-btn {
  background: transparent;
  border: none;
  color: var(--sidebar-text-dim);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  font-size: 15px;
  flex-shrink: 0;
  transition: background 100ms ease, color 100ms ease;
}

.sidebar-collapse-btn:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
}

.sidebar-collapse-btn:focus {
  outline: none;
}

/* --- Sidebar Nav Section --- */

.sb-sidenav-menu {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 4px 8px 0;
  overflow: hidden;
}

.sb-sidenav .sb-sidenav-menu .nav {
  flex-direction: column;
  gap: 1px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.sb-sidenav .text-label {
  display: none;
}

/* Nav Links */
.sb-sidenav .nav-link {
  color: var(--sidebar-text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  height: 32px;
  border-radius: 6px;
  transition: background 100ms ease, color 100ms ease;
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  border: none;
  overflow: hidden;
  line-height: 1;
  white-space: nowrap;
}

.sb-sidenav .nav-link::before {
  display: none;
}

.sb-sidenav .nav-link i,
.sb-sidenav .nav-link .sb-nav-link-icon i {
  font-size: 15px;
  width: 16px;
  flex-shrink: 0;
  text-align: center;
  opacity: 0.55;
  transition: opacity 100ms ease;
}

.sb-sidenav .nav-link .sb-nav-link-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  flex-shrink: 0;
  background: none;
  border-radius: 0;
  margin: 0;
}

/* Hover */
.sb-sidenav .nav-link:hover {
  color: var(--sidebar-text);
  background: var(--sidebar-hover-bg);
  transform: none;
  box-shadow: none;
}

.sb-sidenav .nav-link:hover i,
.sb-sidenav .nav-link:hover .sb-nav-link-icon i {
  opacity: 0.8;
}

/* Active */
.sb-sidenav .nav-link.active {
  color: var(--sidebar-active-text);
  background: var(--sidebar-active-bg);
  font-weight: 500;
  transform: none;
  box-shadow: none;
}

.sb-sidenav .nav-link.active i,
.sb-sidenav .nav-link.active .sb-nav-link-icon i {
  opacity: 1;
}

/* Focus */
.sb-sidenav .nav-link:focus {
  outline: none;
  box-shadow: inset 0 0 0 1.5px var(--sidebar-active-bg);
}

/* ===========================
   Sidebar Lists Section
   =========================== */

.sb-lists-section {
  display: flex;
  flex-direction: column;
}

.sb-lists-toggle {
  position: relative;
}

.sb-lists-chevron {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--sidebar-text-dim);
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  font-size: 12px;
  opacity: 0.5;
  transition: opacity 100ms ease, background 100ms ease;
  flex-shrink: 0;
}

.sb-lists-chevron:hover {
  opacity: 1;
}

.sb-lists-chevron:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
}

.sb-lists-chevron i {
  transition: transform 150ms ease;
  transform: rotate(-90deg);
}

.sb-lists-items {
  display: none;
  flex-direction: column;
  padding: 2px 0 4px 0;
}

.sb-lists-items.open {
  display: flex;
}

.sb-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px 0 34px;
  height: 28px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 400;
  color: var(--sidebar-text-muted);
  text-decoration: none;
  transition: background 100ms ease, color 100ms ease;
  white-space: nowrap;
  overflow: hidden;
}

.sb-list-item:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
}

.sb-list-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  font-weight: 500;
}

.sb-list-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-list-count {
  font-size: 10px;
  font-family: var(--font-family-mono, monospace);
  color: var(--sidebar-text-dim);
  flex-shrink: 0;
  opacity: 0.6;
}

.sb-list-item.active .sb-list-count {
  opacity: 0.8;
}

.sb-list-more {
  color: var(--sidebar-text-dim);
  font-size: 11px;
}

.sb-list-empty {
  padding: 4px 10px 4px 34px;
  font-size: 11px;
  color: var(--sidebar-text-dim);
  opacity: 0.5;
}

/* Hide sub-items when sidebar collapsed */
.sidebar-collapsed .sb-lists-items,
.sidebar-collapsed .sb-lists-chevron {
  display: none !important;
}

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

.sb-sidenav-footer {
  padding: 6px 8px 10px;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex-shrink: 0;
}

.footer-separator {
  display: none;
}

.footer-actions {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.footer-action-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  height: 32px;
  color: var(--sidebar-text-muted);
  text-decoration: none;
  border-radius: 6px;
  transition: background 100ms ease, color 100ms ease;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  white-space: nowrap;
}

.footer-action-link:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
  text-decoration: none;
  transform: none;
}

.footer-action-link.active {
  color: var(--sidebar-active-text);
  background: var(--sidebar-active-bg);
}

.footer-action-link i {
  font-size: 15px;
  width: 16px;
  text-align: center;
  opacity: 0.55;
  flex-shrink: 0;
}

.footer-action-link:hover i {
  opacity: 0.8;
}

.footer-action-link.active i {
  opacity: 1;
}

/* Sidebar Separator */
.sidebar-separator {
  height: 1px;
  background: var(--sidebar-border);
  margin: 5px 10px;
  flex-shrink: 0;
}

/* --- User Profile Section --- */

.user-profile-section {
  position: relative;
}

.user-profile-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 6px 10px;
  background: none;
  border: none;
  border-radius: 6px;
  gap: 8px;
  cursor: pointer;
  transition: background 100ms ease;
  text-align: left;
  overflow: hidden;
}

.user-profile-btn:hover {
  background: var(--sidebar-hover-bg);
}

.user-profile-btn:focus {
  outline: none;
}

.user-profile-btn .profile-avatar {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--sidebar-avatar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.user-profile-btn .profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
}

.user-profile-btn .profile-initial {
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.user-profile-btn .profile-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.user-profile-btn .profile-name {
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.user-profile-btn .profile-email {
  color: var(--sidebar-text-dim);
  font-size: 11px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.user-profile-btn .profile-chevron {
  color: var(--sidebar-text-dim);
  font-size: 12px;
  flex-shrink: 0;
  transition: color 100ms ease;
}

.user-profile-btn:hover .profile-chevron {
  color: var(--sidebar-text-muted);
}

/* User Dropdown */
.user-profile-section .dropdown-menu {
  min-width: 200px;
  padding: 4px;
  border: 1px solid var(--sidebar-border);
  border-radius: 8px;
  background: var(--color-surface);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.02);
}

.user-profile-section .dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--sidebar-text-muted);
  font-size: 13px;
  font-weight: 400;
  padding: 7px 10px;
  border-radius: 5px;
  transition: background 80ms ease, color 80ms ease;
}

.user-profile-section .dropdown-item i {
  font-size: 14px;
  width: 16px;
  text-align: center;
  opacity: 0.5;
}

.user-profile-section .dropdown-item:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text);
}

.user-profile-section .dropdown-item:hover i {
  opacity: 0.7;
}

.user-profile-section .dropdown-item:active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.user-profile-section .dropdown-divider {
  border: none;
  height: 1px;
  background: var(--sidebar-border);
  margin: 3px 4px;
  opacity: 1;
}

/* ===========================
   Sidebar Overlay (Mobile)
   =========================== */

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 1035;
  opacity: 0;
  transition: opacity 200ms ease;
}

#layoutSidenav.sidebar-active .sidebar-overlay {
  display: block;
  opacity: 1;
}

.sidebar-ready #layoutSidenav_nav {
  visibility: visible;
}

/* ===========================
   Desktop Layout (>= 992px)
   =========================== */

@media (min-width: 992px) {
  .main-header {
    display: none !important;
  }

  #layoutSidenav_nav {
    transform: translateX(0);
  }

  #layoutSidenav_content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    padding-top: 24px;
    transition: margin-left 200ms cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* ---- Collapsed icon-only rail ---- */

  .sidebar-collapsed #layoutSidenav_nav {
    width: var(--sidebar-width-collapsed);
  }

  .sidebar-collapsed #layoutSidenav_content {
    margin-left: var(--sidebar-width-collapsed);
  }

  /* Header: hide logo, center toggle */
  .sidebar-collapsed .sidebar-logo-link {
    display: none;
  }

  .sidebar-collapsed .sb-sidenav-header {
    justify-content: center;
    padding: 14px 0 8px;
  }

  .sidebar-collapsed .sidebar-collapse-btn {
    opacity: 1;
  }

  /* Nav: hide text, center icons */
  .sidebar-collapsed .sb-sidenav-menu {
    padding: 4px 8px 0;
  }

  .sidebar-collapsed .sb-sidenav .nav-link {
    justify-content: center;
    padding: 0;
    gap: 0;
  }

  .sidebar-collapsed .sb-sidenav .nav-link span {
    display: none;
  }

  /* Footer: icon-only */
  .sidebar-collapsed .sb-sidenav-footer {
    padding: 6px 8px 10px;
  }

  .sidebar-collapsed .footer-action-link {
    justify-content: center;
    padding: 0;
    gap: 0;
  }

  .sidebar-collapsed .footer-action-link span {
    display: none;
  }

  .sidebar-collapsed .sidebar-separator {
    margin: 5px 6px;
  }

  /* User profile: avatar only */
  .sidebar-collapsed .user-profile-btn {
    justify-content: center;
    padding: 6px 0;
    gap: 0;
  }

  .sidebar-collapsed .user-profile-btn .profile-info,
  .sidebar-collapsed .user-profile-btn .profile-chevron {
    display: none;
  }

  /* Dropdown: position to the right in collapsed mode */
  .sidebar-collapsed .user-profile-section .dropdown-menu {
    position: fixed;
    bottom: 14px;
    left: calc(var(--sidebar-width-collapsed) + 8px);
    top: auto;
    right: auto;
  }

  /* Hide mobile toggle on desktop */
  .sidebar-toggle-btn {
    display: none;
  }

  /* Overlay not needed on desktop */
  .sidebar-overlay {
    display: none !important;
  }
}

/* ===========================
   Mobile Layout (< 992px)
   =========================== */

@media (max-width: 991px) {
  .main-header {
    display: block;
  }

  #layoutSidenav_nav {
    top: 0;
    height: 100vh;
    width: 272px;
    transform: translateX(-100%);
    transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
    z-index: 1040;
  }

  #layoutSidenav.sidebar-active #layoutSidenav_nav {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.06);
  }

  #layoutSidenav_content {
    padding-top: calc(var(--navbar-height) + 24px);
  }

  body.sidebar-lock {
    overflow: hidden;
  }

  /* Hide desktop-only elements on mobile */
  .sidebar-collapse-btn {
    display: none !important;
  }
}

/* Wide screens */
@media (min-width: 1400px) {
  :root {
    --sidebar-width: 252px;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  #layoutSidenav_nav,
  .sidebar-overlay,
  #layoutSidenav_content {
    transition: none !important;
  }
}

/* Mobile touch targets */
@media (max-width: 991px) {
  .sb-sidenav .nav-link {
    height: 36px;
  }

  .footer-action-link {
    height: 36px;
  }
}
