/* ============================================================
   COMPONENT · APPNAV  (c-appnav)
   The real, shell-owned app navigation. Owns its OWN responsiveness — no more
   borrowing a wrap rule from marketing CSS via .site-console. Desktop: a
   persistent left sidebar with IA-grouped sections (engraved plaque group
   headers, warm sentence-case rows). Mobile: a fixed bottom tab bar
   (Today · Inbox · ⊕ Capture · Chat · More) + a grouped "More" sheet using the
   same intent groups, so the mental model is one model. Safe-area insets +
   dynamic viewport units are honored. No debt-count badges (B2). Two themes via
   tokens only; tap states map the mechanical press to :active, never :hover.
   ============================================================ */

/* ---- Desktop sidebar ------------------------------------------------- */
.c-appnav {
  display: none; /* mobile-first: the bottom bar is the phone nav */
  flex-direction: column;
  min-height: 0;
}

.c-appnav__scroll {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  flex: 1 1 auto;
  /* No internal clip: the rail grows to its content so every group (incl.
     Library · Journal) and Chat stay visible. The sidebar as a whole stays in
     view via sticky positioning below. */
  overflow-y: visible;
}

.c-appnav__group {
  margin: var(--space-4) 0 var(--space-1);
  padding-inline: var(--space-3);
  font-family: var(--font-plaque);
  font-size: var(--fs-3xs);
  letter-spacing: var(--ls-widest);
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.c-appnav__group:first-child { margin-top: 0; }

.c-appnav__link {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-xs);
  border-left: 2px solid transparent;
  font-family: var(--font-data);
  font-size: var(--fs-sm);
  color: var(--color-text);
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease-snap),
              color var(--dur-fast) var(--ease-snap);
}
.c-appnav__link:hover {
  background: color-mix(in srgb, var(--color-accent) 8%, transparent);
  color: var(--color-text-emphasis);
  text-shadow: none;
}
.c-appnav__link.is-active {
  background: color-mix(in srgb, var(--color-ok) 12%, transparent);
  border-left-color: var(--color-ok);
  color: var(--color-text-emphasis);
}
.c-appnav__link--settings {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  border-radius: 0;
}

/* ---- Mobile bottom tab bar ------------------------------------------- */
.c-appnav-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-overlay);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  background: color-mix(in srgb, var(--color-surface) 94%, transparent);
  border-top: var(--border-thick) solid var(--color-bezel-dark);
  box-shadow: 0 -4px 16px color-mix(in srgb, var(--shadow-color) 50%, transparent);
  backdrop-filter: blur(8px);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.c-appnav-bar__item,
.c-appnav-bar__more > summary {
  flex: 1 1 0;
  min-width: 0; /* let every tab shrink to an even share — never push siblings off-screen */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px; /* C4: thumb-reachable touch target */
  padding: var(--space-2) 2px;
  list-style: none;
  font-family: var(--font-data);
  font-size: var(--fs-3xs);
  color: var(--color-text-muted);
  text-decoration: none;
  background: none;
  border: 0;
  cursor: pointer;
}
.c-appnav-bar__more > summary::-webkit-details-marker { display: none; }
.c-appnav-bar__icon { font-size: var(--fs-md); line-height: 1; }
/* The label can never widen its tab: it shrinks and ellipsises instead of
   forcing the row past the viewport edge (the bug where ⊕/Chat/More slid off). */
.c-appnav-bar__label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: var(--ls-wide);
}

.c-appnav-bar__item.is-active { color: var(--color-ok); }
.c-appnav-bar__item:active,
.c-appnav-bar__more > summary:active { background: color-mix(in srgb, var(--color-accent) 12%, transparent); }

/* The center ⊕ — a raised mechanical key, the visually dominant control. */
.c-appnav-bar__capture {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  padding: var(--space-1);
  font-family: var(--font-data);
  font-size: var(--fs-3xs);
  letter-spacing: var(--ls-wide);
  color: var(--color-text-emphasis);
  background: none;
  border: 0;
  cursor: pointer;
}
.c-appnav-bar__capture-key {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-top: calc(-1 * var(--space-4)); /* raised above the bar */
  border-radius: 50%;
  font-size: var(--fs-xl);
  line-height: 1;
  color: var(--color-text-inverse);
  background: var(--color-ok);
  border: 2px solid var(--color-surface);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--shadow-color) 60%, transparent);
}
.c-appnav-bar__capture:active .c-appnav-bar__capture-key { transform: translateY(1px); }

/* ---- "More" sheet (grouped long tail) -------------------------------- */
/* The <details> is itself the 5th tab — give it the same even share as the
   other four so the row always divides into 5 and nothing overflows. */
.c-appnav-bar__more { flex: 1 1 0; min-width: 0; display: flex; }

/* Dims the screen behind the open sheet AND is the tap-away close target
   (data-action → details#close). Same layer as the sheet but earlier in the
   DOM, so the sheet paints over it; both sit above the bottom bar. */
.c-appnav-sheet__scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  border: 0;
  background: color-mix(in srgb, var(--shadow-color) 55%, transparent);
}
.c-appnav-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-modal);
  max-height: 80svh;
  overflow-y: auto;
  padding: var(--space-3) var(--space-4);
  padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0));
  background: var(--color-surface-raised);
  border-top: var(--border-thick) solid var(--color-bezel-dark);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  box-shadow: 0 -8px 32px color-mix(in srgb, var(--shadow-color) 60%, transparent);
}
.c-appnav-sheet__handle {
  display: block;
  width: 2.5rem;
  height: 4px;
  margin: 0 auto var(--space-3);
  border-radius: var(--radius-pill, 999px);
  background: var(--color-border);
}
/* A single readable column on a narrow phone; a second column only once the
   screen is genuinely wide enough to not feel cramped (large phones / small
   tablets, still below the --bp-md sidebar breakpoint). */
.c-appnav-sheet__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
}
@media (min-width: 28rem) { /* ~448px */
  .c-appnav-sheet__grid { grid-template-columns: 1fr 1fr; }
}
.c-appnav-sheet__link {
  display: block;
  padding: var(--space-3);
  min-height: 44px;
  border-radius: var(--radius-xs);
  background: color-mix(in srgb, var(--color-surface) 60%, transparent);
  border: 1px solid var(--color-border);
  font-family: var(--font-data);
  font-size: var(--fs-sm);
  color: var(--color-text);
  text-decoration: none;
}
.c-appnav-sheet__link.is-active {
  border-color: var(--color-ok);
  color: var(--color-text-emphasis);
}

/* ---- Desktop breakpoint: sidebar in, bottom bar out ------------------ */
@media (min-width: 45rem) { /* --bp-md (720px) */
  .c-appnav {
    display: flex;
    position: sticky;
    top: 0;
    align-self: start;
    padding: var(--space-5) var(--space-2);
  }
  .c-appnav-bar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .c-appnav__link,
  .c-appbar__menu-caret { transition: none; }
}
