/* ==========================================================================
   Phone shell (wave C1, lane C1-D)

   Up to 1023.98px the shell is three pieces and nothing else. The desktop
   shell (the rail and the top bar) starts at 1024px, the desktop step of the
   breakpoint ladder in design-tokens.md, so a tablet gets the narrow shell:

     header     brand, search, bell, avatar          _phone_header.html
     tab bar    the SECTIONS marked phone "tab"      _tabbar.html, TabBar.tsx
     You sheet  everything else, behind the avatar   _you_sheet.html, YouSheet.tsx

   There is no drawer, no dock and no floating button (fab-cluster.css hides
   them under the same line). The sizes are tokens set in design-tokens.md:
   --topbar-height and --bottom-nav-height; the touch target is --shell-target
   (shell.css). Text direction comes from the document, so the same rules
   mirror in a right-to-left language: every side below is logical.

   The drawer, dock and old phone header rules that theme.css used to carry
   are gone (lane C1-V2); what theme.css keeps of the shell is the rail's outer
   box and the content offsets from 1024px, and the search overlay.
   ========================================================================== */

/* From 1024px up the phone pieces do not exist. */
.shell-phone-header,
#shell-tabbar-root {
  display: none;
}

@media (max-width: 1023.98px) {
  /* The desktop pieces step aside. */
  .shell-sidebar,
  .shell-topbar {
    display: none;
  }

  /* The page starts under the header and uses the whole width. The sidebar
     margin the desktop rules give it (either side, minimised or not) is gone. */
  .shell-frame,
  #sidebar-root + .shell-frame {
    margin-inline: 0;
    padding-block-start: var(--topbar-height);
    --topbar-min-height: var(--topbar-height);
  }

  /* The reduced shell (L6-018) is brand, step and exit: shell.css already hides
     the phone header, so there is no bar here either, and the frame reserves
     neither the header's height above nor the bar's below. The selectors
     carry an id and the body's data-shell so they out-rank the frame rules
     above and the padding shell.css gives a page that has a bar. */
  body[data-shell="reduced"] #shell-tabbar-root {
    display: none;
  }

  body[data-shell="reduced"] #sidebar-root + .shell-frame,
  body[data-shell="reduced"]:has(#shell-tabbar-root) .shell-frame {
    padding-block: 0;
  }

  /* ------------------------------------------------------------------------
     Header
     ------------------------------------------------------------------------ */

  .shell-phone-header {
    position: fixed;
    inset-block-start: 0;
    inset-inline: 0;
    z-index: var(--z-dock);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    block-size: var(--topbar-height);
    padding-inline: var(--space-sm);
    background: var(--bg-secondary);
    border-block-end: 1px solid var(--border-dark);
  }

  .shell-phone-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-inline-size: 0;
    min-block-size: var(--shell-target);
    padding-inline: var(--space-sm);
    color: var(--text-primary);
    font-weight: 700;
    text-decoration: none;
  }

  .shell-phone-brand span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .shell-phone-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: var(--space-xs);
  }

  .shell-phone-btn,
  .shell-phone-bell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-inline-size: var(--shell-target);
    min-block-size: var(--shell-target);
  }

  .shell-phone-btn {
    padding: 0;
    color: var(--text-primary);
    background: none;
    border: 0;
    border-radius: var(--radius-full);
    cursor: pointer;
  }

  .shell-phone-avatar__face {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: 32px;
    block-size: 32px;
    border-radius: var(--radius-full);
    object-fit: cover;
  }

  .shell-phone-avatar__initial {
    color: var(--craft-gradient-contrast);
    background: var(--craft-gradient-hero);
    font-weight: 700;
    font-size: var(--font-size-sm);
  }

  .shell-phone-brand:focus-visible,
  .shell-phone-btn:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: -2px;
  }

  /* ------------------------------------------------------------------------
     Tab bar: the root is the bar's surface, so it is drawn and its height is
     reserved (shell.css pads the page by the same height) before the island
     arrives, and an empty list leaves an empty bar of the same height.
     ------------------------------------------------------------------------ */

  #shell-tabbar-root {
    position: fixed;
    inset-inline: 0;
    inset-block-end: 0;
    z-index: var(--z-dock);
    box-sizing: border-box;
    display: block;
    block-size: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    padding-block-end: env(safe-area-inset-bottom, 0px);
    background: var(--bg-secondary);
    border-block-start: 1px solid var(--border-dark);
  }

  .shell-tabbar {
    display: flex;
    align-items: stretch;
    block-size: calc(var(--bottom-nav-height) - 1px);
    padding-inline: var(--space-xs);
  }

  .shell-tab {
    position: relative;
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-inline-size: 0;
    padding-inline: 2px;
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
    font-weight: 600;
    line-height: 1.15;
    text-decoration: none;
  }

  .shell-tab__glyph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    inline-size: 56px;
    block-size: 32px;
    border-radius: var(--radius-full);
  }

  .shell-tab__label {
    max-inline-size: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Create is the centre tab and the one coloured glyph. */
  .shell-tab--create .shell-tab__glyph {
    color: var(--craft-gradient-contrast);
    background: var(--craft-gradient-hero);
  }

  .shell-tab[aria-current="page"] {
    color: var(--craft-green-text);
  }

  .shell-tab[aria-current="page"]::before {
    content: "";
    position: absolute;
    inset-block-start: 0;
    inset-inline: 30%;
    block-size: 3px;
    border-radius: var(--radius-full);
    background: var(--craft-green-text);
  }

  .shell-tab:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: -2px;
  }

  /* The first-visit "Take a tour" pill sits above the bar, on the reading
     start side, not under it. fab-cluster.css moves it clear of a rail only
     from 1024px, so this plain rule needs no more weight than its base. */
  .tour-launch-btn {
    inset-inline-start: var(--space-md);
    inset-block-end: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + var(--space-md));
  }
}

