/* ==========================================================================
   Layout: app shell (sidebar, phone top bar + tab bar, footer) and
   composition primitives. Mobile first. Breakpoints: 40rem small,
   48rem sidebar appears, 64rem large.
   ========================================================================== */

/* ---- App shell --------------------------------------------------------- */

.app {
  --sidebar-width: 16rem;
  --sidebar-rail: 4.5rem;
  --tabbar-height: 4.25rem;
  --topbar-height: 3.5rem;

  min-height: 100vh;
  min-height: 100dvh;
}

.app__body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  /* Leave room for the fixed tab bar on phones. */
  padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
}

.app__main {
  flex: 1;
  padding-block: var(--space-6) var(--space-8);
}

.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.container--narrow {
  max-width: calc(var(--container-narrow) + 2 * var(--gutter));
}

/* ---- Brand ------------------------------------------------------------- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text);
  font-weight: var(--weight-bold);
  font-size: var(--text-lg);
  letter-spacing: -0.02em;
  text-decoration: none;
  white-space: nowrap;
}

.brand--inverse {
  color: var(--color-on-brand);
  --brand-mark-tick: var(--color-primary);
}

.brand--inverse .brand__mark {
  color: var(--color-on-brand);
}

.brand__mark {
  width: 1.75rem;
  height: 1.75rem;
  flex: none;
  color: var(--color-primary);
}

/* ---- Avatar ------------------------------------------------------------ */

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--color-primary-subtle);
  color: var(--color-primary-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  text-decoration: none;
}

/* ---- Phone top bar ----------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--topbar-height);
  padding: var(--space-2) var(--gutter);
  border-bottom: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
}

/* ---- Phone tab bar ----------------------------------------------------- */

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  padding: var(--space-1) var(--space-1) calc(var(--space-1) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.tabbar__link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 3.5rem;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-decoration: none;
}

.tabbar__link.active {
  color: var(--color-primary-text);
  font-weight: var(--weight-bold);
}

.tabbar__link:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ---- Sidebar (48rem and up) ------------------------------------------ */

.sidebar {
  display: none;
}

@media (min-width: 48rem) {
  .tabbar,
  .topbar__brand {
    display: none;
  }

  .topbar {
    justify-content: flex-end;
    padding-inline: var(--space-6);
  }

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

  .app--collapsed {
    grid-template-columns: var(--sidebar-rail) minmax(0, 1fr);
  }

  .app__body {
    padding-bottom: 0;
  }

  .sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    height: 100vh;
    height: 100dvh;
    padding: var(--space-4) var(--space-3);
    overflow-y: auto;
    border-right: 1px solid var(--color-border);
    background: var(--color-surface);
  }
}

.sidebar__brand {
  padding: var(--space-1) var(--space-2) var(--space-2);
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.sidebar__section {
  padding: var(--space-4) var(--space-3) var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sidebar__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: auto;
  padding: var(--space-3) var(--space-1) 0;
  border-top: 1px solid var(--color-border);
}

/* Collapsed: icon rail. Labels hide; icons centre; tooltips come from title attributes. */
.app--collapsed .sidebar {
  padding-inline: var(--space-2);
}

.app--collapsed .sidebar .nav-link__label,
.app--collapsed .sidebar .nav-link__soon,
.app--collapsed .sidebar__section,
.app--collapsed .sidebar__theme {
  display: none;
}

.app--collapsed .sidebar__foot {
  justify-content: center;
}

.app--collapsed .sidebar .nav-link,
.app--collapsed .sidebar__brand {
  justify-content: center;
  padding-inline: 0;
}

/* ---- Navigation links (sidebar and /menu page) ------------------------ */

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0;
  list-style: none;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 2.5rem;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.nav-link:hover {
  background: var(--color-surface-sunken);
}

.nav-link.active {
  background: var(--color-primary-subtle);
  color: var(--color-primary-text);
  font-weight: var(--weight-semibold);
}

.nav-link:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.nav-link .icon {
  flex: none;
}

.nav-link__label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-link--primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.nav-link--primary:hover {
  background: var(--color-primary-hover);
}

.nav-link--soon {
  color: var(--color-text-muted);
  cursor: default;
}

.nav-link--soon:hover {
  background: none;
}

.nav-link__soon {
  margin-left: auto;
  padding: 0 var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-surface-sunken);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}

.menu-page__section {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---- Footer ------------------------------------------------------------ */

.site-footer {
  border-top: 1px solid var(--color-border);
  padding-block: var(--space-5);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-6);
  justify-content: space-between;
}

/* ---- Composition primitives ------------------------------------------ */

/* Vertical rhythm: children spaced evenly. Modifiers change the gap. */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.stack--sm { gap: var(--space-2); }
.stack--lg { gap: var(--space-6); }

/* Horizontal group that wraps: buttons, badges, inline actions. */
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

/* Responsive columns: as many as fit, each at least --grid-min wide. */
.grid {
  --grid-min: 18rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(var(--grid-min), 100%), 1fr));
  gap: var(--space-6);
}

/* Sidebar + content (e.g. account settings). Stacks on small screens. */
.with-sidebar {
  display: grid;
  gap: var(--space-6);
}

@media (min-width: 48rem) {
  .with-sidebar {
    grid-template-columns: 14rem 1fr;
    align-items: start;
  }
}

.site-footer__note {
  max-width: 36rem;
}

/* Form-width columns (e.g. account pages: form + side panel). Each column is
   capped so single forms don't stretch across wide screens. */
.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(18rem, 100%), 28rem));
  gap: var(--space-7);
  align-items: start;
}

/* ---- Auth pages (split screen) ----------------------------------------- */

.auth {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
}

.auth__brand {
  display: none;
}

.auth__main {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-4) var(--gutter) var(--space-5);
  background: var(--color-bg);
}

.auth__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.auth__top .theme-switch {
  margin-left: auto;
}

.auth__content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth__content > * {
  width: 100%;
  max-width: 26rem;
}

.auth__footer {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

@media (min-width: 64rem) {
  .auth {
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  }

  .auth__brand {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: var(--space-7);
    height: 100vh;
    height: 100dvh;
    padding: var(--space-7) var(--space-8);
    background: var(--brand-gradient);
    color: var(--color-on-brand);
  }

  .auth__mobile-brand {
    display: none;
  }

  .auth__main {
    padding: var(--space-5) var(--space-7);
  }
}

.auth__pitch {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  max-width: 28rem;
}

.auth__headline {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.auth__benefits {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: 0;
  list-style: none;
  font-size: var(--text-lg);
}

.auth__benefits li {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
}

.auth__benefits svg {
  flex: none;
  margin-top: 0.2rem;
  opacity: 0.9;
}

.auth__note {
  max-width: 28rem;
  font-size: var(--text-sm);
  opacity: 0.85;
}
