/* The widgets the new pages are built from, part 1 of 3: buttons, fields, badges, cards, feedback, tabs and crumbs,
   then stat tiles, capacity bars, meters, timelines, key-values and the live operations widgets (see the end).
   Needs tokens.css and base.css. Colors, sizes and spacing come from the tokens, never raw values.
   The ⓘ help tips are tips.css and tips.js, used as they are.
   Tables, the pager, the filter bar and chips are in widgets-data.css; menus, the side panel, dialogs and toasts
   are in widgets-overlays.css. Load them after this file. */

/* Text for screen readers only. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch);
  padding: 0 var(--space-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-md);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn:hover {
  background: var(--surface-sunken);
  border-color: var(--control-line);
}

.btn svg {
  flex: none;
}

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

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

.btn-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
}

.btn-quiet:hover {
  border-color: transparent;
  background: var(--surface-sunken);
  color: var(--text);
}

/* Destructive: the red is the outline and the words, so it reads in both themes without a white-on-pink problem. */
.btn-danger {
  border-color: var(--bad);
  background: var(--surface);
  color: var(--bad);
}

.btn-danger:hover {
  border-color: var(--bad);
  background: var(--bad-soft);
}

.btn-icon {
  width: var(--touch);
  padding: 0;
}

.btn-lg {
  min-height: var(--touch-lg);
  padding: 0 var(--space-5);
  font-size: var(--text-lg);
}

.btn-lg.btn-icon {
  width: var(--touch-lg);
  padding: 0;
}

/* A compact button for the actions in a table row. A finger needs the full size, so it grows back on a touch screen. */
.btn-sm {
  min-height: 32px;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
}

.btn-sm.btn-icon {
  width: 32px;
  padding: 0;
}

@media (pointer: coarse) {
  .btn-sm {
    min-height: var(--touch);
  }

  .btn-sm.btn-icon {
    width: var(--touch);
  }
}

/* The big buttons on the door and room screens. Use it with .btn-primary or .btn. */
.btn-stage {
  min-height: var(--touch-stage);
  padding: 0 var(--space-6);
  border-radius: var(--radius-lg);
  font-size: var(--text-xl);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Waiting for the server: the label stays (change it to "Saving…") and a ring turns before it. */
.btn.is-loading {
  pointer-events: none;
  cursor: progress;
}

.btn.is-loading::before {
  content: "";
  flex: none;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: widget-spin 0.7s linear infinite;
}

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

/* ---- Fields */
.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field > label:not(.check, .radio, .switch),
.field-label {
  font-size: var(--text-sm);
  font-weight: 600;
}

.hint {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  color: var(--bad);
  font-size: var(--text-sm);
  font-weight: 500;
}

/* A mark in front of the words, so an error is never only a color. */
.error::before {
  content: "!";
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--bad);
  color: var(--surface);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-height: var(--touch);
  padding: 0 var(--space-3);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-md);
  line-height: 1.4;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.input:hover:not(:disabled),
.select:hover:not(:disabled),
.textarea:hover:not(:disabled) {
  border-color: var(--text-muted);
}

.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  border-color: var(--accent);
  outline-offset: 0;
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  border-color: var(--line-strong);
  background: var(--surface-sunken);
  color: var(--text-faint);
  cursor: not-allowed;
}

.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"],
.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea {
  border-color: var(--bad);
}

/* Native pickers, styled to match: the same box as a text input, with no picker library. */
.input[type="date"],
.input[type="time"],
.input[type="datetime-local"] {
  font-variant-numeric: tabular-nums;
}

.input[type="date"]::-webkit-date-and-time-value,
.input[type="time"]::-webkit-date-and-time-value,
.input[type="datetime-local"]::-webkit-date-and-time-value {
  min-height: 1.4em;
  text-align: left;
}

.input::-webkit-calendar-picker-indicator {
  cursor: pointer;
}

.select {
  padding-right: 36px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 21px) 50%, calc(100% - 15px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.textarea {
  min-height: 96px;
  padding: 10px var(--space-3);
  resize: vertical;
}

/* A box or a round button with its words. The whole row is the touch target. */
.check,
.radio,
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--touch);
  cursor: pointer;
}

