/* Components, each defined once: buttons, links, pills, disclosures, notes, cards,
   metrics, tabs, fields, stepper, dialog, toast. Markup shapes are in web/DESIGN.md.
   DESIGN_SYSTEM_PLAN.md phase 6. */

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

.faq-item summary {
  font-weight: 700;
  padding: 14px 0;
  cursor: pointer;
  list-style-position: inside;
}

.faq-item p {
  margin-top: 0;
  color: var(--text);
}

.busy-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim-light);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
}

.busy-card {
  display: flex;
  gap: 14px;
  align-items: center;
  font-weight: 600;
  color: var(--text-heading);
  max-width: 82%;
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-heading);
  color: var(--surface-card);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: var(--text-sm);
  box-shadow: 0 6px 24px var(--shadow-color-strong);
  z-index: 40;
  max-width: 90%;
}

.toast.err {
  background: var(--error);
}

.table-check-list {
  display: grid;
  gap: 0.75rem;
}

.table-check-card h4 {
  margin: 0 0 0.35rem;
}

.table-check-summary {
  display: grid;
  gap: 0.35rem;
  margin: 0.35rem 0 0.6rem;
}

.table-check-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.table-check-rows.warn {
  color: var(--error);
  font-weight: 600;
}

.table-check-heard-label {
  margin: 0;
}

.table-check-heard {
  list-style: none;
  margin: 0;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.5;
  overflow-x: auto;
}

.table-check-heard li + li {
  margin-top: 0.3rem;
}

.table-check-heard-none {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.table-row-toggle {
  vertical-align: top;
  background: var(--surface-soft);
}

.table-live-preview {
  margin-top: 0.6rem;
}

.table-continuation {
  margin: 0.5rem 0;
}

.table-continuation p {
  margin: 0 0 0.4rem;
}

.table-check-list > div {
  min-width: 0;
}

.table-check-card {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
}

.table-check-card .review-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.table-check-heard {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.busy-card {
  flex-wrap: wrap;
}

.table-check-card .look-crop {
  margin-top: 6px;
}

a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

[tabindex="-1"]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 1000;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--text-heading);
  color: var(--text-on-inverse);
  transform: translateY(-160%);
}

.skip-link:focus {
  left: 12px;
  transform: translateY(0);
}

.hist-tag {
  letter-spacing: 0;
}

.btn {
  min-height: 44px;
  width: auto;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-size: var(--text-md);
  font-weight: 700;
  line-height: 1.25;
  text-decoration: none;
  cursor: pointer;
}

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

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

.btn-primary[disabled] {
  color: var(--text-muted);
  background: var(--primary-disabled);
  border-color: var(--line);
  cursor: not-allowed;
}

.btn-primary[disabled][aria-busy="true"] {
  cursor: wait;
}

.btn-ghost {
  color: var(--text-heading);
  background: var(--surface-card);
  border-color: var(--line-strong);
}

.btn-ghost:hover {
  color: var(--text-heading);
  background: var(--surface-soft);
}

.btn-quiet {
  color: var(--link);
  background: transparent;
}

.btn-quiet:hover {
  color: var(--text-heading);
  background: var(--surface-soft);
}

.btn-sm {
  min-width: 44px;
  padding: 8px 12px;
  color: var(--text);
  background: var(--surface-card);
  border-color: var(--line-strong);
  font-size: var(--text-sm);
  font-weight: 600;
}

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

.btn-sm:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-sm.danger {
  color: var(--error);
}

.table-row-toggle .btn-sm[aria-pressed="true"] {
  background: var(--primary-soft);
  font-weight: 700;
}

.btn-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 8px;
  border: 0;
  color: var(--link);
  background: none;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.btn-link:hover {
  color: var(--text-heading);
}

.pill, .sev-pill, .gate-badge, .job-pill, .pdf-status, .hist-tag, .ready-badge {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--text);
  background: var(--surface-soft);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: middle;
}

.pill-success, .gate-badge.ok, .job-pill-succeeded, .pdf-status-fixed, .hist-tag, .ready-badge {
  color: var(--success);
  background: var(--success-soft);
  border-color: var(--success-line);
}

.pill-warning, .gate-badge.warn, .job-pill-queued, .job-pill-running, .pdf-status-scope, .ready-badge.warn, .sev-pill.sev-moderate {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: var(--warning-line);
}

.pill-error, .gate-badge.bad, .job-pill-failed, .sev-pill.sev-critical {
  color: var(--error);
  background: var(--error-soft);
  border-color: var(--error-soft);
}

.sev-pill.sev-serious {
  color: var(--severity-serious);
  background: var(--warning-soft);
  border-color: var(--warning-line);
}

.pill-info, .pdf-status-remediation {
  color: var(--info);
  background: var(--info-soft);
  border-color: var(--info-line);
}

.hist-tag {
  align-self: flex-start;
}

.u-flag {
  color: var(--warning);
  font-size: var(--text-xs);
  font-weight: 700;
}

