/*
 * admin/css/base.css — the FrontRow look for every admin page: type scale,
 * buttons, fields, cards, chips, tabs, the save bar, dialogs, empty states,
 * stat tiles and the upload row. Shell chrome (rail, header, drawer) lives in
 * shell.css; page-specific rules in css/pages/<page>.css.
 *
 * Values are copied from FrontRow (read-only):
 *   styles/admin/_admin.scss            .admin-h1, .admin-sub, empty state, fields, .btn
 *   styles/admin/_shared-settings.scss  .settings-page, .save-bar, tabs, asset field, badge
 *   styles/admin/_settings.scss         .settings-card, .field-req, notes
 *   styles/admin/_two-col-settings.scss .admin-two-col
 *   styles/admin/_confirm-dialog.scss   .cdialog-*
 *   styles/admin/_overview.scss         .stat-card*
 *   styles/components/_checkbox.scss    the flat round checkbox
 *   styles/tokens/_interaction.scss     focus ring, status chip, 44px hit area
 * Every colour, radius, font and easing is a var() from tokens.css.
 */

/* ── Reset ──────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, dl, dd, figure {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

img,
video {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

/* `hidden` always hides. Tab panels stay mounted and are toggled with it, and
   any author `display:` on a panel class would otherwise beat the UA rule and
   show every panel at once (FrontRow shipped that twice). */
[hidden] {
  display: none !important;
}

/* Fallback focus ring at reset specificity; components with their own ring win. */
:where(:focus-visible) {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.icon {
  flex: none;
}

/* ── Type scale ─────────────────────────────────────────────────────────── */
/* Plus Jakarta Sans (--font-display) at negative tracking: letter-spacing
   narrows the word space too, so two- and three-word titles ran together
   ("Signed in as" read "Signedinas"). Every display-face class gives the
   space back with word-spacing: 0.1em, and the small (15px) titles track at
   -0.01em; the big ones keep the tight FrontRow display feel. */
.admin-h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(28px, 5vw, 40px);
  letter-spacing: -0.035em;
  word-spacing: 0.1em;
  line-height: 1;
}

.admin-sub {
  color: var(--text-dim);
  font-size: 15px;
  margin-top: 8px;
}

.admin-section-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  word-spacing: 0.1em;
  line-height: 1.2;
  color: var(--text);
}

/* Loading: inline dim text, never a skeleton ("Loading settings…"). */
.admin-loading {
  color: var(--text-faint);
  font-size: 14px;
}

/* ── Page skeleton (ui/page.js) ─────────────────────────────────────────── */
.settings-page {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.settings-page-head {
  display: flex;
  flex-direction: column;
}

/* Drill-down pages: ‹ Parent, a small ghost link above the h1. */
.page-back {
  position: relative;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background var(--dur) var(--ease-ui), color var(--dur) var(--ease-ui);
}

.page-back:hover {
  background: var(--surface);
  color: var(--text);
}

.page-back + .settings-page-head {
  margin-top: -8px;
}

.page-alert-slot {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.page-alert-slot:empty {
  display: none;
}

/* An inline notice block in a status colour (FrontRow status-block). */
.page-alert {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-card);
  font-size: 14px;
  font-weight: 600;
}

.page-alert--danger {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}

.page-alert .btn {
  color: var(--text);
}

/* Passing an aside is the only way a page becomes two-column. */
.admin-two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
  align-items: start;
  gap: 22px;
}

.admin-one-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.settings-main,
.settings-main-body,
.settings-tabpanel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.settings-aside {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  align-self: start;
}

@media (min-width: 1200px) {
  .settings-aside {
    position: sticky;
    top: calc(var(--admin-header-block, 0px) + 8px);
  }
}

/* Below 1200px the aside drops BELOW the controls, so the enable toggle stays
   first, and the save bar stays the LAST thing on the page (spec §4.6, §6).
   The main column dissolves (display: contents), so its body, the aside and
   the save bar become grid items in that order. The bar's sticky containing
   block is then the whole grid: it stays pinned while the operator looks at
   the aside (Branding's Live preview), instead of parking above it with an
   empty slot between the controls and the aside. The DOM is unchanged: the
   bar is still .settings-main's last child (ui/page.js). */
