/*
 * The signed-in dashboard, plus the small signed-out pages that belong to it -
 * login, signup, verification results and error pages.
 *
 * Loaded after base.css, which owns the layer order and the tokens these rules
 * are written against. Nothing here restates a colour: change --ink or --line
 * in base.css and every component below follows.
 */

@layer components {
  /* ══ Page shell ═══════════════════════════════════════════════════════ */

  .app {
    min-block-size: 100%;
    background: var(--surface-sunken);
  }

  .app__header {
    background: var(--surface);
    border-block-end: 1px solid var(--line);
  }

  .app__bar {
    max-inline-size: var(--shell);
    margin-inline: auto;
    padding: 0.75rem var(--gutter);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
  }

  .app__main {
    max-inline-size: var(--shell);
    margin-inline: auto;
    padding: 2rem var(--gutter);
  }

  /* The wordmark, on the dashboard and on the standalone auth pages.
     Same lockup as the public site: mark, hairline, "Cloud". */
  .brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;

    & img {
      block-size: 22px;
      inline-size: auto;
    }
  }

  .brand__suffix {
    padding-inline-start: 0.625rem;
    border-inline-start: 1px solid var(--line);
    font-size: var(--text-base);
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--ink-muted);
  }

  .brand--lg {
    justify-content: center;

    & img {
      block-size: 26px;
    }
  }

  /* ── Primary navigation ─────────────────────────────────────────────── */

  .nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: var(--text-sm);
  }

  .nav__link {
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius);
    color: var(--ink-muted);

    &:hover {
      background: var(--surface-sunken);
      color: var(--ink);
    }

    &[aria-current="page"] {
      background: var(--line-soft);
      font-weight: 500;
      color: var(--ink);
    }
  }

  .nav__signout {
    margin-inline-start: 0.5rem;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius);
    color: var(--ink-muted);

    &:hover {
      background: var(--surface-sunken);
      color: var(--ink);
    }
  }

  /* ══ Buttons ══════════════════════════════════════════════════════════ */

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: var(--text-sm);
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: background-color 120ms, border-color 120ms, color 120ms;

    &:disabled,
    &[disabled] {
      opacity: 0.5;
      cursor: not-allowed;
    }
  }

  .btn--primary {
    background: var(--ink);
    color: #fff;

    &:hover:not(:disabled) {
      background: var(--ink-soft);
    }
  }

  .btn--secondary {
    background: var(--surface);
    border-color: var(--line-strong);
    color: var(--ink);

    &:hover:not(:disabled) {
      background: var(--surface-sunken);
    }
  }

  .btn--danger {
    background: var(--danger-solid);
    color: #fff;

    &:hover:not(:disabled) {
      background: var(--danger-solid-hover);
    }
  }

  /* Reads as a link, sits in a row of buttons. */
  .btn--quiet {
    color: var(--ink-muted);

    &:hover:not(:disabled) {
      color: var(--ink);
    }
  }

  .btn--sm {
    padding: 0.375rem 0.75rem;
  }

  .btn--block {
    inline-size: 100%;
  }

  .btn--busy:disabled {
    opacity: 0.6;
    cursor: wait;
  }

  /* Holds two labels - the resting one and the in-flight one - in the same
     grid cell, so the button is as wide as the longer of them and does not
     resize when they trade places. */
  .btn--swap {
    display: inline-grid;
    grid-template-areas: "label";
    align-items: center;

    & > * {
      grid-area: label;
    }
  }

  /* A link that behaves like body text but is clearly clickable. */
  .link {
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 2px;

    &:hover {
      color: var(--ink);
    }
  }

  .link--danger {
    color: var(--danger-text);
    font-weight: 500;

    &:hover {
      text-decoration: underline;
    }
  }

  /* ══ Cards and sections ═══════════════════════════════════════════════ */

  .card {
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }

  .card--danger {
    border-color: var(--danger-line);

    & > .card__title {
      border-block-end-color: color-mix(in srgb, var(--danger-line) 60%, white);
      color: var(--danger-text);
    }
  }

  .card--plain {
    overflow: visible;
  }

  /* The bar across the top of a card. Sits flush, so it carries its own rule. */
  .card__title {
    padding: 0.75rem 1.25rem;
    border-block-end: 1px solid var(--line-soft);
    font-size: var(--text-sm);
    font-weight: 500;
  }

  .card__title--split {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .card__body {
    padding: 1rem 1.25rem;
  }

  .card__body--roomy {
    padding: 1.25rem;
  }

  /* A heading inside a card body, rather than in the bar across its top. */
  .card__heading {
    font-weight: 500;
  }

  .card__foot {
    padding: 0.75rem 1.25rem;
    border-block-start: 1px solid var(--line-soft);
    font-size: var(--text-xs);
    color: var(--ink-muted);
  }

  .card__note {
    margin-block-start: 0.125rem;
    font-size: var(--text-xs);
    color: var(--ink-muted);
  }

  /* "Nothing here" inside a card that would otherwise hold a table. */
  .card__empty {
    padding: 2rem 1.25rem;
    text-align: center;
    font-size: var(--text-sm);
    color: var(--ink-muted);
  }

  /* The "nothing here yet" box. */
  .empty {
    background: var(--surface);
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-lg);
    padding: 3rem 1.5rem;
    text-align: center;
  }

  .empty__title {
    font-weight: 500;
  }

  .empty__body {
    max-inline-size: 24rem;
    margin: 0.25rem auto 0;
    font-size: var(--text-sm);
    color: var(--ink-muted);
  }

  /* ══ Page headings ════════════════════════════════════════════════════ */

  .page-head {
    margin-block-end: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
  }

  .page-title {
    font-size: var(--text-xl);
    font-weight: 600;
    letter-spacing: -0.025em;
  }

  .page-sub {
    margin-block-start: 0.25rem;
    font-size: var(--text-sm);
    color: var(--ink-muted);
  }

  /* ══ Banners ══════════════════════════════════════════════════════════ */

  /* Tone comes from the modifier; the shape is shared. Every tone set in
     base.css supplies bg/line/text, so a new tone is three tokens, not a
     new rule. */
  .banner {
    padding: 0.75rem 1rem;
    border: 1px solid;
    border-radius: var(--radius);
    font-size: var(--text-sm);

    & p + p {
      margin-block-start: 0.25rem;
    }

    & a {
      font-weight: 500;
      text-decoration: underline;
    }
  }

  .banner__title {
    font-weight: 500;
  }

  .banner--ok {
    background: var(--ok-bg);
    border-color: var(--ok-line);
    color: var(--ok-text);
  }

  .banner--warn {
    background: var(--warn-bg);
    border-color: var(--warn-line);
    color: var(--warn-text);
  }

  .banner--danger {
    background: var(--danger-bg);
    border-color: var(--danger-line);
    color: var(--danger-text);
  }

  .banner--split {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
  }

  /* Stacked above the page content rather than sitting inside a .stack. */
  .banner--page {
    margin-block-end: 1.5rem;
  }

  .banner__list {
    margin-block-start: 0.5rem;
    list-style: disc;
    padding-inline-start: 1.25rem;
  }

  .banner--flush {
    border: 0;
    border-block-end: 1px solid var(--danger-line);
    border-radius: 0;
    padding-inline: 1.25rem;
  }

  /* ══ Badges ═══════════════════════════════════════════════════════════ */

  /* Emitted by the helpers in src/dashboard/render.ts. The tone modifiers
     below are the full set those helpers can produce. */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-pill);
    font-size: var(--text-xs);
    font-weight: 500;
    white-space: nowrap;
    background: var(--neutral-bg);
    color: var(--neutral-text);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--neutral-line) 70%, transparent);
  }

  .badge__dot {
    inline-size: 0.375rem;
    block-size: 0.375rem;
    border-radius: var(--radius-pill);
    background: var(--neutral-dot);
  }

  .badge--ok {
    background: var(--ok-bg);
    color: var(--ok-text);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ok-line) 90%, transparent);

    & > .badge__dot {
      background: var(--ok-dot);
    }
  }

  .badge--warn {
    background: var(--warn-bg);
    color: var(--warn-text);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--warn-line) 90%, transparent);

    & > .badge__dot {
      background: var(--warn-dot);
    }
  }

  .badge--danger {
    background: var(--danger-bg);
    color: var(--danger-text);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--danger-line) 90%, transparent);

    & > .badge__dot {
      background: var(--danger-dot);
    }
  }

  /* ══ Forms ════════════════════════════════════════════════════════════ */

  .field + .field {
    margin-block-start: 1rem;
  }

  .field__label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
  }

  .field__hint {
    margin-block-start: 0.25rem;
    font-size: var(--text-xs);
    color: var(--ink-muted);
  }

  .input {
    display: block;
    inline-size: 100%;
    margin-block-start: 0.25rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: var(--text-sm);
    box-shadow: var(--shadow-sm);

    &::placeholder {
      color: var(--ink-faint);
    }

    &:focus {
      outline: none;
      border-color: var(--ink);
      box-shadow: var(--focus-ring);
    }

    &:focus-visible {
      outline: none;
    }
  }

  .input--danger:focus {
    border-color: var(--danger-solid);
    box-shadow: 0 0 0 1px var(--danger-solid);
  }

  .form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--text-sm);
    color: var(--ink-soft);

    /* One property instead of a bespoke checkbox; the native control keeps
       its keyboard and screen-reader behaviour. */
    & input {
      accent-color: var(--ink);
    }
  }

  /* An input with a fixed suffix glued to it - `myshop` + `.squaark.com`. */
  .input-group {
    display: flex;
    margin-block-start: 0.25rem;
    box-shadow: var(--shadow-sm);
    border-radius: var(--radius);

    & > .input {
      margin-block-start: 0;
      min-inline-size: 0;
      flex: 1;
      border-start-end-radius: 0;
      border-end-end-radius: 0;
      box-shadow: none;
    }
  }

  .input-group__suffix {
    display: inline-flex;
    align-items: center;
    padding-inline: 0.75rem;
    border: 1px solid var(--line-strong);
    border-inline-start: 0;
    border-start-end-radius: var(--radius);
    border-end-end-radius: var(--radius);
    background: var(--surface-sunken);
    font-size: var(--text-sm);
    color: var(--ink-muted);
  }

  /* ── Plan picker ────────────────────────────────────────────────────── */
  /* Shown when subscribing, not when creating a store. Compact on purpose: by
     this point the customer has already read the pricing page. */

  .plan-picker {
    display: grid;
    gap: 0.5rem;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  }

  /* :has() lets the label style itself from the radio inside it, so selection
     needs no JavaScript and no duplicated class on the wrapper. */
  .plan-option {
    display: grid;
    gap: 0.125rem;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;

    &:hover {
      border-color: var(--ink-faint);
    }

    &:has(input:checked) {
      border-color: var(--ink);
      box-shadow: var(--focus-ring);
    }

    &:has(input:focus-visible) {
      outline: 2px solid var(--ink);
      outline-offset: 2px;
    }

    & input {
      position: absolute;
      opacity: 0;
      pointer-events: none;
    }
  }

  .plan-option__name {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: var(--text-sm);
    font-weight: 600;
  }

  .plan-option__tick {
    display: none;
    inline-size: 1rem;
    block-size: 1rem;
  }

  .plan-option:has(input:checked) .plan-option__tick {
    display: block;
  }

  .plan-option__price {
    font-size: var(--text-lg);
    font-weight: 600;

    & span {
      font-size: var(--text-xs);
      font-weight: 400;
      color: var(--ink-muted);
    }
  }

  .plan-option__note {
    font-size: var(--text-xs);
    color: var(--ink-muted);
  }

  /* ── Ticked feature list ────────────────────────────────────────────── */

  .ticks {
    margin-block-start: 1rem;
    display: grid;
    gap: 0.375rem;
    font-size: var(--text-sm);
    color: var(--ink-soft);

    & li {
      display: flex;
      gap: 0.5rem;
    }

    & svg {
      flex: none;
      margin-block-start: 0.125rem;
      inline-size: 1rem;
      block-size: 1rem;
      color: var(--ok-dot);
    }
  }

  /* ══ Data display ═════════════════════════════════════════════════════ */

  /* Label/value rows inside a card, divided by hairlines. */
  .rows {
    font-size: var(--text-sm);

    & > div {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 1rem;
      padding: 0.75rem 1.25rem;
    }

    & > div + div {
      border-block-start: 1px solid var(--line-soft);
    }

    & dt {
      color: var(--ink-muted);
    }

    & dd {
      font-weight: 500;
      text-align: end;
    }
  }

  .rows__id {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 400;
    color: var(--ink-muted);
  }

  /* A row whose term carries a description beneath it, and a value opposite. */
  .rows--pairs {
    & > div {
      align-items: baseline;
    }

    & dt {
      font-weight: 500;
      color: var(--ink);
    }

    & dd {
      font-weight: 400;
      text-align: start;
      color: var(--ink-muted);
    }
  }

  .rows__value {
    /* Never mid-wrap a timestamp or a price - both read as two facts when
       broken across lines. */
    white-space: nowrap;
    font-size: var(--text-sm);
    color: var(--ink-muted);

    & b {
      font-weight: 600;
      color: var(--ink);
    }
  }

  .table {
    font-size: var(--text-sm);

    & thead {
      font-size: var(--text-xs);
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--ink-muted);
    }

    & thead tr {
      border-block-end: 1px solid var(--line-soft);
    }

    & tbody tr + tr {
      border-block-start: 1px solid var(--line-soft);
    }

    & tfoot tr {
      border-block-start: 1px solid var(--line);
    }

    & :is(th, td) {
      padding: 0.75rem 1.25rem;
    }

    & thead :is(th, td) {
      padding-block: 0.5rem;
    }
  }

  .table__scroll {
    overflow-x: auto;
  }

  .table__num {
    text-align: end;
  }

  .table__strong {
    font-weight: 500;
  }

  .table__total {
    font-weight: 600;
  }

  .table__file {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--ink-muted);
  }

  .muted {
    color: var(--ink-muted);
  }

  .cap {
    color: var(--ink-faint);
  }

  /* ══ Dashboard: store list ════════════════════════════════════════════ */

  .stores {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  }

  .store-card {
    /* Column layout so the action row can be pushed to the bottom, keeping it
       on one line across cards of different heights. */
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
  }

  .store-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .store-card__name {
    min-inline-size: 0;

    & a {
      font-weight: 500;

      &:hover {
        text-decoration: underline;
      }
    }
  }

  .store-card__host {
    margin-block-start: 0.125rem;
    font-size: var(--text-sm);
    color: var(--ink-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .store-card__flags {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
    font-size: var(--text-xs);
    font-weight: 500;
    text-align: end;
  }

  .store-card__meta {
    /* The bottom margin, not the action row's top margin, sets the minimum
       gap - the action row's own margin is `auto`, which collapses to nothing
       on a card whose content already fills the height. */
    margin-block: 1rem 1.25rem;
    display: flex;
    gap: 1.5rem;
    font-size: var(--text-sm);

    & dt {
      color: var(--ink-muted);
    }

    & dd {
      margin-block-start: 0.125rem;
      font-weight: 500;
    }
  }

  .store-card__actions {
    margin-block-start: auto;
    padding-block-start: 1rem;
    border-block-start: 1px solid var(--line-soft);
    display: flex;
    gap: 0.5rem;
    font-size: var(--text-sm);
  }

  .store-card__manage {
    margin-inline-start: auto;
  }

  /* ══ Store detail ═════════════════════════════════════════════════════ */

  .store-head {
    margin-block-end: 1.5rem;
    border-block-end: 1px solid var(--line);
  }

  .store-head__top {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding-block-end: 1rem;
  }

  .store-head__title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: var(--text-xl);
    font-weight: 600;
    letter-spacing: -0.025em;
  }

  .store-head__host {
    margin-block-start: 0.25rem;
    font-size: var(--text-sm);
    color: var(--ink-muted);
  }

  .store-head__actions {
    display: flex;
    gap: 0.5rem;
  }

  /* Tabs. The active one is marked with aria-current, so the styling hangs
     off the same attribute a screen reader announces. */
  .tabs {
    display: flex;
    gap: 1.5rem;
    margin-block-end: -1px;
    font-size: var(--text-sm);
    overflow-x: auto;
  }

  .tabs__link {
    padding-block-end: 0.75rem;
    border-block-end: 2px solid transparent;
    color: var(--ink-muted);
    white-space: nowrap;

    &:hover {
      border-block-end-color: var(--line-strong);
      color: var(--ink-soft);
    }

    &[aria-current="page"] {
      border-block-end-color: var(--ink);
      font-weight: 500;
      color: var(--ink);
    }
  }

  .tabs__link--danger {
    &:hover {
      color: var(--danger-text);
    }

    &[aria-current="page"] {
      border-block-end-color: var(--danger-solid);
      color: var(--danger-text);
    }
  }

  /* Two-thirds / one-third on wide screens, stacked below. */
  .split {
    display: grid;
    gap: 1.5rem;

    @media (width >= 64rem) {
      grid-template-columns: 2fr 1fr;
    }
  }

  .usage {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));

    & > div {
      padding: 1rem 1.25rem;
    }

    & > div + div {
      border-inline-start: 1px solid var(--line-soft);
    }

    & dt {
      font-size: var(--text-sm);
      color: var(--ink-muted);
    }

    & dd {
      margin-block-start: 0.25rem;
      font-size: var(--text-lg);
      font-weight: 600;

      /* Nested so it outranks the dd rule above it - a figure we do not have
         is not a figure, and should not be set like one. */
      &.usage__none {
        font-size: var(--text-sm);
        font-weight: 400;
        color: var(--ink-faint);
      }
    }
  }

  /* The cap in "847 / unlimited" - also emitted by the of_limit helper. */
  .usage__unit {
    font-size: var(--text-sm);
    font-weight: 400;
    color: var(--ink-faint);
  }

  /* ══ Domain ═══════════════════════════════════════════════════════════ */

  .domain-state {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .domain-state__name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
  }

  .domain-note {
    margin-block-start: 0.5rem;
    font-size: var(--text-sm);
    color: var(--ink-muted);

    /* The reset makes every svg display:block, which would drop a spinner
       sitting mid-sentence onto a line of its own. */
    & > .spinner {
      display: inline-block;
      vertical-align: -0.2em;
      margin-inline-end: 0.375rem;
    }
  }

  .dns-record {
    margin-block-start: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    background: var(--surface-sunken);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    overflow-wrap: anywhere;
  }

  code.inline {
    padding-inline: 0.25rem;
    border-radius: var(--radius-sm);
    background: var(--line-soft);
  }

  .spinner {
    inline-size: 1rem;
    block-size: 1rem;
    flex: none;
    color: var(--ink-faint);
    animation: spin 1s linear infinite;

    & circle {
      opacity: 0.25;
    }

    & path {
      opacity: 0.75;
    }
  }

  @keyframes spin {
    to {
      rotate: 360deg;
    }
  }

  /* ══ Logs ═════════════════════════════════════════════════════════════ */

  .logs {
    display: grid;
    gap: 1rem;
  }

  .logs__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .logs__viewport {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--ink);
    box-shadow: var(--shadow-sm);
  }

  .logs__tail {
    max-block-size: 32rem;
    overflow: auto;
    padding: 1rem;
    font-size: var(--text-xs);
    line-height: 1.625;
    color: var(--line-soft);
    /* Alpine pins this to the bottom after each swap; browser scroll anchoring
       would otherwise fight it. */
    overflow-anchor: none;
  }

  .logs__empty {
    color: var(--ink-muted);
  }

  .logs__archive {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;

    & summary {
      padding: 0.75rem 1.25rem;
      font-size: var(--text-sm);
      font-weight: 500;
      cursor: pointer;
    }

    & table {
      border-block-start: 1px solid var(--line-soft);
    }

    & :is(td) {
      padding: 0.5rem 1.25rem;
    }
  }

  .logs__live {
    font-family: var(--font-sans);
    color: var(--ink-faint);
  }

  /* ══ Danger zone ══════════════════════════════════════════════════════ */

  .callout {
    margin-block-start: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    background: var(--surface-sunken);
    color: var(--ink-soft);
  }

  .modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgb(15 23 42 / 0.5);
  }

  .modal__panel {
    inline-size: 100%;
    max-inline-size: 28rem;
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
  }

  .modal__title {
    font-weight: 600;
  }

  .modal__body {
    margin-block-start: 0.5rem;
    font-size: var(--text-sm);
    color: var(--ink-soft);
  }

  .modal__actions {
    margin-block-start: 1.25rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
  }

  /* ══ Standalone pages: login, signup, errors, verification ════════════ */

  .single {
    display: grid;
    place-items: center;
    min-block-size: 100%;
    padding: 2.5rem var(--gutter);
    background: var(--surface-sunken);
  }

  .single__inner {
    inline-size: 100%;
    max-inline-size: 24rem;
  }

  .single__brand {
    margin-block-end: 2rem;
  }

  .single__title {
    font-size: var(--text-lg);
    font-weight: 600;
  }

  .single__alt {
    margin-block-start: 1.5rem;
    text-align: center;
    font-size: var(--text-sm);
    color: var(--ink-muted);

    /* The link is the point of the sentence, so it stays full-strength ink
       against the muted text around it. */
    & a {
      color: var(--ink);
    }
  }

  .single__form {
    margin-block-start: 1.25rem;

    & .btn {
      margin-block-start: 1.25rem;
    }
  }

  .notice {
    margin-block-start: 1rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid;
    border-radius: var(--radius);
    font-size: var(--text-sm);
  }

  .notice--ok {
    background: var(--ok-bg);
    border-color: var(--ok-line);
    color: var(--ok-text);
  }

  .notice--danger {
    background: var(--danger-bg);
    border-color: var(--danger-line);
    color: var(--danger-text);
  }

  /* Centred message pages - 404, 500, verification result. */
  .message {
    max-inline-size: 28rem;
    text-align: center;
  }

  .message__status {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--ink-faint);
  }

  .message__title {
    margin-block-start: 0.5rem;
    font-size: var(--text-xl);
    font-weight: 600;
    letter-spacing: -0.025em;
  }

  .message__body {
    margin-block-start: 0.75rem;
    font-size: var(--text-sm);
    line-height: 1.625;
    color: var(--ink-soft);
  }

  .message__actions {
    margin-block-start: 2rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
  }

  .message__ref {
    margin-block-start: 2rem;
    font-size: var(--text-xs);
    color: var(--ink-faint);

    & span {
      font-family: var(--font-mono);
    }
  }

  .message__mark {
    display: grid;
    place-items: center;
    inline-size: 3rem;
    block-size: 3rem;
    margin-inline: auto;
    border-radius: var(--radius-pill);
    background: var(--ok-line);

    & svg {
      inline-size: 1.5rem;
      block-size: 1.5rem;
      color: var(--ok-text);
    }
  }

  /* ══ Status panels ════════════════════════════════════════════════════ */

  .status-panel {
    padding: 1.5rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
  }

  .status-panel__state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
  }

  .status-panel__message {
    margin-block-start: 0.75rem;
    font-size: var(--text-sm);
    color: var(--ink-muted);
  }

  .status-panel__actions {
    margin-block-start: 1rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
  }
}

