/* ==========================================================================
   Layout: the two frames every page sits in.

   1. Public    header, menu sheet, the focus column, footer
   2. App       sidebar, top bar, main column and rail, bottom tab bar

   Breakpoints (a media query cannot read a token, so they are written here;
   these are every width any sheet uses, and a guard holds them to this list):
     359px   the narrowest phones (320px): the public header's brand gives way first
     600px   the acting band says its short sentence
     720px   phone: one column, 16px gutter
     900px   the public menu becomes a bottom sheet; the heatmap drops crowded month names
    1100px   the columns stack: the app sidebar becomes a bottom sheet and the tab
             bar appears; the footer and the landing's two-column sections stack
    1180px   the app rail drops under the main column
    1420px   below this, with the sidebar and the rail beside it, the heatmap is crowded
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Public
   -------------------------------------------------------------------------- */
.public-body {
  display: flex;
  flex-direction: column;
  min-block-size: 100vh;
  min-block-size: 100dvh;
}
.public-body > main {
  flex: 1;
}

.site-header {
  position: sticky;
  inset-block-start: 0;
  z-index: var(--z-header);
  border-block-end: var(--line) solid var(--hairline);
}
/* the blur sits on a pseudo-element, so the header does not become the
   containing block of its own fixed menu sheet */
.site-header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: var(--z-under);
  background: var(--bar);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
.site-header__in {
  display: flex;
  align-items: center;
  gap: var(--sp-8);
  min-block-size: var(--header-h);
}
.site-nav__list {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}
.site-nav__link {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--control-h-sm);
  padding-inline: var(--sp-3);
  border-radius: var(--r-full);
  color: var(--text-2);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  line-height: var(--lh-control);
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.site-nav__link:hover,
.site-nav__link[aria-current="page"] {
  background: var(--surface-2);
  color: var(--text);
}
.site-nav__link .icon,
.site-nav__login {
  display: none;
}
.site-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-inline-start: auto;
}
.nav-toggle {
  display: none;
}

@media (min-width: 901px) {
  .site-nav {
    margin-inline-end: auto;
  }
  .site-nav + .site-actions {
    margin-inline-start: 0;
  }
}

/* Focus: one thing to read or do, centred under the white light.
   Sign-in, "coming" and error pages. */
.focus {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: start;
  min-block-size: 100%;
  padding-block: var(--sp-16) var(--sp-20);
  padding-inline: var(--gutter);
  background: var(--haze-focus) no-repeat;
  isolation: isolate;
  overflow: clip;
}
/* faint dot texture, fading out */
.focus::after {
  content: "";
  position: absolute;
  z-index: var(--z-under);
  inset: 0;
  background-image: var(--dots);
  background-size: var(--dot-grid) var(--dot-grid);
  -webkit-mask-image: var(--dots-fade);
  mask-image: var(--dots-fade);
  pointer-events: none;
}
.focus__inner {
  inline-size: min(100%, var(--form-w));
}
.focus__inner--wide {
  inline-size: min(100%, var(--prose-w));
}
/* a hall's screen: the whole width, the code sized by the screen itself, and
   the page held to one screen's height */
.focus--screen {
  padding-block: var(--sp-6);
}
.focus__inner--screen {
  inline-size: 100%;
}
.focus__notice {
  display: grid;
  justify-items: center;
  gap: var(--sp-4);
  padding-block-start: var(--sp-8);
  text-align: center;
}
.focus__notice > .grouped-list,
.focus__notice > .note,
.focus__notice > .card {
  justify-self: stretch;
  text-align: start;
}
/* The step count of onboarding sits at the start of its panel, its own width */
.welcome-step__count {
  justify-self: start;
}
.focus__title {
  font-size: var(--fs-title);
  line-height: var(--lh-heading);
}
.focus__lead {
  max-inline-size: var(--measure);
  color: var(--text-2);
  font-size: var(--fs-lg-plus);
}
.focus__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-3);
  margin-block-start: var(--sp-4);
}
/* The form card of a focus page */
.focus__card {
  padding: var(--sp-8);
}
.focus__card .focus__title {
  font-size: var(--fs-3xl);
}
.focus__card .focus__lead {
  margin-block-start: var(--sp-2);
  font-size: var(--fs-base);
}
.focus__form {
  margin-block-start: var(--sp-6);
}
.focus__links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2) var(--sp-4);
  margin-block-start: var(--sp-5);
  padding-block-start: var(--sp-5);
  border-block-start: var(--line) solid var(--hairline);
  font-size: var(--fs-md);
}
.focus__links .link {
  min-block-size: var(--tap);
}

