/* ============================================================
   Shell — sidebar owns the left column full-height.
   Topbar spans only the content column (Linear / Vercel pattern).
   Brand lives inside the sidebar header — no visual collision
   with page content or the topbar search.
   ============================================================ */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    'sidebar topbar'
    'sidebar content';
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  transition: grid-template-columns var(--t-base);
}

.app[data-sidebar='collapsed'] {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

/* Auto-hide mode — grid reserves a narrow rail; sidebar floats over content on hover. */
.app[data-sidebar='auto'] {
  grid-template-columns: 12px 1fr;
}
.app[data-sidebar='auto'] .sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  transform: translateX(calc(-1 * (var(--sidebar-w) - 4px)));
  transition: transform 180ms ease;
  z-index: 60;
  box-shadow: 4px 0 24px rgba(0,0,0,.45);
}
.app[data-sidebar='auto'] .sidebar:hover,
.app[data-sidebar='auto'] .sidebar:focus-within,
.app[data-sidebar='auto'] .sidebar.is-peeking {
  transform: translateX(0);
}
/* Visible rail indicator when hidden — a subtle 4px strip so users know the nav exists */
.app[data-sidebar='auto'] .sidebar::before {
  content: '';
  position: absolute;
  top: 0; right: -4px;
  width: 4px; height: 100%;
  background: linear-gradient(to right, transparent, var(--accent) 80%);
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 180ms ease;
}
.app[data-sidebar='auto'] .sidebar:hover::before { opacity: 0; }

/* ============================================================
   Top bar — content column only
   ============================================================ */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-5);
  background: var(--glass-bg);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  z-index: 50;
  position: relative;
  min-width: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}
.topbar-center {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 560px;
  margin-left: var(--sp-2);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
  flex-shrink: 0;
}

.search {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  height: 32px;
  padding: 0 var(--sp-3);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  color: var(--text-3);
  font-size: var(--fs-13);
  cursor: text;
  transition: all var(--t-fast);
}
.search:hover { border-color: var(--border-strong); }
.search svg { color: var(--text-4); }
.search-placeholder { flex: 1; color: var(--text-4); }

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-2);
  color: var(--text-2);
  transition: all var(--t-fast);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 14px;
  height: 14px;
  border-radius: var(--r-pill);
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  border: 2px solid var(--bg);
  line-height: 1;
}

.avatar-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: 32px;
  padding: 0 var(--sp-2);
  border-radius: var(--r-2);
  transition: all var(--t-fast);
}
.avatar-btn:hover { background: var(--bg-hover); }

/* ============================================================
   Sidebar — full-height, owns the brand, collapsible
   ============================================================ */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Sidebar header (brand + collapse toggle) — aligns with topbar height */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: var(--topbar-h);
  padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex: 1;
  min-width: 0;
  color: var(--text);
}
.brand:hover { color: var(--text); }

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--r-2);
  background: linear-gradient(135deg, var(--accent), var(--highlight));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.brand-name {
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.brand-sub {
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.1;
}

/* Sidebar toggle moved to topbar — uses .icon-btn styles instead */

/* Scrollable nav region */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-3) var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-height: 0;
}

.nav-section {
  font-size: var(--fs-11);
  font-weight: 600;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--sp-4) var(--sp-3) var(--sp-1);
  margin-top: var(--sp-2);
}
.nav-section:first-child { margin-top: 0; padding-top: var(--sp-2); }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-3);
  height: 34px;
  border-radius: var(--r-2);
  color: var(--text-2);
  font-size: var(--fs-13);
  font-weight: 500;
  transition: all var(--t-fast);
  cursor: pointer;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.is-active {
  background: var(--accent-100);
  color: var(--accent);
}
.nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.nav-item .nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-item .nav-count {
  margin-left: auto;
  font-size: var(--fs-11);
  color: var(--text-3);
  background: var(--bg-3);
  padding: 0 6px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--r-pill);
  min-width: 18px;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
}
.nav-item.is-active .nav-count { background: var(--accent-100); color: var(--accent); }

/* Mode toggle button */
.mode-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-12);
  font-family: var(--font-mono);
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.mode-toggle:hover {
  background: var(--surface-3);
  border-color: var(--accent);
}
.mode-toggle-label { font-weight: 600; }
.app[data-sidebar='collapsed'] .mode-toggle { display: none; }

