@import url("./shared/tokens.css");
@import url("./shared/chat.css");

/*
 * Account Kit admin layout. Tokens, base elements, buttons, fields, dialogs,
 * status badges and the toast come from shared/tokens.css (shared with the
 * cabinet). The admin is a working tool: a wider page, a dense table, and one
 * customer window that reads like a file — section names in a left gutter,
 * the content to their right, the key plate the one loud thing in it.
 */

:root { --admin-width: 1180px; --cw-gutter: 168px; }

/* ---- header ---- */
.bar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--kit-bg) 88%, transparent);
  border-bottom: 1px solid var(--kit-line);
  backdrop-filter: saturate(1.4) blur(10px);
}
.bar-inner {
  display: flex; align-items: center; gap: 28px;
  max-width: calc(var(--admin-width) + 48px); margin: 0 auto; padding: 0 24px; min-height: 60px;
}
/* Header items never break inside a word (the page wraps long words anywhere): they keep their width or move to their own row. */
.brand { display: inline-flex; align-items: baseline; gap: 8px; flex: none; color: var(--kit-text); text-decoration: none; white-space: nowrap; overflow-wrap: normal; }
.brand-name { font-weight: 700; font-size: 1.0625rem; letter-spacing: -0.01em; }
.brand-tag {
  padding: 1px 7px; border-radius: 6px; background: var(--kit-text); color: var(--kit-bg);
  font-size: 0.75rem; font-weight: 650; line-height: 1.5;
}
.tabs { display: flex; flex: none; gap: 4px; align-self: stretch; }
.tabs a {
  display: flex; align-items: center; padding: 0 12px;
  color: var(--kit-muted); text-decoration: none; font-weight: 560; font-size: 0.9375rem; white-space: nowrap; overflow-wrap: normal;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--kit-text); }
.tabs a[aria-current="page"] { color: var(--kit-text); border-bottom-color: var(--kit-accent); }
.tabs a:focus-visible { outline-offset: -4px; }
.tab-badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 7px; padding: 0 6px;
  border-radius: 999px; background: var(--kit-accent); color: var(--kit-accent-text);
  font-size: 0.75rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums;
}
.bar-end { display: flex; align-items: center; gap: 10px; margin-left: auto; min-width: 0; }

/* Access: a quiet pill; its tooltip explains what "on" and "off" protect. */
.access {
  position: relative; display: inline-flex; align-items: center; gap: 7px; min-width: 0; max-width: 340px;
  padding: 4px 10px; border: 1px solid var(--kit-line); border-radius: 999px;
  color: var(--kit-muted); font-size: 0.8125rem; font-weight: 560; white-space: nowrap; cursor: help;
}
.access-mark { width: 8px; height: 8px; flex: none; border-radius: 50%; box-shadow: inset 0 0 0 1.5px currentColor; }
.access.is-on { color: var(--kit-success); border-color: color-mix(in srgb, var(--kit-success) 40%, var(--kit-line)); }
.access.is-on .access-mark { background: currentColor; box-shadow: none; }
.access-email { overflow: hidden; text-overflow: ellipsis; color: var(--kit-text); font-weight: 500; overflow-wrap: normal; }
.access-tip {
  position: absolute; z-index: 30; top: calc(100% + 8px); right: 0; width: 300px; padding: 10px 12px;
  border: 1px solid var(--kit-line); border-radius: 10px; background: var(--kit-surface); color: var(--kit-text);
  box-shadow: var(--kit-shadow); font-size: 0.8125rem; font-weight: 400; line-height: 1.45; white-space: normal;
  visibility: hidden; opacity: 0; transition: opacity 0.12s ease;
}
/* Hover, or focus (a tap on a phone focuses it too); Esc hides it until the pointer or focus comes back (WCAG 1.4.13). */
.access:hover .access-tip, .access:focus .access-tip { visibility: visible; opacity: 1; }
.access.is-tip-closed .access-tip { visibility: hidden; opacity: 0; }

