/**
 * Datacenter's components: one shared layer for the app, the sign-in pages and
 * the marketing site. Built only from the tokens in site.css (spacing, type,
 * control heights, radii, elevation, tones, motion). Area files (app-*.css)
 * arrange these; they do not restyle them.
 *
 *   page head and tabs     .app-page-head  .tabs-bar .tabs .tab .tab-count .tabs-more .tabs-sub
 *   cards                  .card .card-head .card-title .card-sub .card-actions .card-section
 *   buttons                .btn + .btn-sm|.btn-lg + .btn-primary|.btn-accent|.btn-secondary|.btn-quiet|.btn-danger|.btn-danger-solid  .btn-icon  .icon-button
 *   fields                 .field .field-label .field-input .field-hint .field-error .field-check .switch
 *   choices                .segmented .segment (2 or 3 options)  .chips .chip (filters)
 *   status                 .pill (+ -ok|-warn|-danger|-accent|-info, .pill-dot)  .badge  .checklist
 *   tables                 .table-wrap .table .num .table-empty
 *   feedback               .notice (+ -ok|-warn|-error)  .toast  .empty  .skeleton
 *   overlays               .dialog  .menu-list .menu-row  .cmdk  .kbd
 *   numbers                .stats (+ -2|-3|-4)  .stat .stat-wide .stat-label .stat-value .stat-word .stat-note .stat-body .spark-tile .delta
 *   sections and rows      .app-section-head .app-section-title .app-section-meta  .list .list-row .list-mark .list-main .list-title .list-sub .list-end
 *   the way in             .btn-go (actionLink)
 */

/* ---------------- app and sign-in sizes ----------------
   The app is a tool: 36px controls and 14px text in them. Sign-in pages
   use the 44px step. Every control on a phone is 44px, and fields are 16px
   so iOS does not zoom. */

body.app {
  --btn-h-sm: var(--ctl-h-sm);
  --btn-h-md: var(--ctl-h-md);
  --btn-h-lg: var(--ctl-h-lg);
  --btn-fs-sm: var(--fs-13);
  --btn-fs-md: var(--fs-14);
  --btn-fs-lg: var(--fs-15);
  --btn-px-sm: 10px;
  --btn-px-md: 14px;
  --btn-px-lg: 18px;
  --field-h: var(--ctl-h-md);
  --field-fs: var(--fs-14);
  --seg-h: var(--ctl-h-md);
}

.auth {
  --field-h: var(--ctl-h-lg);
  --btn-h-md: var(--ctl-h-lg);
  --btn-h-lg: var(--ctl-h-lg);
}

@media (max-width: 720px) {
  body.app,
  .auth {
    --btn-h-sm: var(--ctl-h-lg);
    --btn-h-md: var(--ctl-h-lg);
    --btn-h-lg: var(--ctl-h-lg);
    --field-h: var(--ctl-h-lg);
    --field-fs: var(--fs-16);
    --seg-h: var(--ctl-h-lg);
  }
}

/* iOS Safari zooms the whole page into any text field or select under 16px
   the moment it gets focus, and leaves it zoomed. On a phone or a tablet no
   field is smaller, whatever an area file sets (the board's tab select, the
   link form's mono fields). */
@media (max-width: 720px), (pointer: coarse) {
  :where(body) :is(input:not([type='checkbox'], [type='radio'], [type='range'], [type='file'], [type='color'], [type='hidden']), select, textarea) {
    font-size: max(var(--fs-16), 1em) !important;
  }
}

/* ---------------- page transitions ----------------
   Same-origin page loads cross-fade where the browser supports it
   (progressive: nothing happens elsewhere). The header and the side nav keep
   their own names, so only the page under them changes. */

@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }
}

::view-transition-group(root) {
  animation-duration: var(--dur-2);
  animation-timing-function: var(--ease-out);
}

.app-header {
  view-transition-name: app-header;
}

.app-nav {
  view-transition-name: app-nav;
}

/* ---------------- page head ----------------
   appHead() in src/layout.ts: the title, one line under it, actions right. */

.app-page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3) var(--space-4);
  margin-bottom: var(--space-6);
}

.app-page-head h1,
.app-page-head .app-page-name {
  font-size: var(--type-display);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: var(--track-title);
}

.app-page-head .app-page-sub {
  margin-top: var(--space-1);
  font-size: var(--type-body);
  color: var(--text-dim);
}

.app-page-head > .row {
  gap: var(--space-2);
}

/* A short trail above a title: "Links / spring-sale". */
.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  margin-bottom: var(--space-2);
  font-size: var(--type-small);
  color: var(--text-faint);
}

.crumbs a {
  color: var(--text-dim);
}

.app-section + .app-section {
  margin-top: var(--space-8);
}

/* A heading over a group of cards inside a page. */
.app-section-title,
.section-label {
  margin-bottom: var(--space-3);
  font-size: var(--type-heading);
  font-weight: var(--weight-title);
  line-height: var(--lh-snug);
}

@media (max-width: 860px) {
  .app-page-head h1 {
    font-size: var(--fs-24);
  }
}

/* ---------------- tabs ----------------
   Underlined tabs for a page's sections (appTabs). A count rides after the word.
   The bar draws the rule, so "More" (ui.js moves tabs that do not fit into it)
   sits on the same line as the tabs. */

.tabs-bar {
  display: flex;
  align-items: stretch;
  min-width: 0;
  border-bottom: 1px solid var(--line);
}

.tabs {
  display: flex;
  flex: 0 1 auto;
  gap: var(--space-1);
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab[hidden],
.tabs-more[hidden] {
  display: none;
}

.tabs-more {
  flex: 0 0 auto;
}

.tabs-more-button {
  cursor: pointer;
}

.tabs-more-button svg {
  width: 14px;
  height: 14px;
  transition: transform var(--dur-2) var(--ease-out);
}

.tabs-more[open] .tabs-more-button {
  color: var(--text);
}

.tabs-more[open] .tabs-more-button svg {
  transform: rotate(180deg);
}

.tabs-more .menu-list {
  top: calc(100% + 2px);
}

/* The pages inside one tab (appSubTabs): a segmented row under the tabs. */
.tabs-sub {
  margin-top: var(--space-4);
}

/* One step from the tab row, or the pages row under it, to the page, on
   every page: no page starts flush against the tabs. The dashboard
   (.dash and what sits over it) keeps its own spacing. */
:where(body.app) .tabs-bar + :not(.tabs-sub, .dash, .dash-setup, .dash-notice, script, style, template) {
  margin-top: var(--space-6);
}

:where(body.app) .tabs-sub + :not(script, style, template) {
  margin-top: var(--space-5);
}

.tabs::-webkit-scrollbar {
  display: none;
}

/* On a phone the section row tucks under the header while you scroll down and
   comes back the moment you scroll up (ui.js), like Safari's own bars: the
   numbers get the 57px it took. It stays while anything in it has focus. */
@media (max-width: 860px) {
  .app-nav {
    transition: transform var(--dur-3) var(--ease-out), opacity var(--dur-2) ease;
  }
  body.nav-tucked .app-nav:not(:focus-within) {
    transform: translateY(calc(-100% - 1px));
    opacity: 0;
    pointer-events: none;
  }
}

/* On a phone the row scrolls; its edges fade so a cut-off word reads as "more".
   The app's section row under the header does the same. */
@media (max-width: 860px) {
  .app-nav {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
  }
}

@media (max-width: 720px) {
  .tabs {
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 20px), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 20px), transparent 100%);
  }
  /* Once ui.js has fitted the row, nothing is cut off, so nothing fades. */
  .tabs-bar.is-fitted .tabs {
    -webkit-mask-image: none;
    mask-image: none;
  }
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--ctl-h-lg);
  padding: 0 var(--space-3);
  margin-bottom: -1px;
  font-size: var(--type-ui);
  font-weight: var(--weight-medium);
  color: var(--text-dim);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color var(--dur-1) ease, border-color var(--dur-2) var(--ease-out);
}

.tab:hover {
  color: var(--text);
  text-decoration: none;
}

.tab[aria-current='page'],
.tab[aria-selected='true'] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab:focus-visible {
  outline-offset: -4px;
}

.tab-count,
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: var(--fs-11);
  font-weight: var(--weight-strong);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  /* 6.1:1 light, 6.9:1 dark: --bg-active would drop under 4.5. */
  background: var(--bg-tint);
  box-shadow: inset 0 0 0 1px var(--line);
  border-radius: var(--r-pill);
}

