/* ==========================================================================
   Salex - Layout (Sidebar + Topbar + Wrapper)
   ========================================================================== */
.app-wrapper { min-height: 100vh; display: flex; flex-direction: column; }
.app-main {
  margin-left: var(--salex-sidebar-width);
  margin-top: var(--salex-topbar-h);
  padding: 1.5rem;
  min-height: calc(100vh - var(--salex-topbar-h));
  transition: margin-left .25s ease;
}
.app-main-inner { max-width: 1600px; margin: 0 auto; }

/* Sidebar */
.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--salex-sidebar-width);
  background: var(--salex-sidebar-bg);
  color: var(--salex-sidebar-text);
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: width .25s ease, transform .25s ease;
  overflow: hidden;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 1.25rem;
  height: var(--salex-topbar-h);
  border-bottom: 1px solid var(--salex-sidebar-border);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 1.18rem;
  flex-shrink: 0;
}
.sidebar-brand .brand-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--salex-accent) 0%, #D97706 100%);
  display: flex; align-items: center; justify-content: center;
  color: #1B2F6F;
  font-size: 1.15rem;
}
.sidebar-brand .brand-text span { color: var(--salex-accent); }

.sidebar-search {
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--salex-sidebar-border);
}
.sidebar-search .form-control {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 0.82rem;
}
.sidebar-search .form-control::placeholder { color: rgba(255,255,255,0.45); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem 0 1.5rem;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); }
.sidebar-menu { list-style: none; padding: 0; margin: 0; }
.sidebar-heading {
  padding: 0.9rem 1.25rem 0.4rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--salex-sidebar-heading);
  font-weight: 600;
}
.menu-item { padding: 1px 0.6rem; }
.menu-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.75rem;
  color: var(--salex-sidebar-text);
  text-decoration: none;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 500;
  position: relative;
  cursor: pointer;
}
.menu-link i:first-child { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }
.menu-link:hover { background: var(--salex-sidebar-hover); color: #fff; }
.menu-link .menu-arrow { margin-left: auto; font-size: 0.78rem; transition: transform .2s ease; }
.menu-link[aria-expanded="true"] .menu-arrow { transform: rotate(90deg); }
.menu-link.active,
.menu-item.active > .menu-link {
  background: linear-gradient(90deg, rgba(245,158,11,0.18), transparent);
  color: var(--salex-accent);
}
.menu-link.active::before {
  content: "";
  position: absolute;
  left: -0.6rem;
  top: 0; bottom: 0;
  width: 3px;
  background: var(--salex-accent);
  border-radius: 0 3px 3px 0;
}
.menu-text { flex: 1; }
.menu-badge {
  margin-left: auto;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--salex-accent);
  color: #1B2F6F;
  font-weight: 600;
}
.menu-link.active .menu-badge { background: rgba(255,255,255,0.18); color: var(--salex-accent); }

