/* =============================================================================
   Layout — the app shell.

   Desktop (>=900px): a fixed navigation rail on the inline-start side (which
   is the RIGHT edge in this RTL document — all offsets use logical
   properties, so the same rules would mirror correctly for an LTR locale).
   Mobile: the rail collapses into a bottom tab bar with safe-area padding.
   ========================================================================== */

.app-shell { min-height: 100dvh; }

/* --- Top bar -------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  /* Landscape on a notched phone puts the cutout in a side gutter, so the
     safe-area insets are honoured rather than assumed to be zero. These are
     physical on purpose — the notch does not mirror with text direction. */
  padding-left: max(var(--space-4), env(safe-area-inset-left));
  padding-right: max(var(--space-4), env(safe-area-inset-right));
  background: var(--surface-glass);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  min-height: 44px;
  color: var(--text);
  font-weight: 800;
  letter-spacing: -0.01em;
}
.topbar__brand:hover { color: var(--text); }
.topbar__logo {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  color: #fff;
  background: linear-gradient(140deg, var(--brand-500), var(--brand-400) 45%, var(--teal-500));
  box-shadow: var(--shadow-brand);
}
.topbar__title { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.topbar__title span { white-space: nowrap; }
.topbar__title small { font-size: var(--fs-xs); font-weight: 500; color: var(--text-subtle); white-space: nowrap; }

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-inline-start: auto;
  min-width: 0;
}

/* On a phone the bar has to hold brand + identity + theme + logout. Things
   are dropped in order of redundancy: first the tagline, then the account
   name (the avatar monogram still identifies it), then the wordmark (the
   logo still identifies the app) — so the row never has to compress.
   The selectors are scoped to `.topbar` on purpose: the login screen reuses
   the same brand markup in a roomy card, where nothing needs to drop. */
@media (max-width: 620px) {
  .topbar { padding-inline: var(--space-3); gap: var(--space-2); }
  .topbar .topbar__title small { display: none; }
  .topbar__actions .chip span.truncate { display: none; }
  .topbar__actions .chip { padding: 3px; border-radius: var(--r-full); }
}
@media (max-width: 400px) {
  .topbar .topbar__title { display: none; }
}

/* --- Navigation rail (desktop) -------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  max-width: var(--shell-max);
  margin-inline: auto;
  padding-left: max(var(--space-4), env(safe-area-inset-left));
  padding-right: max(var(--space-4), env(safe-area-inset-right));
}
@media (max-width: 380px) {
  .layout { padding-inline: var(--space-3); }
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    gap: var(--space-8);
    align-items: start;
  }
}

/* Chrome-free screens (login) supply their own header and want the whole
   viewport, so the shell's gutters and rail column step out of the way. */
.layout--bare {
  grid-template-columns: 1fr;
  max-width: none;
  padding-inline: 0;
}
.layout--bare > .main { padding-block: 0; }

.rail {
  display: none;
  position: sticky;
  top: calc(var(--topbar-h) + var(--space-5));
  padding-block: var(--space-5);
}
@media (min-width: 900px) { .rail { display: block; } }

.rail__group + .rail__group { margin-top: var(--space-6); }
.rail__label {
  padding-inline: var(--space-3);
  margin-bottom: var(--space-2);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-subtle);
}

.rail__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-weight: 600;
  font-size: var(--fs-sm);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.rail__link:hover { background: var(--surface-3); color: var(--text); }
.rail__link[aria-current="page"] {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
}
.rail__link[aria-current="page"]::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  inset-block: 22%;
  width: 3px;
  border-radius: var(--r-full);
  background: var(--primary);
}
.rail__link .icon { flex: 0 0 auto; opacity: 0.9; }
.rail__badge {
  margin-inline-start: auto;
  min-width: 20px;
  padding-inline: 6px;
  text-align: center;
  font-size: var(--fs-xs);
  font-weight: 700;
  border-radius: var(--r-full);
  background: var(--danger);
  color: var(--text-on-danger);
}

/* --- Main ----------------------------------------------------------------- */
.main {
  min-width: 0;
  padding-block: var(--space-6) calc(var(--tabbar-h) + var(--space-10));
}
@media (min-width: 900px) {
  .main { padding-block: var(--space-8) var(--space-16); }
}
/* The outlet's tabindex="-1" is a focus-parking target, not a control: the
   router moves focus here after navigation so screen readers announce the new
   page. It must never paint the global focus ring — on first load no pointer
   interaction has happened yet, so browsers count that programmatic focus as
   keyboard-initiated and would frame the entire content area until the first
   click or blur. */
.main:focus-visible { outline: none; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}
.page-head__title { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 12rem; }
.page-head__title h1 { letter-spacing: -0.02em; }
.page-head__title p { color: var(--text-muted); font-size: var(--fs-sm); }
.page-head__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* Wrapped actions sit under the title on a phone; stretching them to the full
   width turns two half-buttons into two comfortable ones. */
