/*
 * TW controls.
 *
 * This file is the only owner of shared button, field, select, badge,
 * checkbox, compact segmented control and inspector-field geometry.
 */

.tw-button,
.tw-icon-button,
.tw-input,
.tw-select,
.tw-textarea {
  min-height: var(--tw-control);
  color: var(--tw-color-text);
  background: var(--tw-color-surface-raised);
  border: 1px solid var(--tw-color-border-strong);
  border-radius: var(--tw-radius);
  transition:
    color var(--tw-motion-fast) var(--tw-ease-standard),
    background-color var(--tw-motion-fast) var(--tw-ease-standard),
    border-color var(--tw-motion-fast) var(--tw-ease-standard),
    box-shadow var(--tw-motion-fast) var(--tw-ease-standard);
}

.tw-icon {
  display: block;
  width: var(--tw-icon-sm);
  height: var(--tw-icon-sm);
  flex: 0 0 auto;
  pointer-events: none;
}

.tw-button {
  display: inline-flex;
  padding: 0 var(--tw-space-3);
  align-items: center;
  justify-content: center;
  gap: var(--tw-space-1-5);
  font-size: var(--tw-font-ui);
  font-weight: var(--tw-weight-semibold);
  line-height: var(--tw-line-ui);
  text-decoration: none;
  white-space: nowrap;
}

.tw-button:hover {
  background: var(--tw-color-muted);
}

.tw-button--primary {
  color: var(--tw-color-on-primary);
  background: var(--tw-color-primary);
  border-color: var(--tw-color-primary);
}

.tw-button--primary:hover {
  color: var(--tw-color-on-primary);
  background: var(--tw-color-primary-hover);
  border-color: var(--tw-color-primary-hover);
}

.tw-button--ghost {
  color: var(--tw-color-text-muted);
  background: transparent;
  border-color: transparent;
}

.tw-button--ghost:hover {
  color: var(--tw-color-text);
  background: var(--tw-color-muted);
}

.tw-button--danger {
  color: var(--tw-color-danger);
}

.tw-button--compact,
.tw-icon-button--compact {
  min-height: var(--tw-control-compact);
  height: var(--tw-control-compact);
  font-size: var(--tw-font-meta);
  line-height: var(--tw-line-meta);
}

.tw-button--compact {
  padding-inline: var(--tw-space-2);
}

.tw-button:disabled,
.tw-icon-button:disabled,
.tw-input:disabled,
.tw-select:disabled,
.tw-textarea:disabled {
  cursor: not-allowed;
  opacity: .56;
}

.tw-icon-button {
  display: inline-grid;
  width: var(--tw-control);
  height: var(--tw-control);
  padding: 0;
  flex: 0 0 var(--tw-control);
  place-items: center;
}

.tw-icon-button:hover {
  background: var(--tw-color-muted);
}

.tw-icon-button--compact {
  width: var(--tw-control-compact);
  flex-basis: var(--tw-control-compact);
}

.tw-row-action {
  display: inline-grid;
  width: var(--tw-control-compact);
  height: var(--tw-control-compact);
  padding: 0;
  place-items: center;
  color: var(--tw-color-text-muted);
  background: var(--tw-color-surface-raised);
  border: 1px solid var(--tw-color-border);
  border-radius: var(--tw-radius);
  box-shadow: var(--tw-shadow-xs);
}

.tw-row-action:hover,
.tw-row-action[aria-expanded="true"] {
  color: var(--tw-color-text);
  background: var(--tw-color-muted);
  border-color: var(--tw-color-border-strong);
}

.tw-input,
.tw-select,
.tw-textarea {
  width: 100%;
  min-width: 0;
  outline: 0;
  font-size: var(--tw-font-ui);
  line-height: var(--tw-line-ui);
}

.tw-input {
  padding: 0 var(--tw-space-2-5);
}

