/* App shell: header, tab bar, page containers and shared page patterns. */
.container {
  width: min(100% - 2 * var(--gutter), 72rem);
  margin-inline: auto;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.app-header__inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: var(--header-h);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  margin-right: auto;
  font: 600 1.25rem/1 var(--font-display);
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand__mark {
  display: grid;
  place-items: center;
  width: 1.875rem;
  height: 1.875rem;
  border-radius: 0.5rem;
  background: var(--accent);
  color: var(--accent-contrast);
}

.nav {
  display: none;
  align-items: center;
  gap: 0.25rem;
}
.nav__link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-full);
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
  transition:
    background-color 0.15s,
    color 0.15s;
}
.nav__link:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav__link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--border);
}
.tabbar__link {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.125rem;
  min-height: var(--tabbar-h);
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 500;
  text-decoration: none;
}
.tabbar__link[aria-current="page"] {
  color: var(--accent);
}

main {
  outline: none;
}
.page {
  animation: page-in 0.3s var(--ease);
}
@keyframes page-in {
  from {
    opacity: 0;
  }
}
.page__inner {
  display: grid;
  gap: clamp(1.5rem, 4vw, 2.25rem);
  padding-top: 2rem;
  padding-bottom: 6.5rem;
}
@media screen and (min-width: 700px) {
  .page__inner {
    padding-bottom: 0;
  }
}
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header__title {
  font: 600 clamp(1.75rem, 5vw, 2.5rem)/1.1 var(--font-display);
  letter-spacing: -0.02em;
}
.page-header__sub {
  margin-top: 0.375rem;
  color: var(--muted);
  max-width: 38rem;
}
.page-header__actions {
  display: flex;
  gap: 0.5rem;
}

.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.section__title {
  font: 600 1.125rem/1.3 var(--font-display);
  letter-spacing: -0.01em;
}

.dashboard {
  display: grid;
  gap: 1.5rem;
  align-items: start;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
  margin-bottom: 1.25rem;
}
.search {
  position: relative;
  flex: 1 1 14rem;
  min-width: 0;
}
.search .icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.field__input--search {
  padding-left: 2.5rem;
}
.toolbar .field__select {
  flex: 0 1 11rem;
  width: auto;
  min-width: 9rem;
}

.reader-loading {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.75rem;
  min-height: 100dvh;
  color: var(--muted);
}

/* ---------- Drawer (mobile secondary nav) ---------- */
.drawer__trigger {
  /* Shown only on mobile; hidden once the top nav appears */
  display: inline-flex;
  align-items: center;
}

.drawer {
  /* Position as a left-side panel; fill full height */
  position: fixed;
  inset: 0 auto 0 0;
  width: min(80vw, 18rem);
  max-width: 100%;
  max-height: none;
  height: 100dvh;
  margin: 0;
  padding: 0;
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.drawer[open] {
  display: flex;
  flex-direction: column;
  animation: drawer-in 0.25s var(--ease);
}
.drawer::backdrop {
  background: rgb(8 10 12 / 0.5);
  backdrop-filter: blur(2px);
}
@keyframes drawer-in {
  from {
    opacity: 0;
    transform: translateX(-1.5rem);
  }
}
.drawer__inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.75rem 0.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
  min-height: var(--header-h);
}
.drawer__title {
  font: 600 1rem/1 var(--font-display);
}
.drawer__nav {
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  gap: 0.25rem;
}
.drawer__link {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
  transition:
    background-color 0.15s,
    color 0.15s;
}
.drawer__link:hover {
  background: var(--surface-2);
}
.drawer__link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Footer — desktop only; drawer covers the links on mobile */
.app-footer {
  display: none;
  border-top: 1px solid var(--border);
  padding-block: 1.5rem;
  margin-top: auto;
}
.app-footer__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.app-footer__copy {
  font-size: 0.8125rem;
  color: var(--muted);
}
.app-footer__nav {
  display: flex;
  gap: 1.25rem;
}
.app-footer__link {
  font-size: 0.8125rem;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s;
}
.app-footer__link:hover {
  color: var(--text);
  text-decoration: underline;
}

@media (min-width: 48rem) {
  .drawer__trigger {
    display: none; /* top nav visible — no need for drawer */
  }
  .nav {
    display: flex;
  }
  .tabbar {
    display: none;
  }
  main {
    padding-bottom: 3rem;
  }
  .app-footer {
    display: block; /* revealed on desktop; drawer handles mobile */
  }
}
@media (min-width: 60rem) {
  .dashboard {
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    gap: 1.5rem;
  }
}

/* The reader is full-screen: hide the app shell. */
body[data-route="reader"] .app-header,
body[data-route="reader"] .tabbar,
body[data-route="reader"] .app-footer {
  display: none;
}
body[data-route="reader"] main {
  padding: 0;
  min-height: 0;
}
