/* Optional semantic UI primitives. Load tokens.css first. */
.tf-button {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--techius-command-gap, var(--techius-space-3));
  min-block-size: var(--techius-command-min-size, var(--techius-control-target-size));
  max-inline-size: 100%;
  padding: var(--techius-command-padding-block, var(--techius-space-3)) var(--techius-command-padding-inline, calc(var(--techius-space-4) + 2px));
  border: 1px solid var(--techius-color-border-control);
  border-radius: var(--techius-radius-control);
  background: var(--techius-color-surface);
  color: var(--techius-color-text);
  font-family: inherit;
  font-size: var(--techius-command-font-size);
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
  text-decoration: none;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition:
    background-color 150ms,
    border-color 150ms,
    color 150ms;
}
.tf-button[data-variant="primary"] {
  border-color: transparent;
  background: var(--techius-color-primary);
  color: var(--techius-color-on-primary);
}
.tf-button[data-variant="ghost"] {
  border-color: transparent;
  background: transparent;
  color: var(--techius-color-primary);
}
.tf-button[data-variant="danger"] {
  border-color: transparent;
  background: var(--techius-color-danger);
  color: var(--techius-color-on-danger);
}
.tf-button:not(:disabled):not([aria-busy="true"]):hover {
  background: var(--techius-color-interactive-hover);
}
.tf-button:not(:disabled):not([aria-busy="true"]):active {
  background: var(--techius-color-interactive-active);
}
.tf-button[data-variant="primary"]:not(:disabled):not(
    [aria-busy="true"]
  ):hover {
  background: var(--techius-color-primary-hover);
}
.tf-button[data-variant="ghost"]:not(:disabled):not([aria-busy="true"]):hover {
  background: var(--techius-color-primary-soft);
}
.tf-button[data-variant="danger"]:not(:disabled):not([aria-busy="true"]):hover {
  box-shadow: inset 0 0 0 100vmax rgb(0 0 0 / 12%);
  background: var(--techius-color-danger);
}
.tf-button[data-variant="danger"]:not(:disabled):not([aria-busy="true"]):active {
  box-shadow: inset 0 0 0 100vmax rgb(0 0 0 / 18%);
  background: var(--techius-color-danger);
}
.tf-button:disabled {
  background: var(--techius-color-disabled);
  color: var(--techius-color-on-disabled);
  border-color: transparent;
  cursor: not-allowed;
}
.tf-button[aria-busy="true"] {
  cursor: progress;
}
.tf-button[aria-busy="true"]::after,
.tf-state__spinner {
  content: "";
  box-sizing: border-box;
  display: inline-block;
  inline-size: var(--techius-space-4);
  block-size: var(--techius-space-4);
  flex: 0 0 var(--techius-space-4);
  border: 2px solid currentColor;
  border-inline-end-color: transparent;
  border-radius: 50%;
  animation: tf-ui-spin 800ms linear infinite;
}
.tf-field {
  min-inline-size: 0;
}
.tf-field__label {
  display: block;
  margin-block-end: var(--techius-space-2);
  color: var(--techius-color-text);
  font-size: var(--techius-type-control-label-size);
  font-weight: var(--techius-type-control-label-weight);
}
.tf-field__hint,
.tf-field__error {
  margin-block: var(--techius-space-2) 0;
  font-size: 0.75rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.tf-field__hint {
  color: var(--techius-color-text-muted);
}
.tf-field__error {
  color: var(--techius-color-danger);
}
.tf-control {
  box-sizing: border-box;
  inline-size: 100%;
  min-inline-size: 0;
  min-block-size: var(--techius-control-min-size, var(--techius-control-target-size));
  padding: var(--techius-control-padding-block) var(--techius-control-padding-inline);
  border: 1px solid var(--techius-color-border-control);
  border-radius: var(--techius-radius-control);
  background: var(--techius-color-surface);
  color: var(--techius-color-text);
  font: inherit;
  font-size: var(--techius-control-font-size);
  line-height: var(--techius-control-line-height, inherit);
}
.tf-control:not(:disabled)::placeholder {
  color: var(--techius-color-text-subtle);
  opacity: 1;
}
textarea.tf-control {
  min-block-size: calc(2 * var(--techius-space-12));
  resize: vertical;
  line-height: 1.6;
}
.tf-control:not(:disabled):not([readonly]):not([aria-invalid="true"]):hover {
  border-color: var(--techius-color-primary);
}
.tf-control[readonly] {
  background: var(--techius-color-surface-soft);
  cursor: text;
}
.tf-control:disabled {
  background: var(--techius-color-disabled);
  color: var(--techius-color-on-disabled);
  cursor: not-allowed;
}
.tf-control[aria-invalid="true"] {
  border-color: var(--techius-color-danger);
}
.tf-control[aria-busy="true"] {
  cursor: progress;
}
.tf-choice-field {
  display: flex;
  align-items: center;
  gap: var(--techius-space-2);
  min-block-size: var(--techius-control-target-size);
  color: var(--techius-color-text);
  overflow-wrap: anywhere;
  cursor: pointer;
}
input.tf-choice:is([type="checkbox"], [type="radio"]) {
  inline-size: 1.05rem;
  block-size: 1.05rem;
  flex-shrink: 0;
  accent-color: var(--techius-color-primary);
  cursor: pointer;
}
.tf-choice:disabled,
.tf-choice-field:has(.tf-choice:disabled) {
  cursor: not-allowed;
  opacity: 0.6;
}
.tf-button:focus-visible,
.tf-control:focus-visible,
.tf-choice:focus-visible {
  outline: var(--techius-focus-width) solid var(--techius-color-focus);
  outline-offset: var(--techius-focus-offset);
}
.tf-surface {
  box-sizing: border-box;
  min-inline-size: 0;
  padding: var(--techius-ui-surface-padding, var(--techius-space-6));
  border: 1px solid var(--techius-color-border);
  border-radius: var(--techius-radius-surface);
  background: var(--techius-color-surface);
  color: var(--techius-color-text);
}
.tf-surface[data-variant="card"] {
  box-shadow: var(--techius-shadow-surface);
}
.tf-notice {
  padding: var(--techius-space-4);
  border: 1px solid var(--techius-color-info-border);
  border-radius: var(--techius-radius-control);
  background: var(--techius-color-info-soft);
  color: var(--techius-color-info-text);
  font-size: 0.8125rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.tf-notice[data-tone="success"] {
  border-color: var(--techius-color-success-border);
  background: var(--techius-color-success-soft);
  color: var(--techius-color-success-text);
}
.tf-notice[data-tone="warning"] {
  border-color: var(--techius-color-warning-border);
  background: var(--techius-color-warning-soft);
  color: var(--techius-color-warning-text);
}
.tf-notice[data-tone="error"] {
  border-color: var(--techius-color-danger-border);
  background: var(--techius-color-danger-soft);
  color: var(--techius-color-danger);
}
.tf-ui-state,
.tf-ui-page-header {
  display: block;
  min-inline-size: 0;
}
.tf-state {
  display: flex;
  align-items: flex-start;
  gap: var(--techius-space-3);
  padding: calc(var(--techius-space-3) + 2px);
  border: 1px solid var(--techius-color-border);
  border-radius: var(--techius-radius-control);
  background: var(--techius-color-surface-soft);
  color: var(--techius-color-text);
  font-size: 0.8125rem;
  line-height: 1.5;
}
.tf-state[data-kind="error"] {
  border-color: var(--techius-color-danger-border);
  background: var(--techius-color-danger-soft);
  color: var(--techius-color-danger);
}
.tf-state__content {
  min-inline-size: 0;
  flex: 1;
}
.tf-state__title,
.tf-state__message {
  margin: 0;
  overflow-wrap: anywhere;
}
.tf-state__title {
  margin-block-end: var(--techius-space-2);
  font-weight: 600;
}
.tf-state__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--techius-space-3);
  margin-block-start: var(--techius-space-3);
}
.tf-state__actions:empty,
.tf-page-header__back:empty,
.tf-page-header__metadata:empty,
.tf-page-header__actions:empty {
  display: none;
}
.tf-page-header {
  margin-block-end: var(--techius-space-6);
}
.tf-page-header__back {
  margin-block-end: calc(var(--techius-space-3) + var(--techius-space-2));
}
.tf-page-header__row,
.tf-page-header__actions,
.tf-page-header__metadata {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}
.tf-page-header__row {
  justify-content: space-between;
  gap: var(--techius-space-3) var(--techius-space-6);
}
.tf-page-header__copy {
  min-inline-size: 0;
  flex: 1 1 220px;
}
.tf-page-header__eyebrow {
  margin: 0 0 var(--techius-space-2);
  color: var(--techius-color-primary);
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: 0.16em;
}
.tf-page-header__title {
  margin: 0;
  color: var(--techius-color-text);
  font-size: var(--techius-type-page-title-size);
  font-weight: var(--techius-type-page-title-weight);
  line-height: var(--techius-type-page-title-line-height);
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}
.tf-page-header__description {
  margin: var(--techius-space-2) 0 0;
  color: var(--techius-color-text-muted);
  font-size: 0.75rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.tf-page-header__metadata {
  gap: var(--techius-space-2) var(--techius-space-3);
  margin-block-start: var(--techius-space-2);
}
.tf-page-header__actions {
  min-inline-size: 0;
  gap: var(--techius-space-3);
  flex: 0 1 auto;
}
@keyframes tf-ui-spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .tf-button {
    transition: none;
  }
  .tf-button[aria-busy="true"]::after,
  .tf-state__spinner {
    animation: none;
  }
}
@media (forced-colors: active) {
  .tf-button,
  .tf-control,
  .tf-notice,
  .tf-state {
    border-color: CanvasText;
  }
}