.check input,
.radio input {
  flex: none;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
  cursor: inherit;
}

.check:has(:disabled),
.radio:has(:disabled),
.switch:has(:disabled) {
  color: var(--text-faint);
  cursor: not-allowed;
}

/* On and off by where the knob sits as well as by color. */
.switch input {
  position: relative;
  flex: none;
  width: 40px;
  height: 24px;
  margin: 0;
  border: 1px solid var(--control-line);
  border-radius: 12px;
  background: var(--surface-sunken);
  appearance: none;
  cursor: inherit;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.switch input::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--control-line);
  transition: transform 0.15s ease, background-color 0.15s ease;
}

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

.switch input:checked::before {
  background: var(--on-accent);
  transform: translateX(16px);
}

.switch input:disabled {
  opacity: 0.5;
}

/* A segmented control: a few buttons that act as one choice. Its track, buttons and chosen look are in base.css, shared
   with the theme control; this is the size and the text. */
.seg {
  max-width: 100%;
}

.seg > button {
  min-height: calc(var(--touch) - 8px);
  min-width: calc(var(--touch) - 4px);
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
}

@media (pointer: coarse) {
  .seg > button {
    min-height: var(--touch);
    min-width: var(--touch);
  }
}

.seg > button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.badge-ok {
  border-color: transparent;
  background: var(--ok-soft);
  color: var(--ok);
}

.badge-warn {
  border-color: transparent;
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-bad {
  border-color: transparent;
  background: var(--bad-soft);
  color: var(--bad);
}

.badge-info {
  border-color: transparent;
  background: var(--info-soft);
  color: var(--info);
}

.badge-neutral {
  border-color: var(--line);
  background: var(--surface-sunken);
  color: var(--text-muted);
}

/* A dot in front of the words. The words carry the meaning; the dot is for scanning a column. */
.badge-dot::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ---- Cards */
.card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  min-height: 56px;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--line);
}

.card-head > h2,
.card-head > h3,
.card-head > h4,
.card-title {
  min-width: 0;
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.3;
}

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

.card-body {
  padding: var(--space-5);
}

/* The ⓘ tip keeps its dark popover (tips.css), but the small button itself must read on a light card. */
.card-head .tip,
.field .tip {
  color: var(--text-muted);
}

.card-head .tip:hover,
.card-head .tip[aria-expanded="true"],
.field .tip:hover,
.field .tip[aria-expanded="true"] {
  background: var(--surface-sunken);
  color: var(--text);
}

/* ---- Feedback */
.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text);
  font-size: var(--text-sm);
}

.notice > svg {
  flex: none;
  margin-top: 1px;
}

.notice-body {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.notice-title {
  font-weight: 600;
}

.notice-ok {
  border-left-color: var(--ok);
  background: var(--ok-soft);
}

.notice-ok > svg {
  color: var(--ok);
}

.notice-warn {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}

.notice-warn > svg {
  color: var(--warn);
}

.notice-bad {
  border-left-color: var(--bad);
  background: var(--bad-soft);
}

.notice-bad > svg {
  color: var(--bad);
}

.notice-info {
  border-left-color: var(--info);
  background: var(--info-soft);
}

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

/* The bar across the top when the screen cannot reach the server. */
.offline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--warn);
  background: var(--warn-soft);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 600;
  text-align: center;
}

.offline > svg {
  flex: none;
  color: var(--warn);
}

/* "Saving…", "Saved", "Couldn't save": set data-state to saving, saved or error. */
.save-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.save-state[data-state="saving"]::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: widget-spin 0.7s linear infinite;
}

.save-state[data-state="saved"] {
  color: var(--ok);
}

.save-state[data-state="saved"]::before {
  content: "\2713";
  font-weight: 700;
}

.save-state[data-state="error"] {
  color: var(--bad);
  font-weight: 600;
}

.save-state[data-state="error"]::before {
  content: "!";
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bad);
  color: var(--surface);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-7) var(--space-5);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  text-align: center;
}

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

