/* ==========================================================================
   Forms — CoachOS Design System
   Inputs, selects, textareas, checkboxes, radios, toggles
   ========================================================================== */

/* Form Group
   ========================================================================== */

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

/* Label
   ========================================================================== */

.form-label {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

/* Hint
   ========================================================================== */

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: var(--space-1);
}

/* Tight grouping when a hint immediately follows its label — they read as one
   pair, so the 4px lead-in is redundant. The line-leading still provides
   sufficient visual separation. */
.form-label + .form-hint {
  margin-top: 0;
}

/* Text Inputs, Selects, Textareas
   ========================================================================== */

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: inherit;
  transition: border-color var(--duration-fast), background-color var(--duration-fast);
}

.form-input::placeholder,
.form-select::placeholder,
.form-textarea::placeholder {
  color: var(--input-placeholder);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--input-border-focus);
  background-color: var(--input-bg-focus);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

/* Compact width modifier
   Caps short-form inputs at a phone-width feel on tablets+. Below 640px the
   field stays full-width (inherited from the base rule); at 640px+ it caps
   at --field-max-width-compact (24rem / 384px). Use for inputs whose answer
   doesn't naturally fill the available space — number, date, time, select
   with short labels. Intentionally NOT applied to .form-textarea (multi-line
   is always full-width).
   ========================================================================== */

@media (min-width: 640px) {
  .form-input--compact,
  .form-select--compact {
    max-width: var(--field-max-width-compact);
  }
}

/* Color picker — dropdown swatch selector */
.ee-color-picker {
  position: relative;
}
.ee-color-picker__trigger {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1-5);
  border: 1px dashed var(--accent-muted);
  border-radius: var(--radius-lg);
  background: var(--input-bg);
  cursor: pointer;
  list-style: none;
  transition: border-color var(--duration-fast);
}
.ee-color-picker__trigger::-webkit-details-marker { display: none; }
.ee-color-picker__trigger:hover {
  border-color: var(--accent-primary);
}
.ee-color-picker__preview {
  width: 18px;
  height: 18px;
  border-radius: var(--radius-sm);
  border: 1px solid rgb(0 0 0 / 0.1);
  flex-shrink: 0;
}
.ee-color-picker__dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: var(--z-dropdown);
  display: grid;
  grid-template-columns: repeat(5, 22px);
  gap: 6px;
  padding: 8px;
  background: var(--surface-base);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.ee-swatch {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  outline: none;
  transition: transform var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out);
}
.ee-swatch:hover {
  transform: scale(1.2);
}
.ee-swatch--selected {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px var(--surface-base);
}

/* Textarea
   ========================================================================== */

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

/* Select
   ========================================================================== */

.form-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='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 16px;
  padding-right: var(--space-10);
}

/* Checkbox & Radio
   ========================================================================== */

.form-checkbox,
.form-radio {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-primary);
  border: 2px solid var(--border-default);
  cursor: pointer;
  flex-shrink: 0;
}

.form-checkbox {
  border-radius: var(--radius-sm);
}

.form-radio {
  border-radius: var(--radius-full);
}

.form-checkbox:checked,
.form-radio:checked {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
}

/* Toggle Switch
   ========================================================================== */

.form-toggle {
  width: 44px;
  height: 24px;
  background-color: var(--border-default);
  border-radius: var(--radius-full);
  border: none;
  position: relative;
  transition: background-color var(--duration-fast);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}

.form-toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background-color: white;
  border-radius: var(--radius-full);
  transition: transform var(--duration-fast);
}

.form-toggle[aria-checked="true"],
.form-toggle.form-toggle--checked,
input:checked + .form-toggle {
  background-color: var(--accent-primary);
}

.form-toggle[aria-checked="true"]::after,
.form-toggle.form-toggle--checked::after,
input:checked + .form-toggle::after {
  transform: translateX(20px);
}

/* Error State
   ========================================================================== */

.form-error {
  color: var(--status-error);
  font-size: var(--text-xs);
  margin-top: var(--space-1);
}

/* Rails field_with_errors wrapper */
.field_with_errors input,
.field_with_errors select,
.field_with_errors textarea {
  border-color: var(--status-error);
}

/* Inline Label (checkbox/toggle next to label text)
   ========================================================================== */

.form-label--inline {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

/* Tag Select (multi-select checkboxes rendered as tag grid)
   ========================================================================== */

.form-tag-select {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-lg);
  background: var(--input-bg);
  min-height: 42px;
}

.form-tag-select:focus-within {
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.form-tag-option {
  display: flex;
  align-items: center;
  gap: var(--space-1-5);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  cursor: pointer;
  background: var(--surface-sunken);
  color: var(--text-secondary);
  transition: all var(--duration-fast);
  user-select: none;
}

.form-tag-option:hover {
  background: var(--surface-hover);
}

.form-tag-option:has(input:checked) {
  background: var(--accent-muted);
  color: var(--accent-primary);
  font-weight: 600;
}

.form-tag-option input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent-primary);
  margin: 0;
}

/* Form Row (multi-column layout)
   ========================================================================== */

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