/* Footer */
.site-footer {
  padding-block: var(--sp-16) 0;
  border-block-start: var(--line) solid var(--hairline);
  background: linear-gradient(to bottom, var(--surface-1), transparent 60%);
}
.site-footer__grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 4fr);
  gap: var(--sp-8);
}
.site-footer__brand p {
  margin-block-start: var(--sp-3);
  max-inline-size: var(--measure-sm);
  color: var(--text-muted);
  font-size: var(--fs-base);
  text-wrap: balance;
}
.site-footer__title {
  color: var(--text);
  font-size: var(--fs-md);
}
.site-footer__groups {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--sp-6) var(--sp-8);
}
.site-footer__links {
  display: grid;
  gap: var(--sp-half);
  margin-block-start: var(--sp-2);
}
.site-footer__links a {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--link-h);
  border-radius: var(--r-xs);
  color: var(--text-muted);
  font-size: var(--fs-base);
  transition: color var(--dur) var(--ease);
}
.site-footer__links a:hover {
  color: var(--text);
}
.site-footer__bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-4);
  margin-block-start: var(--sp-12);
  padding-block: var(--sp-5) var(--sp-16);
  border-block-start: var(--line) solid var(--hairline);
  color: var(--text-muted);
  font-size: var(--fs-md);
}
.site-footer__free {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text);
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
}
.site-footer__free .icon {
  color: var(--accent);
}
/* The one-line footer of a focus page */
.site-footer.site-footer--slim {
  padding-block: 0;
  background: none;
}
.site-footer--slim .site-footer__bottom {
  margin-block-start: 0;
  padding-block: var(--sp-5);
  border-block-start: 0;
}

@media (max-width: 1100px) {
  /* touch: the links of the header and the footer are 44px tall, and a
     one-word footer link is as wide as it is tall */
  .site-nav__link,
  .site-footer__links a {
    min-block-size: var(--tap);
  }
  /* a name in a row or a header is a finger's height, not its text's */
  .name-link {
    display: inline-flex;
    align-items: center;
    min-block-size: var(--tap);
  }
  .site-footer__links a {
    min-inline-size: var(--tap);
  }
}

@media (max-width: 1100px) {
  .site-footer__grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .site-footer__groups {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .site-header__in {
    gap: var(--sp-3);
    min-block-size: var(--header-h-narrow);
  }
  .site-login {
    display: none;
  }
  .nav-toggle {
    display: inline-grid;
    inline-size: var(--tap);
    block-size: var(--tap);
  }

  /* While the menu sheet is open the header rises above the backdrop and
     dims itself, so the scrim reads as one layer */
  .sheet-open .site-header {
    z-index: var(--z-header-over-scrim);
  }
  .sheet-open .site-header::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--scrim);
    pointer-events: none;
  }

  /* The public menu is a bottom sheet (.sheet--until-medium): its links
     become the rows of a grouped list */
  .site-nav__list {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    border: var(--line) solid var(--hairline);
    border-radius: var(--r-lg);
    background: var(--surface-1);
    overflow: hidden;
  }
  .site-nav__list li + li {
    border-block-start: var(--line) solid var(--hairline);
  }
  .site-nav__link {
    display: flex;
    gap: var(--sp-3);
    min-block-size: var(--control-h-lg);
    padding-inline: var(--sp-4);
    border-radius: 0;
    color: var(--text);
    font-size: var(--fs-lg);
  }
  .site-nav__link .icon {
    display: block;
    color: var(--text-muted);
  }
  .site-nav__link .site-nav__chevron {
    margin-inline-start: auto;
    inline-size: var(--icon-xs);
    block-size: var(--icon-xs);
    color: var(--text-faint);
  }
  .site-nav__login {
    display: flex;
    inline-size: 100%;
    min-block-size: var(--control-h-lg);
    margin-block-start: var(--sp-4);
    font-size: var(--fs-lg);
  }
}

