/**
 * Repvist Forms — Phase 3
 * Depends on: tokens.css
 */

/* --------------------------------------------------------------------------
   Labels & groups
   -------------------------------------------------------------------------- */

.rv-label {
  display: block;
  margin-block-end: var(--rv-space-2);
  font-size: var(--rv-font-size-sm);
  font-weight: var(--rv-font-weight-medium);
  color: var(--rv-text);
  line-height: var(--rv-line-height-tight);
}

.rv-label--required::after {
  content: " *";
  color: var(--rv-danger);
}

.rv-field {
  margin-block-end: var(--rv-space-5);
}

.rv-hint {
  display: block;
  margin-block-start: var(--rv-space-1);
  font-size: var(--rv-font-size-xs);
  color: var(--rv-text-muted);
  line-height: var(--rv-line-height-normal);
}

.rv-error-msg {
  display: block;
  margin-block-start: var(--rv-space-1);
  font-size: var(--rv-font-size-xs);
  color: var(--rv-danger);
  line-height: var(--rv-line-height-normal);
}

/* --------------------------------------------------------------------------
   Shared input styles
   -------------------------------------------------------------------------- */

.rv-input,
.rv-textarea,
.rv-select {
  display: block;
  width: 100%;
  font-family: var(--rv-font-family);
  font-size: var(--rv-font-size-sm);
  font-weight: var(--rv-font-weight-normal);
  line-height: var(--rv-line-height-normal);
  color: var(--rv-text);
  background-color: var(--rv-surface);
  border: 1px solid var(--rv-border);
  border-radius: var(--rv-radius-lg);
  transition:
    border-color var(--rv-transition-fast),
    box-shadow var(--rv-transition-fast),
    background-color var(--rv-transition-fast);
}

.rv-input::placeholder,
.rv-textarea::placeholder {
  color: var(--rv-text-subtle);
}

.rv-input:hover:not(:disabled):not(:read-only),
.rv-textarea:hover:not(:disabled):not(:read-only),
.rv-select:hover:not(:disabled) {
  border-color: var(--rv-primary-soft-border);
}

.rv-input:focus,
.rv-textarea:focus,
.rv-select:focus {
  outline: none;
  border-color: var(--rv-primary);
  box-shadow: 0 0 0 3px var(--rv-primary-focus-ring);
}

.rv-input:disabled,
.rv-textarea:disabled,
.rv-select:disabled {
  background-color: var(--rv-border-subtle);
  color: var(--rv-text-subtle);
  cursor: not-allowed;
  opacity: 0.75;
}

.rv-input:read-only,
.rv-textarea:read-only {
  background-color: var(--rv-border-subtle);
  cursor: default;
}

/* --------------------------------------------------------------------------
   Input & textarea
   -------------------------------------------------------------------------- */

.rv-input {
  min-height: var(--rv-space-10);
  padding: var(--rv-space-2) var(--rv-space-4);
}

.rv-input--sm {
  min-height: var(--rv-space-8);
  padding: var(--rv-space-1) var(--rv-space-3);
  font-size: var(--rv-font-size-xs);
  border-radius: var(--rv-radius-md);
}

.rv-input--lg {
  min-height: var(--rv-space-12);
  padding: var(--rv-space-3) var(--rv-space-4);
  font-size: var(--rv-font-size-base);
}

.rv-textarea {
  min-height: calc(var(--rv-space-16) + var(--rv-space-4));
  padding: var(--rv-space-3) var(--rv-space-4);
  resize: vertical;
}

/* --------------------------------------------------------------------------
   Select
   -------------------------------------------------------------------------- */

.rv-select {
  min-height: var(--rv-space-10);
  padding: var(--rv-space-2) var(--rv-space-8) var(--rv-space-2) var(--rv-space-4);
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--rv-text-muted) 50%),
    linear-gradient(135deg, var(--rv-text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - var(--rv-space-5)) center,
    calc(100% - var(--rv-space-3)) center;
  background-size: var(--rv-space-1) var(--rv-space-1);
  background-repeat: no-repeat;
  cursor: pointer;
}

[dir="rtl"] .rv-select {
  padding: var(--rv-space-2) var(--rv-space-4) var(--rv-space-2) var(--rv-space-8);
  background-position:
    var(--rv-space-3) center,
    var(--rv-space-5) center;
}

/* --------------------------------------------------------------------------
   Checkbox & radio
   -------------------------------------------------------------------------- */

.rv-check,
.rv-radio {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--rv-space-3);
  cursor: pointer;
  font-size: var(--rv-font-size-sm);
  color: var(--rv-text);
  line-height: var(--rv-line-height-normal);
}

.rv-check--disabled,
.rv-radio--disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.rv-checkbox,
.rv-radio {
  flex-shrink: 0;
  width: var(--rv-space-4);
  height: var(--rv-space-4);
  margin: 0;
  margin-block-start: var(--rv-space-1);
  accent-color: var(--rv-primary);
  cursor: pointer;
}

.rv-checkbox:disabled,
.rv-radio:disabled {
  cursor: not-allowed;
}

.rv-checkbox:focus-visible,
.rv-radio:focus-visible {
  outline: 2px solid var(--rv-primary);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Invalid state
   -------------------------------------------------------------------------- */

.rv-input.is-invalid,
.rv-textarea.is-invalid,
.rv-select.is-invalid {
  border-color: var(--rv-danger);
}

.rv-input.is-invalid:focus,
.rv-textarea.is-invalid:focus,
.rv-select.is-invalid:focus {
  box-shadow: 0 0 0 3px var(--rv-danger-soft);
}

.rv-field.is-invalid .rv-label {
  color: var(--rv-danger);
}

/* --------------------------------------------------------------------------
   Input group (RTL-safe)
   -------------------------------------------------------------------------- */

.rv-input-group {
  display: flex;
  align-items: stretch;
  width: 100%;
}

.rv-input-group .rv-input {
  flex: 1;
  min-width: 0;
  border-radius: 0;
}

.rv-input-group .rv-input:first-child {
  border-start-start-radius: var(--rv-radius-lg);
  border-end-start-radius: var(--rv-radius-lg);
}

.rv-input-group .rv-input:last-child {
  border-start-end-radius: var(--rv-radius-lg);
  border-end-end-radius: var(--rv-radius-lg);
}

.rv-input-group__addon {
  display: flex;
  align-items: center;
  padding-inline: var(--rv-space-3);
  font-size: var(--rv-font-size-sm);
  color: var(--rv-text-muted);
  background-color: var(--rv-border-subtle);
  border: 1px solid var(--rv-border);
  white-space: nowrap;
}

.rv-input-group__addon:first-child {
  border-inline-end: none;
  border-start-start-radius: var(--rv-radius-lg);
  border-end-start-radius: var(--rv-radius-lg);
}

.rv-input-group__addon:last-child {
  border-inline-start: none;
  border-start-end-radius: var(--rv-radius-lg);
  border-end-end-radius: var(--rv-radius-lg);
}