.tab[aria-current='page'] .tab-count,
.badge-accent {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------------- buttons ----------------
   `.btn` plus at most one size and one look.
     size   .btn-sm   (default)   .btn-lg
     look   .btn-primary (green, the one main action)   .btn-secondary (default)
            .btn-accent (blue)   .btn-quiet   .btn-danger   .btn-danger-solid
     shape  .btn-icon (square)   .btn-block (full width)
   Every look changes only six colors. */

.btn {
  --btn-bg: var(--bg-raised);
  --btn-fg: var(--text);
  --btn-line: var(--line-control);
  --btn-bg-hover: var(--bg-hover);
  --btn-fg-hover: var(--btn-fg);
  --btn-line-hover: var(--line-strong);
  --btn-h: var(--btn-h-md);
  --btn-fs: var(--btn-fs-md);
  --btn-px: var(--btn-px-md);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  min-height: var(--btn-h);
  margin: 0;
  padding: 0 var(--btn-px);
  font: inherit;
  font-size: var(--btn-fs);
  font-weight: var(--weight-strong);
  line-height: 1.2;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-line);
  border-radius: var(--btn-radius);
  box-shadow: var(--btn-shadow, none);
  cursor: pointer;
  text-decoration: none;
  /* A label stays on one line wherever its button fits. A button wider than
     its whole box (large text, browser zoom, a 320px phone) breaks its words
     instead of running off the screen. It never shrinks to make room for its
     neighbors, so a row that fits today looks the same. */
  white-space: normal;
  text-align: center;
  flex-shrink: 0;
  max-width: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition:
    background-color var(--dur-1) ease,
    border-color var(--dur-1) ease,
    color var(--dur-1) ease,
    transform var(--dur-1) ease;
}

.btn:hover {
  color: var(--btn-fg-hover);
  background: var(--btn-bg-hover);
  border-color: var(--btn-line-hover);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn:disabled:hover,
.btn[aria-disabled='true']:hover {
  color: var(--btn-fg);
  background: var(--btn-bg);
  border-color: var(--btn-line);
}

/* Working: the words stay, a small ring turns before them. */
.btn[aria-busy='true'] {
  cursor: progress;
}

.btn[aria-busy='true']::before {
  content: '';
  width: 0.95em;
  height: 0.95em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: ui-spin 0.7s linear infinite;
}

@keyframes ui-spin {
  to {
    transform: rotate(360deg);
  }
}

.btn svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
}

.btn-sm {
  --btn-h: var(--btn-h-sm);
  --btn-fs: var(--btn-fs-sm);
  --btn-px: var(--btn-px-sm);
}

.btn-sm svg {
  width: 15px;
  height: 15px;
}

.btn-lg {
  --btn-h: var(--btn-h-lg);
  --btn-fs: var(--btn-fs-lg);
  --btn-px: var(--btn-px-lg);
}

.btn-primary,
.btn-cta {
  --btn-bg: var(--cta);
  --btn-fg: var(--cta-ink);
  --btn-line: transparent;
  --btn-bg-hover: var(--cta-hover);
  --btn-line-hover: transparent;
  --btn-shadow: var(--elev-1);
}

/* The main button keeps its green on hover (one green, site.css --cta) and
   draws a 1px ink ring inside it instead. Inside, not on the edge: on the dark
   ground an ink edge would melt into the page. */
.btn-primary:not(:disabled, [aria-disabled='true']):hover,
.btn-cta:not(:disabled, [aria-disabled='true']):hover {
  box-shadow: inset 0 0 0 1px var(--cta-ink), var(--elev-1);
}

.btn-accent {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-ink);
  --btn-line: transparent;
  --btn-bg-hover: var(--accent-hover);
  --btn-line-hover: transparent;
  --btn-shadow: var(--elev-1);
}

.btn-secondary {
  --btn-bg: var(--bg-raised);
  --btn-fg: var(--text);
  --btn-line: var(--line-control);
  --btn-shadow: var(--elev-1);
}

.btn-quiet {
  --btn-bg: transparent;
  --btn-fg: var(--text-dim);
  --btn-line: transparent;
  --btn-bg-hover: var(--bg-hover);
  --btn-fg-hover: var(--text);
  --btn-line-hover: transparent;
  font-weight: var(--weight-medium);
}

.btn-danger {
  --btn-bg: transparent;
  --btn-fg: var(--danger-fg);
  --btn-line: color-mix(in srgb, var(--danger) 45%, transparent);
  --btn-bg-hover: var(--danger-bg);
  --btn-fg-hover: var(--danger-text);
  --btn-line-hover: var(--danger-line);
}

.btn-danger-solid {
  --btn-bg: var(--danger);
  --btn-fg: var(--danger-ink);
  --btn-line: transparent;
  --btn-bg-hover: var(--danger-hover);
  --btn-fg-hover: var(--danger-ink);
  --btn-line-hover: transparent;
}

.btn-icon {
  flex: 0 0 auto;
  width: var(--btn-h);
  padding: 0;
}

.btn-block {
  display: flex;
  width: 100%;
}

/* A borderless square button: the theme toggle, the menu, a close. */
.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: var(--ctl-h-md);
  height: var(--ctl-h-md);
  padding: 0;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-1) ease, color var(--dur-1) ease;
}

@media (hover: hover) {
  .icon-button:hover {
    color: var(--text);
    background: color-mix(in srgb, var(--text) 6%, transparent);
  }
}

.icon-button:active {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 10%, transparent);
}

.icon-button svg {
  width: 17px;
  height: 17px;
}

@media (max-width: 720px) {
  .icon-button {
    width: var(--ctl-h-lg);
    height: var(--ctl-h-lg);
  }
}

/* The theme button shows where a click goes: the sun while dark, the moon
   while light. Chosen from <html> so the first paint is right. */
.theme-toggle .theme-icon-sun {
  display: none;
}

:root[data-theme='dark'] .theme-toggle .theme-icon-sun {
  display: inline;
}

:root[data-theme='dark'] .theme-toggle .theme-icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .theme-icon-sun {
    display: inline;
  }
  :root:not([data-theme]) .theme-toggle .theme-icon-moon {
    display: none;
  }
}

/* ---------------- segmented control ----------------
   For two or three choices that switch a view. A sunken track with the
   chosen one raised on it, the same everywhere (and in the dashboard).
   <div class="segmented" role="tablist"><button class="segment" role="tab" aria-selected="true">..</button></div>
   Links work too: <a class="segment" aria-current="page">. So do radios:
   <label><input type="radio" class="visually-hidden"><span class="segment">..</span></label>. */

.segmented {
  --seg-h: var(--ctl-h-md);
  display: inline-flex;
  gap: 2px;
  max-width: 100%;
  min-height: var(--seg-h);
  padding: 3px;
  background: var(--bg-tint);
  border: 1px solid var(--line);
  border-radius: calc(var(--r-md) + 2px);
}

.segment {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 0 0 auto;
  min-height: calc(var(--seg-h) - 8px);
  margin: 0;
  padding: 0 var(--space-3);
  font: inherit;
  font-size: var(--fs-13);
  font-weight: var(--weight-strong);
  line-height: 1.2;
  white-space: nowrap;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--dur-2) var(--ease-out), color var(--dur-1) ease, box-shadow var(--dur-2) ease;
}

.segment:hover {
  color: var(--text);
  text-decoration: none;
}

.segment[aria-selected='true'],
.segment[aria-current='page'],
.segment[aria-checked='true'],
.segment[aria-pressed='true'],
input:checked + .segment,
.segment:has(input:checked) {
  color: var(--text);
  background: var(--bg-raised);
  border-color: var(--line);
  box-shadow: var(--elev-1);
}

/* A finger on a phone: the segment keeps its look and gains 8px of tap area
   above and below, so the row reads 44px to a thumb. */
@media (pointer: coarse), (max-width: 720px) {
  .segment {
    position: relative;
  }
  .segment::after {
    content: '';
    position: absolute;
    inset: -8px 0;
  }
}

input:focus-visible + .segment,
.segment:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.segment .count,
.segment .pill {
  margin-left: 2px;
}

@media (max-width: 480px) {
  .segmented {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
  }
  /* Equal shares of the row, never narrower than their words: with large text
     a segment that does not fit moves to a second row instead of overlapping
     its neighbor. */
  .segment {
    flex: 1 1 0;
    min-width: max-content;
    padding-inline: var(--space-2);
  }
}

/* ---------------- form fields ----------------
   field() in src/ui.ts writes:
   <div class="field">
     <label class="field-label" for="x">Email</label>
     <input class="field-input" id="x">
     <p class="field-hint">..</p>   <p class="field-error">..</p>
   </div> */