@media (max-width: 1199px) {
  .admin-two-col {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }

  .admin-two-col > .settings-main {
    display: contents;
  }

  .admin-two-col > .settings-main > .settings-main-body {
    order: 0;
  }

  .settings-aside {
    order: 1;
  }

  .admin-two-col > .settings-main > .save-bar {
    order: 2;
  }
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.settings-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding: 20px 24px;
  border: 0;
  border-radius: var(--radius-card);
  background: var(--surface);
}

.settings-card--danger {
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
}

.settings-card--danger > .settings-card-title {
  color: var(--danger);
}

.settings-card-title {
  margin: 0;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  word-spacing: 0.1em;
  color: var(--text);
}

/* A row of actions inside a card: buttons stay content-width (a lone danger
   button is never a full-width red bar). */
.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* The card's one longer explanation, directly under the title. */
.settings-card-help {
  margin-top: -6px;
}

/* In-card feedback notes (no toasts). */
.settings-saved-note,
.settings-unsaved-note,
.settings-saving-note {
  font-size: 12px;
  font-weight: 600;
}

.settings-saved-note { color: var(--success); }
.settings-unsaved-note { color: var(--warning); }
.settings-saving-note { color: var(--text-dim); }

/* ── Fields ─────────────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

fieldset.field {
  margin: 0;
  padding: 0;
  border: 0;
}

fieldset.field > legend {
  padding: 0;
  margin-bottom: 6px;
}

/* Pairs sit side by side and stack before they squash. */
.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

/* fieldPair(): a full-width field, then a narrow one (.field-input--narrow)
   at its end, so the two read as a pair and fill the row. */
.field-row--pair {
  grid-template-columns: minmax(0, 1fr) 220px;
}

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

.field-label {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.field-input,
.field-select,
.field-textarea {
  width: 100%;
  min-height: 54px;
  padding: 12px 14px;
  border: 0;
  border-radius: var(--radius-input);
  background: var(--field-bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: box-shadow .3s var(--ease-ui);
}

/* Phones: iOS Safari zooms the whole page into any text control under 16px
   when it takes focus, so every field (dialog inputs included: they use the
   same classes) is 16px below the tablet breakpoint. Spec §6's 14px stands
   from 768px up (final review A-M9). */
@media (max-width: 767px) {
  .field-input,
  .field-select,
  .field-textarea {
    font-size: 16px;
  }
}

.field-input::placeholder,
.field-textarea::placeholder {
  color: var(--text-faint);
}

/* Focus is an inset ring: the fields are borderless and an outline would
   square off at the 6px corner. */
.field-input:focus,
.field-select:focus,
.field-textarea:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--field-focus-border);
}

.field-input[aria-invalid="true"],
.field-select[aria-invalid="true"],
.field-textarea[aria-invalid="true"] {
  box-shadow: inset 0 0 0 2px var(--danger);
}

/* Higher specificity, so a field being corrected keeps its focus cue. */
.field-input[aria-invalid="true"]:focus,
.field-select[aria-invalid="true"]:focus,
.field-textarea[aria-invalid="true"]:focus {
  box-shadow: inset 0 0 0 2px var(--field-focus-border);
}

.field-textarea {
  min-height: 88px;
  resize: vertical;
}

/* Sized to the content: a number, a short code, a day count. */
.field-input--narrow {
  max-width: 220px;
}

/* The select draws its own chevron, so its text starts at the same 14px inset
   as an input's and the chevron sits 14px from the right edge. */
.field-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 42px;
  background-image: var(--select-chevron);
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px 16px;
  cursor: pointer;
}

/* Read-only / disabled controls: no fill, a hairline outline and dim text,
   so they read as "shown, not editable" next to editable fields. */