.sidebar-footer {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-11);
  color: var(--text-3);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  flex-shrink: 0;
}
.sidebar-footer .row {
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.sidebar-footer .mono { color: var(--text-2); font-size: var(--fs-11); }

/* ============================================================
   Collapsed sidebar state
   ============================================================ */
.app[data-sidebar='collapsed'] .sidebar-header {
  padding: 0;
  justify-content: center;
  border-bottom-color: transparent;
}
.app[data-sidebar='collapsed'] .brand-text,
.app[data-sidebar='collapsed'] .nav-label,
.app[data-sidebar='collapsed'] .nav-count,
.app[data-sidebar='collapsed'] .nav-section,
.app[data-sidebar='collapsed'] .sidebar-footer {
  display: none;
}
.app[data-sidebar='collapsed'] .brand {
  flex: 0 0 auto;
  justify-content: center;
}
.app[data-sidebar='collapsed'] .sidebar-nav {
  padding: var(--sp-3) var(--sp-2);
  align-items: center;
}
.app[data-sidebar='collapsed'] .nav-item {
  justify-content: center;
  padding: 0;
  width: 40px;
  height: 40px;
  gap: 0;
}
.app[data-sidebar='collapsed'] .nav-item svg {
  width: 18px;
  height: 18px;
}

/* Tooltip when collapsed */
.app[data-sidebar='collapsed'] .nav-item[data-label]:hover::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--fs-12);
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--r-2);
  white-space: nowrap;
  pointer-events: none;
  z-index: 1000;
  box-shadow: var(--shadow-2);
}

/* ============================================================
   Content area
   ============================================================ */
.content {
  grid-area: content;
  overflow-y: auto;
  background: var(--bg);
  position: relative;
}

.page {
  padding: var(--sp-5) var(--sp-6);
  max-width: none;
}
.page--wide { padding: var(--sp-5) var(--sp-5); }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border-subtle);
}
.page-header--nb { border-bottom: none; padding-bottom: 0; }

.page-title {
  font-size: var(--fs-20);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.015em;
  line-height: 1.2;
  margin-bottom: var(--sp-1);
}
.page-subtitle {
  font-size: var(--fs-13);
  color: var(--text-3);
  line-height: 1.4;
  max-width: 640px;
}
.page-actions { display: flex; gap: var(--sp-2); flex-shrink: 0; align-items: center; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-12);
  color: var(--text-3);
  margin-bottom: var(--sp-3);
}
.breadcrumb a { color: var(--text-3); }
.breadcrumb a:hover { color: var(--text); text-decoration: none; }
.breadcrumb svg { width: 12px; height: 12px; color: var(--text-4); }
.breadcrumb-current { color: var(--text); }

/* ============================================================
   Notification panel
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
.overlay.is-open { opacity: 1; pointer-events: auto; }
[data-theme='light'] .overlay { background: rgba(15, 18, 22, 0.3); }

.panel-right {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 100vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 100;
  transform: translateX(100%);
  transition: transform var(--t-base);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-3);
}
.panel-right.is-open { transform: translateX(0); }

.panel-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-head-title { font-size: var(--fs-15); font-weight: 600; color: var(--text); flex: 1; }
.panel-body { flex: 1; overflow-y: auto; padding: var(--sp-3) 0; }

/* Notification rows */
.notif-group {
  padding: var(--sp-1) var(--sp-5);
  font-size: var(--fs-11);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-4);
  margin-top: var(--sp-2);
}
.notif {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  text-decoration: none;
  color: inherit;
  transition: background var(--t-fast);
  position: relative;
}
.notif:hover { background: var(--bg-hover); }
.notif.is-unread { background: var(--bg-subtle, rgba(74, 144, 217, 0.06)); }
.notif-icon { flex-shrink: 0; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: var(--r-2); background: var(--bg-hover); color: var(--text-2); }
.notif-icon svg { width: 14px; height: 14px; }
.notif-title { font-size: var(--fs-13); font-weight: 500; color: var(--text); line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-body { font-size: var(--fs-12); color: var(--text-2); line-height: 1.4; margin-top: 1px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.notif-time { font-size: var(--fs-11); color: var(--text-4); margin-top: 2px; }
.notif-dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 6px;
}

/* ============================================================
   Responsive — auto-collapse sidebar under 960px.
   Users can still toggle back via the topbar's mobile menu
   button (added when viewport is narrow).
   ============================================================ */
@media (max-width: 960px) {
  .app:not([data-sidebar='expanded']) {
    grid-template-columns: var(--sidebar-w-collapsed) 1fr;
  }
  .app:not([data-sidebar='expanded']) .sidebar-header {
    padding: 0;
    justify-content: center;
  }
  .app:not([data-sidebar='expanded']) .brand-text,
  .app:not([data-sidebar='expanded']) .nav-label,
  .app:not([data-sidebar='expanded']) .nav-count,
  .app:not([data-sidebar='expanded']) .nav-section,
  .app:not([data-sidebar='expanded']) .sidebar-footer {
    display: none;
  }
  .app:not([data-sidebar='expanded']) .brand {
    flex: 0 0 auto;
    justify-content: center;
  }
  .app:not([data-sidebar='expanded']) .nav-item {
    justify-content: center;
    padding: 0;
    width: 40px;
    height: 40px;
    gap: 0;
  }
  .page { padding: var(--sp-4); }
}