.form {
  display: grid;
  gap: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  margin: 0;
}

.field-label {
  font-size: var(--type-small);
  font-weight: var(--weight-medium);
  line-height: var(--lh-snug);
  color: var(--text);
}

.field-optional {
  font-weight: 400;
  color: var(--text-faint);
}

.field-hint {
  font-size: var(--type-small);
  line-height: 1.45;
  color: var(--text-dim);
}

.field-input {
  width: 100%;
  min-height: var(--field-h);
  margin: 0;
  padding: 6px var(--field-px);
  font: inherit;
  font-size: var(--field-fs);
  line-height: var(--lh-snug);
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--line-input);
  border-radius: var(--field-radius);
  transition: border-color var(--dur-1) ease, box-shadow var(--dur-2) ease;
}

/* Safari on iPhone centers a date or time in its field; every other field
   reads from the left, so these do too (the custom range, notes, a flow wait). */
.field-input::-webkit-date-and-time-value {
  text-align: start;
}

textarea.field-input {
  min-height: calc(var(--field-h) * 2.4);
  padding-block: var(--space-2);
  resize: vertical;
}

select.field-input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: calc(var(--field-px) + 22px);
  background-image: var(--select-chevron);
  background-repeat: no-repeat;
  background-position: right var(--field-px) center;
  background-size: 14px 14px;
  cursor: pointer;
}

/* Safari lays a long chosen option out past a narrow select's edge, and that
   overflow scrolls the page sideways on a phone (Settings, Currency: 6px at
   390). Clipping it keeps every one-line select inside its own box. */
select:not([multiple]):not([size]) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A file picker: the button looks like a secondary button, the name stays one line. */
input[type='file'].field-input {
  display: flex;
  align-items: center;
  padding: 3px;
  font-size: var(--fs-13);
  color: var(--text-dim);
  text-overflow: ellipsis;
  cursor: pointer;
}

input[type='file']::file-selector-button {
  min-height: calc(var(--field-h) - 8px);
  margin-right: var(--space-3);
  padding: 0 var(--space-3);
  font: inherit;
  font-size: var(--fs-13);
  font-weight: var(--weight-strong);
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--line-control);
  border-radius: var(--r-sm);
  box-shadow: var(--elev-1);
  cursor: pointer;
}

input[type='file']::file-selector-button:hover {
  background: var(--bg-hover);
}

.field-input::placeholder {
  color: var(--text-faint);
  opacity: 1;
}

.field-input:hover:not(:disabled) {
  border-color: var(--text-dim);
}

/* A transparent outline, not none: Windows High Contrast paints it, since it drops box shadows.
   :focus-within too: a date field's focus sits on its day, month or year part, and Chromium
   then leaves the field itself without :focus, so it showed no ring from the keyboard. */
.field-input:focus,
.field-input:focus-within {
  outline: 2px solid transparent;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.field-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.field-input[aria-invalid='true'] {
  border-color: var(--danger);
}

.field-input[aria-invalid='true']:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent);
}

.field-error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: var(--type-small);
  line-height: 1.4;
  font-weight: var(--weight-medium);
  color: var(--danger-fg);
}

/* A mark before the words, so the error is not told by color alone. */
.field-error::before {
  content: '!';
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 1.25em;
  height: 1.25em;
  margin-top: 0.05em;
  font-size: 0.85em;
  font-weight: 700;
  line-height: 1;
  color: var(--bg-raised);
  background: var(--danger-fg);
  border-radius: 50%;
}

.field-check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--type-ui);
  line-height: 1.4;
  cursor: pointer;
}

.field-check input {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.field-row {
  display: flex;
  gap: var(--space-2);
  align-items: stretch;
}

.field-row > .field-input {
  flex: 1 1 auto;
  min-width: 0;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

@media (max-width: 480px) {
  .form-actions .btn {
    flex: 1 1 100%;
  }
}

/* A toggle for one setting that turns on or off at once.
   <label class="switch"><input type="checkbox" role="switch"> Words</label> */
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--ctl-h-sm);
  font-size: var(--type-ui);
  cursor: pointer;
}

.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: 0 0 auto;
  width: 36px;
  height: 22px;
  margin: 0;
  /* --line-input keeps the off track at 3:1 against the card, and the knob at 3:1 on it. */
  background: var(--line-input);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background-color var(--dur-2) ease;
}

.switch input::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform var(--dur-2) var(--ease-out);
}

.switch input:checked {
  background: var(--accent);
}

.switch input:checked::before {
  transform: translateX(14px);
}

.switch input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------------- cards ----------------
   <section class="card">
     <div class="card-head"><div><h2 class="card-title">..</h2><p class="card-sub">..</p></div><div class="card-actions">..</div></div>
     ..
   </section> */

.card {
  min-width: 0;
  padding: var(--card-pad, var(--space-5));
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* In the app every surface wears the dashboard's card chrome
   (public/static/app-analytics.css, .dw): the raised surface, a hairline,
   12px corners, the resting lift and 16px in. A surface inside another
   stays flat, so a page never stacks shadows. */
body.app {
  --card-pad: var(--space-4);
}

:where(body.app) .card,
.card-raised {
  background: var(--bg-raised);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-2);
}

:where(body.app) :is(.card, .list, .table-wrap, .stats) :is(.card, .list, .table-wrap, .stats) {
  box-shadow: none;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
}

.card-head > :first-child {
  min-width: 0;
}

.card-title {
  font-size: var(--type-heading);
  font-weight: var(--weight-title);
  line-height: var(--lh-snug);
}

.card-sub {
  margin-top: var(--space-1);
  font-size: var(--type-small);
  line-height: 1.45;
  color: var(--text-dim);
}

/* Older cards stack a title and its line in a .stack: keep them one unit,
   as cardHead() does, instead of a full gap apart. */
.stack > .card-title + .muted,
.stack > .card-title + .card-sub,
.stack > .card-title + p:not([class]),
.stack > .row-between:has(> .card-title) + .muted,
.stack > .row-between:has(> .card-title) + p:not([class]) {
  margin-top: calc(var(--space-1) - var(--space-4));
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* Parts of one card, split by a hairline. */
.card-section + .card-section {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--line);
}

/* A card that is one big link. */
a.card-link {
  display: block;
  color: inherit;
  transition: border-color var(--dur-1) ease, box-shadow var(--dur-2) ease;
}

a.card-link:hover {
  border-color: var(--line-strong);
  box-shadow: var(--elev-1);
  text-decoration: none;
}

@media (max-width: 480px) {
  .card {
    --card-pad: var(--space-4);
  }
}

/* ---------------- section head ----------------
   sectionHead() in src/ui.ts: a heading over a group of cards, with one
   quiet link or fact on the right. */

.app-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-1) var(--space-3);
  margin-bottom: var(--space-3);
}

.app-section-head .app-section-title {
  margin-bottom: 0;
}

.app-section-meta {
  font-size: var(--type-small);
  color: var(--text-dim);
}

/* ---------------- list rows ----------------
   <ul class="list"><li class="list-row"><span class="list-mark">icon</span>
     <div class="list-main"><p class="list-title">..</p><p class="list-sub">..</p></div>
     <div class="list-end">meta or actions</div></li></ul>
   Rows of one kind (alerts, reports, events): a mark, a title, one line under
   it, and what you can do on the right. Hairlines between, the card's chrome
   around. Inside a card the list runs edge to edge. */

.list {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-2);
  overflow: hidden;
}

.card > .list {
  margin-inline: calc(var(--card-pad) * -1);
  border-inline: 0;
  border-radius: 0;
}

.card > .list:last-child {
  margin-bottom: calc(var(--card-pad) * -1);
  border-bottom: 0;
}

/* Rows keep the card's own inset, so a row's mark lines up with the card's title. */
.card > .list > .list-row {
  padding-inline: var(--card-pad);
}

.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  min-height: 56px;
  padding: var(--space-3) var(--space-4);
}

.list-row:has(> .list-mark) {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.list-row + .list-row {
  border-top: 1px solid var(--line);
}

.list-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  color: var(--text-dim);
  background: var(--bg-tint);
}

.list-mark svg {
  width: 16px;
  height: 16px;
}

.list-mark.is-good {
  color: var(--success-fg);
  background: var(--success-bg);
}

.list-mark.is-bad {
  color: var(--warning-fg);
  background: var(--warning-bg);
}

.list-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.list-title {
  font-size: var(--type-ui);
  font-weight: var(--weight-title);
  line-height: var(--lh-snug);
  color: var(--text);
  overflow-wrap: anywhere;
}

.list-title a {
  color: inherit;
  text-decoration: none;
}