@media (max-width: 720px) {
  .focus {
    padding-block: var(--sp-8) var(--sp-12);
  }
  .focus__card {
    padding: var(--sp-6) var(--sp-5);
  }
  .focus__actions {
    inline-size: 100%;
  }
  .focus__actions .btn {
    inline-size: 100%;
    min-block-size: var(--control-h-lg);
  }
  .focus__form .btn--lg {
    min-block-size: var(--control-h-xl);
  }
  .site-footer {
    padding-block-start: var(--sp-12);
  }
  .site-footer__groups {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-6) var(--sp-5);
  }
  .site-footer__links {
    gap: 0;
  }
  .site-footer__bottom {
    padding-block-end: var(--sp-12);
  }
}

/* --------------------------------------------------------------------------
   2. App shell
   -------------------------------------------------------------------------- */
.app-body {
  background: var(--haze-app), var(--bg);
  background-attachment: fixed;
  font-size: var(--fs-base);
  line-height: var(--lh-ui);
}
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-block-size: 100vh;
  min-block-size: 100dvh;
}
.app__col {
  min-inline-size: 0;
}

/* Sidebar: glass, on the inline-start side. Below 1100px the same element
   is the "more" sheet (.sheet--until-wide), so its frame is set only here. */
@media (min-width: 1101px) {
  .sidebar {
    position: sticky;
    inset-block-start: 0;
    z-index: var(--z-sidebar);
    display: flex;
    flex-direction: column;
    block-size: 100vh;
    block-size: 100dvh;
    padding: var(--sp-3);
    border-inline-end: var(--line) solid var(--hairline);
    background: var(--surface-1);
    overflow-y: auto;
  }
}
.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-block-size: var(--control-h-sm);
  padding-inline: var(--sp-2);
  margin-block-end: var(--sp-4);
}
.sidebar__head .brand {
  font-size: var(--fs-lg-plus);
}
.sidebar__head .logo {
  inline-size: var(--logo-w-sm);
}
.sidebar__close,
.sidebar__title {
  display: none;
}
.side-nav {
  display: grid;
  gap: var(--sp-half);
}
.side-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  inline-size: 100%;
  min-block-size: var(--control-h);
  padding-inline: var(--sp-3);
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  line-height: var(--lh-control);
  text-align: start;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}
.side-link .icon {
  inline-size: var(--icon-lg);
  block-size: var(--icon-lg);
  color: var(--text-muted);
}
.side-link .side-link__chevron {
  display: none;
}
/* a count at the end of a link: unread notifications */
.side-link .badge {
  margin-inline-start: auto;
}
.side-link:hover {
  background: var(--surface-2);
  color: var(--text);
}
.side-link:active {
  transform: var(--press-soft);
}
.side-link[aria-current="page"] {
  background: var(--surface-3);
  box-shadow: var(--highlight);
  color: var(--text);
  font-weight: var(--fw-bold);
}
.side-link[aria-current="page"] .icon:first-child {
  color: var(--accent);
  filter: var(--glow-icon);
}

/* The way back on a phone (layouts/app.html): drawn only where the top bar's crumb is hidden */
.back-link {
  display: none;
}
.back-link .icon {
  flex: none;
  inline-size: var(--icon-sm);
  block-size: var(--icon-sm);
}
/* The back link never widens a page (Task 5 fix round 1, B-2), and a name somebody wrote in it wraps rather
   than being cut (M2 Task 7 fix round 1, B/M-9, decision 24); the link stays a finger tall and its whole text
   is its accessible name. */
