/* site.css: the site's own ts-* building blocks for sections (page layout helpers, states,
   tables, radio choices, dialog hosts, toasts, feedback sheets). Loaded after components.css so it
   can extend the kit's classes (for example .cpd-card.ts-placeholder) without fighting the cascade.
   Everything is built from the design-language tokens; nothing here restyles a cpd-* class globally. */

/* ---- Page building blocks for sections ---- */
.ts-page { display: grid; gap: var(--space-section); align-content: start; min-width: 0; }
.ts-page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-stack); flex-wrap: wrap; }
.ts-page-head > h2 { font-size: var(--type-section-title-size); line-height: var(--type-section-title-line); }
.ts-section-title { font-size: var(--type-section-title-size); line-height: var(--type-section-title-line); font-weight: 700; }
.ts-caption { font-size: var(--type-caption-size); line-height: var(--type-caption-line); color: var(--muted); }
.ts-stack { display: grid; gap: var(--space-stack); align-content: start; min-width: 0; }
.ts-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-compact); }
.ts-grid { display: grid; gap: var(--space-grid); grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.ts-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-compact); }
.ts-field { margin: 0; }
.ts-field textarea { min-height: 140px; }

/* Counters, autosave line, follow-up codes */
.ts-counter { justify-self: end; font-size: var(--type-caption-size); color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; }
.ts-counter.is-over { color: var(--red); }
.ts-autosave { font-size: var(--type-caption-size); color: var(--muted); }
.ts-autosave[data-status="error"], .ts-autosave[data-status="conflict"] { color: var(--red); }
.ts-autosave[data-status="offline"] { color: var(--attendance-amber); }
.ts-followup { font-size: var(--type-caption-size); color: var(--muted); }

/* Status: a word plus an icon, never colour alone */
.ts-status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--type-caption-size); font-weight: 700; line-height: 1.5; }
.ts-status--ok { color: var(--green); }
.ts-status--warn { color: var(--attendance-amber); }
.ts-status--bad { color: var(--red); }
.ts-status--info { color: var(--cpd-blue); }
.ts-stale { display: flex; align-items: center; gap: 8px; color: var(--attendance-amber); font-size: var(--type-caption-size); font-weight: 700; }

/* Banners (offline, staging): full width inside the scroller, above the page */
.ts-banner {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px var(--ts-pad);
  background: var(--gold-tint);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  font-size: var(--type-caption-size);
  font-weight: 700;
}

/* Loading skeleton (never a bare spinner) */
.ts-skeleton { display: grid; gap: var(--space-stack); }
.ts-skeleton__row { display: grid; gap: 10px; padding: var(--space-surface); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-surface); }
.ts-skeleton__bar { display: block; height: 14px; border-radius: 7px; background: var(--line); width: 70%; animation: ts-pulse 1.4s ease-in-out infinite; }
.ts-skeleton__bar--title { height: 20px; width: 40%; }
@keyframes ts-pulse { 50% { opacity: .45; } }

/* States: empty, error, not found, forbidden, coming soon */
.ts-empty { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-surface); }
.ts-state { display: grid; gap: var(--space-stack); max-width: 720px; }
.ts-state__head { display: flex; align-items: center; gap: 12px; }
.ts-state__title { font-size: var(--type-section-title-size); line-height: var(--type-section-title-line); }
.ts-placeholder {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-surface) var(--space-section);
  align-items: center;
  padding: var(--space-section);
  max-width: 760px;
}
.ts-placeholder__icon {
  display: grid;
  place-items: center;
  width: 88px;
  height: 88px;
  border-radius: var(--radius-surface);
  background: var(--paper);
  border: 1px solid var(--line);
}
.ts-placeholder__copy { display: grid; gap: 6px; }
.ts-placeholder__head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.ts-placeholder__head h2 { font-size: var(--type-section-title-size); line-height: var(--type-section-title-line); }
.ts-placeholder__copy p { color: var(--muted); }
.ts-placeholder > .cpd-btn { grid-column: 1 / -1; justify-self: start; }
@media (max-width: 699px) {
  .ts-placeholder { grid-template-columns: minmax(0, 1fr); padding: var(--space-surface); }
  .ts-placeholder > .cpd-btn { justify-self: stretch; }
}

/* Tables (admin lists). Wide tables scroll inside their card, never the page. */
.ts-table-wrap { overflow-x: auto; max-width: 100%; contain: inline-size; }
.ts-table { width: 100%; font-size: var(--type-body-size); }
.ts-table th, .ts-table td { padding: 12px 10px; text-align: start; vertical-align: top; border-bottom: 1px solid var(--line); }
.ts-table th { font-size: var(--type-field-label-size); font-weight: 700; color: var(--muted); white-space: nowrap; }
.ts-table tr:last-child td { border-bottom: 0; }