a.list-title:hover,
.list-title a:hover {
  color: var(--accent);
  text-decoration: none;
}

.list-sub {
  font-size: var(--type-small);
  line-height: 1.45;
  color: var(--text-dim);
}

/* Where and when, after the line: the row's one bit of small print. */
.list-meta {
  font-size: var(--type-caption);
  line-height: 1.45;
  color: var(--text-faint);
}

.list-end {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.list-end form {
  margin: 0;
}

@media (max-width: 560px) {
  .list-row,
  .list-row:has(> .list-mark) {
    grid-template-columns: minmax(0, 1fr);
  }
  .list-row:has(> .list-mark) {
    grid-template-columns: auto minmax(0, 1fr);
  }
  .list-row:has(> .list-mark) > .list-end {
    grid-column: 2;
  }
  .list-end {
    justify-content: flex-start;
  }
}

/* ---------------- the way in ----------------
   actionLink() in src/ui.ts: "Open dashboard" and the like, a secondary
   button with an arrow, so the next step reads as a step and not a link. */

.btn-go svg {
  width: 14px;
  height: 14px;
  transition: transform var(--dur-1) ease;
}

.btn-go:hover svg {
  transform: translateX(2px);
}

@media (prefers-reduced-motion: reduce) {
  .btn-go:hover svg {
    transform: none;
  }
}

/* ---------------- info tip ----------------
   <button class="info-tip" popovertarget="tip-1" title="..">(i)</button><span class="info-tip-pop" id="tip-1" popover>..</span>
   One small (i) in place of a paragraph under a card (infoTip() in src/ui.ts).
   24px target (WCAG 2.5.8) around a 15px mark. The popover sits under its
   button where anchor positioning works, and centered on screen elsewhere. */

.info-tip {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin: -4px 0;
  padding: 0;
  vertical-align: middle;
  color: var(--text-faint);
  background: none;
  border: 0;
  border-radius: var(--r-pill);
  cursor: help;
  transition: color var(--dur-1) ease;
}

.info-tip svg {
  width: 15px;
  height: 15px;
}

.info-tip:hover,
.info-tip:focus-visible {
  color: var(--text);
}

.info-tip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.info-tip-pop {
  max-width: min(320px, calc(100vw - 32px));
  margin: auto;
  padding: var(--space-3) var(--space-4);
  font-size: var(--type-small);
  font-weight: 400;
  line-height: 1.5;
  text-align: left;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  box-shadow: var(--elev-3);
}

/* Phones: a 44px target for a finger, the same 24px of room in the line. */
@media (max-width: 720px) {
  .info-tip {
    width: 44px;
    height: 44px;
    margin: -14px -10px;
  }
}

@supports (position-area: bottom) {
  .info-tip-pop {
    inset: auto;
    margin: var(--space-1) 0 0;
    position-area: bottom span-right;
    /* Near the right edge it opens to the left, then centered; near the bottom, above. Never cut by the viewport. */
    position-try-fallbacks: bottom span-left, bottom, top span-right, top span-left, top;
  }
}

/* ---------------- big numbers ----------------
   <div class="stat"><p class="stat-label">Visitors</p><p class="stat-value">1,147</p><p class="stat-note">last 7 days</p></div> */

/* A stat tile is the dashboard's number tile (public/static/app-analytics.css,
   .dw-num and .dw-stats): a mono label, a 28px number in tabular figures,
   the change beside it, and a small curve when the number has a shape.
   Tiles sit in a .stats row, split by hairlines, inside one frame.

   <div class="stats">
     <div class="stat stat-wide"><p class="stat-label">Visitors, 7 days</p>
       <div class="stat-body"><p class="stat-value">1,041 <span class="delta down">45%</span></p><svg class="spark">..</svg></div></div>
     <div class="stat"><p class="stat-label">Ad spend</p><p class="stat-value">$73.74</p></div>
   </div> */

.stat {
  display: grid;
  align-content: start;
  gap: var(--space-1);
  min-width: 0;
}

.stat-label {
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: var(--type-label);
  font-weight: var(--weight-medium);
  line-height: 1.4;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-faint);
}

.stat-value {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px var(--space-2);
  min-width: 0;
  font-size: var(--fs-28);
  font-weight: var(--weight-title);
  line-height: 1.1;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* A word where a number would be ("Up", "None"): one step down, so a row of
   tiles keeps one baseline. */
.stat-word {
  font-size: var(--fs-24);
}

.stat-value .stat-of,
.stat-value .stat-meta {
  font-size: var(--type-small);
  font-weight: var(--weight-medium);
  letter-spacing: 0;
  color: var(--text-faint);
}

.stat-value .stat-of {
  color: var(--text-dim);
}

.stat-note {
  font-size: var(--type-caption);
  line-height: 1.4;
  color: var(--text-faint);
}

/* The row of tiles: one frame, hairlines between. Each tile draws its line on
   its right and bottom edge; the frame clips the outer ones, so a short last
   row never shows an empty grey cell. */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
  min-width: 0;
  overflow: hidden;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-2);
}

.stats > .stat {
  padding: var(--space-3) 14px;
  box-shadow:
    1px 0 0 var(--line),
    0 1px 0 var(--line);
}

/* A fixed count of columns, when the tiles must line up across cards. */
.stats-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stats-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stats-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* The tile with a curve takes two columns: the number left, the curve right. */
.stat-wide {
  grid-column: span 2;
}

.stat-full,
.stats-2 > .stat-wide {
  grid-column: 1 / -1;
}

.stat-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--space-3);
}

/* The dashboard's sparkline (.dw-spark): the line in the accent, a 10% wash under it. */
.spark-tile {
  display: block;
  width: 96px;
  height: 34px;
  overflow: visible;
  color: var(--accent);
}

.spark-tile-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spark-tile-area {
  fill: currentColor;
  opacity: 0.1;
}

/* Today (or this hour) is still filling up: its stretch is dashed, as on the dashboard's charts. */
.spark-tile-tail {
  stroke-dasharray: 2 3.5;
}

/* The change against the period before, as on the dashboard (.dash-delta). */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--type-small);
  font-weight: var(--weight-title);
  letter-spacing: 0;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.delta.good {
  color: var(--success-fg);
}

.delta.bad {
  color: var(--danger-fg);
}

.delta svg {
  width: 8px;
  height: 8px;
}

/* Phones: two columns; the wide tile keeps the whole row. */
@media (max-width: 560px) {
  .stats,
  .stats-3,
  .stats-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  /* A tile left alone on the last row takes the row, never half of it. */
  .stats > .stat:last-child:nth-child(odd):not(.stat-wide ~ .stat),
  .stats > .stat-wide ~ .stat:last-child:nth-child(even),
  .stat-wide {
    grid-column: 1 / -1;
  }
  .stat-value {
    font-size: var(--fs-24);
  }
  .stat-word {
    font-size: var(--fs-20);
  }
}

.num,
.tabular {
  font-variant-numeric: tabular-nums;
}

/* ---------------- chips, pills and badges ---------------- */

/* A filter chip: one choice in a row of many. Two or three choices that
   switch a view are a .segmented instead. */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--ctl-h-sm);
  padding: 0 var(--space-3);
  font: inherit;
  font-size: var(--fs-13);
  font-weight: var(--weight-medium);
  color: var(--text-dim);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur-1) ease, border-color var(--dur-1) ease, color var(--dur-1) ease;
}

.chip:hover {
  color: var(--text);
  border-color: var(--line-strong);
  text-decoration: none;
}

.chip[aria-pressed='true'],
.chip[aria-current='true'],
.chip[aria-current='page'] {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.chip .count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: var(--fs-11);
  font-weight: var(--weight-strong);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  /* 6.1:1 light, 6.9:1 dark: --bg-active would drop under 4.5. */
  background: var(--bg-tint);
  box-shadow: inset 0 0 0 1px var(--line);
  border-radius: var(--r-pill);
}

.chip[aria-pressed='true'] .count,
.chip[aria-current='page'] .count,
.chip[aria-current='true'] .count {
  /* On the raised ground the blue holds 5.9:1 light, 6.5:1 dark. */
  color: var(--accent);
  background: var(--bg-raised);
  box-shadow: none;
}

@media (max-width: 720px) {
  .chip {
    min-height: var(--ctl-h-lg);
    padding-inline: 14px;
  }
}

/* A status: small, soft, the same shape everywhere.
   Tones: (none) neutral, -ok, -warn, -danger, -accent, -info. */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 0 var(--space-2);
  font-family: var(--sans);
  font-size: var(--type-caption);
  font-weight: var(--weight-medium);
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-dim);
  background: var(--bg-tint);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  white-space: nowrap;
  vertical-align: middle;
}