.lang select {
  min-height: 36px; padding: 0 28px 0 10px;
  border: 1px solid var(--kit-line); border-radius: var(--kit-radius-s);
  background: var(--kit-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%23888' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 8px center / 12px;
  appearance: none; font-size: 0.875rem; cursor: pointer;
}

.offline {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px 16px;
  padding: 10px 16px; background: var(--kit-warning-soft); color: var(--kit-text);
  border-bottom: 1px solid var(--kit-line); font-size: 0.9375rem;
}

/* ---- sign-in ---- */
.signin { display: grid; place-items: start center; padding: 12vh 16px 64px; }
.signin-card {
  width: min(420px, 100%); padding: 32px 28px;
  border: 1px solid var(--kit-line); border-radius: 16px; background: var(--kit-surface); box-shadow: var(--kit-shadow);
}
.signin-product { display: flex; align-items: baseline; gap: 8px; font-weight: 700; color: var(--kit-muted); }
.signin-title { margin: 6px 0 20px; font-size: 1.625rem; font-weight: 700; letter-spacing: -0.01em; }
.input-key { font-family: var(--kit-font-key); letter-spacing: 0.04em; }
.signin-card .btn-wide { margin-top: 16px; min-height: 46px; }
.signin-card .hint { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--kit-line); }
.notice {
  margin-bottom: 18px; padding: 12px 14px; border-radius: 10px; border-left: 3px solid var(--kit-warning);
  background: var(--kit-warning-soft); font-size: 0.9375rem;
}
.notice.is-info { border-left-color: var(--kit-accent); background: var(--kit-surface-2); }

/* ---- page ---- */
main { display: block; max-width: calc(var(--admin-width) + 48px); margin: 0 auto; padding: 32px 24px 96px; }
main:focus { outline: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px 24px; margin-bottom: 24px; }
.page-title { font-size: 1.75rem; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
.page-lead { margin-top: 6px; color: var(--kit-muted); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

/* Tiles: one strip of counts, divided, not five floating cards. */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  border: 1px solid var(--kit-line); border-radius: var(--kit-radius); background: var(--kit-surface); overflow: hidden;
}
.tile {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 18px;
  border-left: 1px solid var(--kit-line); margin-left: -1px; color: var(--kit-text); text-decoration: none;
}
.tile-n { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile-label { color: var(--kit-muted); font-size: 0.875rem; }
.tile.is-alert .tile-n { color: var(--kit-warning); }
.tile-waitingSupport.is-alert .tile-n { color: var(--kit-accent); }
a.tile:hover { background: var(--kit-surface-2); }
a.tile:focus-visible { outline-offset: -3px; }

.toolbar { position: relative; margin-top: 20px; max-width: 520px; }
.search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--kit-muted); display: flex; pointer-events: none; }
.search-input { padding-left: 40px; background: var(--kit-surface); }
.search-hint { margin-top: 6px; color: var(--kit-accent); font-size: 0.875rem; font-weight: 560; }