.back-link__text {
  min-inline-size: 0;
  overflow-wrap: anywhere;
}
/* A way back that has to post (the assistant's prepared screen keeps its answer, M2 Task 6 fix round 1, B-3):
   a button drawn as the link it stands for */
button.back-link {
  padding-block: 0;
  padding-inline-start: 0;
  border: 0;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
}
[dir="ltr"] .back-link .icon {
  transform: scaleX(-1);
}

/* A part of a page reached by its address's fragment clears the sticky top bar (Task 5 fix round 1, B-12). */
[id] {
  scroll-margin-block-start: calc(var(--topbar-h) + var(--sp-3));
}

/* Top bar: translucent, blurred */
.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: var(--z-bar);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-block-size: var(--topbar-h);
  padding-inline: var(--sp-8);
  border-block-end: var(--line) solid var(--hairline);
  background: var(--bar);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
.topbar__brand {
  display: none;
}
.topbar .search {
  flex: 0 1 var(--search-w);
  margin-inline-start: auto;
}
.topbar__tools {
  display: flex;
  align-items: center;
  /* room for a count that grows outward from the bell's corner (.badge--corner) */
  gap: var(--sp-3);
  margin-inline-start: auto;
}
.topbar .search + .topbar__tools {
  margin-inline-start: 0;
}
.topbar__user {
  display: inline-grid;
  place-items: center;
  inline-size: var(--control-h);
  block-size: var(--control-h);
  border-radius: var(--r-round);
  transition: transform var(--dur) var(--ease);
}
.topbar__user:active {
  transform: var(--press-strong);
}

.app-main {
  inline-size: 100%;
  max-inline-size: var(--content-w);
  margin-inline: auto;
  padding: var(--sp-8) var(--sp-8) var(--sp-16);
}
/* The main column, and beside it a rail when the page gives one */
.app-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-5);
  align-items: start;
}
.app-content:has(> .app-content__rail) {
  grid-template-columns: minmax(0, 1fr) var(--rail-w);
}
.app-content__main,
.app-content__rail {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-5);
  min-inline-size: 0;
}
.app-content__rail {
  position: sticky;
  inset-block-start: calc(var(--topbar-h) + var(--sp-5) + var(--acting-offset));
}

/* Bottom tab bar (small screens only) */
.tabbar {
  display: none;
}
/* The entries are drawn the same wherever they appear (the bar on phones, its specimen on /styleguide/) */
.tabbar__item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-half);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: var(--lh-control);
  transition: color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.tabbar__item:active {
  transform: var(--press-strong);
}
.tabbar__item .icon {
  inline-size: var(--icon-2xl);
  block-size: var(--icon-2xl);
}
.tabbar__item[aria-current="page"] {
  color: var(--accent);
  font-weight: var(--fw-bold);
}
/* The current item's icon is its filled form (as iOS marks the current tab):
   the shape takes the text colour, its inner lines are cut out in the canvas */
.tabbar__item[aria-current="page"] .icon {
  stroke: var(--bg);
  filter: var(--glow-icon-strong);
}

@media (max-width: 1180px) {
  .app-content:has(> .app-content__rail) {
    grid-template-columns: minmax(0, 1fr);
  }
  .app-content__rail {
    position: static;
  }
}