.field-input:disabled,
.field-input[readonly],
.field-select:disabled,
.field-textarea:disabled,
.field-textarea[readonly] {
  background-color: transparent;
  box-shadow: inset 0 0 0 1px var(--border);
  color: var(--text-dim);
  cursor: not-allowed;
}

.field-input[readonly]:focus,
.field-textarea[readonly]:focus {
  box-shadow: inset 0 0 0 1px var(--field-focus-border);
}

input[type="file"] {
  max-width: 100%;
}

.field-help {
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-faint);
}

.field-help--warn {
  color: var(--warning);
}

/* A line that belongs to the field above it (Microsite's resulting address,
   an upload's "Uploaded: …" line) when it sits outside the .field: it closes
   the card's 16px gap to the field's own 6px. */
.field-note {
  margin-top: -10px;
}

.field-note code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text-dim);
  overflow-wrap: anywhere;
}

.field-error {
  font-size: 12px;
  color: var(--danger);
  white-space: pre-line;
}

.field-success {
  font-size: 12px;
  color: var(--success);
}

/* validation.js renders help and errors as <small>. */
small.field-help,
small.field-error {
  display: block;
}

/* One qualifier convention per form: a small tag after the label,
   "Required", "Optional" or "Read-only" (ui/fields.js
   field({ required | optional | readOnly })).
   Quieter than the label it qualifies. */
.field-req,
.req-mark {
  margin-left: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  vertical-align: middle;
}

/* The one checkbox: a flat filled circle with a dot set inside it. The dot is
   a background layer, so the ring never composites against it. */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  display: inline-block;
  width: var(--cbx-size);
  height: var(--cbx-size);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--cbx-bg);
  cursor: pointer;
}

input[type="checkbox"]:checked {
  background-image: radial-gradient(closest-side, var(--cbx-dot) 96%, transparent 100%);
  background-repeat: no-repeat;
  background-position: center;
  background-size: calc(var(--cbx-size) * var(--cbx-dot-scale)) calc(var(--cbx-size) * var(--cbx-dot-scale));
}

input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

input[type="checkbox"]:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* A checkbox row: sentence-case label beside the circle. */
.field-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  cursor: pointer;
}

.field-check .field-label {
  text-transform: none;
  letter-spacing: 0.01em;
  font-size: 13px;
  color: var(--text);
}

.field--check > .field-help {
  padding-left: calc(var(--cbx-size) + 10px);
  margin-top: -6px;
}

/* Radios keep the round "one of these" shape, drawn in page ink: a ring that
   reads in both themes (the native dark one is a grey dot on the card), a
   dot when chosen, and the whole row at 50% when disabled. */
.field-radios {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
}

.field-radio {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 34px;
  padding-block: 6px;
  font-size: 14px;
  cursor: pointer;
}

input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 18px;
  height: 18px;
  margin: 1.5px 0 0;
  border: 0;
  border-radius: 50%;
  background: var(--field-bg);
  box-shadow: inset 0 0 0 1.5px var(--text-faint);
  cursor: pointer;
}

input[type="radio"]:checked {
  box-shadow: inset 0 0 0 1.5px var(--accent);
  background-image: radial-gradient(closest-side, var(--accent) 50%, transparent 58%);
}

input[type="radio"]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

input[type="radio"]:disabled {
  cursor: not-allowed;
}

/* Forced colours (Windows High Contrast) drop box-shadows and gradient
   backgrounds, which is all the drawn checkbox and radio are made of: give
   both back their native, system-coloured look. */
@media (forced-colors: active) {
  input[type="checkbox"],
  input[type="radio"] {
    appearance: auto;
    -webkit-appearance: auto;
  }
}

