/* ============================================================
   NexaGrid - App shell (sidebar + header + content)
   Sidebar: 80px icon rail (default) <-> 248px expanded
   ============================================================ */

#app-layout {
  height: 100vh;
  width: 100%;
  display: flex;
  overflow: hidden;
}

#app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--canvas);
}

/* ================= 1. Sidebar (icon rail / expanded) ================= */
#app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 100;
  transition: width 180ms ease;
  overflow: visible;
}

#app-sidebar .app-sidebar-panel {
  width: 100%;
  height: 100%;
  min-width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ----- Brand ----- */
.sidebar-brand-wrap {
  flex-shrink: 0;
}

.sidebar-brand {
  min-height: 76px;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.sidebar-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}

.sidebar-wordmark {
  display: none;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
}

/* ----- Nav ----- */
.sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 0;
}

.sidebar-nav::-webkit-scrollbar {
  width: 0;
}

.sidebar-nav .sb-drop {
  width: auto;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
}

.nav-item-bar {
  position: relative;
  width: 48px;
  height: 48px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  gap: 12px;
  border-radius: 12px;
  color: var(--muted-2);
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.nav-item-bar .sb-item-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-item-bar .sb-item-icon svg {
  width: 20px;
  height: 20px;
}

.nav-item-bar .sb-item-label {
  display: none;
  font-size: 13px;
  font-weight: 600;
  color: inherit;
  white-space: nowrap;
}

.nav-item-bar .sb-item-chev {
  display: none;
  width: 14px;
  height: 14px;
  margin-left: auto;
  color: var(--muted-2);
  flex-shrink: 0;
}

.nav-item-bar:hover {
  color: var(--accent);
  background-color: rgb(var(--accent-rgb) / 0.06);
}

html.dark .nav-item-bar:hover {
  background-color: rgb(var(--accent-rgb) / 0.14);
  color: #ffffff;
}

.nav-item-bar.active {
  color: var(--accent);
  background-color: var(--accent-bg);
}

html.dark .nav-item-bar.active {
  background-color: rgb(var(--accent-rgb) / 0.2);
  color: var(--accent-hover-dark);
}

.nav-item-bar.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 13px;
  bottom: 13px;
  width: 3px;
  border-radius: 3px;
  background-color: var(--accent);
}

/* ----- Expanded layout (data-sidebar + mobile drawer) ----- */
#app-sidebar.open,
html[data-sidebar="expanded"] #app-sidebar {
  width: var(--sidebar-width-expanded);
}

#app-sidebar.open .sidebar-brand,
html[data-sidebar="expanded"] .sidebar-brand {
  justify-content: flex-start;
  padding: 0 18px;
}

#app-sidebar.open .sidebar-wordmark,
html[data-sidebar="expanded"] .sidebar-wordmark {
  display: block;
}

#app-sidebar.open .nav-item-bar,
html[data-sidebar="expanded"] .nav-item-bar {
  justify-content: flex-start;
  margin: 2px 10px;
  padding: 0 12px;
  border-radius: 10px;
  width: calc(100% - 20px);
}

#app-sidebar.open .nav-item-bar .sb-item-label,
html[data-sidebar="expanded"] .nav-item-bar .sb-item-label {
  display: block;
}

#app-sidebar.open .nav-item-bar.sb-drop-trigger .sb-item-chev,
html[data-sidebar="expanded"] .nav-item-bar.sb-drop-trigger .sb-item-chev {
  display: block;
}

#app-sidebar.open .nav-item-bar.active::before,
html[data-sidebar="expanded"] .nav-item-bar.active::before {
  left: -10px;
}

/* ----- Flyout dropdown panels ----- */
.sb-drop {
  position: relative;
  flex-shrink: 0;
}

#app-sidebar.open .sidebar-nav .sb-drop,
html[data-sidebar="expanded"] .sidebar-nav .sb-drop {
  width: calc(100% - 20px);
  margin: 2px 10px;
  justify-content: flex-start;
}

#app-sidebar.open .sidebar-nav .sb-drop .nav-item-bar,
html[data-sidebar="expanded"] .sidebar-nav .sb-drop .nav-item-bar {
  width: 100%;
  margin: 0;
}

