/* App shell: sidebar navigation (drawer on phones) and the main reading column. */

.app {
  display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100dvh;
  /* the sidebar colour runs the full height of long pages, under the sticky sidebar */
  background: linear-gradient(to right, var(--bg-side) calc(var(--side-w) - 1px), var(--line) 0 var(--side-w), transparent 0);
}

/* ---------- brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 1.1875rem; letter-spacing: -0.005em; color: var(--text); white-space: nowrap; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: var(--brg); color: var(--ivory); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 1px 2px rgba(0, 48, 27, 0.3);
}
.brand-mark .ic { width: 15px; height: 15px; stroke-width: 2; transform: translate(-0.5px, 0.5px); }
.brand.on-dark { color: var(--ivory); }
.brand.on-dark .brand-mark { background: var(--ivory); color: var(--brg); }

/* ---------- sidebar ---------- */
.side {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 6px; min-width: 0;
  background: var(--bg-side); border-right: 1px solid var(--line); padding: 14px 12px 12px;
}
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 10px; }
.side-close { display: none; }
.side-scroll { flex: 1 1 auto; min-height: 0; margin: 0 -12px; padding: 4px 12px 12px; display: grid; gap: 14px; align-content: start; }
.nav-group { display: grid; gap: 1px; }
.nav-title { padding: 8px 10px 6px; font-size: 0.75rem; font-weight: 600; color: var(--text-3); }

.nav-new {
  appearance: none; display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0 12px; margin-bottom: 6px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 0.875rem; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: background-color var(--t-fast) ease, border-color var(--t-fast) ease, transform 90ms ease-out;
}
.nav-new:hover { border-color: color-mix(in srgb, var(--accent-text) 45%, var(--line-strong)); }
.nav-new:active { transform: scale(0.99); }
.nav-new .ic { color: var(--accent-text); }

.nav-item {
  appearance: none; position: relative; display: flex; align-items: center; gap: 10px; width: 100%; min-height: 36px; padding: 0 10px;
  min-width: 0; border: 0; border-radius: 10px; background: transparent; color: var(--text); text-align: left; cursor: pointer;
  font-size: 0.875rem; font-weight: 450; line-height: 1.25;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
}
.nav-item > .ic { color: var(--text-2); }
.nav-item:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.nav-item[aria-current="page"] > .ic { color: var(--accent-text); }
.nav-item[aria-current="page"]::before {
  content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent-text);
}
.nav-item .pglyph { --pg: 22px; border-radius: 7px; }
.nav-extra { display: inline-flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 0.75rem; font-weight: 550; padding-right: 2px; }
.nav-item[aria-current="page"] .nav-extra { color: var(--text-2); }
.nav-item.add { color: var(--accent-text); font-weight: 550; margin-top: 4px; }
.add-ic { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; border: 1px dashed color-mix(in srgb, var(--accent-text) 55%, transparent); }

.side-foot { display: grid; gap: 0; padding-top: 8px; border-top: 1px solid var(--line); }
.side-foot .nav-item { min-height: 34px; color: var(--text-2); }
.side-foot .nav-item:hover, .side-foot .nav-item[aria-current="page"] { color: var(--text); }
.side-foot-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; padding: 4px 0 0 10px; }
.side-out { margin-right: -2px; color: var(--text-2); }

.theme-pick { display: inline-flex; align-items: center; gap: 10px; }
.theme-label { font-size: 0.8125rem; color: var(--text-2); }
.theme-switch { display: inline-flex; gap: 2px; padding: 2px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.theme-switch button {
  appearance: none; display: grid; place-items: center; width: 30px; height: 26px; border: 0; border-radius: 999px;
  background: transparent; color: var(--text-3); cursor: pointer; transition: background-color var(--t-fast) ease, color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}
.theme-switch button:hover { color: var(--text); }
.theme-switch button:focus-visible { outline-offset: 0; border-radius: 999px; }
.theme-switch button[aria-checked="true"] { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line-strong); }

/* ---------- content column ---------- */
.content { min-width: 0; display: flex; flex-direction: column; }
.mtop { display: none; }
.main { width: 100%; max-width: 920px; margin: 0 auto; padding: 44px clamp(20px, 4vw, 48px) 96px; outline: none; }
.page { display: grid; grid-template-columns: minmax(0, 1fr); gap: 36px; align-content: start; }
.page > * { min-width: 0; }
.page > section { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

/* ---------- phones and narrow windows: sidebar becomes a drawer ---------- */
.drawer-scrim { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); background: none; }
  .side {
    position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto; width: min(320px, 86vw);
    transform: translateX(-102%); transition: transform var(--t-slow) var(--ease-out); box-shadow: none;
    padding-top: calc(14px + env(safe-area-inset-top)); padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .drawer-open .side { transform: none; box-shadow: var(--shadow-lg); }
  .side-close { display: inline-flex; }
  .drawer-scrim { display: block; position: fixed; inset: 0; z-index: 45; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity var(--t) ease; }
  .drawer-open .drawer-scrim { opacity: 1; pointer-events: auto; }
  .mtop {
    position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 6px;
    min-height: 56px; padding: env(safe-area-inset-top) 8px 0;
    background: color-mix(in srgb, var(--bg) 86%, transparent); border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%);
  }
  .mtop-title { font-weight: 600; font-size: 0.9375rem; text-align: center; opacity: 0; transform: translateY(3px); transition: opacity var(--t) ease, transform var(--t) var(--ease-out); }
  .mtop.titled .mtop-title { opacity: 1; transform: none; }
  .mtop:not(.titled) { border-bottom-color: transparent; background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .mtop-spacer { width: 36px; flex: none; }
  .main { padding: 24px 16px 80px; }
  .page { gap: 28px; }
}
@media (prefers-reduced-transparency: reduce) {
  .mtop { background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
