/*
 * Components — reusable class-based building blocks.
 * Buttons, forms, tables, status dots, cards/panels, empty states, disclosures.
 * Add new component styles here (or in a focused new stylesheet), always on
 * top of tokens from tokens.css.
 */

/* ---------- Buttons ---------- */

.btn,
button,
input[type="submit"] {
  display: inline-block;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: 1.4;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}


.btn:hover,
button:hover,
input[type="submit"]:hover {
  background: var(--color-primary-hover);
  text-decoration: none;
}

.btn--secondary {
  background: var(--color-raised);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

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

.btn--danger {
  background: var(--color-danger);
  color: var(--color-danger-contrast);
}

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

/* button_to renders a form wrapper; keep it inline and spacing-neutral */
.button_to {
  display: inline-block;
  margin: 0;
}
/* Raised, larger buttons (matches taller token spacing). */
.btn { padding: var(--space-3) var(--space-5); }
/* Focusable controls show a visible ring. */
.btn:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
}
/* ---------- Forms ---------- */

label {
  font-weight: var(--font-medium);
  font-size: var(--text-sm);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="file"],
select,
textarea {
  font: inherit;
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  max-width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 0;
  border-color: var(--color-focus);
}

textarea {
  width: 100%;
  max-width: 42rem;
}

.field {
  margin-bottom: var(--space-4);
}

.field label {
  display: block;
  margin-bottom: var(--space-1);
}

/* Checkboxes and radios keep their natural size; only text-like controls
   stretch to the field width. */
.field input:not([type="checkbox"]):not([type="radio"]),
.field select,
.field textarea {
  width: 100%;
  max-width: 28rem;
}

/* Checkboxes/radios wrapped in a label sit inline with the label text. */
.field label:has(input[type="checkbox"]),
.field label:has(input[type="radio"]) {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  margin: 0 0 var(--space-5);
  background: var(--color-raised);
}

legend {
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  padding-inline: var(--space-2);
}

/* Inline filter/toolbar forms above tables */
.toolbar {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: var(--space-4);
}

/* Validation error summary */
.form-errors {
  background: var(--color-danger-bg);
  color: var(--color-danger-fg);
  border: 1px solid var(--color-danger-fg);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
}

.form-errors ul {
  margin: 0;
}

/* ---------- Tables ---------- */
/* Edge shadows reveal horizontal overflow (pure CSS: local-attachment cover
   gradients hide the shadow on the side that has no more content). Views
   pair this with tabindex="0" + role="region" so keyboard users can scroll. */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-5);
  background:
    linear-gradient(to right, var(--color-surface), var(--color-surface)),
    linear-gradient(to right, var(--color-surface), var(--color-surface)),
    linear-gradient(to right, color-mix(in srgb, var(--color-text) 25%, transparent), transparent),
    linear-gradient(to left, color-mix(in srgb, var(--color-text) 25%, transparent), transparent);
  background-color: var(--color-raised);
  background-position: 0 0, 100% 0, 0 0, 100% 0;
  background-repeat: no-repeat;
  background-size: 2rem 100%, 2rem 100%, 0.75rem 100%, 0.75rem 100%;
  background-attachment: local, local, scroll, scroll;
}

/* Identifiers and URLs stay on one line inside scrollable tables; narrow
   viewports scroll the wrapper instead of crushing cells into tall wraps. */
.table-wrapper code {
  white-space: nowrap;
}

/* Visually hidden but available to assistive tech (e.g. table action
   column headers that have no visible label). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Positioned ancestor for .visually-hidden content; without one the absolute
   span anchors to the viewport and widens document scrollable overflow. */
