/*
  COMPONENTS: one `.c-*` family per partial in app/views/components (catalogued in COMPONENTS.md).
  Components read semantic tokens only. Elements never rely on colour alone: every chip, notice
  and state carries a word and usually an icon.
*/

/* ---------- Brand ---------- */

.c-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-strong);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  text-decoration: none;
}

.c-brand:hover {
  color: var(--color-text-strong);
}

.c-brand__mark {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
}

.c-brand__tile {
  fill: var(--color-action);
}

.c-brand__cue {
  fill: var(--color-action-text);
}

.c-brand--lg {
  font-size: var(--text-xl);
}

.c-brand--lg .c-brand__mark {
  width: 1.75rem;
  height: 1.75rem;
}

/* ---------- Button ---------- */

.c-button-form {
  display: inline-flex;
}

.c-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1-5);
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out);
}

.c-button--sm {
  min-height: var(--control-height-sm);
  padding: 0 var(--space-2);
  font-size: var(--text-sm);
}

.c-button--primary {
  background: var(--color-action);
  color: var(--color-action-text);
}

.c-button--primary:hover {
  background: var(--color-action-hover);
  color: var(--color-action-text);
}

.c-button--primary:active {
  background: var(--color-action-active);
}

.c-button--secondary {
  border-color: var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text);
}

.c-button--secondary:hover {
  background: var(--color-surface-hover);
  color: var(--color-text-strong);
}

.c-button--ghost {
  color: var(--color-text-muted);
}

.c-button--ghost:hover {
  background: var(--color-surface-sunken);
  color: var(--color-text-strong);
}

.c-button--ghost[aria-pressed="true"] {
  background: var(--color-surface-selected);
  color: var(--color-text-strong);
}

.c-button--danger {
  border-color: var(--color-danger-border);
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
}

.c-button--danger:hover {
  border-color: var(--color-danger-text);
  color: var(--color-danger-text);
}

.c-button--icon {
  width: var(--control-height);
  padding: 0;
}

.c-button--icon.c-button--sm {
  width: var(--control-height-sm);
}

.c-button:disabled,
.c-button[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

.c-button .c-kbd {
  margin-left: var(--space-1);
}

.c-button--primary .c-kbd {
  border-color: var(--color-action-text);
  background: transparent;
  color: var(--color-action-text);
}

/* ---------- Badge ---------- */

.c-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 1px var(--space-2);
  border: 1px solid var(--badge-border, var(--color-neutral-border));
  border-radius: var(--radius-sm);
  background: var(--badge-bg, var(--color-neutral-bg));
  color: var(--badge-text, var(--color-neutral-text));
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
  white-space: nowrap;
}

.c-badge svg {
  width: 0.875rem;
  height: 0.875rem;
}

.c-badge--outline {
  background: transparent;
}

.c-badge--neutral { --badge-text: var(--color-neutral-text); --badge-bg: var(--color-neutral-bg); --badge-border: var(--color-neutral-border); }
.c-badge--info,
.c-badge--accent { --badge-text: var(--color-info-text); --badge-bg: var(--color-info-bg); --badge-border: var(--color-info-border); }
.c-badge--success { --badge-text: var(--color-success-text); --badge-bg: var(--color-success-bg); --badge-border: var(--color-success-border); }
.c-badge--warning { --badge-text: var(--color-warning-text); --badge-bg: var(--color-warning-bg); --badge-border: var(--color-warning-border); }
.c-badge--danger { --badge-text: var(--color-danger-text); --badge-bg: var(--color-danger-bg); --badge-border: var(--color-danger-border); }

