/* ==========================================================================
   DS-G4RGO Environment Inspection — Forms
   Inputs, selects, textareas, checkboxes, radios, toggles, buttons,
   field groups, help tooltips, form sections, required indicators
   ========================================================================== */

/* --------------------------------------------------------------------------
   Form wrapper
   -------------------------------------------------------------------------- */
.form {
  width: 100%;
}

/* --------------------------------------------------------------------------
   Form sections (titled groups)
   -------------------------------------------------------------------------- */
.form-section {
  margin-bottom: var(--sp-8);
}

.form-section__header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding-bottom: var(--sp-3);
  margin-bottom: var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.form-section__title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text);
}

.form-section__description {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: var(--sp-4);
}

/* --------------------------------------------------------------------------
   Field group
   -------------------------------------------------------------------------- */
.field {
  margin-bottom: var(--sp-5);
}

.field:last-child {
  margin-bottom: 0;
}

.field--inline {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.field--row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
}

/* --------------------------------------------------------------------------
   Labels
   -------------------------------------------------------------------------- */
.field__label {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* Required field indicator */
.field__label--required::after {
  content: '*';
  color: var(--error);
  font-weight: 700;
  margin-left: 2px;
}

/* --------------------------------------------------------------------------
   Help tooltip (icon next to label, shows tooltip on hover)
   -------------------------------------------------------------------------- */
.field__help {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  font-size: 0.5625rem;
  font-weight: 700;
  cursor: help;
  user-select: none;
  flex-shrink: 0;
  line-height: 1;
}

.field__help::before {
  content: '?';
}

.field__help-text {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 240px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg);
  color: var(--text);
  font-size: 0.6875rem;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: normal;
  text-transform: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: var(--z-tooltip);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
  white-space: normal;
}

/* Arrow */
.field__help-text::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--border);
}

.field__help:hover .field__help-text {
  opacity: 1;
  pointer-events: auto;
}

/* --------------------------------------------------------------------------
   Text inputs, number inputs, email, password, search, url, tel
   -------------------------------------------------------------------------- */