.live-now {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  padding: 0 var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  font-size: var(--type-caption);
  font-weight: var(--weight-medium);
  color: var(--text-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.live-now:is(a) {
  text-decoration: none;
  transition: border-color var(--dur-1) ease, background-color var(--dur-1) ease;
}
.live-now:is(a):hover {
  border-color: var(--line-strong);
  background: var(--bg-tint);
}
.live-now[hidden] {
  display: none;
}
.live-dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
}
.live-now.on {
  color: var(--text);
}
.live-now.on .live-dot {
  background: var(--success-fg);
}
.live-now.on .live-dot::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: var(--success-fg);
  animation: live-ping 2s cubic-bezier(0.2, 0.6, 0.4, 1) infinite;
}
@keyframes live-ping {
  from {
    transform: scale(0.4);
    opacity: 0.55;
  }
  to {
    transform: scale(1.6);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .live-now.on .live-dot::after {
    animation: none;
    /* At rest the ring is a soft halo, not a second solid dot. */
    opacity: 0.25;
  }
}
.pill-ok {
  color: var(--success-fg);
  border-color: var(--success-line);
  background: var(--success-bg);
}

.pill-warn {
  color: var(--warning-fg);
  border-color: var(--warning-line);
  background: var(--warning-bg);
}

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

.pill-accent,
.pill-info {
  color: var(--accent);
  border-color: var(--info-line);
  background: var(--accent-soft);
}

/* A live dot before a pill's words. */
.pill-dot::before {
  content: '';
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ---------------- checklist ----------------
   Steps with a progress bar: the setup checklist on /app (src/activation.ts).
   <section class="card checklist"><div class="checklist-head">..</div><div class="checklist-bar"><span style="width: 40%"></span></div>
     <ol class="checklist-steps"><li class="checklist-step is-done|is-next"><span class="checklist-mark"></span><div><p class="checklist-label">..</p><p class="checklist-why">..</p></div>(button)</li></ol>
   </section> */

.checklist {
  display: grid;
  gap: var(--space-3);
}

.checklist-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.checklist-head .muted {
  margin: 2px 0 0;
}

.checklist-bar {
  height: 6px;
  overflow: hidden;
  background: var(--bg-tint);
  border-radius: var(--r-pill);
}

.checklist-bar span {
  display: block;
  height: 100%;
  background: var(--success);
  border-radius: inherit;
  transition: width var(--dur-4) var(--ease-out);
}

.checklist-steps {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.checklist-step {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--ctl-h-lg);
  padding: 6px 0;
}

.checklist-step + .checklist-step {
  border-top: 1px solid var(--line);
}

.checklist-mark {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
}

.checklist-step.is-done .checklist-mark {
  color: var(--success-fg);
  background: var(--success-bg);
  border-color: var(--success-line);
}

.checklist-step.is-next .checklist-mark {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 4px var(--bg-raised), inset 0 0 0 11px var(--accent);
}

.checklist-step.is-done .checklist-label {
  color: var(--text-faint);
}

.checklist-step.is-next .checklist-label {
  font-weight: var(--weight-strong);
}

.checklist-why {
  margin: 2px 0 0;
  font-size: var(--type-small);
  color: var(--text-dim);
}

/* On a phone the next step's button goes under its words. */
@media (max-width: 520px) {
  .checklist-step.is-next {
    grid-template-columns: 22px minmax(0, 1fr);
  }
  .checklist-step.is-next .btn {
    grid-column: 2;
    justify-self: start;
  }
}

/* ---------------- notices ----------------
   notice() in src/ui.ts. A line that stays on the page. Things that just
   happened (saved, failed to save) are toasts instead. */

.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) 14px;
  font-size: var(--type-ui);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.notice > .notice-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  margin-top: 2px;
}

.notice > .notice-icon svg {
  width: 16px;
  height: 16px;
}

.notice-info > .notice-icon {
  color: var(--accent);
}

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

.notice-warn {
  color: var(--warning-fg);
  background: var(--warning-bg);
  border-color: var(--warning-line);
}

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

.notice .btn {
  margin-left: auto;
}

/* ---------------- toasts ----------------
   window.datacenter.toast('Saved') in public/static/ui.js. One region, bottom
   right on a desk and bottom center on a phone. Polite for saves, assertive
   for errors. */

.toast-region {
  position: fixed;
  right: var(--space-6);
  bottom: var(--space-6);
  z-index: 300;
  display: grid;
  justify-items: end;
  gap: var(--space-2);
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 100%;
  min-height: var(--ctl-h-lg);
  padding: var(--space-2) var(--space-2) var(--space-2) 14px;
  font-size: var(--type-ui);
  line-height: 1.4;
  color: var(--bg);
  background: var(--text);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-3);
  pointer-events: auto;
  animation: ui-toast-in var(--dur-3) var(--ease-out);
}

.toast[data-leaving] {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity var(--dur-2) ease, transform var(--dur-2) ease;
}

.toast-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: #ffffff;
  background: var(--success);
}

.toast-error .toast-icon {
  background: var(--danger);
}

.toast-info .toast-icon {
  color: var(--accent-ink);
  background: var(--accent);
}

.toast-icon svg {
  width: 12px;
  height: 12px;
}

.toast-text {
  flex: 1 1 auto;
  min-width: 0;
}

/* Undo, inside the dark toast (a form or a button). */
.toast-action {
  flex: 0 0 auto;
  margin: 0;
}

.toast-action .btn {
  color: var(--bg);
  background: transparent;
  border-color: color-mix(in srgb, var(--bg) 40%, transparent);
}

.toast-action .btn:hover {
  background: color-mix(in srgb, var(--bg) 12%, transparent);
}

.toast .icon-button {
  width: 32px;
  height: 32px;
  color: color-mix(in srgb, var(--bg) 70%, transparent);
}

.toast .icon-button:hover {
  color: var(--bg);
  background: color-mix(in srgb, var(--bg) 14%, transparent);
}

@keyframes ui-toast-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@media (max-width: 720px) {
  .toast-region {
    right: 50%;
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
    justify-items: center;
    transform: translateX(50%);
  }
}

/* ---------------- tables ----------------
   Numbers right-aligned in tabular figures (.num). The head sticks when the
   wrap scrolls (.table-wrap-tall). Rows light up under the pointer. */

.table-wrap {
  /* Positioned, so a visually-hidden label in a wide row scrolls with the table
     instead of widening the page (admin links and billing at 390px). */
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-panel);
}

/* In the app a table is a dashboard card too. */
:where(body.app) .table-wrap {
  background: var(--bg-raised);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-2);
}

:where(body.app) .table th {
  background: var(--bg-raised);
}

.table-wrap-tall {
  max-height: min(70vh, 720px);
  max-height: min(70dvh, 720px);
  overflow-y: auto;
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--type-ui);
}

.table th,
.table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 40px;
  padding-block: 0;
  font-family: var(--mono);
  font-size: var(--type-label);
  font-weight: var(--weight-medium);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
  background: var(--bg-panel);
}

/* The head styles above are for column heads. A row's name (tbody th) is a
   cell like its neighbors: the same padding, so it shares their line, and it
   never sticks to the top of a scrolling table. */
.table tbody th,
.table tfoot th {
  position: static;
  height: auto;
  padding-block: 10px;
}

/* The frame closes the table: the last row's name loses its rule too. */
.table tbody tr:last-child > :is(td, th) {
  border-bottom: none;
}

.table tbody tr {
  transition: background-color var(--dur-1) ease;
}

/* A table wider than its card (a phone, six models side by side): it scrolls
   inside the card, its first column stays put so every row keeps its name,
   and the right edge fades while there is more to see. ui.js sets .is-wide
   and .has-more from the real widths. */