@media (max-width: 560px) {
  .page-head { gap: var(--space-3); margin-bottom: var(--space-5); }
  .page-head__actions { width: 100%; }
  .page-head__actions > .btn { flex: 1 1 auto; }
}

/* Reusable responsive grids. */
.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); }

.split {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 1020px) {
  .split { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
}

/* --- Bottom tab bar (mobile) ---------------------------------------------- */
.tabbar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 45;
  display: grid;
  grid-auto-flow: column;
  /* `minmax(0, 1fr)` rather than `1fr`: a plain 1fr track refuses to shrink
     below its content's min-content width, so one long label used to push the
     whole bar off the side of the screen. */
  grid-auto-columns: minmax(0, 1fr);
  gap: 2px;
  padding-block: var(--space-2) calc(var(--space-2) + env(safe-area-inset-bottom));
  padding-left: max(var(--space-2), env(safe-area-inset-left));
  padding-right: max(var(--space-2), env(safe-area-inset-right));
  background: var(--surface-glass);
  backdrop-filter: saturate(1.6) blur(16px);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--border);
}
@media (min-width: 900px) { .tabbar { display: none; } }

.tabbar__link {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 3px;
  min-width: 0;
  min-height: 50px;
  padding: var(--space-2) 2px;
  border-radius: var(--r-md);
  color: var(--text-subtle);
  font-size: 0.68rem;
  font-weight: 600;
  transition: color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.tabbar__link[aria-current="page"] { color: var(--primary); background: var(--primary-soft); }
.tabbar__link:active { background: var(--surface-3); }
.tabbar__link span {
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Navigation count badge ------------------------------------------------ */
/*
 * The pending-approvals number on a nav item. Two shapes for the two navs:
 * a pill that sits at the end of the desktop rail row, and a small disc pinned
 * to the icon in the mobile tab bar, where there is no room for a pill.
 */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  margin-inline-start: auto;
  padding-inline: 0.4rem;
  border-radius: var(--r-full);
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  flex: 0 0 auto;
}
.rail__link[aria-current="page"] .nav-badge { background: var(--danger); }

.tabbar__icon {
  position: relative;
  display: inline-flex;
}
/*
 * Pinned to the icon's top-inline-start corner. `inset-inline` keeps it on the
 * correct side when the document flips direction, and the ring blends it into
 * whatever the tab bar's background currently is.
 */
.nav-badge--dot {
  position: absolute;
  inset-block-start: -6px;
  inset-inline-start: -8px;
  min-width: 1.15rem;
  height: 1.15rem;
  margin-inline-start: 0;
  padding-inline: 0.3rem;
  font-size: 0.62rem;
  box-shadow: 0 0 0 2px var(--surface);
}
.tabbar__link[aria-current="page"] .nav-badge--dot { box-shadow: 0 0 0 2px var(--primary-soft); }

/* --- Public / marketing shell --------------------------------------------- */
.public-main {
  max-width: var(--shell-max);
  margin-inline: auto;
  padding-block: var(--space-8) var(--space-16);
}
@media (max-width: 640px) {
  .public-main { padding-block: var(--space-5) var(--space-10); }
}

.hero {
  display: grid;
  gap: var(--space-8);
  align-items: center;
  padding-block: var(--space-8);
}
@media (min-width: 940px) {
  .hero { grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr); }
}
.hero h1 {
  font-size: var(--fs-display);
  letter-spacing: -0.03em;
  font-weight: 800;
}
.hero__lead { font-size: 1.05rem; color: var(--text-muted); max-width: 34rem; }
.hero__cta { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-2); }

.hero__art {
  position: relative;
  min-height: clamp(15rem, 46vw, 22rem);
  border-radius: var(--r-2xl);
  background:
    radial-gradient(28rem 20rem at 20% 15%, var(--bg-tint-1), transparent 70%),
    linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: var(--space-6);
}

.footer {
  border-top: 1px solid var(--divider);
  margin-top: var(--space-12);
  padding-block: var(--space-6);
  color: var(--text-subtle);
  font-size: var(--fs-sm);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  justify-content: space-between;
}

/* --- Centered auth / focus layout ------------------------------------------ */
.focus-layout {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--space-5) max(var(--space-4), env(safe-area-inset-right)) calc(var(--space-5) + env(safe-area-inset-bottom)) max(var(--space-4), env(safe-area-inset-left));
}
/* Short viewports (a phone in landscape, or the keyboard taking half the
   screen) should scroll from the top rather than centre a card that no
   longer fits. */
@media (max-height: 620px) {
  .focus-layout { align-items: start; padding-block: var(--space-5); }
}
.focus-card {
  width: min(100%, 27rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-8) var(--space-6);
}
@media (max-width: 400px) {
  .focus-card { padding: var(--space-6) var(--space-4); }
}