.tw-input--compact {
  min-height: var(--tw-control-compact);
  height: var(--tw-control-compact);
  font-size: var(--tw-font-meta);
  line-height: var(--tw-line-meta);
}

.tw-select {
  padding: 0 30px 0 var(--tw-space-2);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2369717d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-position: calc(100% - 9px) 50%;
  background-size: 14px 14px;
  background-repeat: no-repeat;
}

.tw-custom-select {
  position: relative;
  display: inline-block;
  width: min(100%, var(--tw-custom-select-width, 100%));
  min-width: 0;
  max-width: 100%;
  vertical-align: middle;
}

.tw-custom-select__native {
  display: none;
}

.tw-custom-select__trigger {
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: var(--tw-control);
  padding: 0 var(--tw-space-2-5);
  align-items: center;
  gap: var(--tw-space-1);
  color: var(--tw-color-text);
  background: var(--tw-color-surface-raised);
  border: 1px solid var(--tw-color-border-strong);
  border-radius: var(--tw-radius);
  font: inherit;
  font-size: var(--tw-font-ui);
  line-height: var(--tw-line-ui);
  text-align: left;
  cursor: pointer;
}

.tw-custom-select__trigger:hover {
  border-color: var(--tw-color-text-muted);
}

.tw-custom-select.is-open .tw-custom-select__trigger {
  border-color: var(--tw-color-focus);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--tw-color-focus) 24%, transparent);
}

.tw-custom-select__value {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tw-custom-select__chevron {
  width: 12px;
  height: 12px;
  color: var(--tw-color-text-muted);
  transition: transform var(--tw-motion-fast) var(--tw-ease-standard);
}

.tw-custom-select.is-open .tw-custom-select__chevron {
  transform: rotate(180deg);
}

.tw-custom-select__menu {
  position: fixed;
  z-index: 110;
  display: grid;
  max-height: min(240px, calc(100dvh - var(--tw-space-4)));
  margin: 0;
  padding: var(--tw-space-1);
  gap: 1px;
  overflow-y: auto;
  color: var(--tw-color-text);
  background: var(--tw-color-surface-raised);
  border: 1px solid var(--tw-color-border-strong);
  border-radius: var(--tw-radius);
  box-shadow: var(--tw-shadow);
}

.tw-custom-select__option {
  display: grid;
  width: 100%;
  min-height: var(--tw-menu-item);
  padding: 0 var(--tw-space-2-5);
  grid-template-columns: minmax(0, 1fr) 14px;
  align-items: center;
  gap: var(--tw-space-2);
  color: var(--tw-color-text-muted);
  background: transparent;
  border: 0;
  border-radius: var(--tw-radius);
  font: inherit;
  font-size: var(--tw-font-meta);
  line-height: var(--tw-line-meta);
  text-align: left;
}

.tw-custom-select__option::after {
  width: 14px;
  height: 14px;
  content: "";
  opacity: 0;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center / contain no-repeat;
}

.tw-custom-select__option:hover,
html[data-input-modality="keyboard"] .tw-custom-select__option:focus-visible {
  color: var(--tw-color-text);
  background: var(--tw-color-surface-subtle);
}

.tw-custom-select__option.is-selected {
  color: var(--tw-color-accent-text);
  background: var(--tw-color-accent);
}

.tw-custom-select__option.is-selected::after {
  opacity: 1;
}

.tw-custom-select__trigger:disabled,
.tw-custom-select__option:disabled {
  cursor: not-allowed;
  opacity: .56;
}

.tw-custom-select--compact .tw-custom-select__trigger,
.tw-registry-toolbar .tw-custom-select__trigger,
.tw-filter-panel .tw-custom-select__trigger,
.tw-registry-footer .tw-custom-select__trigger {
  min-height: var(--tw-control-compact);
  height: var(--tw-control-compact);
  font-size: var(--tw-font-meta);
  line-height: var(--tw-line-meta);
}

.tw-textarea {
  min-height: 76px;
  padding: var(--tw-space-2) var(--tw-space-2-5);
  resize: vertical;
}

.tw-input::placeholder,
.tw-textarea::placeholder {
  color: var(--tw-color-text-muted);
}

.tw-input:hover,
.tw-select:hover,
.tw-textarea:hover {
  border-color: var(--tw-color-text-muted);
}

.tw-input:focus,
.tw-select:focus,
.tw-textarea:focus {
  border-color: var(--tw-color-focus);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--tw-color-focus) 24%, transparent);
}