.sb-drop-trigger[aria-expanded="true"] {
  color: var(--accent);
  background-color: var(--accent-bg);
}

.sb-drop-panel {
  position: fixed;
  z-index: 999999;
  min-width: 212px;
  max-width: 252px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 7px;
  opacity: 0;
  transform: translateY(4px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.16s, transform 0.16s;
}

.sb-drop-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.sb-drop-head {
  padding: 7px 11px 5px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-2);
}

.sb-drop-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.sb-drop-item:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.sb-drop-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.sb-drop-item.active svg {
  color: var(--accent);
}

.sb-drop-item svg {
  width: 15px;
  height: 15px;
  color: var(--muted-2);
  flex-shrink: 0;
}

.sb-drop-item.disabled,
.sb-drop-item.disabled:hover {
  opacity: 0.5;
  cursor: default;
  color: var(--ink);
  background: transparent;
  pointer-events: none;
}

.sb-drop-item .sb-soon {
  margin-left: auto;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-round);
  padding: 2px 7px;
}

/* ----- Sidebar foot + profile button ----- */
.sidebar-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0 4px;
  margin-top: auto;
  flex-shrink: 0;
}

.sb-profile {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

.sb-avatar-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--surface-inset);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  cursor: pointer;
  flex-shrink: 0;
}

.sb-avatar-btn:hover,
.sb-avatar-btn[aria-expanded="true"] {
  background: var(--accent);
}

.sb-profile-copy {
  display: none;
}

.sb-profile-copy b {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-profile-copy span {
  display: block;
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#app-sidebar.open .sb-profile,
html[data-sidebar="expanded"] .sb-profile {
  justify-content: flex-start;
  padding: 0 10px;
}

#app-sidebar.open .sb-avatar-btn,
html[data-sidebar="expanded"] .sb-avatar-btn {
  width: 100%;
  justify-content: flex-start;
  gap: 10px;
  padding: 0 10px;
  background: var(--surface-inset);
}

#app-sidebar.open .sb-avatar-btn:hover,
html[data-sidebar="expanded"] .sb-avatar-btn:hover {
  background: var(--accent-soft);
}

#app-sidebar.open .sb-profile-copy,
html[data-sidebar="expanded"] .sb-profile-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ----- Collapse toggle ----- */
.sb-collapse-toggle {
  flex-shrink: 0;
  height: 42px;
  margin: 2px 8px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: var(--radius-md);
  color: var(--muted-2);
  cursor: pointer;
  transition: all 0.15s ease;
}

.sb-collapse-toggle:hover {
  background: var(--surface-inset);
  color: var(--ink);
}

.sb-collapse-toggle svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.sb-collapse-toggle .sb-item-label {
  display: none;
  font-size: 12px;
  font-weight: 600;
  color: inherit;
  white-space: nowrap;
}

.sb-collapse-toggle .icon-expand {
  display: none;
}

html[data-sidebar="collapsed"] .sb-collapse-toggle .icon-collapse {
  display: none;
}

html[data-sidebar="collapsed"] .sb-collapse-toggle .icon-expand {
  display: block;
}

#app-sidebar.open .sb-collapse-toggle,
html[data-sidebar="expanded"] .sb-collapse-toggle {
  justify-content: flex-start;
  padding: 0 14px;
}

#app-sidebar.open .sb-collapse-toggle .sb-item-label,
html[data-sidebar="expanded"] .sb-collapse-toggle .sb-item-label {
  display: block;
}

/* profile popover (extends sb-drop-panel base) */
.sb-profile-popover {
  width: 232px;
  margin-top: -6px;
}

.sp-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 10px;
  min-width: 0;
}

.sp-head .avatar {
  flex-shrink: 0;
}

.sp-head-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sp-head-info b {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sp-head-info span {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sp-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 8px;
}

.sp-logout {
  color: var(--color-danger) !important;
}
.sp-logout:hover {
  background: var(--danger-soft) !important;
  color: var(--color-danger) !important;
}

/* ================= 2. Header (64px, canvas) ================= */
#app-header {
  flex-shrink: 0;
  background: var(--surface);
}

html.dark #app-header {
  background: var(--canvas);
}