.c-badge--pending { --badge-text: var(--color-status-pending-text); --badge-bg: var(--color-status-pending-bg); --badge-border: var(--color-status-pending-border); }
.c-badge--approved,
.c-badge--executing { --badge-text: var(--color-status-approved-text); --badge-bg: var(--color-status-approved-bg); --badge-border: var(--color-status-approved-border); }
.c-badge--executed { --badge-text: var(--color-action-text); --badge-bg: var(--color-status-executed-solid); --badge-border: var(--color-status-executed-solid); }
.c-badge--rejected { --badge-text: var(--color-status-rejected-text); --badge-bg: var(--color-status-rejected-bg); --badge-border: var(--color-status-rejected-border); }
.c-badge--stale { --badge-text: var(--color-status-stale-text); --badge-bg: var(--color-status-stale-bg); --badge-border: var(--color-status-stale-border); }
.c-badge--expired { --badge-text: var(--color-status-expired-text); --badge-border: var(--color-status-expired-border); border-style: dashed; }
.c-badge--failed { --badge-text: var(--color-status-failed-text); --badge-bg: var(--color-status-failed-bg); --badge-border: var(--color-status-failed-border); }

.c-badge--risk_low { --badge-text: var(--color-risk-low-text); --badge-border: var(--color-risk-low-border); }
.c-badge--risk_medium { --badge-text: var(--color-risk-medium-text); --badge-border: var(--color-risk-medium-border); }
.c-badge--risk_high { --badge-text: var(--color-risk-high-text); --badge-border: var(--color-risk-high-border); }

/* ---------- Key caps and the hint bar ---------- */

.c-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 var(--space-1);
  border: 1px solid var(--color-border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-family: var(--font-sans);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  line-height: 1;
}

.c-kbd--mono {
  font-family: var(--font-mono);
}

.c-kbd-seq {
  display: inline-flex;
  gap: var(--space-0-5);
}

.c-hint-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.c-hint-bar__item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1-5);
}

/* ---------- Notice and flash ---------- */

.c-notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--notice-border);
  border-radius: var(--radius-md);
  background: var(--notice-bg);
  color: var(--notice-text);
  font-size: var(--text-md);
}

.c-notice > svg {
  margin-top: 0.1875rem;
}

.c-notice--info { --notice-text: var(--color-info-text); --notice-bg: var(--color-info-bg); --notice-border: var(--color-info-border); }
.c-notice--success { --notice-text: var(--color-success-text); --notice-bg: var(--color-success-bg); --notice-border: var(--color-success-border); }
.c-notice--warning { --notice-text: var(--color-warning-text); --notice-bg: var(--color-warning-bg); --notice-border: var(--color-warning-border); }
.c-notice--danger { --notice-text: var(--color-danger-text); --notice-bg: var(--color-danger-bg); --notice-border: var(--color-danger-border); }
.c-notice--neutral { --notice-text: var(--color-neutral-text); --notice-bg: var(--color-neutral-bg); --notice-border: var(--color-neutral-border); }

.c-notice__body {
  flex: 1;
  min-width: 0;
}

.c-notice__title {
  font-weight: var(--weight-semibold);
}

.c-notice__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-height-sm);
  height: var(--control-height-sm);
  margin: calc(var(--space-1) * -1) calc(var(--space-2) * -1) calc(var(--space-1) * -1) 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
}

.c-notice__close:hover {
  background: var(--color-surface-sunken);
}

.c-flash {
  display: contents;
}

/* ---------- State ---------- */

.c-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-12) var(--space-4);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  color: var(--color-text-muted);
  text-align: center;
}

.c-state--compact {
  padding: var(--space-6) var(--space-4);
}

.c-state__icon {
  color: var(--color-text-subtle);
}

.c-state__icon svg {
  width: 1.5rem;
  height: 1.5rem;
}

.c-state--loading .c-state__icon svg {
  animation: c-state-spin 1s linear infinite;
}

.c-state--error .c-state__icon {
  color: var(--color-danger-text);
}

.c-state__title {
  color: var(--color-text-strong);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
}

.c-state__body {
  max-width: var(--container-prose);
  font-size: var(--text-base);
}

.c-state__actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

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

/* ---------- Page header ---------- */

.c-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.c-page-header__title {
  font-size: var(--text-xl);
}

.c-page-header__description {
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--text-base);
}

.c-page-header__actions {
  display: flex;
  gap: var(--space-2);
}

/* ---------- Nav ---------- */

.c-nav {
  display: flex;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.c-nav__link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1-5);
  min-height: var(--control-height);
  padding: 0 var(--space-2);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
  text-decoration: none;
}