html[data-input-modality="keyboard"] .tw-button:focus-visible,
html[data-input-modality="keyboard"] .tw-icon-button:focus-visible,
html[data-input-modality="keyboard"] .tw-row-action:focus-visible {
  outline: 2px solid var(--tw-color-focus);
  outline-offset: 2px;
}

.tw-input[aria-invalid="true"],
.tw-select[aria-invalid="true"],
.tw-textarea[aria-invalid="true"] {
  border-color: var(--tw-color-danger);
}

.tw-is-ready,
.tw-is-success {
  color: var(--tw-color-success);
}

.tw-is-warning {
  color: var(--tw-color-warning);
}

.tw-is-error {
  color: var(--tw-color-danger);
}

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

.tw-status-icon {
  display: inline-grid;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  place-items: center;
}

.tw-status-icon .tw-icon {
  width: 13px;
  height: 13px;
}

.tw-provider-mark,
.tw-avatar,
.tw-mini-avatar {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  background: var(--tw-color-muted);
  border-radius: var(--tw-radius);
  font-weight: var(--tw-weight-bold);
}

.tw-provider-mark {
  width: 22px;
  height: 22px;
  font-size: var(--tw-font-micro);
}

.tw-provider-mark .tw-icon {
  width: 12px;
  height: 12px;
}

.tw-provider-mark--web {
  color: var(--tw-color-provider-web);
}

.tw-provider-mark--tg {
  color: var(--tw-color-provider-telegram);
}

.tw-provider-mark--max {
  color: var(--tw-color-provider-max);
}

.tw-provider-mark--mail {
  color: var(--tw-color-provider-email);
}

.tw-avatar {
  width: var(--tw-control);
  height: var(--tw-control);
  border-radius: 50%;
  font-size: var(--tw-font-meta);
}

.tw-mini-avatar {
  width: var(--tw-control-compact);
  height: var(--tw-control-compact);
  flex-basis: var(--tw-control-compact);
  border-radius: 50%;
  font-size: var(--tw-font-micro);
}

.tw-avatar--xs {
  width: 22px;
  height: 22px;
  font-size: var(--tw-font-micro);
}

.tw-avatar--sm {
  width: var(--tw-control-compact);
  height: var(--tw-control-compact);
  font-size: var(--tw-font-micro);
}

.tw-avatar--md {
  width: var(--tw-control);
  height: var(--tw-control);
  font-size: var(--tw-font-meta);
}

/*
 * AssigneeStack: COPY/PORT of the useful Chatus XA EntityCard avatar stack.
 * Controls owns the avatar/add-button skin; consumers own only placement.
 */
.tw-assignee-stack {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0;
}

.tw-assignee-avatar {
  position: relative;
  display: inline-grid;
  width: var(--tw-control-compact);
  height: var(--tw-control-compact);
  margin-left: -6px;
  padding: 0;
  flex: 0 0 var(--tw-control-compact);
  place-items: center;
  color: var(--tw-color-text);
  background: var(--tw-color-muted);
  border: 2px solid var(--tw-color-surface);
  border-radius: 50%;
  font: inherit;
  font-size: var(--tw-font-micro);
  font-weight: var(--tw-weight-bold);
  line-height: 1;
  cursor: pointer;
}

.tw-assignee-avatar:first-child {
  margin-left: 0;
}