.input {
  display: block;
  width: 100%;
  height: 36px;
  padding: 0 var(--sp-3);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

.input:hover {
  border-color: var(--muted);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* Input sizes */
.input--sm {
  height: 28px;
  font-size: 0.75rem;
  padding: 0 var(--sp-2);
}

.input--lg {
  height: 44px;
  font-size: 0.875rem;
  padding: 0 var(--sp-4);
}

/* Input states */
.input--error {
  border-color: var(--error);
}

.input--error:focus {
  box-shadow: 0 0 0 1px var(--error);
}

.input--success {
  border-color: var(--success);
}

.input[disabled],
.input[readonly] {
  opacity: 0.5;
  cursor: not-allowed;
}

.input[readonly] {
  opacity: 0.7;
  background: var(--panel);
}

/* --------------------------------------------------------------------------
   Input with icon / prefix / suffix
   -------------------------------------------------------------------------- */
.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group .input {
  flex: 1;
}

.input-group__prefix,
.input-group__suffix {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 var(--sp-3);
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.input-group__prefix {
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
}

.input-group__prefix + .input {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.input-group__suffix {
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.input-group .input:has(+ .input-group__suffix) {
  border-radius: var(--radius) 0 0 var(--radius);
}

.input-group__icon {
  position: absolute;
  left: var(--sp-3);
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

.input-group--icon-left .input {
  padding-left: calc(var(--sp-3) + 16px + var(--sp-2));
}

/* --------------------------------------------------------------------------
   Select
   -------------------------------------------------------------------------- */
.select {
  display: block;
  width: 100%;
  height: 36px;
  padding: 0 calc(var(--sp-3) + 20px) 0 var(--sp-3);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%239fb0c3' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.select:hover {
  border-color: var(--muted);
}

.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.select--sm {
  height: 28px;
  font-size: 0.75rem;
}

.select--lg {
  height: 44px;
  font-size: 0.875rem;
}

.select[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Textarea
   -------------------------------------------------------------------------- */
.textarea {
  display: block;
  width: 100%;
  min-height: 80px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
  resize: vertical;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.textarea::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

.textarea:hover {
  border-color: var(--muted);
}

.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.textarea[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Checkbox
   -------------------------------------------------------------------------- */
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--text);
  user-select: none;
}

.checkbox__input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.checkbox__box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

/* Checkmark */
.checkbox__box::after {
  content: '';
  display: block;
  width: 4px;
  height: 8px;
  border: solid var(--bg);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.checkbox__input:checked + .checkbox__box {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox__input:checked + .checkbox__box::after {
  opacity: 1;
}

.checkbox__input:focus-visible + .checkbox__box {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.checkbox__input:disabled + .checkbox__box {
  opacity: 0.4;
  cursor: not-allowed;
}

.checkbox__input:disabled ~ .checkbox__text {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Radio button
   -------------------------------------------------------------------------- */
.radio {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--text);
  user-select: none;
}

.radio__input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.radio__circle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  transition: border-color var(--transition-fast);
}

.radio__circle::after {
  content: '';
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  transform: scale(0);
  transition: transform var(--transition-fast);
}

.radio__input:checked + .radio__circle {
  border-color: var(--accent);
}

.radio__input:checked + .radio__circle::after {
  transform: scale(1);
}

.radio__input:focus-visible + .radio__circle {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.radio__input:disabled + .radio__circle {
  opacity: 0.4;
  cursor: not-allowed;
}

.radio__input:disabled ~ .radio__text {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Radio group */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.radio-group--horizontal {
  flex-direction: row;
  gap: var(--sp-5);
}

/* --------------------------------------------------------------------------
   Toggle switch
   -------------------------------------------------------------------------- */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--text);
  user-select: none;
}

.toggle__input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle__track {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  flex-shrink: 0;
  transition: background var(--transition-base);
}

.toggle__track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text);
  border-radius: 50%;
  transition: transform var(--transition-base);
}

.toggle__input:checked + .toggle__track {
  background: var(--accent);
}

.toggle__input:checked + .toggle__track::after {
  transform: translateX(16px);
}

.toggle__input:focus-visible + .toggle__track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toggle__input:disabled + .toggle__track {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-4);
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background var(--transition-fast), border-color var(--transition-fast),
    color var(--transition-fast), box-shadow var(--transition-fast);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn__icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Primary */
.btn--primary {
  background: var(--accent);
  color: #0b0f14;
  border-color: var(--accent);
}

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

.btn--primary:active {
  background: #2e7acc;
}

/* Secondary */
.btn--secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn--secondary:hover {
  background: var(--panel-hover);
  border-color: var(--muted);
}

.btn--secondary:active {
  background: var(--border);
}

/* Danger */
.btn--danger {
  background: var(--error);
  color: #0b0f14;
  border-color: var(--error);
}

.btn--danger:hover {
  background: #e65b5b;
  border-color: #e65b5b;
}

.btn--danger:active {
  background: #d44848;
}

/* Ghost (borderless) */
.btn--ghost {
  background: transparent;
  color: var(--muted);
}

.btn--ghost:hover {
  background: var(--panel-hover);
  color: var(--text);
}

/* Success */
.btn--success {
  background: var(--success);
  color: #0b0f14;
  border-color: var(--success);
}

.btn--success:hover {
  background: #2bb87f;
  border-color: #2bb87f;
}

/* Button sizes */
.btn--sm {
  height: 28px;
  padding: 0 var(--sp-3);
  font-size: 0.75rem;
}

.btn--lg {
  height: 44px;
  padding: 0 var(--sp-6);
  font-size: 0.875rem;
}

.btn--block {
  display: flex;
  width: 100%;
}

/* Button group */
.btn-group {
  display: inline-flex;
}

.btn-group .btn {
  border-radius: 0;
}

.btn-group .btn:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

.btn-group .btn:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.btn-group .btn + .btn {
  margin-left: -1px;
}

/* --------------------------------------------------------------------------
   Field hints and error messages
   -------------------------------------------------------------------------- */
.field__hint {
  margin-top: var(--sp-1);
  font-size: 0.6875rem;
  color: var(--muted);
}

.field__error {
  margin-top: var(--sp-1);
  font-size: 0.6875rem;
  color: var(--error);
}

/* --------------------------------------------------------------------------
   Form actions (button row at the bottom of a form)
   -------------------------------------------------------------------------- */
.form-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding-top: var(--sp-5);
  margin-top: var(--sp-6);
  border-top: 1px solid var(--border);
}

.form-actions--right {
  justify-content: flex-end;
}

.form-actions--between {
  justify-content: space-between;
}

/* --------------------------------------------------------------------------
   File input
   -------------------------------------------------------------------------- */
.file-input {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.file-input__trigger {
  flex-shrink: 0;
}

.file-input__name {
  font-size: 0.8125rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Checkbox / Radio list inside a panel
   -------------------------------------------------------------------------- */
.check-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.check-list--grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-3);
}

/* --------------------------------------------------------------------------
   Inline field pair (label : value, read-only style)
   -------------------------------------------------------------------------- */
.field-pair {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
}

.field-pair:last-child {
  border-bottom: none;
}

.field-pair__label {
  flex-shrink: 0;
  width: 140px;
  color: var(--muted);
  font-size: 0.75rem;
}

.field-pair__value {
  color: var(--text);
  font-family: var(--font-mono);
}

/* --------------------------------------------------------------------------
   Responsive form adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .field--row {
    grid-template-columns: 1fr;
  }

  .radio-group--horizontal {
    flex-direction: column;
    gap: var(--sp-3);
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }

  .check-list--grid {
    grid-template-columns: 1fr;
  }

  .field-pair {
    flex-direction: column;
    gap: var(--sp-1);
  }

  .field-pair__label {
    width: auto;
  }
}