.c-nav__link:hover {
  background: var(--color-surface-sunken);
  color: var(--color-text-strong);
}

.c-nav__link[aria-current="page"] {
  background: var(--color-surface-selected);
  color: var(--color-text-strong);
}

.c-nav__link[aria-disabled="true"] {
  color: var(--color-text-subtle);
  cursor: not-allowed;
}

.c-nav__link[aria-disabled="true"]:hover {
  background: transparent;
  color: var(--color-text-subtle);
}

.c-nav--section {
  flex-direction: column;
}

/* ---------- Table ---------- */

.c-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.c-table {
  width: 100%;
  font-size: var(--text-md);
}

.c-table th,
.c-table td {
  padding: var(--space-1-5) var(--space-3);
  text-align: left;
  vertical-align: middle;
}

.c-table td {
  min-height: var(--row-min-height);
}

.c-table thead th {
  border-bottom: 1px solid var(--color-border-strong);
  background: var(--color-surface-sunken);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
}

.c-table tbody tr + tr td {
  border-top: 1px solid var(--color-border);
}

.c-table tbody tr:hover {
  background: var(--color-surface-hover);
}

.c-table .c-table__num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- Field ---------- */

.c-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.c-field--check {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.c-field__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.c-field__label {
  color: var(--color-text-strong);
  font-weight: var(--weight-medium);
}

.c-field__required {
  color: var(--color-danger-text);
}

.c-field__control {
  min-height: var(--control-height);
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.c-field__check {
  width: 1rem;
  height: 1rem;
  accent-color: var(--color-action);
}

.c-field--invalid .c-field__control {
  border-color: var(--color-danger-text);
}

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

.c-field__error {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-danger-text);
  font-size: var(--text-sm);
}

.c-field__error svg {
  width: 1rem;
  height: 1rem;
}

/* ---------- Toggle ---------- */

.c-toggle-form {
  display: inline-flex;
}

.c-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-1);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.c-toggle__track {
  display: inline-flex;
  align-items: center;
  width: 2rem;
  height: 1.125rem;
  padding: 0.125rem;
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-pill);
  background: var(--color-surface-sunken);
  transition: background-color var(--duration-fast) var(--ease-out);
}

.c-toggle__thumb {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: var(--radius-pill);
  background: var(--color-text-muted);
  transition: transform var(--duration-fast) var(--ease-out);
}

.c-toggle[aria-checked="true"] .c-toggle__track {
  border-color: var(--color-action);
  background: var(--color-action);
}

.c-toggle[aria-checked="true"] .c-toggle__thumb {
  background: var(--color-action-text);
  transform: translateX(0.875rem);
}

.c-toggle__state {
  min-width: 1.5rem;
}

/* ---------- Dialog ---------- */

.c-dialog-host {
  display: inline-flex;
}

.c-dialog {
  z-index: var(--z-dialog);
  width: min(32rem, calc(100vw - var(--space-8)));
  padding: 0;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface-raised);
  color: var(--color-text);
  box-shadow: var(--shadow-md);
}

.c-dialog::backdrop {
  background: var(--color-overlay);
}

.c-dialog__panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
}

.c-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.c-dialog__title {
  font-size: var(--text-lg);
}

.c-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* ---------- Admin ---------- */

.c-admin-nav {
  margin-bottom: var(--space-4);
}

/* Four sections no longer fit a phone's width on one line. */
.c-admin-nav .c-nav {
  flex-wrap: wrap;
}

.c-form {
  max-width: var(--container-prose);
}

.c-form__group {
  min-width: 0;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

/* ---------- Playbooks ---------- */

.c-section-title {
  font-size: var(--text-lg, 1.125rem);
  margin: 0;
}

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

.c-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin: 0;
}

.c-meta dt {
  color: var(--color-text-muted);
  font-size: 0.85em;
}

.c-meta dd {
  margin: 0;
}