/* ==========================================================================
   You sheet

   A bottom sheet over a dimmed page. It is only opened below 1024px, but it is
   styled at every width, so a phone turned on its side while it is open keeps
   its shape: it never grows wider than a phone.
   ========================================================================== */

@keyframes shell-sheet-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes shell-sheet-out {
  from { transform: translateY(0); }
  to { transform: translateY(100%); }
}

@keyframes shell-sheet-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes shell-sheet-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

.shell-sheet__overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(8, 22, 40, 0.6);
}

.shell-sheet__overlay[data-state="open"] {
  animation: shell-sheet-fade-in var(--transition-base) both;
}

.shell-sheet__overlay[data-state="closed"] {
  animation: shell-sheet-fade-out var(--transition-fast) both;
}

.shell-sheet {
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  z-index: calc(var(--z-modal) + 1);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  max-inline-size: 32rem;
  max-block-size: 88vh;
  margin-inline: auto;
  padding-block-end: env(safe-area-inset-bottom, 0px);
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-dark);
  border-block-end: 0;
  border-start-start-radius: var(--radius-xl);
  border-start-end-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
}

@supports (height: 1dvh) {
  .shell-sheet {
    max-block-size: 88dvh;
  }
}

.shell-sheet[data-state="open"] {
  animation: shell-sheet-in var(--transition-base) var(--ease-out-quart) both;
}

.shell-sheet[data-state="closed"] {
  animation: shell-sheet-out var(--transition-fast) ease-in both;
}

@media (prefers-reduced-motion: reduce) {
  .shell-sheet[data-state],
  .shell-sheet__overlay[data-state] {
    animation: none;
  }
}

.shell-sheet__grip {
  flex: none;
  inline-size: 36px;
  block-size: 4px;
  margin: var(--space-sm) auto 0;
  border-radius: var(--radius-full);
  background: var(--border-dark);
}