.faq-item {
  margin: 0;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.faq-item summary {
  min-height: 52px;
  padding: 14px 0;
}

.busy-card, .toast {
  border-radius: var(--radius-md);
}

.table-review-confirmation {
  position: relative;
  z-index: 1;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  background: var(--surface-card);
}

.table-review-confirmation .u-reviewed, .table-review-confirmation .field-hint {
  margin: 0;
}

.table-review-confirmation .field-hint {
  margin-top: 6px;
}

.table-structure-controls {
  margin: 12px 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 220px));
  gap: 12px;
}

.table-cell-editor, .table-cell-kind {
  width: 100%;
  min-height: 44px;
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text-heading);
  background: var(--surface-card);
  font: inherit;
}

.table-cell-editor {
  min-height: 72px;
  resize: vertical;
}

.table-cell-kind {
  margin-top: 6px;
}

.table-edit-caveat {
  margin: 12px 0;
  font-size: var(--text-sm);
}

.table-cell-span {
  margin-top: 5px;
  display: block;
  color: var(--text-muted);
}

.ready-technical {
  margin: 16px 0;
  padding-block: 12px;
  border-block: 1px solid var(--line);
}

.ready-technical > summary, .secondary-tools-disclosure > summary, .faq-item summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-strong);
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.ready-technical > summary::-webkit-details-marker, .secondary-tools-disclosure > summary::-webkit-details-marker, .faq-item summary::-webkit-details-marker {
  display: none;
}

.ready-technical > summary::after, .secondary-tools-disclosure > summary::after, .faq-item summary::after {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  margin: 0 6px 4px 0;
  content: "";
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  color: var(--text-heading);
  transform: rotate(45deg);
  transition: transform 160ms ease;
}

.ready-technical[open] > summary::after, .secondary-tools-disclosure[open] > summary::after, .faq-item[open] summary::after {
  margin: 4px 6px 0 0;
  transform: rotate(-135deg);
}

.ready-technical > summary:hover, .secondary-tools-disclosure > summary:hover, .faq-item summary:hover {
  color: var(--text-heading);
  background: var(--surface-soft);
}

.ready-faq {
  max-width: 760px;
  margin-top: 22px;
}