.empty-body {
  max-width: 44ch;
  color: var(--text-muted);
}

.empty-action {
  margin-top: var(--space-3);
}

/* A placeholder for text that is still loading. */
.skel-lines {
  display: grid;
  gap: var(--space-3);
}

.skeleton {
  display: block;
  height: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--line) 25%, var(--surface-sunken) 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: widget-shimmer 1.4s ease-in-out infinite;
}

.skeleton:last-child:not(:only-child) {
  width: 60%;
}

@keyframes widget-shimmer {
  from {
    background-position: 100% 0;
  }

  to {
    background-position: -100% 0;
  }
}

/* ---- Tabs and crumbs */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  /* The tabs' underline sits 1px over the line; without this the row also scrolls (and shows a bar) for that 1px. */
  overflow-y: hidden;
}

.tabs > [role="tab"] {
  flex: none;
  min-height: var(--touch);
  padding: 0 var(--space-4);
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-md);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.tabs > [role="tab"]:hover {
  color: var(--text);
}

.tabs > [role="tab"][aria-selected="true"] {
  border-bottom-color: var(--accent-line);
  color: var(--text);
}

.tabs > [role="tab"]:focus-visible {
  outline-offset: -2px;
}

.crumbs ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.crumbs li + li::before {
  content: "/";
  margin-right: var(--space-2);
  color: var(--text-faint);
}

.crumbs a {
  display: inline-flex;
  align-items: center;
  color: var(--text-muted);
  text-decoration: none;
}

.crumbs a:hover {
  color: var(--text);
  text-decoration: underline;
}

.crumbs [aria-current="page"] {
  color: var(--text);
  font-weight: 600;
}

@media (pointer: coarse) {
  .crumbs a {
    min-height: var(--touch);
  }
}

/* ---- Numbers and status */
.stat {
  min-width: 0;
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.stat-label {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

.stat-value {
  margin-top: var(--space-1);
  font-size: var(--text-3xl);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.stat-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-3);
  margin-top: var(--space-1);
  font-size: var(--text-sm);
}

.stat-change {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-change-ok { color: var(--ok); }
.stat-change-bad { color: var(--bad); }
.stat-change-neutral { color: var(--text-muted); }

.stat-note {
  color: var(--text-muted);
}

.stat-spark {
  margin-top: var(--space-2);
}

/* A row of stat tiles that splits evenly: every row is full width and no tile sits alone on a row unless the row is one
   tile wide. Put data-count="N" on the row (the number of tiles showing; keep it up to date if tiles come and go) and the
   tiles take their place by the row's own width, not the window's:
     2 tiles: 2, else 1.   3: 3, else 1.   4: 4, else 2 + 2, else 1.
     5: 5, else 3 + 2 (the two wider), else 1.   6: 6, else 3 + 3, else 2 + 2 + 2, else 1.
   Each tile asks for a share of the row (--per-row tiles across, less the gaps) and the rest of the row is shared out
   between them, so a row always fills the width. A tile is never narrower than 160px when two are across (a phone) and
   180px when three or more are: k across needs k * 180px + (k - 1) * 16px (the gap), which is the min-width of each
   step below. Where the row is under 572px the numbers are a size smaller, so a time like 7:38 PM fits a tile.
   A hidden tile must come first in the row, so the 3 + 2 split can find the last two by counting from the end. */
.tiles {
  container-type: inline-size;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.tiles > * {
  --per-row: 1;
  flex: 1 1 calc((100% - (var(--per-row) - 1) * var(--space-4)) / var(--per-row) - 1px);
  min-width: 0;
}

/* The space under a row of tiles that has a page's table or cards after it. */
.tiles-spaced {
  margin-bottom: var(--space-4);
}

@container (max-width: 571px) {
  .tiles .stat {
    padding: var(--space-3);
  }

  .tiles .stat-value {
    font-size: var(--text-2xl);
  }
}

@container (min-width: 336px) {
  .tiles[data-count="2"] > *,
  .tiles[data-count="4"] > *,
  .tiles[data-count="6"] > * {
    --per-row: 2;
  }
}

@container (min-width: 572px) {
  .tiles[data-count="3"] > *,
  .tiles[data-count="5"] > *,
  .tiles[data-count="6"] > * {
    --per-row: 3;
  }

  .tiles[data-count="5"] > :nth-last-child(-n + 2) {
    --per-row: 2;
  }
}

@container (min-width: 768px) {
  .tiles[data-count="4"] > * {
    --per-row: 4;
  }
}

@container (min-width: 964px) {
  .tiles[data-count="5"] > *,
  .tiles[data-count="5"] > :nth-last-child(-n + 2) {
    --per-row: 5;
  }
}

@container (min-width: 1160px) {
  .tiles[data-count="6"] > * {
    --per-row: 6;
  }
}

/* Capacity bar: the words and the count come first, the bar is the glance. Sold out also gets stripes. */
.capbar {
  --capbar-c: var(--ok);
  --capbar-soft: var(--ok-soft);
  min-width: 0;
}

.capbar-warn { --capbar-c: var(--warn); --capbar-soft: var(--warn-soft); }
.capbar-bad { --capbar-c: var(--bad); --capbar-soft: var(--bad-soft); }

.capbar-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
  margin-bottom: var(--space-1);
  font-size: var(--text-sm);
}

.capbar-label {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
}

.capbar-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.capbar-none .capbar-count {
  color: var(--text-muted);
  font-weight: 500;
}

.capbar-word {
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--capbar-soft);
  color: var(--capbar-c);
  font-size: var(--text-xs);
  font-weight: 700;
}

.capbar-track {
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-sunken);
}