.shell-sheet__head {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  min-block-size: 52px;
  padding-inline: var(--space-md) var(--space-sm);
}

.shell-sheet__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--font-size-lg);
  font-weight: 700;
}

.shell-sheet__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 44px;
  block-size: 44px;
  padding: 0;
  color: inherit;
  background: none;
  border: 0;
  border-radius: var(--radius-full);
  cursor: pointer;
}

.shell-sheet__scroll {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--space-sm) var(--space-md);
}

.shell-sheet__who {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm);
}

.shell-sheet__face {
  flex: none;
  inline-size: 40px;
  block-size: 40px;
  border-radius: var(--radius-full);
  object-fit: cover;
}

.shell-sheet__face--initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--craft-gradient-contrast);
  background: var(--craft-gradient-hero);
  font-weight: 700;
}

.shell-sheet__name {
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.shell-sheet__badge {
  padding: 2px var(--space-sm);
  color: var(--craft-green-text);
  background: var(--craft-indigo-tint);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 700;
}

.shell-sheet__list {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* The invite button: a small round button at the end of the member's row (a
   44px tap target). It opens the invite popup below, a second dialog over the
   sheet, so its layers sit above the sheet's two. */
.shell-sheet__invite {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  margin-inline-start: auto;
  inline-size: 44px;
  block-size: 44px;
  padding: 0;
  color: var(--text-primary);
  background: var(--craft-indigo-tint);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-full);
  cursor: pointer;
}

.shell-sheet__invite:active {
  background: var(--border-light);
}

.shell-sheet__invite:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.shell-invite__overlay,
.shell-accounts__overlay {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-modal) + 2);
  background: rgba(8, 22, 40, 0.6);
}

/* Centred by auto margins, not by a translate, so it sits right in both
   reading directions. The Switch account popup (SwitchAccountButton) is the same
   card, so it shares these rules and its layers sit with the invite popup's. */
.shell-invite,
.shell-accounts {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-modal) + 3);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  inline-size: min(22rem, calc(100% - 2rem));
  block-size: fit-content;
  max-block-size: calc(100% - 2rem);
  margin: auto;
  padding: var(--space-lg);
  overflow-y: auto;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
}

.shell-invite__title,
.shell-accounts__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--font-size-lg);
  font-weight: 700;
}

/* The accounts fill the card's width. The rows are the desktop menu's
   (.account-switcher-row, styled by AccountSwitcher.tsx), 44px tall; their name
   follows the reading direction here, where the desktop popover pins it left. */
.shell-accounts {
  align-items: stretch;
}

.shell-accounts__title {
  text-align: center;
}

.shell-accounts .account-switcher-row {
  text-align: start;
}

.shell-accounts .shell-accounts__close {
  inline-size: 100%;
}

/* Dark modules on a light ground in every theme: a phone camera needs the
   contrast. The code paints its own light ground and quiet zone (InviteButton),
   so this box adds no colour of its own. */
.shell-invite__qr {
  flex: none;
  max-inline-size: 100%;
  overflow: hidden;
  line-height: 0;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
}

.shell-invite__qr svg {
  max-inline-size: 100%;
  block-size: auto;
}

.shell-invite__link {
  box-sizing: border-box;
  inline-size: 100%;
  min-block-size: 44px;
  padding-inline: var(--space-sm);
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  font: inherit;
  font-size: var(--font-size-sm);
  text-overflow: ellipsis;
}

.shell-invite__link:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.shell-invite__actions {
  display: flex;
  gap: var(--space-sm);
  inline-size: 100%;
}

.shell-invite .shell-invite__action {
  flex: 1 1 0;
  min-inline-size: 0;
}

.shell-invite__status {
  min-block-size: 1.25em;
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
}

/* The buttons here wear the shared button contract ([data-btn], components.css,
   which owns focus, disabled and press states); the two-class selector below
   turns its centred pill into a left-aligned row, at the same specificity and
   later in the cascade. The links are plain rows of the same shape. */