.field-radio:has(input:disabled) {
  opacity: .5;
  cursor: not-allowed;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
/* Filled tonal shape, no border; ghost and danger draw an outline instead. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius-btn);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur) var(--ease), transform .15s var(--ease), filter var(--dur) var(--ease);
}

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

.btn:hover { background: var(--surface-hi); }
.btn:active { transform: scale(.98); }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: .5;
  cursor: not-allowed;
}

.btn:disabled:active { transform: none; }

/* One rule for secondary actions: inside a card (Copy, Show, Duplicate…,
   Hide, Upload / Replace / Remove, Cancel in the save bar) they are --ghost.
   The tonal base is shell chrome: the hub top bar and the workspace header. */
.btn--ghost {
  border: 1px solid var(--border);
  background: transparent;
}

.btn--ghost:hover { background: var(--surface); }

.btn--primary {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn--primary:hover {
  background: var(--accent);
  filter: brightness(1.08);
}

/* Destructive: red ink and a 40% red outline, never filled. */
.btn--danger {
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  background: transparent;
  color: var(--danger);
}

.btn--danger:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); }

/* A square icon button (theme toggle, menu, close). */
.btn-icon {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background var(--dur) var(--ease-ui), color var(--dur) var(--ease-ui);
}

.btn-icon:hover {
  background: var(--surface);
  color: var(--text);
}

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

.btn-icon .icon {
  width: 22px;
  height: 22px;
}

/* Small controls keep a 44px target without growing their visible box. */
.page-back::before,
.settings-tab::before,
.pill::before {
  content: '';
  position: absolute;
  inset-block: min(0px, calc((100% - 44px) / 2));
  inset-inline: min(0px, calc((100% - 44px) / 2));
}

/* ── Chips ──────────────────────────────────────────────────────────────── */
.settings-immediate-badge,
.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--surface-hi);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: middle;
}

/* Status chips: the status ink on an 8% wash of itself. */
.chip--success { color: var(--success); background: color-mix(in srgb, var(--success) 8%, transparent); }
.chip--warning { color: var(--warning); background: color-mix(in srgb, var(--warning) 8%, transparent); }
.chip--danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }

/* ── Tabs (ui/tabs.js) and pill groups ──────────────────────────────────── */
.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.settings-tabs--sticky {
  position: sticky;
  top: calc(var(--admin-header-block, 0px) + 8px);
  z-index: 6;
  padding: 8px 0;
  background: var(--bg);
}

/* ── Pill group: in-place filters (Events status, Library presets, Mine /
   Shared). The SAME pill as a tab — one look for every pill strip (spec §4.2,
   §6: 14px/300, 999px, --surface; the selected one in accent). A tab switches
   panels (role=tab, aria-selected); a pill filters in place (aria-pressed):
     <div class="pill-group" role="group" aria-label="…">
       <button type="button" class="pill" aria-pressed="true">All</button> … */
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.settings-tab,
.pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 300;
  cursor: pointer;
  transition: background var(--dur) var(--ease-ui), color var(--dur) var(--ease-ui);
}

.settings-tab:hover,
.pill:hover {
  background: var(--surface-hi);
  color: var(--text);
}

.settings-tab:focus-visible,
.pill:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.settings-tab--active,
.settings-tab--active:hover,
.pill[aria-pressed="true"],
.pill[aria-pressed="true"]:hover {
  background: var(--accent);
  color: var(--accent-fg);
}

.settings-tab-badge {
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-hi);
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 700;
}

/* On the filled active pill the default badge would vanish into the accent. */
.settings-tab--active .settings-tab-badge {
  background: color-mix(in srgb, var(--accent-fg) 20%, transparent);
  color: var(--accent-fg);
}

/* ── Save bar (ui/savebar.js) ───────────────────────────────────────────── */
/* Sticky at the bottom of the main column. Its top rule is the one hairline
   kept on purpose: the divider a long form scrolls under. */
.save-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.save-bar-secondary {
  display: flex;
  align-items: center;
  gap: 8px;
}

.save-bar-status {
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  white-space: pre-line;
}

.save-bar-status:empty {
  display: none;
}

.save-bar-status.tone-neutral { color: var(--text-dim); }
.save-bar-status.tone-warning { color: var(--warning); }
.save-bar-status.tone-success { color: var(--success); }
.save-bar-status.tone-error { color: var(--danger); }