.tw-assignee-stack > .tw-assignee-avatar:nth-of-type(n + 4):not(.tw-assignee-avatar--add) {
  display: none;
}

.tw-assignee-avatar:hover,
.tw-assignee-avatar:focus-visible {
  z-index: 1;
  border-color: var(--tw-color-border-strong);
}

.tw-assignee-avatar:focus-visible {
  outline: 2px solid var(--tw-color-focus);
  outline-offset: 1px;
}

.tw-assignee-avatar--add {
  color: var(--tw-color-text-muted);
  background: var(--tw-color-surface);
  border-color: var(--tw-color-border-strong);
  border-style: dashed;
}

.tw-assignee-avatar--add .tw-icon {
  width: 12px;
  height: 12px;
}

.tw-table-checkbox,
.tw-check-input {
  position: relative;
  display: inline-grid;
  width: var(--tw-checkbox-size);
  height: var(--tw-checkbox-size);
  margin: 0;
  appearance: none;
  place-items: center;
  background: var(--tw-color-surface-raised);
  border: 1px solid var(--tw-color-border-strong);
  border-radius: var(--tw-radius);
  cursor: pointer;
}

.tw-table-checkbox::after,
.tw-check-input::after {
  width: 10px;
  height: 10px;
  content: "";
  opacity: 0;
  background: var(--tw-color-on-primary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center / contain no-repeat;
}

.tw-table-checkbox:checked,
.tw-table-checkbox:indeterminate,
.tw-check-input:checked {
  background: var(--tw-color-primary);
  border-color: var(--tw-color-primary);
}

.tw-table-checkbox:checked::after,
.tw-check-input:checked::after {
  opacity: 1;
}

.tw-table-checkbox:indeterminate::after {
  width: 10px;
  height: 10px;
  opacity: 1;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Cline x1='5' y1='12' x2='19' y2='12'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Cline x1='5' y1='12' x2='19' y2='12'/%3E%3C/svg%3E");
}

.tw-radio-input {
  position: relative;
  display: inline-grid;
  width: var(--tw-checkbox-size);
  height: var(--tw-checkbox-size);
  margin: 0;
  appearance: none;
  place-items: center;
  background: var(--tw-color-surface-raised);
  border: 1px solid var(--tw-color-border-strong);
  border-radius: var(--tw-radius-dot);
  cursor: pointer;
}

.tw-radio-input::after {
  width: 6px;
  height: 6px;
  content: "";
  opacity: 0;
  background: var(--tw-color-on-primary);
  border-radius: var(--tw-radius-dot);
}

.tw-radio-input:checked {
  background: var(--tw-color-primary);
  border-color: var(--tw-color-primary);
}

.tw-radio-input:checked::after {
  opacity: 1;
}

.tw-control-count,
.tw-unread-count,
.tw-context-count {
  display: inline-flex;
  min-width: 16px;
  height: 16px;
  padding-inline: var(--tw-space-1);
  align-items: center;
  justify-content: center;
  color: var(--tw-color-on-primary);
  background: var(--tw-color-primary);
  border-radius: var(--tw-radius);
  font-size: var(--tw-font-micro);
  font-weight: var(--tw-weight-bold);
  line-height: var(--tw-line-micro);
  font-variant-numeric: tabular-nums;
}

.tw-context-count {
  color: var(--tw-color-text-muted);
  background: var(--tw-color-surface-raised);
  border: 1px solid var(--tw-color-border);
}

.tw-search-field {
  position: relative;
  display: block;
}

.tw-search-field__icon {
  position: absolute;
  top: 50%;
  left: var(--tw-space-2-5);
  z-index: 1;
  width: var(--tw-icon-sm);
  height: var(--tw-icon-sm);
  color: var(--tw-color-text-muted);
  pointer-events: none;
  transform: translateY(-50%);
}

.tw-search-field .tw-input {
  padding-left: 28px;
}