.shell-sheet .shell-sheet__row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-md);
  box-sizing: border-box;
  inline-size: 100%;
  min-block-size: 48px;
  padding-inline: var(--space-sm);
  color: var(--text-primary);
  background: none;
  border: 0;
  border-radius: var(--radius-md);
  font: inherit;
  text-align: start;
  text-decoration: none;
  white-space: normal;
  cursor: pointer;
}

.shell-sheet .shell-sheet__row:active {
  background: var(--craft-indigo-tint);
}

.shell-sheet .shell-sheet__row[aria-current="page"] {
  color: var(--craft-green-text);
  background: var(--craft-indigo-tint);
  font-weight: 700;
}

.shell-sheet__glyph {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  inline-size: 24px;
  color: var(--text-secondary);
}

.shell-sheet .shell-sheet__row[aria-current="page"] .shell-sheet__glyph {
  color: inherit;
}

.shell-sheet__label {
  flex: 1 1 auto;
  min-inline-size: 0;
}

.shell-sheet__heading {
  margin: var(--space-md) var(--space-sm) 0;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  font-weight: 700;
}

.shell-sheet__settings,
.shell-sheet__foot {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.shell-sheet__foot {
  padding-block-start: var(--space-sm);
  border-block-start: 1px solid var(--border-dark);
}

/* Preferences sit between the first rows and the rest (QC13), parted from
   both by a line, and fold away under their heading's minus or plus sign. */
.shell-sheet__settings {
  padding-block: var(--space-xs);
  border-block: 1px solid var(--border-dark);
}

.shell-sheet__settings .shell-sheet__heading {
  margin-block-start: 0;
}

.shell-sheet__fold {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  inline-size: 100%;
  min-block-size: 44px;
  padding: 0;
  color: inherit;
  background: none;
  border: 0;
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.shell-sheet__fold-sign {
  inline-size: 1ch;
  font-size: var(--font-size-base);
  font-weight: 700;
  text-align: center;
}

.shell-sheet__prefs {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.shell-sheet__prefs[hidden] {
  display: none;
}

.shell-sheet__langs {
  display: flex;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
}

.shell-sheet__lang-form {
  flex: 1 1 0;
}

.shell-sheet .shell-sheet__lang {
  box-sizing: border-box;
  inline-size: 100%;
  min-block-size: 44px;
  padding-inline: var(--space-sm);
  color: var(--text-primary);
  background: none;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-md);
  font: inherit;
  cursor: pointer;
}

.shell-sheet .shell-sheet__lang[aria-pressed="true"] {
  color: var(--craft-green-text);
  background: var(--craft-indigo-tint);
  border-color: var(--craft-green-text);
  font-weight: 700;
}

.shell-sheet__track {
  position: relative;
  flex: none;
  inline-size: 44px;
  block-size: 26px;
  background: var(--text-muted);
  border-radius: var(--radius-full);
  transition: background-color var(--transition-fast);
}

.shell-sheet__thumb {
  position: absolute;
  inset-block-start: 3px;
  inset-inline-start: 3px;
  inline-size: 20px;
  block-size: 20px;
  background: var(--bg-card);
  border-radius: var(--radius-full);
  transition: inset-inline-start var(--transition-fast);
}

.shell-sheet__switch[aria-checked="true"] .shell-sheet__track {
  background: var(--craft-green-text);
}

.shell-sheet__switch[aria-checked="true"] .shell-sheet__thumb {
  inset-inline-start: 21px;
}

@media (prefers-reduced-motion: reduce) {
  .shell-sheet__track,
  .shell-sheet__thumb {
    transition: none;
  }
}

.shell-sheet .shell-sheet__row:focus-visible,
.shell-sheet .shell-sheet__lang:focus-visible,
.shell-sheet__close:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}