/* ---- the table ---- */
.table-wrap {
  margin-top: 16px; border: 1px solid var(--kit-line); border-radius: var(--kit-radius);
  background: var(--kit-surface); overflow-x: auto;
}
.table-wrap[aria-busy="true"] { opacity: 0.6; transition: opacity 0.15s ease 0.15s; }
.customers { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.customers th {
  padding: 10px 14px; text-align: left; white-space: nowrap;
  color: var(--kit-muted); font-size: 0.8125rem; font-weight: 600; border-bottom: 1px solid var(--kit-line);
  background: var(--kit-surface-2);
}
.customers td { padding: 11px 14px; border-top: 1px solid var(--kit-line); vertical-align: middle; }
.customers tbody tr:first-child td { border-top: 0; }
.customers tbody tr { cursor: pointer; }
.customers tbody tr:hover { background: var(--kit-surface-2); }
.customers tbody tr:has(.row-link:focus-visible) { background: var(--kit-accent-soft); }
.c-email { min-width: 220px; }
.row-link { color: var(--kit-text); font-weight: 600; text-decoration: none; margin-right: 8px; }
.row-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.c-until, .c-devices, .c-lastSeen { white-space: nowrap; font-variant-numeric: tabular-nums; }
.c-source { white-space: nowrap; color: var(--kit-muted); }
/* The short ID stays on one line: breaking anywhere would let the column shrink to one letter. */
.c-id .id { white-space: nowrap; overflow-wrap: normal; }
.id { font-family: var(--kit-font-key); font-size: 0.8125rem; color: var(--kit-muted); overflow-wrap: anywhere; }
.seats { font-variant-numeric: tabular-nums; }
.seats.is-full { color: var(--kit-warning); font-weight: 650; }
.tag-danger { border-color: transparent; background: var(--kit-danger-soft); color: var(--kit-danger); }

.list-empty {
  margin-top: 16px; padding: 36px 28px; border: 1px dashed var(--kit-line); border-radius: var(--kit-radius);
  background: var(--kit-surface);
}
.list-empty h2 { font-size: 1.125rem; font-weight: 650; }
.list-empty p { margin-top: 6px; color: var(--kit-muted); max-width: 60ch; }
.list-empty .state { padding: 0; }
.list-foot { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-top: 14px; font-size: 0.875rem; }

/* ---- support: the inbox ---- */
.inbox-group + .inbox-group { margin-top: 28px; }
.inbox-heading { margin-bottom: 10px; font-size: 0.9375rem; font-weight: 650; }
.inbox {
  border: 1px solid var(--kit-line); border-radius: var(--kit-radius);
  background: var(--kit-surface); overflow: hidden;
}
.inbox-item + .inbox-item { border-top: 1px solid var(--kit-line); }
.inbox-row {
  display: grid; grid-template-columns: minmax(180px, 280px) minmax(0, 1fr) auto; align-items: center; gap: 4px 24px;
  padding: 14px 18px; color: var(--kit-text); text-decoration: none;
}
.inbox-row:hover { background: var(--kit-surface-2); }
.inbox-row:focus-visible { outline-offset: -3px; background: var(--kit-accent-soft); }
.is-waiting .inbox-row { box-shadow: inset 3px 0 0 var(--kit-accent); }
.inbox-who { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 0; }
.inbox-email { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; overflow-wrap: normal; }
.inbox-row:hover .inbox-email { text-decoration: underline; text-underline-offset: 3px; }
.inbox-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--kit-muted); font-size: 0.9375rem; overflow-wrap: normal; }
.inbox-preview.is-unreadable { font-style: italic; }
.inbox-you { color: var(--kit-text); font-weight: 560; }
.inbox-time { color: var(--kit-muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.is-waiting .inbox-time { color: var(--kit-accent); font-weight: 600; }
.tag-done { border-color: transparent; background: var(--kit-success-soft); color: var(--kit-success); }
.list-empty-mark {
  display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 14px;
  border-radius: 12px; background: var(--kit-accent-soft); color: var(--kit-accent); font-size: 1.375rem;
}

/* ---- support: one conversation ---- */
.crumbs { margin-bottom: 10px; font-size: 0.875rem; }
.crumbs ol { display: flex; flex-wrap: wrap; gap: 4px 8px; margin: 0; padding: 0; list-style: none; color: var(--kit-muted); }
.crumbs li { min-width: 0; overflow-wrap: anywhere; }
.crumbs li + li::before { content: "/"; margin-right: 8px; color: var(--kit-line); }
.crumbs a { color: var(--kit-muted); text-underline-offset: 3px; }
.crumbs a:hover { color: var(--kit-text); }
.thread-head { align-items: flex-start; }
.thread-who { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; min-width: 0; }
.thread-email { overflow-wrap: anywhere; }
.thread-head .btn { flex: none; }

/* The card to the right of the conversation; above it on a narrower screen. */
.thread-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.thread-layout.is-single { grid-template-columns: minmax(0, 1fr); }
.thread-chat { grid-column: 1; grid-row: 1; min-width: 0; }
.thread-log { height: clamp(320px, calc(100dvh - 390px), 760px); overflow-anchor: none; } /* the page keeps the place itself when older messages come in */
.chat-older { display: flex; justify-content: center; min-height: 32px; }
.chat-start { color: var(--kit-muted); font-size: 0.8125rem; }
.chat-none { margin: auto; color: var(--kit-muted); }
.chat-note { margin-top: 10px; color: var(--kit-muted); font-size: 0.8125rem; }
.ccard {
  grid-column: 2; grid-row: 1; position: sticky; top: 84px;
  padding: 18px 20px 20px; border: 1px solid var(--kit-line); border-radius: var(--kit-radius); background: var(--kit-surface);
}
.ccard-title { margin-bottom: 12px; font-size: 0.9375rem; font-weight: 650; }
/* One label column for all the facts; the ID (long, monospaced) under its label. */
.ccard-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px 14px; align-items: baseline; font-size: 0.875rem; }
.ccard-facts .fact { display: contents; }
.ccard-facts .fact-id { display: grid; grid-column: 1 / -1; gap: 2px; }
.fact-id dt { color: var(--kit-muted); }
.ccard-facts .status { justify-self: start; }
.ccard-open { width: 100%; margin-top: 18px; }

/* ---- loading, error ---- */
.skeleton-art { display: grid; gap: 14px; }
.sk { display: block; border-radius: 8px; background: var(--kit-surface-2); }
.sk-title { width: 180px; height: 32px; }
.sk-tiles { height: 76px; border-radius: var(--kit-radius); border: 1px solid var(--kit-line); background: var(--kit-surface); }
.sk-line { width: min(520px, 90%); height: 44px; }
.sk-card { height: 320px; border-radius: var(--kit-radius); border: 1px solid var(--kit-line); background: var(--kit-surface); }
.sk-short { height: 140px; }
.skeleton .sk {
  background-image: linear-gradient(90deg, transparent 0, color-mix(in srgb, var(--kit-line) 55%, transparent) 50%, transparent 100%);
  background-size: 200% 100%; background-repeat: no-repeat;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
.state { padding: 24px 0; }
.state p { margin: 10px 0 20px; color: var(--kit-muted); max-width: 60ch; }

/* ---- add user ---- */
.check { display: flex; align-items: center; gap: 10px; margin-top: 18px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--kit-accent); }
#add .field-error .inline-link { margin-left: 4px; font-weight: 650; }

/* ---- the customer window ---- */
/* The list behind stays put while a window is open: the wheel scrolls the window. */
:root:has(dialog[open]) { overflow: hidden; }
.cw {
  width: min(920px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 48px); padding: 0;
  border: 1px solid var(--kit-line); border-radius: 16px;
  background: var(--kit-surface); color: var(--kit-text); box-shadow: var(--kit-shadow);
  overflow: auto; overscroll-behavior: contain;
}
.cw::backdrop { background: var(--kit-backdrop); backdrop-filter: blur(3px); }
.cw[open] { animation: rise 0.2s cubic-bezier(0.2, 0.8, 0.2, 1); }
.cw-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 22px 28px 18px; border-bottom: 1px solid var(--kit-line); background: var(--kit-surface);
}
.cw-who { min-width: 0; }
.cw-title { font-size: 1.375rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.25; overflow-wrap: anywhere; }
.cw-title .sk-title { width: 260px; height: 28px; }
.cw-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.cw-tags:empty { display: none; }
.cw-facts { margin-top: 10px; }
.cw-guest { margin-top: 8px; color: var(--kit-muted); font-size: 0.875rem; }
.cw-close { margin: -6px -10px 0 0; flex: none; }
.cw-body { padding: 4px 28px 28px; }
.cw-body.skeleton { display: grid; gap: 16px; padding-top: 24px; }
.cw-state p { margin: 20px 0 4px; max-width: 56ch; color: var(--kit-muted); }