/* ── Dialog (ui/dialog.js) ──────────────────────────────────────────────── */
.cdialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(0,0,0,.64);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: cdialog-backdrop-in 220ms var(--ease-ui) both;
}

@keyframes cdialog-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.cdialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
}

.cdialog-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 420px;
  padding: 28px 24px 24px;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(0,0,0,.45);
  animation: cdialog-card-in 220ms var(--ease) both;
}

.cdialog-card:focus {
  outline: none;
}

.cdialog-card--wide {
  max-width: 720px;
}

@keyframes cdialog-card-in {
  from { opacity: 0; transform: scale(.94) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.cdialog-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.03em;
  word-spacing: 0.1em;
  line-height: 1.1;
  color: var(--text);
}

.cdialog-card--danger .cdialog-title {
  color: var(--danger);
}

.cdialog-message {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-dim);
}

.cdialog-message p {
  margin: 0;
  white-space: pre-line;
}

.cdialog-message p + p {
  margin-top: 10px;
}

.cdialog-body {
  min-width: 0;
  font-size: 14px;
}

/* The slug must read exactly as it has to be typed: no uppercase transform. */
.cdialog-typed-confirmation {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
}

.cdialog-typed-confirmation .field-label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
}

.cdialog-typed-confirmation strong {
  color: var(--text);
  font-weight: 700;
}

.cdialog-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
}

@media (max-width: 480px) {
  .cdialog-card {
    padding: 22px 18px 20px;
  }

  .cdialog-actions {
    flex-direction: column;
  }

  .cdialog-actions .btn {
    width: 100%;
  }
}

/* ── Theme cards (Themes page, Library, Import from library) ─────────────── */
/* One object, one look: a borderless 20px card on --surface, a 4:3 feature
   thumb on the checkerboard, title / id / chips, then a left-aligned action
   row. A card that opens something wraps thumb + body in .theme-card-link
   (with a chevron cue); the actions stay outside the link.
     <article class="theme-card">
       [<a class="theme-card-link">] <div class="theme-card-media checker-plate"/>
         <div class="theme-card-body"><div class="theme-card-head"><h2|h3 class="theme-card-title"/>…</div>
           <code class="theme-card-id"/> <p class="theme-card-meta">chips</p></div> [</a>]
       <div class="theme-card-actions">buttons</div>
     </article> */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.theme-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border-radius: var(--radius-card);
  background: var(--surface);
}

.theme-card-link {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  transition: background var(--dur) var(--ease-ui);
}

.theme-card-link:hover {
  background: var(--surface);
}

.theme-card-link:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}

.theme-card-link:hover .theme-card-title {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.theme-card-media {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.theme-card-media img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Opaque, so the checkerboard never shows through the label. */
.theme-card-noimg {
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 12px;
}

/* The Library loads its thumbs late: the note hides once one has landed. */
.theme-card-media.has-image .theme-card-noimg {
  visibility: hidden;
}

.theme-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 14px 18px 4px;
}

.theme-card-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

.theme-card-title {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  word-spacing: 0.1em;
  line-height: 1.3;
  color: var(--text);
  overflow-wrap: anywhere;
}

/* "This opens": a chevron at rest, not only an underline on hover. */
.theme-card-cue {
  flex: none;
  display: flex;
  color: var(--text-faint);
}

.theme-card-cue .icon {
  width: 16px;
  height: 16px;
  stroke-width: 1.6px;
  transform: rotate(-90deg);
}

.theme-card-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-faint);
  overflow-wrap: anywhere;
}

.theme-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.theme-card-meta:empty {
  display: none;
}

.theme-card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 10px 18px 18px;
}

.theme-card-actions .btn {
  padding: 0 14px;
}

/* ── Accent colour control (ui/accent-row.js) ───────────────────────────── */
/* Branding's accent colours and Operator settings' accent fallbacks: label
   above (the field anatomy), then picker · hex · swatch · Reset on one line,
   at every width. */