@layer utilities {
  /* A vertical rhythm primitive: space between children, nothing around the
     edges. Used where the gap is the only thing a wrapper is there to set. */
  .stack {
    display: grid;
    gap: 1.5rem;
    align-content: start;
  }

  .stack--sm {
    gap: 1rem;
  }

  .stack--xs {
    gap: 0.75rem;
  }

  .prose-narrow {
    max-inline-size: 42rem;
    margin-inline: auto;
  }

  .prose-wide {
    max-inline-size: 48rem;
    margin-inline: auto;
  }

  .centred-page {
    max-inline-size: 28rem;
    margin-inline: auto;
    padding-block: 2.5rem;
    text-align: center;
  }

  /* Reserved by htmx swaps that may render nothing at all. */
  .empty\:hidden:empty {
    display: none;
  }
}

@layer components {
  /* ── Operator ────────────────────────────────────────────────────────────
     The platform metrics page. Everything here is read-only, so it is all
     display: no inputs, no states, nothing that needs a busy or error style. */

  .metrics {
    margin-block-end: 2.5rem;

    & > * + * {
      margin-block-start: 1rem;
    }
  }

  .section-title {
    font-size: var(--text-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-muted);
  }

  .section-sub {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--ink-soft);
    margin-block-end: 0.5rem;
  }

  /* Auto-fit rather than a fixed count: the same grid carries four cards on a
     laptop and one on a phone without a media query, and stays right if a
     fifth metric is added later. */
  .metric-grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
  }

  .metric {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1rem 1.125rem;
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
  }

  .metric__label {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-muted);
  }

  .metric__value {
    /* Tabular figures so a number changing on refresh doesn't shift the card
       around it, and lining across a row of cards. */
    font-variant-numeric: tabular-nums;
    font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
    font-weight: 650;
    line-height: 1.1;
    color: var(--ink);
  }

  .metric__note {
    font-size: var(--text-xs);
    color: var(--ink-muted);
    text-wrap: pretty;
  }

  .metric--hero {
    background: var(--ink);
    border-color: var(--ink);

    & .metric__label,
    & .metric__note {
      color: color-mix(in srgb, white 72%, transparent);
    }

    & .metric__value {
      color: white;
    }
  }

  .metric--warn {
    border-color: var(--warn-line);
    background: var(--warn-bg);

    & .metric__value {
      color: var(--warn-text);
    }
  }

  .metric--danger {
    border-color: var(--danger-line);
    background: var(--danger-bg);

    & .metric__value {
      color: var(--danger-text);
    }
  }

  /* Drawn server-side as a polyline; see sparkline() in routes/dashboard/
     operator.ts. preserveAspectRatio is none on the element so the line
     stretches to whatever width the card ends up. */
  .spark {
    inline-size: 100%;
    block-size: 2.25rem;
    overflow: visible;

    & polyline {
      fill: none;
      stroke: var(--ink-faint);
      stroke-width: 1.5;
      stroke-linecap: round;
      stroke-linejoin: round;
      vector-effect: non-scaling-stroke;
    }
  }

  .metric--hero .spark polyline {
    stroke: color-mix(in srgb, white 60%, transparent);
  }

  .leaks {
    display: grid;
    gap: 0.5rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
    list-style: none;
    padding: 0;
    margin: 0;
  }

  .leak {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-sunken);
    font-size: var(--text-sm);
    color: var(--ink-soft);
  }

  .leak__n {
    font-variant-numeric: tabular-nums;
    font-size: var(--text-lg);
    font-weight: 650;
    color: var(--ink);
  }

  /* Amber only when the count is non-zero - a leak of nobody is good news and
     should not be wearing a warning colour. */
  .leak--warn {
    border-color: var(--warn-line);
    background: var(--warn-bg);
    color: var(--warn-text);

    & .leak__n {
      color: var(--warn-text);
    }
  }

  .range {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
  }

  .range__option {
    padding: 0.375rem 0.75rem;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--ink-muted);
    text-decoration: none;

    & + & {
      border-inline-start: 1px solid var(--line);
    }

    &:hover {
      background: var(--surface-sunken);
      color: var(--ink);
    }

    /* Selection hangs off aria-current, so the accessible state and the visual
       one cannot drift apart. */
    &[aria-current] {
      background: var(--ink);
      color: white;
    }
  }

  .two-col {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
    align-items: start;
  }

  .nav__link--operator::before {
    content: "";
    display: inline-block;
    inline-size: 0.375rem;
    block-size: 0.375rem;
    margin-inline-end: 0.375rem;
    border-radius: var(--radius-pill);
    background: var(--ok-dot);
    vertical-align: middle;
  }
}
