.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }

/* ---- sidebar: the book spine ---- */
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px;
  padding: 20px 14px 16px; border-right: 1px solid var(--rule); background: linear-gradient(180deg, var(--paper-deep), var(--paper) 70%);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 18px; color: var(--ink); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-seal {
  width: 38px; height: 38px; border-radius: 6px; display: grid; place-items: center; background: var(--vermilion);
  color: #fff7ee; font: 700 15px/1 var(--font-display); letter-spacing: .02em; box-shadow: inset 0 0 0 2px rgba(255, 240, 228, .35), 0 6px 14px -8px rgba(192, 67, 46, .8);
  transform: rotate(-3deg); writing-mode: vertical-rl;
}
.brand-name { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name strong { font: 700 18px/1.2 var(--font-display); letter-spacing: .12em; }
.brand-name small { font-size: 10.5px; letter-spacing: .22em; color: var(--ink-3); margin-top: 3px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { margin: 14px 10px 6px; }
.nav a {
  position: relative; display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 8px; color: var(--ink-2);
  font-size: var(--text-base); text-decoration: none; transition: background var(--duration-fast), color var(--duration-fast);
}
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: rgba(28, 34, 31, .045); color: var(--ink); }
.nav a.active { background: var(--sheet-raised); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-paper); }
.nav a.active::before {
  content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 4px; border-radius: 0 4px 4px 0; background: var(--rose);
}
.nav a .badge { margin-left: auto; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 999px; background: var(--rose); color: #fff; font-size: 11px; font-weight: 600; display: grid; place-items: center; }
.nav a .badge.quiet { background: var(--paper-deep); color: var(--ink-3); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 12px; border-top: 1px solid var(--rule-soft); }
.role-switch { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 999px; background: var(--paper-deep); border: 1px solid var(--rule-soft); }
.role-switch button { border: 0; background: transparent; border-radius: 999px; padding: 6px 0; font-size: var(--text-xs); color: var(--ink-3); cursor: pointer; }
.role-switch button[aria-pressed="true"] { background: var(--sheet-raised); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-paper); }
.ai-status { display: flex; align-items: center; gap: 8px; padding: 0 8px; font-size: 11.5px; color: var(--ink-3); }
.ai-status .dot { background: var(--celadon); box-shadow: 0 0 0 3px rgba(85, 122, 104, .18); }
.ai-status.off .dot { background: var(--ink-4); box-shadow: none; }
.ai-status.warn .dot { background: var(--ochre); box-shadow: 0 0 0 3px rgba(176, 130, 58, .2); }

/* ---- main ---- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 14px 32px;
  background: rgba(243, 238, 228, .86); backdrop-filter: blur(10px); border-bottom: 1px solid transparent; transition: border-color var(--duration);
}
.topbar.scrolled { border-bottom-color: var(--rule-soft); }
.topbar .crumb { display: flex; flex-direction: column; min-width: 0; }
.topbar .crumb h1 { font-size: 22px; line-height: 1.3; }
.page { padding: 8px 32px 56px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; gap: 18px; margin: 10px 0 22px; flex-wrap: wrap; }
.page-head .lede { max-width: 640px; color: var(--ink-2); margin-top: 6px; }
.page-head .spacer { flex: 1; }

@media (max-width: 1080px) {
  :root { --sidebar: 76px; }
  .brand-name, .nav-label, .nav a span, .nav a .badge, .role-switch, .ai-status span { display: none; }
  .nav a { justify-content: center; }
  .brand { justify-content: center; padding-bottom: 12px; }
  .page, .topbar { padding-left: 22px; padding-right: 22px; }
}
@media (max-width: 680px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 30; flex-direction: row; padding: 6px 8px;
    border-right: 0; border-top: 1px solid var(--rule); background: var(--sheet);
  }
  .brand, .sidebar-foot, .nav-label { display: none; }
  .nav { flex-direction: row; justify-content: space-around; width: 100%; }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 10px; }
  .nav a span { display: inline; }
  .nav a svg { width: 20px; height: 20px; }
  .nav a.active::before { display: none; }
  .page { padding: 4px 16px 96px; }
  .topbar { padding: 12px 16px; }
}