.ready-faq > h3 {
  max-width: none;
  margin: 0 0 2px;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.ready-faq .ready-technical {
  margin: 0;
  padding-block: 4px;
  border-block: 0;
  border-top: 1px solid var(--line);
}

.ready-faq .ready-technical:last-child {
  border-bottom: 1px solid var(--line);
}

.ready-faq .ready-technical > :not(summary) {
  margin-inline: 10px;
}

.faq-item summary {
  padding-inline: 0;
}

.ready-faq .ready-technical > p, .ready-faq .ready-technical > h4 {
  margin-block: 8px;
  font-size: var(--text-sm);
}

.ready-check-list {
  padding: 0;
  list-style: none;
}

.ready-check {
  display: grid;
  grid-template-columns: minmax(0, 11rem) minmax(0, 1fr);
  gap: 2px 14px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.ready-check:first-child {
  border-top: 0;
}

.ready-check small {
  grid-column: 2;
}

.ready-check.warn strong {
  color: var(--warning);
}

.review-notifications {
  position: fixed;
  z-index: 90;
  right: 20px;
  bottom: 20px;
  width: min(420px, calc(100% - 40px));
  max-height: min(60vh, 560px);
  display: grid;
  gap: 8px;
  overflow-y: auto;
}

.review-notification {
  padding: 12px 12px 12px 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: start;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--info);
  border-radius: var(--radius-md);
  color: var(--text-strong);
  background: var(--surface-card);
  box-shadow: 0 12px 28px var(--shadow-color);
}

.review-notification.err {
  border-left-color: var(--error);
  background: var(--error-soft);
}

.review-notification p {
  margin: 5px 0;
  overflow-wrap: anywhere;
}

.review-notification-dismiss {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  color: var(--text-strong);
  background: transparent;
  font-size: var(--text-xl);
  line-height: 1;
}

.secondary-tools-disclosure {
  max-width: 760px;
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.secondary-tools-disclosure > summary {
  position: relative;
  min-height: 44px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  border-radius: var(--radius-sm);
  color: var(--text-strong);
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.secondary-tools-disclosure > p {
  margin: 8px 10px;
  color: var(--text-muted);
}

.lifecycle {
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  list-style: none;
}

.lifecycle-audit {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.lifecycle li {
  --node-radius: 5px;
  --previous-node-radius: 5px;
  position: relative;
  padding: 18px 8px 0;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  text-align: center;
}

.lifecycle li::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  z-index: 2;
  box-sizing: border-box;
  width: 10px;
  height: 10px;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface-card);
  transform: translateX(-50%);
}

.lifecycle li::after {
  content: "";
  position: absolute;
  right: calc(50% + var(--node-radius));
  top: 5px;
  z-index: 1;
  width: calc(100% - var(--previous-node-radius) - var(--node-radius));
  height: 2px;
  background: var(--line);
  transform: translateY(-50%);
}

.lifecycle li:first-child::after {
  display: none;
}

.lifecycle li.done, .lifecycle li.current {
  color: var(--text-heading);
}

.lifecycle li.done::before {
  border-color: var(--success);
  background: var(--success);
}

.lifecycle li.done::after, .lifecycle li.current::after {
  background: var(--success);
}

.lifecycle li.current::before {
  top: -2px;
  width: 14px;
  height: 14px;
  border: 4px solid var(--primary-soft);
  background: var(--primary);
  box-shadow: 0 0 0 2px var(--primary);
}

.lifecycle li.current {
  --node-radius: 7px;
}

.lifecycle li.current + li {
  --previous-node-radius: 7px;
}

.lifecycle li.current.failed::before {
  border-color: var(--error-soft);
  background: var(--error);
  box-shadow: 0 0 0 2px var(--error);
}

.stage-dialog {
  width: min(100% - 32px, 620px);
  max-height: min(86vh, 720px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  color: var(--text);
  background: var(--surface-card);
  box-shadow: 0 24px 60px var(--shadow-color-strong);
}

.stage-dialog::backdrop {
  background: var(--scrim);
}

.stage-dialog-header, .stage-dialog-body, .stage-dialog-actions {
  padding: 20px 24px;
}

.stage-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
}

.stage-dialog-header .eyebrow {
  margin-bottom: 2px;
}

.stage-dialog-header h2 {
  margin: 0;
  font-size: var(--text-xl);
}

.stage-dialog-close {
  width: auto;
  flex: 0 0 auto;
}

.stage-dialog-body p:first-child {
  margin-top: 0;
}

.stage-dialog-body p:last-child {
  margin-bottom: 0;
}

.stage-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  border-top: 1px solid var(--line);
  background: var(--surface-page);
}

@media (max-width: 720px) {
  .table-structure-controls {
    grid-template-columns: 1fr;
  }

  .table-review-confirmation .btn {
    width: 100%;
    white-space: normal;
  }

  .review-notifications {
    right: 16px;
    bottom: 16px;
    width: calc(100% - 32px);
  }
}

@media (max-width: 720px) {
  .lifecycle {
    display: none;
  }

  .stage-dialog-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .stage-dialog-actions .btn {
    width: 100%;
  }

  .stage-dialog-header, .stage-dialog-body, .stage-dialog-actions {
    padding: 18px;
  }

  .stage-dialog-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .stage-dialog-close {
    align-self: start;
  }
}

@media (forced-colors: active) {
  .lifecycle li::before {
    border: 1px solid CanvasText;
    forced-color-adjust: auto;
  }

  .lifecycle li::after {
    background: CanvasText;
    forced-color-adjust: none;
  }

  .lifecycle li.done::after, .lifecycle li.current::after {
    background: Highlight;
  }
}

.note, .table-edit-caveat, .table-continuation {
  margin: 12px 0;
  padding: 12px 14px;
  border-left: 4px solid var(--info);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text);
  background: var(--info-soft);
}

.note-success {
  border-left-color: var(--success);
  background: var(--success-soft);
}

.note-warning {
  border-left-color: var(--warning);
  background: var(--warning-soft);
}

.note-error {
  border-left-color: var(--error);
  background: var(--error-soft);
}

.note-primary {
  border-left-color: var(--primary);
  background: var(--primary-soft);
}

.card, .table-check-card, .busy-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-card);
  box-shadow: none;
}

.card-compact {
  padding: 12px;
}

.metric-grid {
  margin: 24px 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  border-block: 1px solid var(--line);
}

.metric {
  min-width: 0;
  padding: 14px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.metric:first-child {
  padding-left: 0;
}

.metric:last-child {
  border-right: 0;
}

.metric-label, .ready-check span {
  display: block;
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: none;
}

.metric-value, .ready-check strong {
  display: block;
  margin: 4px 0 0;
  color: var(--text-heading);
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: 1.2;
}

.metric-detail, .ready-check small {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: 1.35;
}

.metric.warn .metric-value, .ready-check.warn strong {
  color: var(--warning);
}

.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 44px;
  margin-bottom: -1px;
  padding: 10px 14px;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--text-muted);
  background: transparent;
  font: inherit;
  font-size: var(--text-md);
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}

.tab:hover {
  color: var(--text-heading);
  background: var(--surface-soft);
}

.tab[aria-selected="true"], .tab[aria-current="page"] {
  border-bottom-color: var(--primary);
  color: var(--text-heading);
  background: transparent;
}

.field-input {
  box-sizing: border-box;
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--text);
  background: var(--surface-card);
  font: inherit;
  font-size: var(--text-md);
}

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

.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-strong);
  font-size: var(--text-sm);
  font-weight: 700;
}

.field-hint {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.field-error {
  margin: 6px 0 0;
  color: var(--error);
  font-size: var(--text-sm);
  font-weight: 700;
}

@media (max-width: 720px) {
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    padding: 12px 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metric:last-child {
    border-bottom: 0;
  }
}