@media (max-width: 1100px) {
  /* a fixed background repaints on every scroll frame on a phone */
  .app-body {
    background-attachment: scroll;
  }
  .app {
    display: block;
  }

  /* The sidebar is now a sheet: its links become the rows of a grouped list */
  .sidebar__head {
    min-block-size: var(--tap);
    padding-inline: var(--sp-1);
    margin-block-end: var(--sp-3);
  }
  .sidebar__close {
    display: inline-grid;
  }
  /* as the «بیشتر» sheet it is named by its title; the brand is on the page behind it */
  .sidebar__head .brand {
    display: none;
  }
  .sidebar__title {
    display: block;
    font-size: var(--fs-xl);
    font-weight: var(--fw-bold);
  }
  .side-nav {
    gap: 0;
    border: var(--line) solid var(--hairline);
    border-radius: var(--r-lg);
    background: var(--surface-1);
    overflow: hidden;
  }
  .side-nav li + li {
    border-block-start: var(--line) solid var(--hairline);
  }
  .side-link {
    min-block-size: var(--control-h-lg);
    padding-inline: var(--sp-4);
    border-radius: 0;
    color: var(--text);
    font-size: var(--fs-lg);
  }
  /* the list clips its rounded corners, so a link's ring is drawn inside the link */
  .side-link:focus-visible {
    outline-offset: calc(-1 * var(--ring-room));
  }
  .side-link .side-link__chevron {
    display: block;
    margin-inline-start: auto;
    inline-size: var(--icon-xs);
    block-size: var(--icon-xs);
    color: var(--text-faint);
  }
  .side-link[aria-current="page"] {
    background: var(--surface-2);
    box-shadow: none;
  }

  .topbar {
    flex-wrap: wrap;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-4);
  }
  .topbar__brand {
    display: inline-flex;
    min-block-size: var(--tap);
    margin-inline-end: auto;
    font-size: var(--fs-lg-plus);
  }
  .topbar__brand .logo {
    inline-size: var(--logo-w-sm);
  }
  .topbar .breadcrumb {
    display: none;
  }
  /* the top bar's crumb is hidden: the page's parent is drawn once, before its heading */
  .back-link {
    display: inline-flex;
    max-inline-size: 100%;
    align-items: center;
    gap: var(--sp-1);
    min-block-size: var(--tap);
    margin-block-end: var(--sp-1);
    padding-inline-end: var(--sp-2);
    border-radius: var(--r-xs);
    color: var(--text-2);
    font-size: var(--fs-md);
    font-weight: var(--fw-medium);
  }
  .back-link:hover {
    color: var(--text);
  }
  .topbar .search {
    order: 3;
    flex: 1 1 100%;
    margin: 0 0 var(--sp-1);
  }
  .topbar__tools {
    gap: var(--sp-2);
    margin-inline-start: 0;
  }
  .topbar__user {
    inline-size: var(--tap);
    block-size: var(--tap);
  }
  .app-main {
    padding: var(--sp-5) var(--sp-4) calc(var(--tabbar-h) + var(--safe-bottom) + var(--sp-10));
  }
  /* a node's public page, read by a visitor: no tab bar to clear */
  .public-body > .app-main {
    padding-block-end: var(--sp-10);
  }

  .tabbar {
    position: fixed;
    inset-inline: 0;
    inset-block-end: 0;
    z-index: var(--z-tabbar);
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    block-size: calc(var(--tabbar-h) + var(--safe-bottom));
    padding-block-end: var(--safe-bottom);
    border-block-start: var(--line) solid var(--hairline);
    background: var(--bar);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
  }
  /* toasts clear the tab bar */
  .app-body .toasts {
    inset-block-end: calc(var(--tabbar-h) + var(--safe-bottom) + var(--sp-3));
  }
}

@media (prefers-reduced-motion: reduce) {
  .side-link:active,
  .tabbar__item:active,
  .topbar__user:active {
    transform: none;
  }
}

/* The narrowest phones (320px): the header's buttons stay inside the page (fix round 1 of M2 Task 2, part B
   small item 11), and the product's name is never cut: the sign-up button gives way to «عضویت» instead
   (M2 Task 7, fix round 1, B/M-10). */
@media (max-width: 359px) {
  .site-header__in {
    gap: var(--sp-2);
  }
  .site-header__in .brand span {
    white-space: nowrap;
  }
  .site-actions {
    gap: var(--sp-1);
  }
  .site-actions__free {
    display: none;
  }
}
