/* Localish web presentation: approved artwork and adaptive brand color,
   bundled typography, semantic controls, and platform accessibility preferences. */
@layer tokens, base, components, utilities;

@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/assets/BricolageGrotesque-8f830ec8.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: "Manrope";
  src: url("/assets/Manrope-b839e300.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
}

@layer components {
  .host-recovery {
    color: var(--label);
    background: var(--page);
    border: 0;
    padding: max(2rem, env(safe-area-inset-top)) max(1.5rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(1.5rem, env(safe-area-inset-left));
    margin: auto;
    inline-size: 100%;
    max-inline-size: 100%;
    block-size: 100%;
    max-block-size: 100%;
    overflow: auto;
    &[open] { display: grid; align-items: center; }
    &::backdrop { background: var(--page); }
    & .host-recovery-content { inline-size: 100%; max-inline-size: 28rem; margin-inline: auto; text-align: center; }
    & h1 { font-size: var(--t-section); }
    & p { overflow-wrap: anywhere; }
    & [data-recovery-status] { min-block-size: 1.5em; }
    & [data-recovery-retry] { min-block-size: 44px; }
  }
}

/* Sheet drag progress (1 = fully presented, 0 = dragged away). Registered
   so transitions can animate it — the backdrop derives blur radius and
   tint alpha from it, and ::backdrop inherits from its dialog. */
@property --sheet-progress {
  syntax: "<number>";
  inherits: true;
  initial-value: 1;
}

@layer tokens {
  :root {
    color-scheme: light dark;
    accent-color: var(--accent);

    --paper: #f7f3ea;
    --ink: #252a27;
    --clay: #b94e32;
    --apricot: #f2b68f;
    --stone: #e6dfd2;
    --label:           light-dark(var(--ink), var(--paper));
    --label-secondary: light-dark(#64665d, #c3c2b7);
    --separator:       light-dark(#d3cbbb, #535950);
    --fill:            light-dark(#e6dfd2, #3a403a);
    --fill-secondary:  light-dark(#d8cfbf, #484e45);
    --page:            light-dark(var(--paper), var(--ink));
    --card:            light-dark(#fffcf7, #303631);
    --accent:          light-dark(var(--clay), var(--apricot));
    --accent-hover:    light-dark(#ac452c, #f8c5a2);
    --accent-label:    light-dark(var(--paper), var(--ink));
    /* Deeper Clay keeps small links legible on quiet Stone surfaces too. */
    --link:            light-dark(#a54128, var(--apricot));
    --red:             light-dark(#bf2030, #ff8c91);
    --green:           light-dark(#267039, #8bd39a);
    --orange:          light-dark(#9b4b0b, #f5b866);
    --radius:          11px;
    --radius-control:  8px;
    --hairline:        .5px solid var(--separator);
    --space-row:       .75rem;
    --space-group:     1.5rem;
    --space-section:   2rem;
    --shadow-card:     none;
    --shadow-sheet:    0 24px 60px rgb(0 0 0 / .35);
    --focus-ring:      0 0 0 3.5px color-mix(in srgb, var(--accent) 35%, transparent);
    --mono:            ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;

    /* The one spring — sheets, tab underline, page entrance, snap-back
       (UIKit's presentation curve). */
    --spring: cubic-bezier(0.32, 0.72, 0, 1);

    /* iCloud.com's measured ramp (px @ 17px base → rem): 40/44 titles,
       32/36 sections, 21/25 headers, 17 body (21px UI · 25px prose line
       heights), 14 secondary. Weights are 400/600 only. */
    --t-title:   2.353rem;   /* 40px */
    --t-section: 1.882rem;   /* 32px */
    --t-header:  1.235rem;   /* 21px */
    --t-body:    1rem;       /* 17px */
    --t-sub:     .824rem;    /* 14px */
    --lh-tight:  1.1;
    --lh-ui:     1.235;      /* 21/17 */
    --lh-prose:  1.47;       /* 25/17 */

    /* light-dark() can't wrap comma lists — shadows switch by media query */
    @media (prefers-color-scheme: dark) {
      --shadow-card: none;
      --shadow-sheet: 0 24px 60px rgb(0 0 0 / .6);
    }

    /* Increased-contrast preference: stronger secondary labels,
       solid separators — mirroring macOS's Increase Contrast switch. */
    @media (prefers-contrast: more) {
      --link:            light-dark(#7b2d1d, #ffd5b8);
      --label-secondary: light-dark(rgb(0 0 0 / .78), rgb(255 255 255 / .88));
      --separator:       light-dark(#8e8e93, #98989d);
    }
  }
}

@layer base {
  *, *::before, *::after { box-sizing: border-box; }


  /* Match iCloud.com's 17px body size using a percentage of the 16px
     browser default so font-size preferences still scale the rem ramp. */
  html {
    font-size: 106.25%;
    /* The root itself carries the page color: Safari tints its toolbar
       from the topmost painted pixel, and a transparent root lets the UA
       default bleed through for a frame on navigation. */
    background: var(--page);
  }

  body {
    margin: 0;
    font-family: "Manrope", system-ui, sans-serif;
    font-weight: 400;
    font-size: 1rem;
    line-height: var(--lh-prose);
    background: var(--page);
    color: var(--label);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  /* text-box trims the leading above cap height so headings sit on the
     spacing grid exactly (SwiftUI-style); text-wrap keeps multi-line
     headings balanced. Both degrade silently. */
  :is(h1, h2, h3) {
    font-family: "Bricolage Grotesque", system-ui, sans-serif;
    font-optical-sizing: auto;
    font-weight: 600; letter-spacing: 0;
    text-box: trim-both cap alphabetic;
    text-wrap: balance;
  }
  h1 { font-size: var(--t-title); line-height: var(--lh-tight);
       margin: 0 0 1.18rem; }
  h2 { font-size: var(--t-section); line-height: 1.125; margin: 0 0 1.25rem; }
  h3 { font-size: var(--t-header); line-height: var(--lh-ui); margin: 0; }
  b, strong, th { font-weight: 600; }

  /* Prose: no orphans, hung punctuation where Safari offers it. */
  p { text-wrap: pretty; hanging-punctuation: first last; }

  code, pre { font-family: var(--mono); font-size: inherit; }
  code { overflow-wrap: anywhere; }
  * { min-inline-size: 0; }

  a {
    color: var(--link);
    text-decoration: none;
    &:hover { text-decoration: underline; }
    &:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
  }

  ::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }

  :is(a, button, .card-button, input, textarea, select, label) {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  main {
    max-width: 66rem;
    margin-inline: auto;
    padding: var(--space-section) clamp(1.25rem, 5vw, 2.5rem) 4rem;
    container-type: inline-size;
    /* Programmatic focus target after same-document swaps (reading-order
       reset for AT) — never a visible ring; main isn't tab-reachable. */
    outline: none;

    &.narrow { max-width: 28rem; padding-block-start: clamp(2rem, 10vh, 5rem); }
  }
  .page-sub { color: var(--label-secondary); font-size: var(--t-body);
              max-width: 42rem; margin: 0 0 var(--space-group); }

  section { margin-block-end: var(--space-section); }

  @media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
  }
}

@layer components {
  /* Chrome — two stacked bars, Apple-site style (developer.apple.com,
     iCloud settings): a global brand bar that scrolls away, then a local
     nav bar with its own hairline that PINS. Same collapsing behavior on
     every viewport; no script, no negative-inset tricks. */

  /* Shared alignment: column centering plus main's own inline padding —
     bar content and body text share one left edge. */
  .masthead, .tabbar {
    padding-inline: calc(max((100vw - 66rem) / 2, 0px) + clamp(1.25rem, 5vw, 2.5rem));
  }
  /* Standalone: a fixed cap paints the status-bar area page color — the
     native nav-bar-under-status look, without padding any in-flow bar. */
  @media (display-mode: standalone) {
    body::before {
      content: ""; position: fixed; inset: 0 0 auto 0;
      block-size: env(safe-area-inset-top, 0px);
      background: var(--page); z-index: 30;
    }
  }

  .localish-icon {
    display: inline-flex; inline-size: 1.1em; block-size: 1.1em; flex: none;
    vertical-align: -.15em;
    & svg { display: block; inline-size: 100%; block-size: 100%; fill: currentColor; }
  }
  .brand-mark { display: block; inline-size: 100%; block-size: 100%; color: var(--accent); }
  .brand-mark svg, .brand-wordmark svg { display: block; inline-size: 100%; block-size: auto; }
  .brand-glyph { display: inline-flex; inline-size: 3.5rem; block-size: 3.5rem; color: var(--accent); }
  .brand-glyph > .localish-icon { inline-size: 100%; block-size: 100%; }
  .status-symbol > .localish-icon { inline-size: 100%; block-size: 100%; }
  /* Brand bar: opaque, full-bleed hairline, scrolls away. Extends under
     the status bar in standalone (inset is 0 in-browser). */
  .masthead {
    display: flex; align-items: center; gap: .75rem;
    background: var(--page);
    border-block-end: var(--hairline);
    padding-block: 1.1rem;
    padding-block-start: calc(1.1rem + env(safe-area-inset-top, 0px));

    & .wordmark {
      display: flex; align-items: center; gap: .6rem;
      color: var(--label);
      &:hover { text-decoration: none; }

      & .mark { inline-size: 2rem; aspect-ratio: 115 / 100; flex: none; }
      & .brand-wordmark { inline-size: clamp(6.4rem, 24vw, 8rem); }
    }
    & .auth-control { display: flex; align-items: center; gap: .6rem;
             color: var(--label-secondary); font-size: var(--t-sub);
             margin-inline-start: auto; }
  }

  .tabbar {
    position: sticky; inset-block-start: 0; z-index: 20;
    /* Opaque bars keep the page tint consistent with Safari's chrome. */
    background: var(--page);

    /* Standalone: pin BELOW the fixed status-bar cap. */
    @media (display-mode: standalone) {
      inset-block-start: env(safe-area-inset-top, 0px);
    }

    /* Narrow viewports: the divider goes edge to edge — with slim insets
       a column-width line reads as a mistake, not a choice. Wide: the
       divider belongs to the nav and spans the content column. */
    @media (max-width: 37.5em) {
      border-block-end: var(--hairline);
      & .tabs { border-block-end: none; }
      &:has(.sysnav) { border-block-end: none; }
    }
  }

  .tabs {
    display: flex; gap: 2.5rem;
    @media (max-width: 37.5em) { gap: 1.25rem; }
    border-block-end: var(--hairline);
    /* Overflow, not wrap, never a hamburger: extra destinations scroll
       like iOS tab rows. overflow-y pinned (a lone overflow-x computes a
       vertical scroll axis Safari rubber-bands); contained overscroll so
       a tab swipe can't leak into Safari's back gesture. */
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
    overscroll-behavior: contain;
    &::-webkit-scrollbar { display: none; }

    & a {
      position: relative; flex-shrink: 0;
      display: inline-flex; align-items: center; gap: .45rem;
      /* A real bar: ~48px tall, above the tap-target floor. */
      padding-block: .9rem;
      /* Constant weight both states — identical pixels riding the page
         crossfade cannot blink. Selection is the underline's job, with
         label color as reinforcement. */
      font-size: var(--t-body); font-weight: 400;
      color: var(--label-secondary);
      &:hover { color: var(--label); text-decoration: none; }

      &[aria-current="page"] {
        color: var(--label);
        /* Sits ON the bar's hairline — flush, not offset, because
           overflow-y: hidden clips anything past the padding edge. */
        &::after {
          content: ""; position: absolute;
          inset-inline: 0; inset-block-end: 0;
          block-size: 2px; background: var(--label);
        }
      }
      &.sliding::after {
        transform-origin: left;
        animation: underline-slide .28s var(--spring) both;
      }
    }
  }
  @keyframes underline-slide {
    from { transform: translateX(var(--from-x, 0)) scaleX(var(--from-scale, 1)); }
    to   { transform: none; }
  }

  /* Direction carries information: content enters from the side of its tab, so
     motion teaches the nav's spatial order, underline and page moving
     as one gesture. Slide-in only; nothing serializes before the swap. */
  main.enter-forward { animation: enter-forward .3s var(--spring) both; }
  main.enter-back    { animation: enter-back    .3s var(--spring) both; }
  @keyframes enter-forward { from { opacity: 0; transform: translateX(3rem); } }
  @keyframes enter-back    { from { opacity: 0; transform: translateX(-3rem); } }

  /* Related content shares a flat surface; elevation belongs to presentations. */
  .card, .list, .card-button, pre.log {
    background: var(--card);
    border: var(--hairline);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
  }

  .card { padding: 1.25rem; }
  .card + .card { margin-block-start: var(--space-group); }
  .card h2 { font-size: var(--t-header); line-height: var(--lh-ui); }
  .card > :last-child { margin-block-end: 0; }

  .section-title {
    font-size: var(--t-body); font-weight: 600; color: var(--label);
    margin: 0 0 var(--space-row);
  }

  /* Controls */
  label { display: block; font-size: var(--t-sub); font-weight: 400;
          color: var(--label-secondary); margin-block-end: .3rem; }

  :is(input, textarea, select) {
    inline-size: 100%; box-sizing: border-box;
    padding: .5rem .65rem; margin-block-end: 1rem;
    font: inherit; font-size: var(--t-body);
    color: var(--label); background: var(--card);
    border: .5px solid color-mix(in srgb, CanvasText 22%, transparent);
    border-radius: var(--radius-control);
    transition: box-shadow .15s ease, border-color .15s ease;

    &:focus-visible {
      outline: none;
      border-color: var(--accent);
      box-shadow: var(--focus-ring);
    }
  }
  textarea { min-block-size: 6.5rem; resize: vertical;
             font-family: var(--mono); font-size: var(--t-sub); }

  .credential-field { margin-block-end: 1rem; }
  .credential-input {
    display: flex; align-items: center; gap: .5rem;
    & input { flex: 1; min-inline-size: 0; margin: 0; }
    & button { flex-shrink: 0; }
  }
  .authorization-icon {
    display: flex; justify-content: center; margin-block-end: 1rem;
    & .glyph { inline-size: 4rem; block-size: 4rem; }
  }
  .authorization-details { margin-block-end: 1.5rem; }
  main.narrow h1 { font-size: var(--t-section); line-height: 1.125; }
  /* Routine save feedback keeps the next field in place. Errors may wrap. */
  .save-feedback { min-block-size: 1.5em; }

  @media (pointer: coarse), (max-width: 37.5em) {
    button, .button, [data-close], summary, .tabs a {
      min-block-size: 44px; min-inline-size: 44px;
    }
    summary { align-content: center; }
    .card > a, .card > p > a:only-child, .sysnav a {
      display: inline-flex; align-items: center;
      min-block-size: 44px; min-inline-size: 44px;
    }
  }

  /* Buttons — filled pill primary (apple.com), quiet + destructive variants */
  button, .button {
    font: inherit; font-size: var(--t-body); font-weight: 400;
    padding: .5rem 1.1rem;
    border: 0; border-radius: 980px;
    background: var(--accent); color: var(--accent-label);
    cursor: pointer;
    /* Switch the fill with its label so appearance changes preserve contrast. */
    transition: transform .02s ease;

    &:hover  { background: var(--accent-hover); }
    &:active { transform: scale(.98); }
    &:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; box-shadow: var(--focus-ring); }

    &.block { inline-size: 100%; padding-block: .6rem; }
    &.mini  { font-size: var(--t-sub); padding: .3rem .8rem; }

    &.quiet {
      background: var(--fill); color: var(--label);
      border: var(--hairline);
      &:hover { background: var(--fill-secondary); filter: none; }
    }
    &.destructive {
      background: none; color: var(--red);
      border: .5px solid color-mix(in srgb, var(--red) 45%, transparent);
      &:hover { background: color-mix(in srgb, var(--red) 8%, transparent); filter: none; }
    }
  }

  /* Card/list header band — standalone so card-buttons share it */
  .list-header {
    display: flex; align-items: center; gap: 1rem;
    padding: 1rem 1.25rem;

    & > div { min-inline-size: 0; flex: 1; }
    & .caption { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    & .spread { flex: none; margin-inline-start: auto; }

    @container (max-width: 40rem) {
      & { flex-wrap: wrap; }
      & > div { flex-basis: calc(100% - 3.5rem); }
      & .spread { flex-basis: 100%; margin-inline-start: 0; }
      & .caption { white-space: normal; overflow: visible;
                   text-overflow: clip; overflow-wrap: anywhere; }
    }
  }

  /* Inset-grouped lists — the iCloud.com card-with-hairline-rows idiom */
  .list {
    margin-block-end: 1.5rem;
    overflow: hidden;

    & .list-row {
      display: flex; align-items: center; gap: 1.5rem;
      padding: var(--space-row) 1.25rem;
      border-block-start: var(--hairline);
      font-size: var(--t-body); line-height: var(--lh-ui);

      & .primary   { flex: 0 0 13rem; }
      & .grow      { flex: 1; min-inline-size: 0; }
      & .trailing  { display: flex; gap: .4rem; align-items: center;
                     margin-inline-start: auto; white-space: nowrap;

      }

      @container (max-width: 40rem) {
        & { flex-wrap: wrap; row-gap: .6rem; }
        & .primary { flex-basis: 100%; }
        & .grow    { flex-basis: 100%; }
        & .trailing { margin-inline-start: 0; white-space: normal;
                      flex-wrap: wrap; justify-content: flex-start; }
      }
    }
  }

  /* Quiet monograms keep the service name readable when no artwork is supplied. */
  .glyph {
    display: grid; place-items: center;
    inline-size: 2.5rem; block-size: 2.5rem; flex: none;
    border-radius: .6rem;
    font-size: 1.15rem; font-weight: 600;
    color: var(--label); background: var(--fill);
    text-transform: uppercase;
  }
  .glyph.service-icon { object-fit: contain; background: transparent; }

  /* Messaging */
  .error {
    color: var(--red); font-size: var(--t-sub);
    margin-block: .5rem 1rem;
    overflow-wrap: anywhere;
  }

  .copy-status {
    display: block; min-block-size: 1.5em; min-inline-size: 6ch;
    color: var(--label-secondary); font-size: var(--t-sub);
  }

  /* Card grid — the Data Recovery idiom: standalone feature cards */
  .card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(26rem, 100%), 1fr));
    gap: 1.5rem;
    container-type: inline-size;
    & > .card { margin-block: 0; }
  }

  /* Clickable summary cards (open a sheet) */
  .card-button {
    display: block; text-decoration: none;
    cursor: pointer; text-align: start; padding: 0;
    color: var(--label);
    font: inherit; font-weight: 400;
    transition: background .15s ease;

    &:hover { background: color-mix(in srgb, var(--label) 3%, var(--card));
              text-decoration: none; }
  }

  /* Sheets — the iCloud modal idiom, on the native dialog element */
  dialog.sheet {
    &:not([open]) { display: none; }
    &[open]:not(.modal) {
      display: block; position: relative; inset: auto;
      margin: 1.5rem auto; inline-size: min(34rem, 100%);
      max-block-size: none; opacity: 1; transform: none; transition: none;
    }
    inline-size: min(34rem, calc(100vw - 2.5rem));
    max-block-size: min(85vh, 46rem);
    padding: 2.5rem 2rem calc(2rem + env(safe-area-inset-bottom, 0px));
    border: var(--hairline);
    border-radius: 1rem;
    background: var(--card); color: var(--label);
    box-shadow: var(--shadow-sheet);

    overflow-y: auto;
    overscroll-behavior: contain;
    outline: none;   /* the dialog takes focus on open; no ring on a surface */

    /* iOS sheet motion: the one spring over 500ms — entry, drag
       snap-back, and exit alike. (closeSheet in app.js reads this
       duration from the computed style.) */
    opacity: 1; transform: translateY(0) scale(1);
    transition: opacity .5s var(--spring), transform .5s var(--spring),
                --sheet-progress .5s var(--spring);
    @starting-style { opacity: 0; transform: translateY(1.25rem) scale(.98); }
    /* While a finger owns the sheet, everything tracks it 1:1. */
    &.dragging { transition: none; }

    &::backdrop {
      /* Uniform blur and tint avoid visible bands. Safari's toolbar dims
         in sync via live theme-color to match the page beneath it. */
      /* Blur and tint follow the drag: less sheet, less blur — the
         backdrop hands the page back as the drawer leaves. */
      background: light-dark(rgb(0 0 0 / calc(.1 * var(--sheet-progress, 1))),
                             rgb(0 0 0 / calc(.35 * var(--sheet-progress, 1))));
      /* ~thin-material weight: the background should stay recognizable
         (HIG prescribes named materials, not radii — thinner ones keep
         the underlying context legible, which is the point of an
         interactive backdrop you can hand the page back through). */
      -webkit-backdrop-filter: blur(calc(12px * var(--sheet-progress, 1))) saturate(1.1);
      backdrop-filter: blur(calc(12px * var(--sheet-progress, 1))) saturate(1.1);
      transition: opacity .5s var(--spring);
      @starting-style { opacity: 0; }
    }

    /* Animated dismissal (driven by closeSheet in script) */
    &.closing { opacity: 0; transform: translateY(1.25rem) scale(.98); }
    &.closing::backdrop { opacity: 0; }

    /* Phones: the iOS bottom-sheet idiom — full-width, rounded top,
       rising over most of the screen, honoring the home-indicator inset. */
    @media (max-width: 37.5em) {
      inline-size: 100dvw; max-inline-size: 100dvw;
      overflow-x: hidden;
      /* 100dvh reaches under the status bar — clear it (env when
         reported, a Dynamic-Island-sized floor when not) plus breathing
         room, so the sheet's top never enters Safari's blur band. */
      max-block-size: calc(100dvh - max(env(safe-area-inset-top, 0px), 3.75rem) - 1.5rem);
      margin: auto 0 0;
      border: none; border-radius: 1.25rem 1.25rem 0 0;
      padding: 2.25rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
      box-shadow: 0 -12px 40px rgb(0 0 0 / .4);
      @starting-style { opacity: 1; transform: translateY(100%); }
      &.closing { opacity: 1; transform: translateY(100%); }
    }

    & .sheet-close {
      position: absolute; inset-block-start: 1rem; inset-inline-end: 1rem;
      inline-size: 1.9rem; block-size: 1.9rem; padding: 0;
      display: grid; place-items: center;
      background: var(--fill); color: var(--label-secondary);
      border-radius: 50%; font-size: var(--t-body);
      &:hover { background: var(--fill-secondary); filter: none; }
    }
    & .sheet-head {
      display: flex; align-items: center; gap: 1rem;
      text-align: start; margin: 0 0 var(--space-group); padding-inline-end: 3rem;

      & .glyph { inline-size: 3.55rem; block-size: 3.55rem;
                 border-radius: .9rem; font-size: 1.65rem; }
      & h2 { margin: 0; font-size: var(--t-header); }
      & p { margin: 0; color: var(--label-secondary); font-size: var(--t-sub);
            max-inline-size: 24rem; }
    }
    & .service-overview .sheet-head {
      flex-direction: column; text-align: center; padding-inline-end: 0;
      & .glyph { inline-size: 7.1rem; block-size: 7.1rem;
                 border-radius: 1.8rem; font-size: 3.3rem; }
    }
  }

  /* Copy rows (connect page) — stack when the container narrows */
  .snippet {
    display: flex; align-items: center; gap: .6rem; margin-block: .5rem;

    & > label { min-inline-size: 8.5rem; margin: 0; font-weight: 400;
                font-size: var(--t-sub); color: var(--label-secondary); }
    & pre { flex: 1; margin: 0; padding: .55rem .75rem; overflow-x: auto;
            font-size: var(--t-sub);
            background: var(--fill); border: var(--hairline);
            border-radius: var(--radius-control); white-space: pre;
            user-select: all; -webkit-user-select: all; }

    @container (max-width: 34rem) {
      & { flex-wrap: wrap; }
      & > label { min-inline-size: 100%; }
    }
  }

  /* Secondary navigation scrolls horizontally when its links exceed the available width. */
  .sysnav {
    display: flex; gap: .5rem;
    padding-block: .6rem .75rem;
    border-block-end: var(--hairline);
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
    overscroll-behavior-x: contain;
    font-size: var(--t-sub);

    & a {
      color: var(--label-secondary); text-decoration: none;
      padding: .4rem .9rem; border-radius: 999px;
      border: .5px solid transparent;
      background: transparent;
      line-height: 1; white-space: nowrap; flex: none;
    }
    & a:hover { color: var(--label);
                background: color-mix(in srgb, CanvasText 5%, var(--card)); }
    & a[aria-current="page"] {
      color: var(--label); background: var(--fill); border-color: transparent;
      font-weight: 600;
    }
  }

  .status-summary {
    display: flex; align-items: center; gap: 1rem;
    max-inline-size: 640px; margin-inline: auto; padding-block: 1rem;
    & h2 { font-size: var(--t-header); margin: 0 0 .5rem; }
    & p { margin: 0; overflow-wrap: anywhere; }
  }
  .status-page > .card { max-inline-size: 640px; margin: 0 auto 1.5rem; }
  .status-page > .card > a, .status-diagnostics .sysnav a {
    display: inline-flex; align-items: center; min-block-size: 44px;
  }
  .status-diagnostics summary { min-block-size: 44px; align-content: center; cursor: pointer; }
  .server-details {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem 1rem;
    & dd { margin: 0; text-align: end; overflow-wrap: anywhere; }
  }
  .status-symbol {
    display: block; inline-size: 48px; block-size: 48px; flex: none;
  }
  .status-symbol.status-starting {
    box-sizing: border-box; background: none; border-radius: 50%;
    border: 6px solid var(--separator); border-top-color: var(--label-secondary);
    animation: status-spin 1s linear infinite;
  }
  @keyframes status-spin { to { transform: rotate(360deg); } }
  .server-settings { max-inline-size: 42rem; }
  .server-settings .card { margin-block-end: var(--space-group); }
  .server-settings summary { min-block-size: 44px; align-content: center; cursor: pointer; }
  .server-overview { padding: 1.25rem 1rem 1.5rem; margin-block-end: var(--space-group); text-align: center; }
  .server-status-link {
    display: block;
    color: var(--label); text-decoration: none; min-block-size: 44px;
    & .status-summary { flex-direction: column; min-inline-size: 0; margin: 0; padding-block: .5rem 1rem; gap: .75rem; }
    & .status-symbol { inline-size: 72px; block-size: 72px; }
    & .status-verdict { display: flex; align-items: center; justify-content: center; gap: .5rem; }
    & .status-summary h2 { margin: 0; font-size: 1.176rem; overflow-wrap: anywhere; }
  }
  .server-address {
    padding-block-start: .25rem;
    & p { margin-block: .25rem 0; color: var(--label-secondary); font-size: var(--t-sub); }
  }
  .navigation-disclosure { display: inline-flex; flex: none; color: var(--label-secondary); }
  [dir="rtl"] .navigation-disclosure { transform: scaleX(-1); }
  .server-setting-copy { display: flex; flex-direction: column; gap: .25rem; }
  .server-overview-rows { padding-block-end: 2.5rem; }
  .server-overview-rows .card { margin-block: 0 1rem; padding-block: 0; }
  .server-overview-rows .server-setting-label > .localish-icon { inline-size: 24px; block-size: 24px; }
  .server-access > .section-title { margin-inline: 1.25rem; color: var(--label-secondary); font-weight: 400; }
  .server-overview-rows .server-setting { padding-block: 1rem; }
  .server-setting-value { display: flex; align-items: center; gap: .5rem; margin-inline-start: auto; }
  .server-settings .navigation-rows > a { color: var(--label); }
  .server-setting-label > .localish-icon { color: var(--accent); }
  .server-settings summary::marker { color: var(--label-secondary); }
  .server-setting-label { display: flex; align-items: center; gap: var(--space-row); }
  .server-settings .server-maintenance {
    padding-block: .25rem;
    & > details + details { border-block-start: var(--hairline); }
  }
  .server-setting { justify-content: space-between; gap: var(--space-row); flex-wrap: wrap; }
  .navigation-rows {
    margin-block: var(--space-row);
    & > a {
      display: flex; align-items: center; min-block-size: 44px;
      padding-block: var(--space-row);
      border-block-end: var(--hairline);
    }
    & > a:last-child { border-block-end: none; }
  }
  .service-overview {
    padding-block-end: var(--space-group);
    border-block-end: var(--hairline);
    & > :last-child { margin-block-end: 0; }
    & > [data-connection-action] {
      display: flex; inline-size: fit-content; margin-inline: auto;
    }
  }
  .service-settings {
    margin-block-start: var(--space-group);
    & > summary { padding-block: var(--space-row); }
  }
  .service-access > a > span {
    display: grid; gap: .25rem;
    & .caption { margin: 0; }
  }
  .service-review-head {
    display: flex; align-items: center; gap: var(--space-group); margin-block-end: var(--space-row);
    & h1 { margin: 0; font-size: var(--t-section); line-height: 1.125; }
  }
  .member-summary {
    padding: var(--space-row) 1.25rem;
    & > span { margin-inline-end: var(--space-row); }
  }
  .account-actions > summary {
    padding: var(--space-row) 1.25rem;
    min-block-size: 44px;
    align-content: center;
    cursor: pointer;
  }
  .member-actions { padding: var(--space-row) 1.25rem; border-block-start: var(--hairline); }
  .member-actions > span { display: flex; gap: .5rem; flex-wrap: wrap; }
  #invitations .list { background: transparent; border: 0; box-shadow: none; margin-block-end: 0; }
  #invitations .list-row { padding-inline: 0; }

  /* Audit filter row */
  .filter-row {
    display: flex; gap: .6rem; align-items: center; flex-wrap: wrap;
    margin-block-end: 1rem;

    & select, & input { margin: 0; font-size: var(--t-sub);
                        padding: .35rem .6rem; inline-size: auto; }
  }

  /* The log tail — surface recipe comes from the shared rule above */
  pre.log {
    padding: 1rem 1.25rem;
    font-size: var(--t-sub); line-height: 1.5;
    max-block-size: 32rem; overflow: auto;
    white-space: pre-wrap; overflow-wrap: anywhere;
  }

  /* Add Service: catalog rows — name/description left, one action right */
  .catalog-entry {
    display: flex; align-items: center; gap: 1rem;
    padding-block: .7rem;
    &:not(:nth-of-type(1)) { border-block-start: var(--hairline); }
    & .entry-text { flex: 1; min-inline-size: 0; }
    & .entry-text p { margin: .15rem 0 0; }
    & form { flex-shrink: 0; }
    @container (max-width: 24rem) {
      flex-wrap: wrap;
      & .entry-text { flex-basis: calc(100% - 4rem); }
      & form { margin-inline-start: 3.35rem; }
    }
  }

  .install-review { max-inline-size: 46rem; }
  .install-review form.inline { display: flex; flex-wrap: wrap; gap: var(--space-row); }
  .review-value {
    margin-block: 0; padding-block: var(--space-row); border-block-end: var(--hairline);
    & dt { color: var(--label-secondary); font-size: var(--t-sub); margin-block-end: .35rem; }
    & dd { margin: 0; overflow-wrap: anywhere; line-height: var(--lh-prose); }
  }

  /* Manifest review: canonical JSON, or a line diff on updates */
  pre.diff {
    font-size: var(--t-sub); line-height: 1.5;
    background: var(--card); border: 1px solid var(--separator);
    border-radius: .6rem; padding: .75rem 1rem;
    overflow-x: auto;

    & span { display: block; white-space: pre; }
    & .add { background: light-dark(#e6f6ea, #15281b); }
    & .del { background: light-dark(#fdebec, #2c181a); }
  }
}

@layer utilities {
  .subtitle     { color: var(--label-secondary); font-size: var(--t-body); margin: 0 0 1.5rem; }
  .footnote, .caption { color: var(--label-secondary); font-size: var(--t-sub); }
  .status-good  { color: var(--green); }
  .status-bad   { color: var(--red); }
  .status-warn  { color: var(--orange); }
  .inline       { display: inline; }
  /* A modal sheet owns the viewport: the page beneath neither scrolls
     nor rubber-bands (showModal already makes it inert to clicks).
     BOTH roots — iOS ignores overflow:hidden on body alone. */
  html.sheet-open,
  html.sheet-open body { overflow: hidden; }

  /* Auth cards */
  .brand-row    { display: flex; justify-content: center; margin-block-end: 1.5rem; }
  .gap-above    { margin-block-start: 1rem; }
  .consent-lead { font-size: var(--t-body); margin: 0 0 .5rem; }
  .scope-list   { font-size: var(--t-sub); padding-inline-start: 1.2rem; margin: 0 0 1.5rem; }
  /* Sheet configuration section */
  .config-section { margin-block: var(--space-group); }
  form.autosave button:not([data-retry]) { display: none; }
  [data-service-setup] { margin-block-end: var(--space-group); }
  .service-actions { margin-block-start: var(--space-group); padding-block-start: var(--space-group); border-block-start: var(--hairline); }

  .list-header.plain { background: none; }
  .footnote.tight { margin: .25rem 0 .75rem; }
  .snippet form  { gap: .4rem; }
  .snippet form input { margin: 0; font-size: var(--t-sub); padding: .35rem .6rem; }
  dialog.sheet > .caption { margin-block: 1.25rem 0; }

  .sr-only      { position: absolute; inline-size: 1px; block-size: 1px;
                  clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
  .center       { text-align: center; }
  .row          { display: flex; gap: .75rem; }
  .grow         { flex: 1; }
}

@layer components {
  main.hosting-wizard { max-width: 42rem; padding-block-start: 2rem; }
  .hosting-wizard {
    & h1 { font-size: var(--t-section); }
    & h2 { font-size: var(--t-header); margin-block-end: .75rem; }
    & .card { margin-block-end: 1.5rem; }
    & fieldset { border: var(--hairline); border-radius: var(--radius-control); padding: .75rem; min-inline-size: 0; }
    & label:has(input:is([type="radio"], [type="checkbox"])) {
      display: flex; align-items: start; gap: .5rem; min-block-size: 44px;
      font-size: var(--t-body); color: var(--label);
      & input { inline-size: auto; flex-shrink: 0; margin: .25rem 0 0; }
    }
    & fieldset p { overflow-wrap: anywhere; margin-block: 0 .75rem; }
  }
  .hosting-steps {
    list-style: none;
    padding: 0;
    display: grid;
    gap: .75rem;
    & li { display: flex; gap: .75rem; align-items: start; }
    & li p { margin-block: .25rem 0; }
    & li[aria-current="step"] .hosting-step-number { color: var(--link); }
  }
  .hosting-step-number { min-inline-size: 1.5rem; font-weight: 600; }
  .hosting-address { overflow-wrap: anywhere; }
  .hosting-qr { display: block; max-inline-size: 100%; block-size: auto; margin-block: 1rem; image-rendering: pixelated; }
}

@layer components {
  .page-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-block-end: var(--space-group); }
  .page-heading h1 { margin-bottom: 0; }
  .workspace-notice { margin-block: 1rem; }
  .workspace-notice h2 { font-size: var(--t-header); }
  .empty-workspace { text-align: center; padding: 2.5rem 1.5rem; }
  .connection-task { max-width: 680px; margin-inline: auto; }
  .connection-task > h1 { margin-top: 1.5rem; }
  .connection-methods {
    background: var(--card); border-radius: var(--radius);
    padding-inline: var(--space-group);
    & a { color: var(--label); gap: var(--space-row); justify-content: space-between; }
    & a::after { content: "›"; color: var(--label-secondary); }
    & small { display: block; margin-block-start: .25rem; }
  }
  .connection-instructions > .snippet { margin-block: var(--space-group); flex-wrap: wrap; }
  .connection-instructions > .snippet > label { flex-basis: 100%; }
  .connection-instructions > .snippet > pre { flex-basis: 100%; white-space: pre-wrap; overflow-wrap: anywhere; }
  .connection-methods + .section-title { margin-block-start: var(--space-section); }
  .connection-steps {
    padding-inline-start: 1.5rem; margin-block: var(--space-section);
    & li { padding-inline-start: .5rem; margin-block: var(--space-group); }
    & p { margin-block: .25rem 0; }
  }
  .task-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: var(--space-row); margin-block-start: var(--space-group); }
  .app-permission { margin-block: 1rem; overflow-wrap: anywhere; }
  .app-permission h3 { margin: 0; }
  .app-permission form { margin-top: 1rem; }
  @media (max-width: 37.5em) {
    .list .invitation-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .invitation-actions > .grow { grid-column: 1 / -1; }
  }
}

@layer components {
  .observation-time {
    display: flex; flex-wrap: wrap; align-items: baseline; gap: .35rem .75rem; margin-block: 1rem;
    & p { margin: 0; }
    & [data-stale-message] { flex-basis: 100%; }
    & a { display: inline-flex; align-items: center; min-height: 44px; }
  }
}
