.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--navbar-h) 1fr;
  grid-template-areas:
    "sidebar navbar"
    "sidebar main";
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---- Navbar ---- */
.navbar {
  grid-area: navbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 0 var(--sp-6);
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 20;
  min-width: 0;
}

.navbar__left {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
}

.navbar__route {
  font-family: var(--font-mono);
  font-size: var(--fs-00);
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.navbar__route strong { color: var(--text-primary); font-weight: var(--fw-semibold); }

.navbar__right {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-shrink: 0;
}

/* Menu button — hidden on desktop, shown at drawer breakpoint */
.menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: background var(--dur-med) var(--ease), color var(--dur-med) var(--ease);
}
.menu-btn:hover { background: var(--bg-sunken); color: var(--text-primary); }
.menu-btn:active { background: var(--border); }
.menu-btn:focus-visible { box-shadow: var(--focus-ring); }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--fw-bold);
  font-size: var(--fs-00);
  flex-shrink: 0;
}

/* ---- Sidebar ---- */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-sunken);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--sp-5) var(--sp-4);
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  transition: transform var(--dur-med) var(--ease);
}

.sidebar__brand {
  font-family: var(--font-display);
  font-weight: var(--fw-extrabold);
  font-size: var(--fs-2);
  letter-spacing: var(--ls-snug);
  padding: 0 var(--sp-2);
  margin: 0 0 var(--sp-7);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.brand-mark {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  /* No color set here on purpose — inherits currentColor from its
     context, so the same mark is automatically theme-correct
     whether it sits on the sidebar (colored) or the always-dark
     auth panel (on-dark-surface). */
}
.sidebar__brand .brand-mark { color: var(--brand); }

.sidebar__group-label {
  font-family: var(--font-mono);
  font-size: var(--fs-000);
  font-weight: var(--fw-medium);
  text-transform: uppercase;
  letter-spacing: var(--ls-wider);
  color: var(--text-tertiary);
  padding: 0 var(--sp-2);
  margin: var(--sp-5) 0 var(--sp-2);
}
.sidebar__group-label:first-of-type { margin-top: 0; }

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.navlink {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 44px;
  padding: var(--sp-3);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-weight: var(--fw-medium);
  font-size: var(--fs-0);
  transition: background var(--dur-med) var(--ease), color var(--dur-med) var(--ease), box-shadow var(--dur-med) var(--ease);
}

.navlink:hover {
  background: var(--bg-raised);
  color: var(--text-primary);
  text-decoration: none;
}
.navlink:active { background: var(--border); }
.navlink:focus-visible { box-shadow: var(--focus-ring); }

.navlink.is-active {
  background: var(--bg-raised);
  color: var(--brand-strong);
  box-shadow: var(--shadow-sm);
  font-weight: var(--fw-semibold);
}
.navlink.is-active:hover { background: var(--bg-raised); }
.navlink.is-active .ic { opacity: 1; }

.navlink .ic {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
  display: flex;
  align-items: center;
  justify-content: center;
}

.navlink.is-stub {
  opacity: 0.55;
  cursor: default;
  justify-content: space-between;
}
.navlink.is-stub:hover { background: none; color: var(--text-secondary); }
.navlink.is-stub .navlink__label {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.sidebar__footer {
  margin-top: auto;
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.sidebar__footer-name {
  font-size: var(--fs-00);
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
}

/* ---- Main content ---- */
.app-main {
  grid-area: main;
  padding: var(--sp-6);
  min-width: 0;
}

.content-frame {
  max-width: 1180px;
  margin: 0 auto;
}

/* ---- Empty state ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--sp-9) var(--sp-5);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-lg);
  min-height: 320px;
  margin-top: var(--sp-6);
}

.empty-state h3 { margin-bottom: var(--sp-2); }
.empty-state p { max-width: 36ch; }

.page-head { margin-bottom: var(--sp-6); }
.page-head h1 { margin-bottom: var(--sp-1); }
.page-head > p { margin-bottom: 0; }

.empty-state__illustration {
  width: 160px;
  height: auto;
  max-width: 60vw;
  color: var(--text-tertiary);
  margin-bottom: var(--sp-5);
}

/* ============================================================
   PREVIEW GRID — skeleton cards hinting at upcoming modules.
   Placeholder-only (Phase 1/2 rule): no real data, just a
   structured, intentional-looking "coming soon" layout instead
   of a single empty box.
   ============================================================ */
.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-4);
  margin-top: var(--sp-6);
}

.preview-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}

.preview-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}

.preview-card__title {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: var(--fw-semibold);
  font-size: var(--fs-0);
  color: var(--text-primary);
}

.preview-card__title .icon { color: var(--text-tertiary); width: 16px; height: 16px; }

.preview-card .skeleton { height: 10px; margin-bottom: var(--sp-2); }
.preview-card .skeleton:last-child { margin-bottom: 0; width: 60%; }

/* ---- Sidebar backdrop (mobile/tablet drawer) ---- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(2px);
  z-index: 29;
  opacity: 0;
  transition: opacity var(--dur-med) var(--ease);
}

/* ============================================================
   BREAKPOINT: laptop — sidebar narrows slightly, content frame
   loses its max-width ceiling comfortably.
   ============================================================ */
@media (max-width: 1280px) {
  :root { --sidebar-w: 224px; }
}

/* ============================================================
   BREAKPOINT: tablet/small-laptop — collapse to icon rail.
   ============================================================ */
@media (max-width: 1024px) and (min-width: 769px) {
  .app-shell { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }
  .sidebar__brand span:last-child,
  .sidebar__group-label,
  .navlink span:last-child,
  .sidebar__footer span { display: none; }
  .navlink { justify-content: center; }
  .sidebar__footer { justify-content: center; }
}

/* ============================================================
   BREAKPOINT: mobile/tablet-portrait — sidebar becomes an
   off-canvas drawer, opened via the navbar menu button.
   ============================================================ */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "navbar"
      "main";
  }

  .menu-btn { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: min(280px, 82vw);
    max-width: 320px;
    z-index: 30;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
  }

  .sidebar__brand span:last-child,
  .sidebar__group-label,
  .navlink span:last-child { display: inline; } /* full labels inside the drawer */
  .navlink { justify-content: flex-start; }

  /* JS toggles this on <body> when the drawer is open */
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop {
    display: block;
    opacity: 1;
  }
  body.sidebar-open { overflow: hidden; }

  .navbar { padding: 0 var(--sp-4); }
  .navbar__route { font-size: var(--fs-000); }

  .app-main { padding: var(--sp-4); }
}

@media (max-width: 480px) {
  .app-main { padding: var(--sp-4) var(--sp-3); }
  .empty-state { padding: var(--sp-7) var(--sp-4); min-height: 240px; }
  .empty-state__illustration { width: 120px; margin-bottom: var(--sp-4); }
  .navbar { height: var(--navbar-h); }
  .brand-mark { width: 22px; height: 22px; }
}