.table-wrap.is-wide :is(th, td):first-child {
  position: sticky;
  /* A wrap with side padding: the column sticks at the wrap's edge, not inside
     the padding, so nothing scrolls by in a gap beside it (--wrap-pad, ui.js). */
  left: calc(-1 * var(--wrap-pad, 0px));
  z-index: 2;
  background: var(--bg-raised);
  box-shadow: inset -1px 0 0 var(--line);
}
.table-wrap.is-wide th:first-child {
  z-index: 3;
}
.table-wrap.is-wide.has-more {
  -webkit-mask-image: linear-gradient(to left, transparent 0, #000 28px);
  mask-image: linear-gradient(to left, transparent 0, #000 28px);
}

.table tbody tr:hover td {
  background: color-mix(in srgb, var(--bg-hover) 60%, transparent);
}

.table .num,
.table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-empty td {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--text-dim);
}

/* ---------------- code ---------------- */

.code {
  position: relative;
  margin: 0;
  padding: 14px var(--space-4);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: var(--fs-13);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  white-space: pre;
}

.code-block {
  display: grid;
  gap: var(--space-2);
}

.code-block .row-between {
  flex-wrap: nowrap;
  font-size: var(--fs-13);
  color: var(--text-dim);
}

.code-block .row-between > .btn {
  flex: 0 0 auto;
}

/* Snippets in the app wrap instead of scrolling: one line of HTML reads whole,
   with no scroll bars at any width. Line breaks in longer code are kept. */
.code-block:not(.doc-code) .code {
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

:not(pre) > code {
  padding: 1px 5px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
}

/* A key on the keyboard. */
.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  font-family: var(--sans);
  font-size: var(--fs-11);
  font-weight: var(--weight-medium);
  line-height: 1;
  color: var(--text-dim);
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
}

/* ---------------- empty state ----------------
   emptyState() in src/ui.ts: one icon, one line, one action. */

.empty {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-10) var(--space-6);
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background-color: var(--bg-panel);
  background-image: radial-gradient(var(--site-dot) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* Inside a card: no second frame. */
.card .empty,
.empty-plain {
  padding: var(--space-8) var(--space-4);
  border: 0;
  background: none;
}

.empty-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--space-1);
  border-radius: var(--r-lg);
  color: var(--accent);
  background: var(--accent-soft);
}

.empty-mark svg {
  width: 20px;
  height: 20px;
}

.empty-title {
  font-size: var(--type-heading);
  font-weight: var(--weight-title);
  line-height: var(--lh-snug);
  color: var(--text);
}

.empty p:not(.empty-title) {
  max-width: 40ch;
  font-size: var(--type-ui);
  color: var(--text-dim);
}

.empty .btn {
  margin-top: var(--space-2);
}

/* ---------------- loading skeletons ----------------
   Grey shapes where slow numbers and lists will land, so the page does not
   jump. A soft sweep while waiting; still under reduced motion. */

.skeleton {
  display: block;
  min-height: 12px;
  color: transparent !important;
  background: linear-gradient(90deg, var(--bg-active) 0%, var(--bg-hover) 50%, var(--bg-active) 100%) 0 0 / 200% 100%;
  border-radius: var(--r-sm);
  animation: ui-shimmer 1.4s ease-in-out infinite;
  user-select: none;
}

.skeleton-line {
  height: 12px;
  margin-block: 6px;
}

.skeleton-num {
  width: 5ch;
  height: 28px;
}

.skeleton-row {
  height: 40px;
  margin-bottom: var(--space-2);
}

@keyframes ui-shimmer {
  to {
    background-position: -200% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
  }
}

/* With script off nothing will land, so no shapes wait for it: the page's
   <noscript> notice says what is needed instead. */
@media (scripting: none) {
  .skeleton,
  .dw-sk,
  .live-body,
  .live-cards,
  .live-sub {
    display: none !important;
  }
}

/* ---------------- menus ----------------
   A dropdown is a <details data-menu> (site.js closes it on a click outside
   and on Escape, and moves with the arrow keys): its <summary> is the button,
   then .menu-list holds .menu-row items. */

.dropdown {
  position: relative;
}

.dropdown > summary {
  list-style: none;
}

.dropdown > summary::-webkit-details-marker {
  display: none;
}

.dropdown[open] > summary.btn {
  color: var(--text);
  background: var(--bg-hover);
}

/* A small mono heading over a group of rows. */
.menu-heading {
  padding: var(--space-2) 10px var(--space-1);
  font-family: var(--mono);
  font-size: var(--type-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-faint);
}

.menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  min-width: 220px;
  max-width: calc(100vw - 24px);
  padding: var(--space-1);
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-3);
  transform-origin: top right;
  animation: ui-pop var(--dur-2) var(--ease-out);
}

.menu-list-start {
  right: auto;
  left: 0;
  transform-origin: top left;
}

@keyframes ui-pop {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
}

.sheet-row,
.menu-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--ctl-h-md);
  padding: 6px 10px;
  text-align: left;
  font: inherit;
  font-size: var(--type-ui);
  line-height: 1.25;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
  text-decoration: none;
}

.sheet-row {
  min-height: var(--ctl-h-lg);
  font-size: var(--fs-15);
}

.menu-row svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
}

.sheet-row:hover,
.menu-row:hover,
.menu-row:focus-visible {
  background: var(--bg-hover);
  text-decoration: none;
}

.menu-row:hover svg {
  color: var(--accent);
}

.menu-row:focus-visible {
  outline: 2px solid transparent;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.menu-row-danger,
.menu-row-danger svg {
  color: var(--danger-fg);
}

.sheet-row[aria-current='page'] {
  color: var(--accent);
  font-weight: var(--weight-strong);
}

.menu-sep {
  height: 1px;
  margin: var(--space-1) var(--space-1);
  background: var(--line);
}

.menu-list form {
  margin: 0;
}

@media (max-width: 720px) {
  .menu-row {
    min-height: var(--ctl-h-lg);
    font-size: var(--fs-15);
  }
}

/* ---------------- stars ----------------
   favStar() in src/favorites.ts: an outline star in the faint ink, filled
   with --warning once starred (3.4:1 on white, 7:1 on the dark card, so the
   state reads without color too: filled or not). 32px on a desk, 44px on
   a phone. */

.fav {
  display: inline-flex;
  flex: none;
  margin: 0;
}

.fav-btn {
  display: inline-grid;
  place-items: center;
  width: var(--ctl-h-sm);
  height: var(--ctl-h-sm);
  padding: 0;
  color: var(--text-faint);
  background: transparent;
  border: 0;
  border-radius: var(--r-md);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    color var(--dur-1) var(--ease-out),
    background-color var(--dur-1) var(--ease-out);
}

.fav-btn svg {
  width: 18px;
  height: 18px;
  transition: transform var(--dur-2) var(--ease-out);
}

@media (hover: hover) {
  .fav-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
  }
}

.fav-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.fav-btn[aria-pressed='true'] {
  color: var(--warning);
}

.fav-btn[aria-pressed='true'] svg {
  fill: currentColor;
}

.fav-btn[aria-pressed='true']:active svg {
  transform: scale(0.88);
}

@media (max-width: 720px) {
  .fav-btn {
    width: var(--ctl-h-lg);
    height: var(--ctl-h-lg);
  }
}

/* On a site card, settings and the star take the top right corner, beside the name. */
.site-card-corner {
  display: flex;
  align-items: center;
  align-self: flex-start;
  margin: -6px -6px 0 auto;
}

/* ---------------- site switcher ----------------
   siteSwitch() in src/favorites.ts, one look everywhere: a chevron right
   after the page's title, opening a menu of sites: a search box from 7
   sites, Starred, Sites, each row with its star, then Add site. */

.site-switch-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--ctl-h-sm);
  min-height: var(--ctl-h-sm);
  color: var(--text-dim);
  border-radius: var(--r-md);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.site-switch-btn svg {
  flex: none;
  width: 18px;
  height: 18px;
  transition: transform var(--dur-2) var(--ease-out);
}

.site-switch[open] > .site-switch-btn svg {
  transform: rotate(180deg);
}

.site-switch-btn:hover,
.site-switch[open] > .site-switch-btn {
  color: var(--text);
  background: var(--bg-hover);
}

.site-switch-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.site-switch-list {
  display: flex;
  flex-direction: column;
  width: 320px;
  padding: 0;
  overflow: hidden;
}

.site-switch-search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  border-bottom: 1px solid var(--line);
}

.site-switch-search svg {
  flex: none;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
}

.site-switch-q {
  flex: 1;
  min-width: 0;
  height: var(--ctl-h-lg);
  padding: 0;
  font: inherit;
  /* 16px keeps phones from zooming into the box. */
  font-size: var(--fs-16);
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 2px solid transparent;
  -webkit-appearance: none;
  appearance: none;
}

.site-switch-q::placeholder {
  color: var(--text-faint);
}

.site-switch-q::-webkit-search-cancel-button {
  display: none;
}

.site-switch-search:focus-within {
  box-shadow: inset 0 -2px 0 var(--accent);
}

