/* Huddle — Controls: buttons, inputs, selects, textarea, checkbox, radio, switch, form field */

/* ============ Button ============ */
.hds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease, box-shadow .12s ease;
  user-select: none;
}
.hds-btn:disabled,
.hds-btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: .55;
}
.hds-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.hds-btn svg { flex: 0 0 auto; }

/* sizes */
.hds-btn--sm { height: 32px; padding: 0 12px; font-size: var(--text-sm); }
.hds-btn--md { height: 40px; padding: 0 16px; font-size: var(--text-sm); }
.hds-btn--lg { height: 44px; padding: 0 20px; font-size: var(--text-md); }
.hds-btn--icon-sm { width: 18px; height: 18px; }
.hds-btn--icon-md { width: 18px; height: 18px; }
.hds-btn--block { width: 100%; }

/* variants */
.hds-btn--primary { background: var(--primary); color: var(--on-primary); }
.hds-btn--primary:hover:not(:disabled) { background: var(--primary-hover); }
.hds-btn--primary:active:not(:disabled) { background: var(--primary-active); }

.hds-btn--secondary { background: var(--bg-card); color: var(--text-secondary); border-color: var(--border-default); box-shadow: var(--shadow-xs); }
.hds-btn--secondary:hover:not(:disabled) { background: var(--gray-50); color: var(--text-primary); }
.hds-btn--secondary:active:not(:disabled) { background: var(--gray-100); }

.hds-btn--ghost { background: transparent; color: var(--text-secondary); }
.hds-btn--ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.hds-btn--ghost:active:not(:disabled) { background: var(--bg-active); }

.hds-btn--danger { background: var(--danger); color: #fff; }
.hds-btn--danger:hover:not(:disabled) { background: var(--danger-hover); }

.hds-btn--link { background: transparent; color: var(--text-link); padding-left: 4px; padding-right: 4px; height: auto; }
.hds-btn--link:hover:not(:disabled) { text-decoration: underline; }

/* ============ IconButton ============ */
.hds-iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color .12s ease, color .12s ease, box-shadow .12s ease;
}
.hds-iconbtn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.hds-iconbtn:active:not(:disabled) { background: var(--bg-active); }
.hds-iconbtn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.hds-iconbtn:disabled { opacity: .5; cursor: not-allowed; }
.hds-iconbtn--sm { width: 32px; height: 32px; }
.hds-iconbtn--md { width: 40px; height: 40px; }
.hds-iconbtn--bordered { border-color: var(--border-default); background: var(--bg-card); box-shadow: var(--shadow-xs); }
.hds-iconbtn svg { width: 18px; height: 18px; }

/* ============ Form field wrapper ============ */
.hds-field { display: flex; flex-direction: column; gap: 6px; }
.hds-field__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  display: flex; align-items: center; gap: 4px;
}
.hds-field__req { color: var(--danger); }
.hds-field__hint { font-size: var(--text-xs); color: var(--text-muted); }
.hds-field__error { font-size: var(--text-xs); color: var(--danger); }

/* ============ Input / Textarea / Select ============ */
.hds-input,
.hds-textarea,
.hds-select {
  width: 100%;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.hds-input, .hds-select { height: 40px; padding: 0 12px; }
.hds-textarea { padding: 10px 12px; min-height: 88px; resize: vertical; line-height: var(--leading-sm); }
.hds-input::placeholder, .hds-textarea::placeholder { color: var(--text-disabled); }
.hds-input:hover, .hds-textarea:hover, .hds-select:hover { border-color: var(--border-strong); }
.hds-input:focus, .hds-textarea:focus, .hds-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--focus-ring);
}
.hds-input:disabled, .hds-textarea:disabled, .hds-select:disabled {
  background: var(--bg-subtle); color: var(--text-disabled); cursor: not-allowed;
}
.hds-input--invalid, .hds-textarea--invalid, .hds-select--invalid { border-color: var(--danger); }
.hds-input--invalid:focus, .hds-textarea--invalid:focus, .hds-select--invalid:focus { box-shadow: 0 0 0 4px var(--red-100); }

/* input with leading/trailing adornments */
.hds-input-group { position: relative; display: flex; align-items: center; }
.hds-input-group .hds-input { padding-left: 38px; }
.hds-input-group__icon {
  position: absolute; left: 12px; display: inline-flex; color: var(--text-muted); pointer-events: none;
}
.hds-input-group__icon svg { width: 16px; height: 16px; }

/* select with chevron */
.hds-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ============ Checkbox & Radio ============ */
.hds-check { display: inline-flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: var(--text-sm); color: var(--text-secondary); }
.hds-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.hds-check__box {
  flex: 0 0 auto; width: 18px; height: 18px; margin-top: 1px;
  border: 1px solid var(--border-default); border-radius: var(--radius-xs);
  background: var(--bg-card); box-shadow: var(--shadow-xs);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background-color .12s ease, border-color .12s ease;
}
.hds-check--radio .hds-check__box { border-radius: var(--radius-pill); }
.hds-check__box svg { width: 12px; height: 12px; color: #fff; opacity: 0; }
.hds-check input:checked + .hds-check__box { background: var(--primary); border-color: var(--primary); }
.hds-check input:checked + .hds-check__box svg { opacity: 1; }
.hds-check--radio .hds-check__dot { width: 7px; height: 7px; border-radius: 50%; background: #fff; opacity: 0; }
.hds-check input:checked + .hds-check__box .hds-check__dot { opacity: 1; }
.hds-check input:focus-visible + .hds-check__box { box-shadow: var(--focus-ring); }
.hds-check input:disabled ~ * { opacity: .55; }

/* ============ Switch ============ */
.hds-switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--text-sm); color: var(--text-secondary); }
.hds-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.hds-switch__track {
  width: 36px; height: 20px; border-radius: var(--radius-pill);
  background: var(--gray-300); position: relative; transition: background-color .15s ease; flex: 0 0 auto;
}
.hds-switch__thumb {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-sm); transition: transform .15s ease;
}
.hds-switch input:checked + .hds-switch__track { background: var(--primary); }
.hds-switch input:checked + .hds-switch__track .hds-switch__thumb { transform: translateX(16px); }
.hds-switch input:focus-visible + .hds-switch__track { box-shadow: var(--focus-ring); }
.hds-switch input:disabled + .hds-switch__track { opacity: .5; }
