/* Shared primitives for app, portals and separate windows. Local geometry may
   specialize these defaults; colors and font families must remain token based. */
:where(button, input, textarea, select) {
  font-family: var(--scarlet-font-mono);
  font-size: var(--scarlet-size-control);
  line-height: 1.5;
  color: var(--scarlet-text);
  background: var(--scarlet-surface);
  border: 1px solid var(--scarlet-border-strong);
  border-radius: var(--scarlet-radius);
}
:where(
  button,
  input:not([type="checkbox"], [type="radio"], [type="range"]),
  select
) {
  min-height: var(--scarlet-control-height);
}
:root[data-scarlet-density="compact"] {
  --scarlet-control-height: var(--scarlet-control-compact);
}
:where(button) {
  overflow-wrap: anywhere;
}
:where(button, input, textarea, a, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--scarlet-accent-text);
  outline-offset: 2px;
}

/* Shared by native tables and virtual registries. Headers and spacers stay static. */
@media (hover: hover) and (pointer: fine) {
  :is(.data-row, table > tbody > tr:not([aria-hidden="true"])) {
    transition: background-color var(--scarlet-row-fade) ease-out;
  }
  :is(.data-row, table > tbody > tr:not([aria-hidden="true"])):hover {
    background-color: var(--scarlet-row-hover);
    transition-duration: var(--scarlet-row-enter);
  }
  :is(.data-row.selected, table > tbody > tr[aria-selected="true"]):hover {
    background-color: var(--scarlet-row-selected-hover);
  }
}
@media (prefers-reduced-motion: reduce) {
  :is(.data-row, table > tbody > tr:not([aria-hidden="true"])) {
    transition: none;
  }
}
:root[data-scarlet-motion="off"]
  :is(.data-row, table > tbody > tr:not([aria-hidden="true"])),
.app:is(.operational, .reduced, .hidden)
  :is(.data-row, table > tbody > tr:not([aria-hidden="true"])) {
  transition: none;
}
:where(h1, h2, h3, h4, h5, h6) {
  font-family: var(--scarlet-font-display);
  font-weight: var(--scarlet-font-heading-weight);
  color: var(--scarlet-accent);
  line-height: 1.2;
  overflow-wrap: anywhere;
}
:where(h1) {
  font-size: var(--scarlet-size-h1);
}
:where(h2) {
  font-size: var(--scarlet-size-h2);
}
:where(h3, h4, h5, h6) {
  font-size: var(--scarlet-size-h3);
}
:where(strong, b) {
  font-weight: 700;
}
:where(em, i) {
  font-style: italic;
}
:where(code, pre, kbd, samp) {
  font-family: var(--scarlet-font-mono);
}
:where(pre, code, td, dd) {
  font-variant-numeric: tabular-nums;
}
:where(a) {
  color: var(--scarlet-text);
  text-underline-offset: 3px;
}
:where(small, dt) {
  color: var(--scarlet-muted);
  font-size: var(--scarlet-size-meta);
}
:where(label, p, dd, [role="alert"]) {
  overflow-wrap: anywhere;
}
:where(p) {
  line-height: 1.7;
}
:where(.scarlet-prose, .synapse-rich-text, .tutorial p) {
  font-size: var(--scarlet-size-body);
}
:where(.scarlet-actions) {
  display: flex;
  flex-wrap: wrap;
  gap: var(--scarlet-space-2);
  align-items: center;
}
.scarlet-action-grid,
.evidence-actions.scarlet-action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  gap: var(--scarlet-space-2);
  align-items: stretch;
  min-width: 0;
}
.scarlet-action-grid > button {
  width: 100%;
  min-width: 0;
  height: auto;
  white-space: normal;
}
.scarlet-action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--scarlet-space-2);
  min-width: 0;
}
.scarlet-primary {
  border-color: var(--scarlet-accent);
  font-weight: 600;
}
.scarlet-danger {
  color: var(--scarlet-error);
  border-color: var(--scarlet-accent);
}
:where(.scarlet-note) {
  color: var(--scarlet-muted);
  font-size: var(--scarlet-size-meta);
}
/* These are geometry controls, not full-height form fields. */
:where(.scarlet-column-resize, .pane-divider, .shell-pane-divider) {
  min-height: 0;
}
:where(.inventory-clock-controls button, .inventory-clock-controls input) {
  min-height: var(--scarlet-control-compact);
}
/* Fixed toolbars must grow for translated or enlarged text. */
.relay-browser-footer {
  height: auto;
  min-height: 26px;
  flex-wrap: wrap;
  padding-block: var(--scarlet-space-1);
}
.relay-browser-error {
  height: auto;
  white-space: normal;
  max-height: 40vh;
  overflow: auto;
}
.scarlet-select-value {
  white-space: normal;
  overflow-wrap: anywhere;
}
.scarlet-select-menu [role="option"] {
  min-height: var(--scarlet-control-height);
}
/* An emphasis marker must remain real text, even without italic support. */
.scarlet-prose em,
.scarlet-note em {
  font-style: italic;
}

.synapse-rich-text {
  font-size: var(--scarlet-size-body);
}
.scarlet-menu button,
.scarlet-select-menu,
.scarlet-combobox-menu {
  font-size: var(--scarlet-size-control);
}

fieldset {
  min-width: 0;
  border: 1px solid var(--scarlet-border-strong);
  border-radius: var(--scarlet-radius);
  padding: var(--scarlet-space-3);
}
legend {
  color: var(--scarlet-muted);
  padding-inline: var(--scarlet-space-1);
}
progress {
  accent-color: var(--scarlet-accent-text);
}
.scarlet-primary {
  background: var(--scarlet-selected);
}
.scarlet-select-trigger {
  border-color: var(--scarlet-border-strong);
}

.scarlet-font-status {
  position: fixed;
  bottom: var(--scarlet-space-4);
  left: var(--scarlet-space-4);
  right: var(--scarlet-space-4);
  z-index: 100;
  padding: var(--scarlet-space-3);
  background: var(--scarlet-surface);
  color: var(--scarlet-text);
  border: 1px solid var(--scarlet-border-strong);
  font: var(--scarlet-size-control) / 1.5 var(--scarlet-font-mono);
}

/* Shared native file chooser action; the input retains browser file semantics. */
::file-selector-button {
  font: inherit;
  color: var(--scarlet-text);
  background: var(--scarlet-raised);
  border: 1px solid var(--scarlet-border-strong);
  border-radius: var(--scarlet-radius);
  padding: var(--scarlet-space-2);
  margin-right: var(--scarlet-space-2);
}