.site-switch-scroll {
  max-height: min(420px, 60vh);
  max-height: min(420px, 60dvh);
  padding: var(--space-1);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.site-switch-group[hidden] {
  display: none;
}

.site-switch-group + .site-switch-group {
  margin-top: var(--space-1);
  padding-top: var(--space-1);
  border-top: 1px solid var(--line);
}

.site-switch-rows {
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-switch-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.site-switch-row[hidden] {
  display: none;
}

.site-switch-row .menu-row {
  flex: 1;
  min-width: 0;
}

.site-switch-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-switch-domain {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--type-caption);
  color: var(--text-faint);
}

.site-switch-row .menu-row[aria-current='page'] {
  font-weight: var(--weight-strong);
}

.site-switch-row .menu-row[aria-current='page'] svg {
  margin-left: auto;
  color: var(--accent);
}

.site-switch-none {
  margin: 0;
  padding: var(--space-3) 10px;
  font-size: var(--type-small);
  color: var(--text-faint);
}

.site-switch-none[hidden] {
  display: none;
}

/* The title row: the name with the site switcher right after it (src/favorites.ts switchTitle). */
.app-page-title {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
}

.app-page-title .app-page-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 720px) {
  .site-switch-btn {
    width: var(--ctl-h-lg);
    min-height: var(--ctl-h-lg);
  }
  /* The menu spans the page head, right under the button (top: auto keeps
     it where it falls), so it never runs off a narrow screen. */
  .site-switch {
    position: static;
  }
  .app-page-head:has(.site-switch) {
    position: relative;
  }
  .site-switch-list {
    top: auto;
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
    margin-top: 6px;
  }
}

/* ---------------- dialogs and sheets ----------------
   A native <dialog class="dialog"> opened with showModal(): the browser
   traps focus and closes it on Escape; ui.js puts focus back where it was.
   On a phone it rises from the bottom as a sheet. */

.dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: min(86vh, 760px);
  max-height: min(86dvh, 760px);
  padding: 0;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--elev-4);
  overflow: auto;
  overscroll-behavior: contain;
}

/* A yes-or-no question: narrow, the answer bottom right. */
.dialog-confirm {
  width: min(420px, calc(100vw - 32px));
}

.dialog-confirm .dialog-body p {
  color: var(--text-dim);
}

.dialog[open] {
  animation: ui-dialog-in var(--dur-3) var(--ease-out);
}

/* Safari before 17.4 gives ::backdrop none of the page's custom properties, so
   var(--scrim) alone left the page behind a dialog undimmed on older iPhones.
   The fallback is a dim that reads in light and dark. */
.dialog::backdrop {
  background: var(--scrim, rgba(20, 17, 13, 0.5));
  animation: ui-fade var(--dur-3, 240ms) ease;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) 0 var(--space-6);
}

.dialog-title {
  font-size: var(--type-title);
  font-weight: var(--weight-title);
  line-height: var(--lh-snug);
  letter-spacing: var(--track-title);
}

.dialog-head .icon-button {
  margin: -6px -6px 0 0;
}

.dialog-body {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
}

.dialog-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6) var(--space-5);
}

@keyframes ui-dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@keyframes ui-fade {
  from {
    opacity: 0;
  }
}

@media (max-width: 720px) {
  .dialog {
    width: 100%;
    max-width: 100%;
    /* Above the on-screen keyboard when one is open (--kb and --vvh, ui.js). */
    max-height: min(86dvh, 760px, calc(var(--vvh, 100dvh) - var(--space-4)));
    margin: auto 0 var(--kb, 0px);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .dialog[open] {
    animation-name: ui-sheet-in;
  }
  /* The grab handle: says the sheet can be pulled down to close (ui.js swipeToClose). */
  .dialog::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    width: 36px;
    height: 5px;
    margin-left: -18px;
    border-radius: var(--r-pill);
    background: var(--line-strong);
    pointer-events: none;
  }
  .dialog.is-dragging {
    transition: none;
    animation: none;
  }
  .dialog-foot .btn {
    flex: 1 1 0;
  }
}

/* While a dialog or sheet is open the page under it stays put: a finger on
   the dim area no longer scrolls the page behind (iOS Safari did). */
:root:has(dialog.dialog[open]:modal) {
  overflow: hidden;
}

@keyframes ui-sheet-in {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

/* ---------------- command palette ----------------
   Cmd+K or Ctrl+K anywhere in the app (public/static/ui.js). */

.cmdk {
  width: min(620px, calc(100vw - 32px));
  max-height: min(72vh, 620px);
  max-height: min(72dvh, 620px);
  margin: 12vh auto auto;
  margin: 12dvh auto auto;
  padding: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--elev-4);
}

.cmdk[open] {
  display: flex;
  flex-direction: column;
  animation: ui-dialog-in var(--dur-2) var(--ease-out);
}

.cmdk::backdrop {
  background: var(--scrim, rgba(20, 17, 13, 0.5));
}

.cmdk-search {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--line);
}

.cmdk-search svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  color: var(--text-faint);
}

.cmdk-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 52px;
  padding: 0;
  font: inherit;
  font-size: var(--fs-16);
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
}

.cmdk-input::placeholder {
  color: var(--text-faint);
}

.cmdk-list {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: var(--space-2);
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.cmdk-group {
  padding: var(--space-3) 10px var(--space-1);
  font-family: var(--mono);
  font-size: var(--type-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-faint);
}

.cmdk-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 40px;
  padding: 0 10px;
  font-size: var(--type-ui);
  color: var(--text);
  border-radius: var(--r-md);
  cursor: pointer;
}

.cmdk-item svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
}

.cmdk-item[aria-selected='true'] {
  background: var(--bg-active);
}

.cmdk-item[aria-selected='true'] svg {
  color: var(--accent);
}

.cmdk-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cmdk-hint {
  flex: 0 0 auto;
  font-size: var(--type-caption);
  color: var(--text-faint);
}

.cmdk-keys {
  display: inline-flex;
  gap: 3px;
}

.cmdk-none {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  font-size: var(--type-ui);
  color: var(--text-dim);
}

.cmdk-foot {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  padding: 10px var(--space-4);
  font-size: var(--type-caption);
  color: var(--text-faint);
  border-top: 1px solid var(--line);
  background: var(--bg-panel);
}

.cmdk-foot span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* No keyboard on a touch screen: no key hints. */
@media (hover: none) {
  .cmdk-foot,
  .cmdk-item .cmdk-keys {
    display: none;
  }
}

/* The search hint in the app header: opens the palette. */
.cmdk-open {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 200px;
  height: var(--ctl-h-sm);
  padding: 0 6px 0 10px;
  font: inherit;
  font-size: var(--fs-13);
  color: var(--text-faint);
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--dur-1) ease, color var(--dur-1) ease;
}

.cmdk-open:hover {
  color: var(--text-dim);
  border-color: var(--line-strong);
}

.cmdk-open svg {
  width: 15px;
  height: 15px;
}

.cmdk-open .cmdk-keys {
  margin-left: auto;
}

@media (max-width: 860px) {
  .cmdk-open {
    min-width: 0;
    width: var(--ctl-h-lg);
    height: var(--ctl-h-lg);
    padding: 0;
    justify-content: center;
    background: transparent;
    border-color: transparent;
  }
  .cmdk-open .cmdk-open-text,
  .cmdk-open .cmdk-keys {
    display: none;
  }
  .cmdk {
    margin-top: var(--space-4);
    max-height: calc(100dvh - 32px);
  }
}

/* ---------------- phone tap targets ----------------
   Links that act like buttons get a finger's height on a phone. Links inside
   running text keep their line. */
@media (max-width: 720px) {
  .site-card-foot a,
  .site-card-foot .btn {
    display: inline-flex;
    align-items: center;
    min-height: var(--ctl-h-lg);
  }
  .scs-action,
  .site-card-name,
  .link-short,
  .link-head-short > a,
  .crumbs a,
  .code-block .row-between a {
    display: inline-flex;
    align-items: center;
    min-height: var(--ctl-h-sm);
  }
}

/* ---------------- Windows High Contrast ----------------
   Forced colors drop backgrounds and box shadows. Focus, switches and the
   chosen tab, segment or chip show that way here, so each gets a system-color
   line instead. */