.cw-warning {
  margin-top: 20px; padding: 12px 14px; border-radius: 10px; border-left: 3px solid var(--kit-warning);
  background: var(--kit-warning-soft); font-size: 0.9375rem;
}

.cw-section {
  display: grid; grid-template-columns: var(--cw-gutter) minmax(0, 1fr); gap: 8px 24px;
  padding: 22px 0; border-top: 1px solid var(--kit-line);
}
.cw-body > .cw-section:first-of-type, .cw-warning + .cw-section { border-top: 0; }
.cw-label h3 { font-size: 0.9375rem; font-weight: 650; }
.cw-count { display: flex; align-items: center; gap: 8px; margin-top: 6px; color: var(--kit-muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.cw-content { min-width: 0; }
.cw-content > .actions { margin-top: 14px; }
.cw-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; margin-top: 14px; }
.cw-content > .cw-row:first-child { margin-top: 0; }

.facts { display: flex; flex-wrap: wrap; gap: 2px 20px; font-size: 0.875rem; }
.fact { display: flex; gap: 6px; }
.fact dt { color: var(--kit-muted); }
.fact dd { font-variant-numeric: tabular-nums; }

/* The key plate (same build as the cabinet's). */
.plate {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px 16px;
  padding: 14px; border-radius: 12px;
  background: var(--kit-plate-bg); color: var(--kit-plate-text);
  box-shadow: inset 0 0 0 1px var(--kit-plate-line);
}
.plate :focus-visible { outline-color: var(--kit-plate-focus); }
.plate-code { min-width: 0; }
.plate-key {
  display: flex; flex-wrap: wrap; align-items: center; row-gap: 6px;
  font: 600 clamp(0.8125rem, 2.6vw, 1.1875rem)/1 var(--kit-font-key);
  letter-spacing: 0.06em; font-variant-numeric: tabular-nums slashed-zero;
}
.plate-group {
  padding: 0.42em 0.42em 0.38em 0.48em; border-radius: 6px;
  background: var(--kit-plate-cell); box-shadow: inset 0 0 0 1px var(--kit-plate-line);
}
.plate-group.is-hidden { color: var(--kit-plate-muted); }
.plate-dash { width: 0.7em; text-align: center; color: var(--kit-plate-muted); }
.plate-code.is-shown .plate-group { user-select: all; }
.plate-actions { display: flex; gap: 8px; }
.btn-plate {
  min-height: 36px; padding: 0 12px; background: transparent; color: var(--kit-plate-text);
  border-color: var(--kit-plate-line); font-size: 0.875rem;
}
.btn-plate:hover { background: var(--kit-plate-cell); }
.btn-plate[aria-busy="true"]::after { border-color: var(--kit-plate-muted); border-right-color: transparent; }

.cw-status { display: flex; align-items: flex-start; gap: 12px; }
.cw-status .status { flex: none; }
.cw-term-form { margin-top: 16px; }
.cw-term-form .cw-row { margin-top: 0; }
.input-date { width: auto; min-width: 180px; font-variant-numeric: tabular-nums; }

.meter { display: inline-flex; gap: 3px; }
.pip { width: 10px; height: 10px; border-radius: 3px; box-shadow: inset 0 0 0 1.5px var(--kit-muted); opacity: 0.7; }
.pip.is-on { background: var(--kit-accent); box-shadow: none; opacity: 1; }
.devices li {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 10px 0; border-top: 1px dashed var(--kit-line);
}
.devices li:first-child { border-top: 0; padding-top: 0; }
.device-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: var(--kit-surface-2); color: var(--kit-muted); }
.device-name { color: var(--kit-text); font-size: 0.875rem; }