#app-header > header {
  height: var(--header-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#sidebar-toggle {
  display: none;
  width: var(--control-height-sm);
  height: var(--control-height-sm);
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
}

#sidebar-toggle:hover {
  background: var(--surface-inset);
  color: var(--ink);
}

.global-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: min(460px, 42vw);
}

.global-search-wrap .search-icon {
  position: absolute;
  left: 16px;
  width: 18px;
  height: 18px;
  color: var(--muted-2);
  pointer-events: none;
}

.global-search-wrap input {
  width: 100%;
  padding-left: 44px;
  padding-right: 64px;
}

.global-search-wrap .kbd-hint {
  position: absolute;
  right: 14px;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted-2);
  background: var(--surface-inset);
  padding: 2px 7px;
  border-radius: 7px;
  box-shadow: inset 0 0 0 1px var(--border);
  pointer-events: none;
}

.header-actions-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-action-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: all 0.15s ease;
}

.header-action-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.header-action-btn svg {
  width: 18px;
  height: 18px;
}

/* Nav-select buttons (Dashboards / Apps) */
.header-nav-select {
  height: 40px;
  min-width: 0;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.header-nav-select > svg {
  width: 16px;
  height: 16px;
  color: var(--muted-2);
  flex-shrink: 0;
}

.header-nav-select:hover {
  background: var(--surface-inset);
}

.header-nav-select[aria-expanded="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.header-nav-select[aria-expanded="true"] > svg {
  color: var(--accent);
}

.header-right .icon-pill {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--surface-inset);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  position: relative;
}

.header-right .icon-pill:hover {
  color: var(--accent);
}

.header-right .icon-pill svg {
  width: 18px;
  height: 18px;
}

.header-right .icon-pill .dot {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 7px;
  height: 7px;
  border-radius: var(--radius-round);
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--surface-inset);
}

/* ================= 2b. Avatar component (reusable - circular) ================= */
.avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-round);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.avatar.sm {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-round);
  font-size: 10px;
}

.avatar.lg {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-round);
  font-size: 14px;
}

.avatar.xl {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-round);
  font-size: 18px;
}

/* ================= 3. Page breadcrumbs (pinned bottom bar) ================= */
.page-breadcrumbs {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  height: 48px;
  min-height: 48px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
  z-index: 20;
}

html.dark .page-breadcrumbs {
  background: var(--surface);
}

.page-breadcrumbs a.bc-root {
  color: var(--muted);
  transition: color 0.15s;
}
.page-breadcrumbs a.bc-root:hover {
  color: var(--accent);
}

.page-breadcrumbs .bc-mid,
.page-breadcrumbs a.bc-mid {
  color: var(--muted);
  transition: color 0.15s;
}

.page-breadcrumbs a.bc-mid:hover {
  color: var(--accent);
}

.page-breadcrumbs .bc-icon {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  flex-shrink: 0;
}

.page-breadcrumbs .bc-chevron {
  width: 14px;
  height: 14px;
  color: var(--muted-2);
  flex-shrink: 0;
}

.page-breadcrumbs .bc-current {
  color: var(--ink);
  font-weight: 600;
}

/* ================= 4. Content ================= */
#app-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

.page-shell {
  flex: 1;
  padding: 4px 20px 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 100%;
}

/* ================= 5. Mobile drawer ================= */
.sidebar-overlay {
  display: none;
}

@media (max-width: 1024px) {
  #sidebar-toggle {
    display: flex;
  }

  #app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), width 180ms ease;
    box-shadow: none;
  }

  #app-sidebar.open {
    transform: translateX(0);
    box-shadow: 0 0 0 100vmax rgb(3 7 18 / 0.45);
    width: var(--sidebar-width-expanded);
  }

  .sb-collapse-toggle {
    display: none;
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgb(3 7 18 / 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s;
    z-index: 99;
  }

  .sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }

  .global-search-wrap {
    width: min(360px, 48vw);
  }
}

@media (max-width: 560px) {
  #app-header > header {
    padding: 0 12px;
  }

  .header-actions-group {
    display: none;
  }

  .global-search-wrap {
    width: 100%;
  }

  #app-content {
    padding-left: 12px;
    padding-right: 12px;
  }
}