.visually-hidden-host {
  position: relative;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

th,
td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

/* Column headers are typographic labels on the white surface — small-caps
   muted text over a hairline, no grey fill. */
thead th {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Interactive rows signal clickability with a neutral fill, not accent tint */
tbody tr:hover {
  background: var(--color-surface-sunken);
}

tbody tr:last-child td,
tr:last-child th,
tr:last-child td {
  border-bottom: 0;
}

/* Key/value detail tables (first column is the label) */
table:not(:has(thead)) th {
  white-space: nowrap;
  color: var(--color-text-muted);
  font-weight: var(--font-medium);
  width: 1%;
}

/* ---------- Status dots & severity text (Ledger language) ----------
   Statuses are a small dot + plain text; color is functional only
   (grey = neutral/done, blue = running, amber = waiting, red = failed).
   Severity is plain weighted text — no badge washes. */
.st {
  white-space: nowrap;
  color: var(--color-text);
}

.st::before {
  content: "";
  display: inline-block;
  width: 0.45em;
  height: 0.45em;
  border-radius: 50%;
  margin-right: 0.5em;
  background: var(--color-border-strong);
  vertical-align: 0.08em;
}

.st--run::before {
  background: var(--color-info-fg);
}

.st--wait::before {
  background: #d9a53f; /* derived: #f7bd63 mixed 18% toward #1d262f */
}

.st--fail::before {
  background: var(--color-danger-fg);
}

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


.sev--high {
  color: var(--color-danger-fg);
}

.sev--medium {
  color: var(--color-warning-fg);
}

.sev--low {
  color: var(--color-text-muted);
}

/* ---------- Cards & panels ---------- */

.card {
  background: var(--color-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.card__header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

.card__header h2,
.card__header h3 {
  margin: 0;
}

/* ---------- Empty states ---------- */

.empty-state {
  background: var(--color-raised);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

/* ---------- Disclosures (run logs) ---------- */

details {
  background: var(--color-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
}

summary {
  cursor: pointer;
  font-weight: var(--font-medium);
}

details[open] summary {
  margin-bottom: var(--space-3);
}

/* ---------- Misc ---------- */

/* Page header: eyebrow + title + right-aligned action region. The hairline
   under the header gives every page the same structural rhythm. */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3) var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.page-header h1 {
  margin: 0;
}

.page-header__eyebrow {
  margin: 0 0 var(--space-1);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-primary);
  letter-spacing: .1em;
  text-transform: uppercase;
}

.page-header__actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

/* Section header: small-caps label with a single dark rule — document
   sectioning via type and one hairline (pending items). */
.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-6);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--color-heading);
}

.section-header h2 {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* Lead paragraph under a page header (home, intros) */
.lead {
  font-size: var(--text-lg);
  color: var(--color-text-muted);
  max-width: 46rem;
}

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

/* Shared review surfaces, including list pages, settings and detail pages. */
.card > h2:first-child { margin: 0 0 var(--space-3); }
.card > h3:first-child { margin-top: 0; }
.page-header__text { min-width: 0; }
.page-header h1 { letter-spacing: -.025em; }
.page-header__actions .btn { white-space: nowrap; }
.table-wrapper { box-shadow: var(--shadow-sm); }
.table-wrapper a { font-weight: var(--font-semibold); }
.toolbar { padding: var(--space-4); background: var(--color-raised); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
.card .toolbar { padding: 0; border: 0; background: none; }
@media (max-width: 760px) {
  .page-header { align-items: stretch; }
  .page-header__actions { width: 100%; }
  .page-header__actions .btn { flex: 1; text-align: center; }
  .toolbar > input:not([type=hidden]), .toolbar > select { flex: 1 1 10rem; min-width: 0; }
  .card { padding: var(--space-4); }
}

/* Status pill, tinted by state (model settings). */
.review-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  line-height: 1.5;
  white-space: nowrap;
  color: var(--color-neutral-fg);
  background: var(--color-neutral-bg);
  text-decoration: none;
}

.review-pill::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}

.review-pill--not-reviewed {
  background: transparent;
  color: var(--color-text-muted);
  padding-inline: 0;
}

.review-pill--not-reviewed::before { opacity: 0.4; }
.review-pill--no-issue { color: var(--color-success-fg); background: var(--color-success-bg); }
.review-pill--issue { color: var(--color-danger-fg); background: var(--color-danger-bg); }
.review-pill--outdated { color: var(--color-warning-fg); background: var(--color-warning-bg); }
.review-pill--reviewing { color: var(--color-info-fg); background: var(--color-info-bg); }
.review-pill--reviewing::before { animation: review-pulse 1.2s ease-in-out infinite; }

.review-pill--link:hover {
  text-decoration: none;
  filter: brightness(0.96);
}

.review-pill--link:hover .review-pill__chevron { transform: translateX(2px); }

@keyframes review-pulse {
  50% { opacity: 0.25; }
}

/* Compact data tables (usage, model settings). */
.data-table th,
.data-table td {
  padding: var(--space-2) var(--space-3);
  vertical-align: middle;
}
.data-table thead th { background: var(--color-surface-sunken); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Status dots (owner decision, 2026-10-11) ----------
 * One vocabulary everywhere: idle grey, running a spinner, done green,
 * warning amber, failed red. The chat-thread controller keeps every spinner
 * in phase by anchoring its animation (status-dot-spin) to the page timeline. */
.status-dot {
  display: inline-block;
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: -1px;
  background: var(--color-border-strong);
}
.status-dot--done { background: var(--color-success-fg); }
.status-dot--warning { background: var(--color-warning-fg); }
.status-dot--failed { background: var(--color-danger-fg); }
.status-dot--running {
  background: none;
  border: 2px solid var(--color-primary);
  border-right-color: transparent;
  animation: status-dot-spin 900ms linear infinite;
}
@keyframes status-dot-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .status-dot--running { animation: none; border-right-color: var(--color-primary); opacity: 0.7; }
}