.payments li {
  display: grid; grid-template-columns: 1fr auto auto; gap: 4px 20px; align-items: baseline;
  padding: 8px 0; border-top: 1px dashed var(--kit-line); font-size: 0.9375rem;
}
.payments li:first-child { border-top: 0; padding-top: 0; }
.pay-amount { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.pay-amount.is-void { color: var(--kit-muted); text-decoration: line-through; }
.pay-date { color: var(--kit-muted); font-variant-numeric: tabular-nums; text-align: right; font-size: 0.875rem; }
.pay-status { margin-left: 8px; }

.cw-support { margin-top: 0; }
.cw-push { margin-left: auto; }

.journal li {
  display: grid; grid-template-columns: 11.5em 1fr; gap: 2px 16px;
  padding: 7px 0; border-top: 1px dashed var(--kit-line); font-size: 0.875rem;
}
.journal li:first-child { border-top: 0; padding-top: 0; }
.journal-at { color: var(--kit-muted); font-variant-numeric: tabular-nums; }
.actor { font-weight: 650; }
.actor-client { color: var(--kit-accent); }
.actor-system { color: var(--kit-warning); }
.journal-note { margin-top: 2px; color: var(--kit-muted); font-family: var(--kit-font-key); font-size: 0.75rem; overflow-wrap: anywhere; }
.cw-journal .link { margin-top: 10px; }

/* The danger zone: tinted, at the end, each action with what it does. */
.cw-danger {
  margin: 8px -28px -28px; padding: 22px 28px 26px;
  background: color-mix(in srgb, var(--kit-danger-soft) 55%, var(--kit-surface));
  border-top: 1px solid color-mix(in srgb, var(--kit-danger) 30%, var(--kit-line));
}
.cw-danger .cw-label h3 { color: var(--kit-danger); }
.danger-items { display: grid; gap: 14px; }
.danger-item { display: grid; grid-template-columns: 13.5em 1fr; align-items: center; gap: 6px 16px; }
.danger-item .btn { justify-content: flex-start; }
.danger-item p { font-size: 0.875rem; }

/* ---- narrow screens (to 320px) ---- */
@media (max-width: 1023px) {
  .thread-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .thread-chat, .ccard { grid-column: auto; grid-row: auto; }
  .ccard { position: static; padding: 14px 16px; }
  .ccard-title { margin-bottom: 8px; }
  .ccard-facts { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 20px; }
  .ccard-facts .fact, .ccard-facts .fact-id { display: flex; gap: 8px; grid-column: auto; }
  .ccard-open { width: auto; margin-top: 14px; }
}

@media (max-width: 900px) {
  /* Tablets: brand, Access, language and sign out on the first row; the tabs get their own row below. */
  .bar-inner {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "brand access lang out" "tabs tabs tabs tabs";
    gap: 0 10px; min-height: 0;
  }
  .brand { grid-area: brand; padding: 12px 0; }
  .bar-end { display: contents; }
  .access { grid-area: access; justify-self: end; }
  .lang { grid-area: lang; }
  #signout { grid-area: out; }
  .tabs { grid-area: tabs; margin: 0 -24px; padding: 0 12px; border-top: 1px solid var(--kit-line); }
  .tabs a { min-height: 44px; }
  .access-email { display: none; }
  .danger-item { grid-template-columns: 1fr; }
  .danger-item .btn { justify-self: start; }
}

@media (max-width: 640px) {
  /* Brand, language and sign out on top; the Access state on its own slim row; then the tabs. */
  .bar-inner {
    display: grid; grid-template-columns: 1fr auto auto;
    grid-template-areas: "brand lang out" "access access access" "tabs tabs tabs";
    gap: 0 8px; padding: 0 16px; min-height: 0;
  }
  .brand { grid-area: brand; padding: 12px 0; }
  .bar-end { display: contents; }
  .lang { grid-area: lang; }
  #signout { grid-area: out; }
  .access { grid-area: access; justify-self: start; margin-bottom: 10px; }
  .access-tip { right: auto; left: 0; width: min(300px, calc(100vw - 32px)); }
  .tabs { grid-area: tabs; margin: 0 -16px; padding: 0 4px; border-top: 1px solid var(--kit-line); }
  .tabs a { flex: 1; justify-content: center; min-height: 44px; padding: 0 6px; }
  main { padding: 24px 16px 88px; }
  .page-title { font-size: 1.5rem; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile { padding: 12px 14px; border-top: 1px solid var(--kit-line); margin-top: -1px; }
  .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .toolbar { max-width: none; }

  .inbox-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "who time" "preview preview"; gap: 6px 12px; padding: 12px 14px; }
  .inbox-who { grid-area: who; }
  .inbox-time { grid-area: time; align-self: start; }
  .inbox-preview { grid-area: preview; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .thread-head .btn { width: 100%; }
  .thread-log { height: clamp(280px, calc(100dvh - 330px), 560px); }
  .ccard-facts { grid-template-columns: 1fr; }
  .ccard-facts .fact-id { flex-direction: column; gap: 2px; }

  /* The table becomes a list of cards: each cell labelled by its column. */
  .table-wrap { border: 0; background: none; overflow: visible; }
  .customers, .customers tbody, .customers tr, .customers td { display: block; }
  .customers thead { display: none; }
  .customers tbody { display: grid; gap: 10px; }
  .customers tbody tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; padding: 14px 16px;
    border: 1px solid var(--kit-line); border-radius: 12px; background: var(--kit-surface);
  }
  .customers td { padding: 0; border: 0; font-size: 0.875rem; }
  .customers td::before { content: attr(data-label); display: block; color: var(--kit-muted); font-size: 0.75rem; }
  .customers td.c-email { grid-column: 1 / -1; order: -2; font-size: 1rem; }
  .customers td.c-email::before, .customers td.c-status::before { content: none; }
  .customers td.c-status { grid-column: 1 / -1; order: -1; }
  .customers td.c-id { grid-column: 1 / -1; order: 9; }
  .customers td.c-id::before { display: inline; margin-right: 6px; }

  .signin { padding-top: 6vh; }
  .signin-card { padding: 26px 18px; }

  /* The window is a full-screen sheet. */
  .cw {
    width: 100vw; height: 100dvh; max-height: none; margin: 0; border: 0; border-radius: 0;
  }
  .cw-head { padding: 16px 16px 14px; }
  .cw-body { padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
  .cw-section { grid-template-columns: 1fr; padding: 18px 0; }
  .cw-label { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
  .cw-count { margin-top: 0; }
  .plate { padding: 12px; }
  .plate-key { font-size: clamp(0.6875rem, 3.35vw, 1rem); }
  .plate-group { padding: 0.42em 0.3em 0.38em 0.36em; }
  .plate-dash { width: 0.5em; }
  .plate-actions { width: 100%; }
  .plate-actions .btn { flex: 1; }
  .btn-plate { min-height: 44px; }
  .devices li { grid-template-columns: 1fr auto; }
  .device-icon { display: none; }
  .payments li { grid-template-columns: 1fr auto; }
  .pay-date { grid-column: 1 / -1; text-align: left; }
  .journal li { grid-template-columns: 1fr; }
  .cw-push { margin-left: 0; }
  .cw-danger { margin: 8px -16px calc(-24px - env(safe-area-inset-bottom)); padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .btn-plate[aria-busy="true"]::after { border-right-color: currentColor; }
  .table-wrap[aria-busy="true"] { transition: none; }
}

@media (forced-colors: active) {
  .tab-badge, .brand-tag { forced-color-adjust: none; background: CanvasText; color: Canvas; }
  .pip.is-on, .access.is-on .access-mark { background: CanvasText; }
  .cw-danger { border-top: 2px solid CanvasText; }
  .is-waiting .inbox-row { box-shadow: none; border-left: 3px solid CanvasText; }
}
