@layer components {
  /* Logos keep their brand colours; the dark variant swaps in with the theme, as the release media do. */
  .service-logo { display: block; flex: none; object-fit: contain; }
  .service-logo--xs { width: 12px; height: 12px; }
  .service-logo--sm { width: 20px; height: 20px; }
  .service-logo--md { width: 28px; height: 28px; }
  .service-logo--lg { width: 40px; height: 40px; }
  .service-logo-dark { display: none; }
  :root[data-theme="dark"] .service-logo-dark { display: block; }
  :root[data-theme="dark"] .service-logo-light { display: none; }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .service-logo-dark { display: block; }
    :root:not([data-theme="light"]) .service-logo-light { display: none; }
  }
  .service-monogram {
    display: inline-grid; place-items: center; flex: none; border-radius: 8px; font-weight: 600;
    background: var(--jx-accent-soft); color: var(--jx-accent);
  }
  .service-monogram.service-logo--xs { border-radius: 3px; font-size: 11px; line-height: 1; } /* decorative initials */

  /* The connect card sits under a reply like a file card: logo, two lines, one button. */
  .connect-card {
    display: flex; gap: 12px; align-items: center; padding: 12px;
    border: 1px solid var(--border); border-radius: 9px; background: var(--card);
  }
  .connect-card-text { flex: 1; min-width: 0; }
  .connect-card-text p { margin: 0; }
  .connect-card-title { font-weight: 600; }
  @media (max-width: 767px) {
    .connect-card { flex-wrap: wrap; }
    .connect-card-action { min-height: var(--tap); width: 100%; }
  }

  /* The Services page: one card per service in a grid that falls to a single column on a phone. */
  .service-cards {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px;
    list-style: none; margin: 16px 0; padding: 0;
  }
  .service-card {
    display: flex; gap: 12px; align-items: flex-start; padding: 12px;
    border: 1px solid var(--border); border-radius: 12px; background: var(--card);
  }
  .service-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
  .service-card-text p, .service-card-name { margin: 0; }
  .service-card-name { font-size: 1rem; }
  .service-state { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; white-space: normal; }
  .service-state svg { flex: none; }
  .service-card-actions { display: flex; flex-direction: column; gap: 6px; }
  @media (max-width: 767px) {
    .service-cards { grid-template-columns: 1fr; }
    .service-card { flex-wrap: wrap; }
    .service-card-actions { width: 100%; }
    .service-card-action { min-height: var(--tap); width: 100%; }
  }

  /* Where to create one's key: a direct button, then numbered steps readable on a phone. */
  .key-guide { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
  .key-guide-steps { flex-basis: 100%; margin: 0; padding: 0; list-style: decimal inside; line-height: 1.5; }
  .key-guide-steps li { margin: 4px 0; }
  @media (max-width: 767px) {
    .key-guide .button { min-height: var(--tap); width: 100%; justify-content: center; }
  }

  /* One page per service: a head, numbered sections, an index of them and a sticky save bar. */
  .service-page { gap: 12px; }
  .service-back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 8px; color: var(--muted-foreground); text-decoration: none; }
  .service-head { display: flex; gap: 14px; align-items: flex-start; margin: 0 0 12px; }
  .service-head-title { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
  .service-head-title h1 { margin: 0; }
  .service-head p { margin: 2px 0 0; }
  .notice {
    border-radius: 8px; padding: 10px 12px; margin: 8px 0; font-size: 0.9rem; background: var(--secondary);
  }
  .notice--wait { background: var(--jx-wait-soft); }
  .notice--ok { background: var(--jx-ok-soft); }
  .notice--no { background: var(--jx-no-soft); }
  .notice--info { background: var(--jx-accent-soft); }
  .service-steps { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0 0 14px; padding: 0; counter-reset: step; }
  .service-steps li {
    counter-increment: step; display: flex; gap: 6px; align-items: center; font-size: 0.8125rem;
    padding: 4px 10px 4px 4px; border-radius: 99px; border: 1px solid var(--border); background: var(--card);
  }
  .service-steps li::before {
    content: counter(step); display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
    background: var(--secondary); font-size: 0.8125rem; font-weight: 600;
  }
  .service-steps li[aria-current="step"] { border-color: var(--jx-accent-line); background: var(--jx-accent-soft); color: var(--jx-accent); font-weight: 600; }
  .service-steps li.done::before { content: "✓"; background: var(--jx-ok-soft); color: var(--jx-ok); }
  .service-upgrade h2 { font-size: 1rem; margin: 0 0 4px; }
  .service-page-toc ol { display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 0 0 14px; padding: 0; list-style: none; font-size: 0.85rem; }
  .service-page-toc a {
    display: inline-block; padding: 2px 8px; border: 1px solid var(--border); border-radius: 99px;
    text-decoration: none; color: var(--foreground);
  }
  .service-page-form { display: flex; flex-direction: column; gap: 12px; }
  .service-section {
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--card);
    padding: 16px 18px; margin: 0 0 12px;
  }
  .service-section--danger { border-color: color-mix(in oklch, var(--jx-no) 35%, var(--border)); }
  .service-section--muted { background: transparent; border-style: dashed; }
  .service-section-head { display: flex; gap: 10px; align-items: flex-start; margin: 0 0 6px; }
  .service-section-head h2 { font-size: 1rem; margin: 0; }
  .service-section-head p { margin: 2px 0 0; }
  .service-section-number {
    display: inline-grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 50%;
    border: 1px solid var(--jx-accent-line); color: var(--jx-accent); font-size: 0.8125rem; font-weight: 600; margin-top: 1px;
  }
  .service-section fieldset { border: 0; margin: 12px 0; padding: 0; min-width: 0; }
  .service-section legend { font-weight: 500; padding: 0; margin: 0 0 6px; }
  .service-section .field { display: grid; gap: 4px; margin: 12px 0; }
  .service-section .mono { font-family: var(--font-mono); }
  .service-section .sub { display: grid; gap: 6px; margin: 6px 0 0 26px; }
  .service-select { max-width: 220px; }
  .service-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .service-choice {
    display: grid; align-content: start; gap: 4px; padding: 12px 14px; cursor: pointer;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--background);
  }
  .service-choice.is-on, .service-choice:has(input:checked) { border-color: var(--jx-accent-line); background: var(--jx-accent-soft); }
  .service-choice-title { display: flex; gap: 8px; align-items: center; font-weight: 600; }
  .service-choice-title input { margin: 0; }
  .service-sub { border-left: 3px solid var(--jx-accent-line); padding: 2px 0 2px 14px; margin: 12px 0 0; }
  [data-reveal-when][hidden] { display: none; }
  .service-check { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; min-height: 24px; }
  .service-tools { width: 100%; border-collapse: collapse; }
  .service-tools th, .service-tools td { padding: 8px 6px; text-align: left; vertical-align: top; }
  .service-tools td { width: 220px; }
  .service-tools .hint { display: block; }
  .service-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
  .service-buttons form { margin: 0; }
  .service-page-footer {
    position: sticky; bottom: 0; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; justify-content: flex-end;
    padding: 12px 16px; margin: 12px 0 0; border-top: 1px solid var(--border);
    background: color-mix(in oklch, var(--background) 92%, transparent);
  }
  .service-page-footer .hint { margin: 0 auto 0 0; }
  /* Where the floating tab bar shows, the save bar rests on it; the keyboard hides that bar, so no gap then. */
  @media (max-width: 1099px) {
    body:not(:has(:is(.app-main--flush, .app-main--stack))) .service-page-footer {
      bottom: calc(var(--tab-bar-height) + var(--tab-bar-bottom) + 8px);
    }
    html[data-keyboard] .service-page-footer { bottom: 0; }
  }
  @media (max-width: 767px) {
    .service-choices { grid-template-columns: 1fr; }
    .service-tools thead { display: none; }
    .service-tools tr { display: grid; gap: 4px; padding: 8px 0; border-bottom: 1px solid var(--border); }
    .service-tools th, .service-tools td { padding: 0; width: auto; }
    .service-buttons .button, .service-buttons form, .service-page-footer .button { flex: 1 1 100%; min-height: var(--tap); }
  }
}