.sidebar-submenu {
  list-style: none;
  padding: 0.2rem 0 0.4rem 2rem;
  margin: 0;
}
.submenu-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.42rem 0.75rem;
  color: rgba(199,210,254,0.75);
  text-decoration: none;
  font-size: 0.81rem;
  border-radius: 6px;
  position: relative;
}
.submenu-link::before {
  content: "";
  width: 4px; height: 4px;
  border-radius: 50%;
  background: rgba(199,210,254,0.4);
  flex-shrink: 0;
}
.submenu-link:hover { color: #fff; background: rgba(255,255,255,0.04); }
.submenu-link.active { color: var(--salex-accent); }
.submenu-link.active::before { background: var(--salex-accent); }

.sidebar-footer {
  padding: 0.9rem 1.1rem;
  border-top: 1px solid var(--salex-sidebar-border);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}
.sidebar-footer .avatar { width: 36px; height: 36px; border-radius: 50%; }
.sidebar-footer .name { color: #fff; font-weight: 500; font-size: 0.85rem; }
.sidebar-footer .role { color: var(--salex-sidebar-heading); font-size: 0.72rem; }

/* Topbar */
.app-topbar {
  position: fixed;
  top: 0;
  left: var(--salex-sidebar-width);
  right: 0;
  height: var(--salex-topbar-h);
  background: var(--salex-topbar-bg);
  border-bottom: 1px solid var(--salex-topbar-border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  z-index: 1030;
  gap: 0.5rem;
  transition: left .25s ease;
}
.topbar-toggle {
  background: transparent;
  border: none;
  color: var(--salex-text);
  font-size: 1.3rem;
  width: 38px; height: 38px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.topbar-toggle:hover { background: var(--salex-border-soft); }
.topbar-search {
  position: relative;
  flex: 1;
  max-width: 460px;
}
.topbar-search input {
  width: 100%;
  padding-left: 2.4rem;
  height: 40px;
  background: var(--salex-border-soft);
  border-color: transparent;
}
.topbar-search input:focus { background: #fff; }
.topbar-search .bi-search {
  position: absolute;
  top: 50%; left: 0.85rem;
  transform: translateY(-50%);
  color: var(--salex-text-muted);
}
.topbar-search .kbd-hint {
  position: absolute;
  top: 50%; right: 0.6rem;
  transform: translateY(-50%);
  font-size: 0.7rem;
}
.topbar-search-menu {
  width: 100%;
  max-height: 70vh;
  overflow-y: auto;
  margin-top: 0.25rem;
}
.topbar-search-menu .dropdown-header { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; }
.topbar-search-menu .dropdown-item { white-space: normal; display: flex; align-items: center; gap: 0.6rem; }
.topbar-search-menu .dropdown-item .badge { margin-left: auto; text-transform: capitalize; }
.topbar-search-menu .dropdown-item.active, .topbar-search-menu .dropdown-item:active { color: inherit; background: var(--salex-border-soft); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 0.25rem; }
.topbar-icon-btn {
  width: 38px; height: 38px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--salex-text-muted);
  font-size: 1.1rem;
  display: inline-flex; align-items: center; justify-content: center;
  position: relative;
}
.topbar-icon-btn:hover { background: var(--salex-border-soft); color: var(--salex-primary); }
.topbar-icon-btn .dot {
  position: absolute;
  top: 8px; right: 9px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--salex-danger);
  border: 2px solid #fff;
}
.topbar-user {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.3rem 0.55rem 0.3rem 0.4rem;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid var(--salex-border-soft);
  margin-left: 0.4rem;
  transition: background .15s ease;
}
.topbar-user:hover { background: var(--salex-border-soft); }
.topbar-user .avatar { width: 30px; height: 30px; border-radius: 50%; }
.topbar-user .name { font-weight: 500; font-size: 0.83rem; line-height: 1; color: var(--salex-heading); }
.topbar-user .role { font-size: 0.7rem; color: var(--salex-text-muted); line-height: 1.4; }

/* Footer */
.app-footer {
  margin-left: var(--salex-sidebar-width);
  padding: 1rem 1.5rem;
  background: #fff;
  border-top: 1px solid var(--salex-border);
  font-size: 0.82rem;
  color: var(--salex-text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  transition: margin-left .25s ease;
}

/* Page Header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-title { font-size: 1.4rem; font-weight: 700; margin: 0; color: var(--salex-heading); }
.page-subtitle { font-size: 0.83rem; color: var(--salex-text-muted); margin: 0.2rem 0 0; }
.breadcrumb { margin: 0; font-size: 0.8rem; }
.breadcrumb-item { color: var(--salex-text-muted); }
.breadcrumb-item.active { color: var(--salex-text); }
.breadcrumb-item a { color: var(--salex-text-muted); }
.breadcrumb-item + .breadcrumb-item::before { content: "/"; color: var(--salex-text-soft); }

/* Sidebar collapsed */
.app-sidebar.collapsed { width: var(--salex-sidebar-collapsed); }
.app-sidebar.collapsed .menu-text,
.app-sidebar.collapsed .menu-arrow,
.app-sidebar.collapsed .menu-badge,
.app-sidebar.collapsed .sidebar-heading,
.app-sidebar.collapsed .sidebar-search,
.app-sidebar.collapsed .sidebar-submenu,
.app-sidebar.collapsed .sidebar-footer .text { display: none; }
.app-sidebar.collapsed .brand-text { display: none; }
.app-sidebar.collapsed .sidebar-brand { justify-content: center; padding: 0; }
.app-sidebar.collapsed + .app-topbar,
.app-sidebar.collapsed ~ .app-topbar { left: var(--salex-sidebar-collapsed); }
body.sidebar-collapsed .app-main,
body.sidebar-collapsed .app-footer { margin-left: var(--salex-sidebar-collapsed); }
body.sidebar-collapsed .app-topbar { left: var(--salex-sidebar-collapsed); }
body.sidebar-collapsed .app-sidebar { width: var(--salex-sidebar-collapsed); }
body.sidebar-collapsed .menu-text,
body.sidebar-collapsed .menu-arrow,
body.sidebar-collapsed .menu-badge,
body.sidebar-collapsed .sidebar-heading,
body.sidebar-collapsed .sidebar-search,
body.sidebar-collapsed .sidebar-submenu,
body.sidebar-collapsed .sidebar-footer .text { display: none; }
body.sidebar-collapsed .brand-text { display: none; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 0; }

/* Mobile */
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-sidebar.show { transform: translateX(0); box-shadow: 0 0 64px rgba(0,0,0,0.3); }
  .app-topbar { left: 0; }
  .app-main, .app-footer { margin-left: 0; padding-left: 1rem; padding-right: 1rem; }
  .topbar-search { display: none; }
  .topbar-user .name, .topbar-user .role { display: none; }
  body.sidebar-open { overflow: hidden; }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11,20,55,0.5);
    z-index: 1035;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
  }
  body.sidebar-open .sidebar-overlay { opacity: 1; pointer-events: auto; }
}

/* Dark mode — layout overrides */
html.theme-dark .app-topbar { background: var(--salex-topbar-bg); border-bottom-color: var(--salex-topbar-border); }
html.theme-dark .topbar-toggle { color: var(--salex-text); }
html.theme-dark .topbar-toggle:hover { background: rgba(255,255,255,0.06); }
html.theme-dark .topbar-search input { background: rgba(255,255,255,0.06); color: var(--salex-text); border-color: transparent; }
html.theme-dark .topbar-search input::placeholder { color: var(--salex-text-soft); }
html.theme-dark .topbar-search input:focus { background: rgba(255,255,255,0.1); }
html.theme-dark .topbar-search .bi-search { color: var(--salex-text-muted); }
html.theme-dark .topbar-icon-btn { color: var(--salex-text-muted); }
html.theme-dark .topbar-icon-btn:hover { background: rgba(255,255,255,0.06); color: var(--salex-accent); }
html.theme-dark .topbar-icon-btn .dot { border-color: var(--salex-topbar-bg); }
html.theme-dark .topbar-user { border-color: var(--salex-border); }
html.theme-dark .topbar-user:hover { background: rgba(255,255,255,0.04); }
html.theme-dark .topbar-user .name { color: var(--salex-text); }
html.theme-dark .topbar-user .role { color: var(--salex-text-muted); }
html.theme-dark .app-footer { background: var(--salex-card-bg); border-top-color: var(--salex-border); color: var(--salex-text-muted); }
html.theme-dark .page-title { color: var(--salex-heading); }
html.theme-dark .page-subtitle { color: var(--salex-text-muted); }