.capbar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--capbar-c);
}

.capbar-bad .capbar-fill {
  background-image: repeating-linear-gradient(135deg, var(--surface) 0 2px, transparent 2px 6px);
}

/* Meter: a ring, with the percentage written in it. */
.meter {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  max-width: 100%;
  text-align: center;
}

.meter-track {
  stroke: var(--line-strong);
  stroke-width: 7;
}

.meter-fill {
  stroke: var(--series-1);
  stroke-width: 7;
  stroke-linecap: round;
}

.meter-value {
  fill: var(--text);
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.meter-label {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* Timeline: a time, a mark with an icon in it, and a sentence, joined by a line. */
.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline-item {
  --tl-c: var(--text-muted);
  --tl-soft: var(--surface-sunken);
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: var(--space-3);
  padding-bottom: var(--space-4);
}

.timeline-ok { --tl-c: var(--ok); --tl-soft: var(--ok-soft); }
.timeline-warn { --tl-c: var(--warn); --tl-soft: var(--warn-soft); }
.timeline-bad { --tl-c: var(--bad); --tl-soft: var(--bad-soft); }
.timeline-info { --tl-c: var(--info); --tl-soft: var(--info-soft); }

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-item:not(:last-child)::before {
  content: "";
  position: absolute;
  top: 28px;
  bottom: 0;
  left: 13px;
  width: 2px;
  background: var(--line);
}

.timeline-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--tl-soft);
  color: var(--tl-c);
}

.timeline-body {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding-top: 2px;
}

.timeline-at {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.timeline-text {
  overflow-wrap: anywhere;
}

/* Key-values: a name and its value on each line. */
.kv {
  margin: 0;
}

.kv-row {
  display: grid;
  grid-template-columns: minmax(6rem, 38%) minmax(0, 1fr);
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--text-sm);
}

.kv-row:last-child {
  border-bottom: 0;
}

.kv dt {
  color: var(--text-muted);
}