@media (forced-colors: active) {
  :focus-visible,
  .field-input:focus,
  .as-compose:focus-within {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }
  .switch input,
  .cap-switch-track {
    forced-color-adjust: none;
    background: Canvas;
    border: 1px solid ButtonText;
  }
  .switch input::before,
  .cap-switch-track::after {
    top: 1px;
    left: 1px;
    background: ButtonText;
    box-shadow: none;
  }
  .switch input:checked,
  .cap-switch[aria-checked='true'] .cap-switch-track {
    background: Highlight;
    border-color: Highlight;
  }
  .switch input:checked::before,
  .cap-switch[aria-checked='true'] .cap-switch-track::after {
    background: HighlightText;
  }
  /* A transparent border turns to text color here, so only the chosen tab keeps one. */
  .tab {
    border-bottom-color: Canvas;
  }
  .tab[aria-current='page'],
  .tab[aria-selected='true'] {
    border-bottom-color: Highlight;
  }
  .segment[aria-selected='true'],
  .segment[aria-current='page'],
  .segment[aria-checked='true'],
  .segment[aria-pressed='true'],
  input:checked + .segment,
  .segment:has(input:checked),
  .chip[aria-pressed='true'],
  .chip[aria-current='true'],
  .chip[aria-current='page'],
  .cmdk-item[aria-selected='true'],
  .menu-row[aria-current='page'],
  .app-nav-link[aria-current='page'],
  .sheet-row[aria-current='page'] {
    border: 1px solid Highlight;
    outline: 1px solid Highlight;
  }
  .btn,
  .icon-button {
    border: 1px solid ButtonText;
  }
}

/* Phones: a short row of filter chips wraps in balanced lines, never a full
   line and one chip alone. Balancing works on inline content. A row marked
   .chips-scroll keeps one line and scrolls sideways instead, its ends fading
   so a cut chip reads as "more this way"; in a card it runs edge to edge. */
@media (max-width: 720px) {
  nav.chips:not(.chips-scroll) {
    display: block;
    text-wrap: balance;
  }
  nav.chips:not(.chips-scroll) > * {
    display: inline-flex;
    margin: 0 4px 6px 0;
    vertical-align: middle;
  }
  .chips-scroll {
    --chips-in: 0px;
    flex-wrap: nowrap;
    margin-inline: calc(-1 * var(--chips-in));
    padding-inline: var(--chips-in) var(--space-6);
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to right, transparent, #000 var(--chips-in), #000 calc(100% - var(--space-6)), transparent);
    mask-image: linear-gradient(to right, transparent, #000 var(--chips-in), #000 calc(100% - var(--space-6)), transparent);
  }
  .card .chips-scroll {
    --chips-in: var(--card-pad, var(--space-4));
  }
  .chips-scroll::-webkit-scrollbar {
    display: none;
  }
  .chips-scroll > * {
    flex: 0 0 auto;
  }
}

/* Tracking health as a score ring (src/tracking/health.ts healthRing): the arc
   fills to the score from the top, its color says the status, the number sits
   inside. Small in badges and the overview, large on the health page. */
.hl-ring {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  vertical-align: middle;
}
.hl-ring svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.hl-ring circle {
  fill: none;
  stroke-width: 3.5;
}
.hl-ring-track {
  stroke: var(--line);
}
.hl-ring-arc {
  stroke: var(--text-faint);
  stroke-linecap: round;
  transition: stroke-dasharray var(--dur-2) var(--ease-out);
}
.hl-ring-good .hl-ring-arc {
  stroke: var(--success-fg);
}
.hl-ring-warn .hl-ring-arc {
  stroke: var(--warning-fg);
}
.hl-ring-bad .hl-ring-arc {
  stroke: var(--danger-text);
}
.hl-ring-num {
  position: relative;
  font-size: 8.5px;
  font-weight: var(--weight-strong);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
}
.hl-ring-lg {
  width: 88px;
  height: 88px;
}
.hl-ring-lg circle {
  stroke-width: 3;
}
.hl-ring-lg .hl-ring-num {
  font-size: 28px;
  font-weight: var(--weight-title);
}
.hl-badge-ring {
  gap: 7px;
  padding: 3px 11px 3px 4px;
}
/* Inside a pill the ring sits inset, with the same space top, bottom and left. */
.hl-badge-ring .hl-ring {
  width: 22px;
  height: 22px;
}
.hl-badge-ring .hl-ring circle {
  stroke-width: 3;
}
.hl-badge-ring .hl-ring-num {
  font-size: 8px;
  letter-spacing: -0.04em;
}
@media (prefers-reduced-motion: reduce) {
  .hl-ring-arc {
    transition: none;
  }
}

/* A pill that is a link shows it by its fill, not an underline. */
a.pill {
  transition: border-color var(--dur-1) ease, background-color var(--dur-1) ease;
}
a.pill:hover {
  border-color: var(--line-strong);
  background: var(--bg-tint);
}

/* ---- shared with the app ----------------------------------------------------------------
   Plan cards (pricing, and Billing in the app) and the arrow link. They live here, not in
   site-marketing.css, because app pages do not load the marketing stylesheets. */

/* A link with an arrow that moves a little on hover. */
.text-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  font-weight: 600;
}

.text-link svg {
  width: 16px;
  height: 16px;
  transition: transform 0.15s ease;
}

.text-link:hover {
  text-decoration: none;
}

.text-link:hover svg {
  transform: translateX(3px);
}

/* Plans with a price: four across on wide screens, two by two below 1100px, one column on phones. Custom sits under them (.plan-wide). */
.plan-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
}

.plan-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 22px;
  color: inherit;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.plan-card:hover {
  border-color: var(--line-strong);
  text-decoration: none;
}

.plan-card.highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

a.plan-card-link:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-menu);
}

.plan-name {
  display: block;
  font-size: 17px;
  font-weight: 700;
}

.plan-tagline {
  display: block;
  margin-top: 5px;
  color: var(--text-dim);
  font-size: 13.5px;
}

.plan-price {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 16px;
}

.plan-amount {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.plan-period,
.plan-billing {
  color: var(--text-dim);
  font-size: 13.5px;
}

.plan-billing {
  margin-top: 2px;
  color: var(--text-faint);
}

.plan-features {
  flex: 1 1 auto;
  margin: 18px 0 22px;
  padding: 0;
  list-style: none;
  font-size: 14px;
  color: var(--text-dim);
}

.plan-features li {
  position: relative;
  padding-left: 22px;
  margin-bottom: 8px;
}

.plan-features li::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 0.58em;
  width: 8px;
  height: 4px;
  border-left: 2px solid var(--chip-ok-fg);
  border-bottom: 2px solid var(--chip-ok-fg);
  transform: rotate(-45deg);
}

.plan-card .btn {
  width: 100%;
}

.plan-teaser .plan-features {
  margin-bottom: 0;
}

.plans-notice {
  justify-content: center;
  max-width: 640px;
  margin: 22px auto 0;
  font-size: 13.5px;
}

@media (max-width: 1099px) {
  .plan-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 760px;
    margin-inline: auto;
  }
}

@media (max-width: 640px) {
  .plan-grid {
    grid-template-columns: minmax(0, 1fr);
    max-width: 480px;
  }
}

.plan-flag {
  position: absolute;
  top: -11px;
  left: 20px;
  margin: 0;
  padding: 2px 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
}

.plan-card:not(.highlight) .plan-flag {
  display: none;
}

/* A plan priced per deal (Custom): one wide card under the grid. Head,
   features and the "Talk to us" side by side; stacked below 900px. */
.plan-wide {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(0, 2fr) minmax(200px, 1fr);
  gap: 16px 32px;
  align-items: center;
  margin-top: 16px;
}

.plan-wide .plan-wide-head {
  display: block;
  min-width: 0;
}

.marketing .plan-wide .plan-tagline {
  min-height: 0;
}

.plan-wide .plan-price {
  margin-top: 0;
}

/* Two flowing columns, so a long line never leaves a gap in the other one. */
.plan-wide .plan-wide-features {
  columns: 2;
  column-gap: 24px;
  margin: 0;
}

.plan-wide .plan-wide-features li {
  break-inside: avoid;
}

.plan-wide .plan-wide-action {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.plan-wide .plan-wide-action .btn {
  margin-top: 14px;
}

.plan-wide-teaser .plan-wide-action {
  align-items: flex-end;
  text-align: right;
}

.plan-wide-teaser .plan-wide-action .text-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-weight: 600;
}

.plan-teaser + .plan-wide {
  margin-top: 16px;
}

@media (max-width: 1099px) {
  .plan-wide {
    max-width: 760px;
    margin-inline: auto;
  }
}

@media (max-width: 899px) {
  .plan-wide {
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
  }
  .plan-wide-teaser .plan-wide-action {
    flex-direction: row;
    /* With large text the link drops under the price instead of spilling. */
    flex-wrap: wrap;
    gap: 4px 12px;
    align-items: baseline;
    justify-content: space-between;
  }
}

@media (max-width: 640px) {
  .plan-wide {
    max-width: 480px;
  }
  .plan-wide .plan-wide-features {
    columns: 1;
  }
}