/* Radio choices (48px rows) */
.ts-choices { display: grid; gap: 6px; }
.ts-choices__legend { margin-bottom: 8px; font-size: var(--type-field-label-size); font-weight: 700; }
.ts-choice {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--target-min);
  padding: 8px 12px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius-field);
  background: var(--surface);
  cursor: pointer;
}
.ts-choice:has(input:checked) { background: var(--gold-tint); border-color: var(--gold-deep); font-weight: 700; }
.ts-choice input { width: 20px; height: 20px; margin: 0; accent-color: var(--gold-deep); flex: none; }

/* ---- Dialog hosts (native <dialog>; the kit's .cpd-sheet / .cpd-alert panels go inside) ---- */
.ts-dialog {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px);
  overflow: visible;
}
.ts-dialog::backdrop { background: var(--scrim); }
.ts-dialog--alert { width: 340px; }
.ts-dialog--alert .cpd-alert { width: 100%; background: var(--surface); }
.ts-dialog--sheet { width: min(560px, calc(100vw - 32px)); }
.ts-dialog--sheet .cpd-sheet { width: 100%; }
.ts-dialog--popover {
  position: fixed;
  inset: calc(var(--ts-masthead-h) + 8px) var(--ts-pad) auto auto;
  margin: 0;
  width: min(380px, calc(100vw - 32px));
}
:root[dir="rtl"] .ts-dialog--popover { inset: calc(var(--ts-masthead-h) + 8px) auto auto var(--ts-pad); }
.ts-dialog--popover::backdrop { background: color-mix(in srgb, var(--scrim) 45%, transparent); }
.ts-sheet { max-height: calc(100dvh - 48px); }
.ts-sheet .cpd-sheet__content { display: grid; gap: var(--space-stack); }
.ts-sheet .cpd-sheet__actions { margin-top: 8px; }
.ts-sheet-error { margin: 0; }
.ts-alert h2 { overflow-wrap: anywhere; }
@media (max-width: 699px) {
  /* Phones: sheets and the account menu rise from the bottom edge. */
  .ts-dialog--sheet, .ts-dialog--popover, :root[dir="rtl"] .ts-dialog--popover {
    position: fixed;
    inset: auto 0 0 0;
    margin: 0;
    width: 100vw;
    max-width: 100vw;
    max-height: calc(100dvh - 24px);
  }
  .ts-dialog--sheet .cpd-sheet, .ts-dialog--popover .ts-account {
    border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
    max-height: calc(100dvh - 24px);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ---- Toasts: bottom centre, above the tab bar and the suggest pill ---- */
.ts-toasts {
  position: fixed;
  inset-inline: 0;
  bottom: calc(24px + 56px);
  z-index: 60;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding-inline: 16px;
  pointer-events: none;
}
.ts-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(508px, 100%);
  padding-block: 10px;
  padding-inline: 14px 10px;
}
.ts-toast__text { flex: 1; min-width: 0; }
.ts-toast__action, .ts-toast__close {
  flex: none;
  min-height: var(--target-min);
  min-width: var(--target-min);
  padding: 4px 10px;
  border: 0;
  border-radius: var(--radius-button);
  background: transparent;
  color: inherit;
  font-weight: 700;
}
.ts-toast__action { text-decoration: underline; text-underline-offset: 3px; }
.ts-toast__close { display: grid; place-items: center; padding: 0; }
.ts-toast__action:focus-visible, .ts-toast__close:focus-visible { outline-color: var(--gold); outline-offset: 0; }
@media (max-width: 699px) {
  .ts-toasts { bottom: calc(var(--ts-tabbar-h) + env(safe-area-inset-bottom) + 72px); }
}

/* ---- Feedback sheets ---- */
.ts-feedback__q { margin: 0; color: var(--ink); font-size: var(--type-body-size); font-weight: 700; }
.ts-feedback__page { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: var(--type-caption-size); }
.ts-shot { flex-wrap: wrap; }
.ts-shot__copy { display: grid; gap: 4px; flex: 1; min-width: 200px; }
.ts-shot__copy small { color: var(--muted); font-size: var(--type-caption-size); }
.ts-shot__pick { justify-self: start; cursor: pointer; }
.ts-shot__preview { display: flex; align-items: center; gap: 10px; width: 100%; }
.ts-shot__preview:empty { display: none; }
.ts-shot__img { max-height: 96px; width: auto; border: 1px solid var(--line); border-radius: var(--radius-field); }

/* Boot failure and noscript */
.ts-boot-error, .ts-noscript {
  max-width: 560px;
  margin: 15vh auto 0;
  padding: var(--space-section);
  display: grid;
  gap: var(--space-stack);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-surface);
}
