/* =========================
   Shell Layout (Holy Grail)
   ========================= */

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Header --- */
#app-header {
  height: 64px;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  /* Ensure high z-index */
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  box-sizing: border-box;
  /* Prevent overflow */
}

.brand {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 20px;
  color: var(--fg);
  text-decoration: none;
  letter-spacing: -0.5px;
}

/* --- Main Layout Wrapper --- */
.layout-wrapper {
  display: flex;
  width: 100%;
  padding-top: 64px;
  /* Space for fixed header */
  min-height: 100vh;
  box-sizing: border-box;
}

/* --- Main Content (Left) --- */
.main-content {
  flex: 1;
  padding: 24px 48px;
  /* Reduced top/bottom padding */
  min-width: 0;
  /* Prevent flex overflow */
}

/* --- Sidebar (Right) --- */
#app-sidebar {
  width: 360px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg);
  /* Same as base bg */
  height: calc(100vh - 64px);
  position: sticky;
  top: 64px;
  overflow-y: hidden;
  /* Hide main scroll, use inner scroll */
  display: flex;
  flex-direction: column;
}

/* --- Sidebar Internals --- */
.sidebar-search {
  padding: 24px 16px;
  margin-top: -2px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  /* Match sidebar */
  flex-shrink: 0;
  /* Prevent shrinking */
  z-index: 10;
}

.search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--bg);
  box-sizing: border-box;
}

.sidebar-list {
  padding: 16px;
  flex: 1;
  overflow-y: auto;
  /* Scroll only list */
}

.sidebar-category {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
  font-weight: 600;
  margin: 24px 0 8px 8px;
}

.sidebar-category:first-child {
  margin-top: 0;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--fg);
  transition: background 0.1s ease;
  margin-bottom: 2px;
}

.sidebar-item:hover {
  background: rgba(0, 0, 0, 0.04);
}

.sidebar-item.active {
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 500;
}

.item-icon {
  font-size: 16px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-radius: 4px;
  border: none;
  color: var(--fg-muted);
  /* Muted by default */
}

.sidebar-item.active .item-icon {
  color: var(--accent);
  /* Accent when active */
}

/* Mobile Responsiveness */
/* Mobile Responsiveness & Drawer */
@media (max-width: 1024px) {

  /* Layout: Sidebar no longer shares width. */
  .layout-wrapper {
    flex-direction: column;
    padding-top: 64px;
    /* Default */
  }

  /* Header: Show Menu Toggle */
  #menu-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  /* Sidebar: Drawer Mode */
  #app-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 300px;
    /* Drawer width */
    height: 100vh;
    border-left: 1px solid var(--border);
    border-top: none;
    z-index: 2000;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.15);
    display: flex;
    /* Override flex-col from desktop if needed */
  }

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

  /* Sidebar Header (Mobile Only) */
  .sidebar-mobile-header {
    display: flex !important;
  }

  /* Backdrop */
  #sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
  }

  .sidebar-open #sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* Main Content Adjustments */
  .main-content {
    padding: 24px;
    width: 100%;
    box-sizing: border-box;
  }

  /* Prevent scroll when sidebar open */
  .sidebar-open {
    overflow: hidden;
  }
}

/* Tablet / Mobile Tweaks */
@media (max-width: 768px) {
  .brand {
    font-size: 18px;
  }
}