.accent-rows {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.accent-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.accent-picker {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  padding: 6px;
  border: 0;
  border-radius: var(--radius-input);
  background: var(--field-bg);
  cursor: pointer;
}

.accent-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.accent-picker::-webkit-color-swatch {
  border: 0;
  border-radius: var(--radius-input);
}

.accent-picker::-moz-color-swatch {
  border: 0;
  border-radius: var(--radius-input);
}

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

/* No text-transform: the field shows exactly the case that is sent. */
.field-input.accent-hex {
  flex: 0 0 auto;
  width: 132px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* Spec §6: the swatch is one of the few bordered shapes. */
.swatch {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
}

/* A server or client error under a hex wraps onto its own line, below the
   whole row (it is inserted after the hex, so `order` moves it past the
   swatch and Reset). */
.accent-controls .field-error {
  flex-basis: 100%;
  order: 1;
}

/* Phone: a narrower hex keeps swatch and Reset on the picker's line. */
@media (max-width: 640px) {
  .accent-controls {
    gap: 8px;
  }

  .field-input.accent-hex {
    width: 108px;
  }
}

/* ── Empty / error state (ui/empty.js) ──────────────────────────────────── */
.admin-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 32px;
  border-radius: var(--radius-card);
  background: var(--surface);
  text-align: center;
}

.admin-empty-state-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
  word-spacing: 0.1em;
  color: var(--text);
}

.admin-empty-state-sub {
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--text-dim);
}

/* ── Stat tiles (ui/stat.js) ────────────────────────────────────────────── */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

@media (max-width: 640px) {
  .stat-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* One tile, one size on every page (Overview, Activity): content-height and
   top-aligned, so labels and numbers line up across a row whether or not a
   tile has a sub-line. */
.stat-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 4px;
  min-width: 0;
  padding: 16px 18px;
  border: 0;
  border-radius: var(--radius-card);
}

.stat-card--cool { background: var(--tile-cool); }
.stat-card--warm { background: var(--tile-warm); }
.stat-card--hot { background: var(--tile-hot); }
.stat-card--green { background: var(--tile-green); }

.stat-card--cool .stat-card-value { color: var(--tile-cool-ink); }
.stat-card--warm .stat-card-value { color: var(--warning); }
.stat-card--hot .stat-card-value { color: var(--tile-hot-ink); }
.stat-card--green .stat-card-value { color: var(--success); }

/* Colour is reserved for status: a zero carries none, so a 0 Failed never
   reads as an alarm. */
.stat-card--zero .stat-card-value { color: var(--text); }

.stat-card-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.stat-card-value {
  overflow-wrap: anywhere;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-card-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-faint);
}

/* ── Upload row (ui/asset-field.js) ─────────────────────────────────────── */
.asset-field-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.asset-field-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

/* Framed to the target ratio (aspect-ratio is set inline from `ratio`). */
.asset-thumb {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 96px;
  overflow: hidden;
  border-radius: var(--radius-btn);
  background: var(--surface-hi);
}

.asset-thumb--wide {
  width: 160px;
}

.asset-thumb--audio {
  width: 56px;
}

.asset-thumb img,
.asset-thumb video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* The checkerboard plate: transparency in a PNG reads as transparency. */
.checker-plate {
  background-color: var(--checker-a);
  background-image: repeating-conic-gradient(var(--checker-b) 0 25%, transparent 0 50%);
  background-size: 12px 12px;
}

.asset-thumb.is-empty {
  background: var(--surface-hi);
}

.asset-thumb-empty {
  padding: 4px;
  font-size: 10px;
  text-align: center;
  color: var(--text-faint);
}

.asset-thumb-glyph {
  font-size: 24px;
  line-height: 1;
  color: var(--text-dim);
}

.asset-field-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.asset-field-busy {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.asset-audio {
  width: 100%;
  max-width: 360px;
  height: 36px;
}