.kv dd {
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* ---- Live operations */

/* The live dot differs in shape as well as color: a filled circle, a dashed ring, a hollow square. */
.live {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.live-dot {
  flex: none;
  box-sizing: border-box;
  width: 12px;
  height: 12px;
}

.live-live .live-dot {
  border-radius: 50%;
  background: var(--ok);
}

.live-connecting .live-dot {
  border: 2px dashed var(--warn);
  border-radius: 50%;
}

.live-offline .live-dot {
  border: 2px solid var(--bad);
  border-radius: 2px;
}

@media (prefers-reduced-motion: no-preference) {
  .live-live .live-dot {
    animation: live-pulse 2s ease-out infinite;
  }

  .live-connecting .live-dot {
    animation: live-spin 1.4s linear infinite;
  }
}

@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 var(--ok-soft); }
  70% { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

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

/* The pace key and the group chip share their marks, on a solid pace fill with the text color for that fill
   (--on-pace-*). Waiting is a dashed inner ring, on pace is plain, longer than usual has one "!" and much longer
   has two, so none of it rests on color. */
.pace-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.pace-legend li {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.pace-key,
.group-chip {
  --pace-c: var(--pace-ok);
  --on-pace: var(--on-pace-ok);
}

.pace-key-wait, .group-chip-wait { --pace-c: var(--pace-wait); --on-pace: var(--on-pace-wait); }
.pace-key-warn, .group-chip-warn { --pace-c: var(--pace-warn); --on-pace: var(--on-pace-warn); }
.pace-key-bad, .group-chip-bad { --pace-c: var(--pace-bad); --on-pace: var(--on-pace-bad); }

.pace-key {
  display: inline-grid;
  place-items: center;
  flex: none;
  box-sizing: border-box;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--pace-c);
  color: var(--on-pace);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.pace-key-wait {
  outline: 2px dashed var(--on-pace);
  outline-offset: -4px;
}

.pace-key-warn::before { content: "!"; }
.pace-key-bad::before { content: "!!"; }

/* The button is the touch area (44px); the solid disc inside it is what shows. */
.group-chip {
  position: relative;
  display: inline-grid;
  place-items: center;
  box-sizing: border-box;
  min-width: var(--touch);
  min-height: var(--touch);
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.group-chip-card {
  position: relative;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--pace-c);
  color: var(--on-pace);
  font-size: var(--text-xs);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}

.group-chip-wait .group-chip-card {
  outline: 2px dashed var(--on-pace);
  outline-offset: -5px;
}

/* Compact: about 34px for a crowded map. The button shrinks to the disc and a hidden 44px square keeps the touch area. */
.group-chip-compact {
  min-width: 34px;
  min-height: 34px;
}

.group-chip-compact::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--touch);
  height: var(--touch);
  transform: translate(-50%, -50%);
}

.group-chip-compact .group-chip-card {
  width: 34px;
  height: 34px;
  font-size: 11px;
}

.group-chip-compact.group-chip-wait .group-chip-card {
  outline-offset: -4px;
}

/* The pace mark, low on the left: the fill's text color as its background, so it reads against the dot. */
.group-chip-warn .group-chip-card::after,
.group-chip-bad .group-chip-card::after {
  position: absolute;
  bottom: -5px;
  left: -5px;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  min-width: 17px;
  height: 17px;
  padding: 0 2px;
  border: 1.5px solid var(--pace-c);
  border-radius: 9px;
  background: var(--on-pace);
  color: var(--pace-c);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.group-chip-warn .group-chip-card::after { content: "!"; }
.group-chip-bad .group-chip-card::after { content: "!!"; }

/* Selected: a heavy two-tone ring outside the dot, so it shows on a light or a dark map. */
.group-chip-selected .group-chip-card {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 5px var(--text);
}

/* Caught up with the group ahead: a striped band around the dot, like the band that joins the dots on the map. */
.group-chip-caught {
  padding: 0 14px;
  background: repeating-linear-gradient(135deg, var(--warn) 0 3px, var(--warn-soft) 3px 7px);
}

.group-chip-caught.group-chip-compact::before {
  width: calc(var(--touch) + 28px);
}

/* Passed, or was passed: the ⇄ mark, high on the right. */
.group-chip-pass {
  position: absolute;
  top: 0;
  right: 0;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--text);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  line-height: 1;
}

.group-chip-caught .group-chip-pass {
  right: 6px;
}

.group-chip-compact .group-chip-pass {
  top: -5px;
  right: -5px;
}

.group-chip-compact.group-chip-caught .group-chip-pass {
  right: 9px;
}

/* ---- Ticket-type editor: a repeatable list of fieldsets, each with its own Remove. Built by ticket-widgets.js. */
.ttedit {
  display: grid;
  gap: var(--space-4);
}

.ttedit-list {
  display: grid;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.ttedit-fieldset {
  min-width: 0;
  margin: 0;
  padding: var(--space-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.ttedit-fieldset legend {
  padding: 0 var(--space-2);
  font-size: var(--text-sm);
  font-weight: 600;
}

.ttedit-fields {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: var(--space-3);
}

.ttedit-note {
  grid-column: 1 / -1;
}

.ttedit-remove {
  display: flex;
  margin: var(--space-3) 0 0 auto;
}

.ttedit-empty {
  margin: 0;
  color: var(--text-muted);
}

@media (max-width: 599.98px) {
  .ttedit-fields {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* A "$" in front of a price box. */
.input-affix {
  position: relative;
  display: block;
}

.input-affix-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--space-3);
  display: flex;
  align-items: center;
  color: var(--text-muted);
  pointer-events: none;
}

.input-affix .input {
  padding-left: calc(var(--space-3) + 1ch + var(--space-2));
  font-variant-numeric: tabular-nums;
}

/* A small number with its unit after it ("60 sec", "15 min", "115 %"): the box is as wide as its value and the unit sits
   in a sunken tag on its edge. The input stays a real number input; name it with a label, or with aria-labelledby on the
   words of the sentence it sits in. Put the box and the unit in a .numfield:
   <span class="numfield"><input class="input" type="number" min="1" max="900"><span class="numfield-unit">sec</span></span>
   A time or an m:ss box is the same idea with .timefield on the input. */
.numfield {
  display: inline-flex;
  align-items: stretch;
  max-width: 100%;
  vertical-align: middle;
  border: 1px solid var(--control-line);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}

.numfield:hover {
  border-color: var(--text-muted);
}

.numfield:has(.input:focus-visible) {
  border-color: var(--accent);
  outline: 2px solid var(--focus-ring, var(--accent));
  outline-offset: 2px;
}

.numfield:has(.input[aria-invalid="true"]) {
  border-color: var(--bad);
}

.numfield:has(.input:disabled) {
  border-color: var(--line-strong);
  background: var(--surface-sunken);
}

.numfield > .input {
  flex: 0 1 72px;
  width: 72px;
  min-width: 0;
  min-height: 40px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-variant-numeric: tabular-nums;
  text-align: right;
  appearance: textfield;
  -moz-appearance: textfield;
}

.numfield > .input:focus-visible {
  outline: 0;
}

.numfield > .input::-webkit-outer-spin-button,
.numfield > .input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.numfield-unit {
  display: flex;
  flex: none;
  align-items: center;
  padding: 0 var(--space-3);
  border-left: 1px solid var(--line);
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.input.timefield {
  display: inline-block;
  width: 132px;
  max-width: 100%;
  min-height: 40px;
  vertical-align: middle;
}

/* In a field's grid they keep their own width instead of stretching to the column. */
.field > .numfield,
.field > .timefield {
  justify-self: start;
}

@media (pointer: coarse) {
  .numfield > .input,
  .input.timefield {
    min-height: var(--touch);
  }
}

/* ---- Guest and stage surfaces, and nested themes
   The colors come from the surface and theme blocks in tokens.css, --control-line (a control's edge) included. */

/* A stage screen paints its own ground, so a stage panel in a light page is dark right through. */
[data-surface="stage"] {
  background: var(--bg);
  color: var(--text);
}

/* The room screen's DONE: a dark fill with red text, and an edge so the button still reads on the dark panel. */
[data-surface="stage"][data-stage="red"] .btn-primary,
[data-surface="stage"][data-stage="red"] .btn-primary:hover {
  border-color: var(--line-strong);
}

/* ---- Page head */
/* The row at the top of .content for a page's own controls: a picker, the primary action, the save state. */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

/* A picker in the head is as wide as its choices, not the whole row. */
.page-head > .select,
.page-head > .input {
  width: auto;
  max-width: 100%;
}