.c-pre {
  margin: 0;
  padding: var(--space-3);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.c-change {
  margin: 0;
  padding: 0;
  list-style: none;
}

.c-change__details summary {
  cursor: pointer;
}

.c-diff__add { display: block; background: var(--color-success-bg); color: var(--color-success-text); }
.c-diff__del { display: block; background: var(--color-danger-bg); color: var(--color-danger-text); }
.c-diff__same { display: block; }
.c-version { font-weight: var(--weight-semibold); }

/* ---------- External link ---------- */

.c-external-link {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  overflow-wrap: anywhere;
}

.c-external-link svg {
  width: 0.875rem;
  height: 0.875rem;
  flex: none;
}

.c-external-link__host {
  color: var(--color-text-muted);
}

.c-external-link--refused .c-external-link__host {
  color: var(--color-warning-text);
}

/* ---------- Inbox ----------
   A listbox of cues beside the selected cue's detail. Below 64rem they stack, detail first. With
   aria-activedescendant, focus stays on the list, so the selected option shows the focus ring. */

.c-inbox {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: minmax(0, 1fr);
}

.c-inbox__list { order: 2; min-width: 0; }
.c-inbox__detail { order: 1; min-width: 0; }

@media (min-width: 64rem) {
  .c-inbox { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); align-items: start; }
  .c-inbox__list { order: 1; }
  .c-inbox__detail { order: 2; position: sticky; top: calc(var(--topbar-height) + var(--space-4)); }
}

.c-inbox__options {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.c-inbox__options:focus-visible { outline: none; }
.c-inbox__options:focus-visible [aria-selected="true"] { box-shadow: inset 3px 0 0 var(--color-action), var(--focus-ring); }

.c-inbox__more {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-top: var(--space-3);
}

.c-inbox__more p { margin: 0; }

.c-cue-option {
  display: flex;
  flex-direction: column;
  gap: var(--space-0-5);
  min-height: var(--row-min-height);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
}

.c-cue-option:last-child { border-bottom: 0; }
.c-cue-option:hover { background: var(--color-surface-hover); }
.c-cue-option[aria-selected="true"] { background: var(--color-surface-selected); }
.c-cue-option:not([data-status="pending"]) .c-cue-option__name,
.c-cue-option:not([data-status="pending"]) .c-cue-option__preview { color: var(--color-text-muted); }
.c-cue-option[aria-busy="true"] { opacity: 0.7; }

.c-cue-option__head,
.c-cue-option__meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.c-cue-option__name { font-weight: var(--weight-semibold); }
.c-cue-option__confidence { margin-left: auto; color: var(--color-text-muted); font-size: var(--text-sm); }
.c-cue-option__preview { color: var(--color-text); font-size: var(--text-sm); }
.c-cue-option__meta { color: var(--color-text-muted); font-size: var(--text-xs); }
.c-cue-option__meta time { margin-left: auto; }

.c-cue-detail {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.c-cue-detail[hidden] { display: none; }

.c-cue-detail__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.c-cue-detail__title { margin: 0; font-size: var(--text-lg); }
.c-cue-detail__section { display: flex; flex-direction: column; gap: var(--space-1); }
.c-cue-detail__section h3 { margin: 0; }

.c-cue-detail__text {
  margin: 0;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.c-cue-detail__decide,
.c-cue-detail__approve,
.c-cue-detail__other {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.c-cue-detail__options {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: 0;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.c-cue-detail__reasons summary { cursor: pointer; }
.c-cue-detail__reasons[open] { display: flex; flex-direction: column; gap: var(--space-3); }

.c-cue-links {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.c-shortcuts {
  display: grid;
  gap: var(--space-2);
  margin: 0;
}

.c-shortcuts div { display: flex; align-items: center; gap: var(--space-3); }
.c-shortcuts dt { min-width: 7rem; }
.c-shortcuts dd { margin: 0; }

/* ---------- Calibration (admin) ---------- */

.c-calibration-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
}

/* A per-bucket bar chart as inline SVG: the bar is the rate, the tick is a bucket with no sample. */
.c-bars {
  display: block;
  width: 7.5rem;
  height: 1.5rem;
  border-bottom: 1px solid var(--color-border-strong);
}

.c-bars__bar { fill: var(--color-action); }
.c-bars__none { fill: var(--color-border-strong); }