.tf-button[data-variant="primary"]:not(:disabled):not([aria-busy="true"]):active {
  background: var(--techius-color-primary-active);
}
.tf-button[aria-pressed="true"]:not([data-variant="primary"]):not([data-variant="danger"]):not(:disabled) {
  background: var(--techius-color-selection);
  color: var(--techius-color-on-selection);
  border-color: var(--techius-color-primary);
}

/* Commands share density metrics without imposing application placement or keyboard policy. */
.tf-commands {
  min-inline-size: 0;
  max-inline-size: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--techius-command-group-gap, var(--techius-space-3));
}
.tf-icon {
  inline-size: var(--techius-command-icon-size);
  block-size: var(--techius-command-icon-size);
  flex-shrink: 0;
  vertical-align: middle;
  pointer-events: none;
}
.tf-button[data-content="icon"] {
  position: relative;
  min-inline-size: var(--techius-command-min-size, var(--techius-control-target-size));
  padding: 0;
  flex-shrink: 0;
}
.tf-button[data-content="icon"][aria-busy="true"] .tf-icon {
  visibility: hidden;
}
.tf-button[data-content="icon"][aria-busy="true"]::after {
  position: absolute;
  inset: 0;
  margin: auto;
}

/* A native exclusive value choice, not tab navigation. The radio remains the full hit target. */
.tf-segmented {
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.tf-segmented__options {
  display: inline-flex;
  flex-wrap: wrap;
  max-inline-size: 100%;
  gap: var(--techius-space-1);
  padding: 0;
  border: 0;
  border-radius: var(--techius-radius-control);
  background: var(--techius-color-surface-soft);
}
.tf-segmented__option {
  position: relative;
  display: inline-flex;
  min-inline-size: 0;
  max-inline-size: 100%;
}
.tf-segmented__option input {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.tf-segmented__option span {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: var(--techius-command-min-size, var(--techius-control-target-size));
  min-inline-size: var(--techius-command-min-size, var(--techius-control-target-size));
  padding: var(--techius-command-padding-block, var(--techius-space-3)) var(--techius-command-padding-inline, calc(var(--techius-space-4) + 2px));
  border: 1px solid transparent;
  border-radius: var(--techius-radius-sm);
  color: var(--techius-color-text-muted);
  font-size: var(--techius-command-font-size);
  font-weight: 600;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.tf-segmented__option input:not(:disabled):hover + span {
  background: var(--techius-color-interactive-hover);
  color: var(--techius-color-text);
}
.tf-segmented__option input:checked + span {
  border-color: var(--techius-color-primary);
  background: var(--techius-color-selection);
  color: var(--techius-color-on-selection);
}
.tf-segmented__option input:focus-visible + span {
  outline: var(--techius-focus-width) solid var(--techius-color-focus);
  outline-offset: var(--techius-focus-offset);
}
.tf-segmented__option input:disabled {
  cursor: not-allowed;
}
.tf-segmented__option input:disabled + span {
  background: var(--techius-color-disabled);
  color: var(--techius-color-on-disabled);
}

/* Native top-layer disclosure inherits tokens from its DOM parent, including local density. */
.tf-surface[popover] {
  box-sizing: border-box;
  inline-size: min(24rem, calc(100dvi - 2 * var(--techius-space-4)));
  max-block-size: calc(100dvb - 2 * var(--techius-space-4));
  overflow: auto;
  border-color: var(--techius-color-border-control);
  background: var(--techius-color-surface-elevated);
  box-shadow: var(--techius-shadow-overlay);
}

/* Native popovertarget provides the implicit anchor; keep the panel within the viewport. */
@supports (position-area: block-end) and (justify-self: anchor-center) {
  .tf-surface[popover] {
    inset: auto;
    margin: var(--techius-space-2) var(--techius-space-4);
    position-area: block-end span-all;
    justify-self: anchor-center;
    position-try-fallbacks: flip-block;
  }
}

/* Progressive enhancement: unsupported browsers retain a native select and native picker.
   Only selects explicitly opting into picker sizing change their platform appearance. */
@supports (appearance: base-select) {
  .tf-control:where(select[data-picker-width]:not([multiple]):not([size])),
  .tf-control:where(select[data-picker-width]:not([multiple]):not([size]))::picker(select) {
    appearance: base-select;
  }
  .tf-control:where(select[data-picker-width]:not([multiple]):not([size])) {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--techius-command-gap, var(--techius-space-3));
    text-align: start;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .tf-control:where(select[data-picker-width]:not([multiple]):not([size]))::picker-icon {
    flex-shrink: 0;
    color: var(--techius-color-text-muted);
    font-size: var(--techius-command-icon-size);
    line-height: 1;
  }
  .tf-control:where(select[data-picker-width]:not([multiple]):not([size]))::picker(select) {
    box-sizing: border-box;
    inline-size: anchor-size(self-inline);
    min-inline-size: 0;
    max-inline-size: calc(100dvi - 2 * var(--techius-space-4));
    max-block-size: min(20rem, calc(100dvb - 2 * var(--techius-space-4)));
    margin-block-start: var(--techius-space-1);
    padding: var(--techius-space-1);
    overflow: auto;
    border: 1px solid var(--techius-color-border-control);
    border-radius: var(--techius-radius-control);
    background: var(--techius-color-surface-elevated);
    color: var(--techius-color-text);
    box-shadow: var(--techius-shadow-overlay);
    font-family: inherit;
    font-size: var(--techius-control-font-size);
  }
  .tf-control:where(select[data-picker-width="content"]:not([multiple]):not([size]))::picker(select) {
    inline-size: max-content;
    min-inline-size: min(anchor-size(self-inline), calc(100dvi - 2 * var(--techius-space-4)));
  }
  .tf-control:where(select[data-picker-width]:not([multiple]):not([size])) option {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: var(--techius-command-gap, var(--techius-space-3));
    min-block-size: var(--techius-command-min-size, var(--techius-control-target-size));
    padding: var(--techius-control-padding-block) var(--techius-control-padding-inline);
    border-radius: var(--techius-radius-sm);
    font: inherit;
    line-height: 1.5;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .tf-control:where(select[data-picker-width]) option:checked {
    background: var(--techius-color-selection);
    color: var(--techius-color-on-selection);
  }
  .tf-control:where(select[data-picker-width]) option:not(:disabled):hover {
    background: var(--techius-color-interactive-hover);
  }
  .tf-control:where(select[data-picker-width]) option:focus-visible {
    outline: var(--techius-focus-width) solid var(--techius-color-focus);
    outline-offset: calc(-1 * var(--techius-focus-width));
  }
  .tf-control:where(select[data-picker-width]) option:disabled {
    color: var(--techius-color-on-disabled);
  }
}

.tf-type-page-title {
  margin: 0 0 var(--techius-type-heading-gap);
  color: var(--techius-color-text);
  font-size: var(--techius-type-page-title-size);
  font-weight: var(--techius-type-page-title-weight);
  line-height: var(--techius-type-page-title-line-height);
  overflow-wrap: anywhere;
}

.tf-type-section-title {
  margin: 0 0 var(--techius-type-heading-gap);
  color: var(--techius-color-text);
  font-size: var(--techius-type-section-title-size);
  font-weight: var(--techius-type-section-title-weight);
  line-height: var(--techius-type-section-title-line-height);
  overflow-wrap: anywhere;
}

.tf-type-panel-title {
  margin: 0 0 var(--techius-type-heading-gap);
  color: var(--techius-color-text);
  font-size: var(--techius-type-panel-title-size);
  font-weight: var(--techius-type-panel-title-weight);
  line-height: var(--techius-type-panel-title-line-height);
  overflow-wrap: anywhere;
}

.tf-type-control-label {
  margin: 0 0 var(--techius-type-copy-gap);
  color: var(--techius-color-text);
  font-size: var(--techius-type-control-label-size);
  font-weight: var(--techius-type-control-label-weight);
  line-height: var(--techius-type-control-label-line-height);
  overflow-wrap: anywhere;
}

.tf-type-body {
  margin: 0 0 var(--techius-type-copy-gap);
  color: var(--techius-color-text);
  font-size: var(--techius-type-body-size);
  font-weight: var(--techius-type-body-weight);
  line-height: var(--techius-type-body-line-height);
  overflow-wrap: anywhere;
}

.tf-type-status {
  margin: 0 0 var(--techius-type-copy-gap);
  color: var(--techius-color-text-muted);
  font-size: var(--techius-type-status-size);
  font-weight: var(--techius-type-status-weight);
  line-height: var(--techius-type-status-line-height);
  overflow-wrap: anywhere;
}

.tf-type-helper {
  margin: 0 0 var(--techius-type-copy-gap);
  color: var(--techius-color-text-muted);
  font-size: var(--techius-type-helper-size);
  font-weight: var(--techius-type-helper-weight);
  line-height: var(--techius-type-helper-line-height);
  overflow-wrap: anywhere;
}

@media (forced-colors: active) {
  .tf-button[aria-pressed="true"]:not([data-variant="primary"]):not([data-variant="danger"]):not(:disabled) {
    border-style: dashed;
    text-decoration: underline;
    text-underline-offset: 0.2em;
  }
  .tf-segmented__option input:checked + span {
    border-color: Highlight;
    background: Highlight;
    color: HighlightText;
  }
  .tf-segmented__option input:focus-visible + span {
    outline-color: Highlight;
  }
}
