/**
 * Forms — canonical, token-driven.
 *
 * Promoted from DriverReports (the fullest token-driven form styling) as the
 * canonical shared form design; every value resolves against variables.css so
 * one palette drives the whole estate. The widget blocks below the base rules
 * (buttons, disabled/readonly, dropdown-multiselect, floating labels) are kept
 * from the previous Intranet-sourced file — consumers depend on them — but
 * re-expressed as tokens rather than hardcoded colours/spacing.
 */

/* ============================================================================
   BASE FIELDS
   ============================================================================ */

.form-group {
  margin-bottom: var(--spacing-md);
}

.form-group:last-child {
  margin-bottom: 0;
}

label {
  display: block;
  margin-bottom: var(--spacing-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--text-dark);
  font-size: var(--font-size-base);
}

.required::after {
  content: ' *';
  color: var(--error);
}

input[type='text'],
input[type='email'],
input[type='password'],
input[type='search'],
input[type='url'],
input[type='tel'],
input[type='number'],
input[type='date'],
input[type='time'],
input[type='datetime-local'],
input[type='month'],
input[type='week'],
input[type='color'],
textarea,
select {
  width: 100%;
  padding: var(--spacing-sm);
  font-size: var(--font-size-base);
  font-family: var(--font-family-base);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius-md);
  background-color: var(--bg-white);
  color: var(--text-primary);
  transition: border-color var(--transition-default), box-shadow var(--transition-default);
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

input[type='text']:focus,
input[type='email']:focus,
input[type='password']:focus,
input[type='search']:focus,
input[type='url']:focus,
input[type='tel']:focus,
input[type='number']:focus,
input[type='date']:focus,
input[type='time']:focus,
input[type='datetime-local']:focus,
input[type='month']:focus,
input[type='week']:focus,
input[type='color']:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: var(--focus-glow);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

select {
  background-image: url('data:image/svg+xml;charset=UTF-8,%3csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22currentColor%22%3e%3cpath d=%22M6 9l6 6 6-6%22/%3e%3c/svg%3e');
  background-repeat: no-repeat;
  background-position: right var(--spacing-sm) center;
  background-size: 1.5em 1.5em;
  padding-right: 2.5rem;
}

input[type='checkbox'],
input[type='radio'] {
  width: auto;
  margin-right: var(--spacing-xs);
  cursor: pointer;
  accent-color: var(--brand-primary);
}

.form-check {
  display: flex;
  align-items: center;
  margin-bottom: var(--spacing-sm);
}

.form-check input {
  margin-right: var(--spacing-sm);
}

.form-check label {
  margin-bottom: 0;
  font-weight: var(--font-weight-normal);
}

select:disabled,
input:disabled,
textarea:disabled {
  background-color: var(--gray-light);
  cursor: not-allowed;
}

input[readonly] {
  background-color: var(--bg-light);
  cursor: not-allowed;
}

/* ============================================================================
   VALIDATION STATES
   ============================================================================ */

.form-group.has-error input,
.form-group.has-error textarea,
.form-group.has-error select {
  border-color: var(--error);
}

.form-group.has-error input:focus,
.form-group.has-error textarea:focus,
.form-group.has-error select:focus {
  box-shadow: var(--focus-glow-error);
}

.form-error,
form .error {
  color: var(--error);
  font-size: var(--font-size-sm);
  margin-top: 0.25rem;
}

.form-success,
form .success {
  color: var(--success);
  font-size: var(--font-size-sm);
  margin-top: 0.25rem;
}

/* ============================================================================
   SPACING HELPERS (intent-revealing vertical rhythm)
   ============================================================================ */

.field-group {
  margin-bottom: var(--spacing-sm);
}

.form-section-gap {
  margin-bottom: var(--spacing-md);
}

.section-gap {
  margin-bottom: var(--spacing-lg);
}

/* ============================================================================
   FORM BUTTONS (kept for consumers; tokenised)
   ============================================================================ */

a.btn,
form button[type='submit'],
form button[type='button'] {
  display: inline-block;
  padding: var(--spacing-sm) var(--spacing-md);
  margin-top: var(--spacing-sm);
  border: none;
  border-radius: var(--border-radius-md);
  background-color: var(--brand-primary);
  color: var(--text-white);
  font-size: var(--font-size-base);
  font-family: var(--font-family-base);
  cursor: pointer;
  transition: background-color var(--transition-default);
}

a.btn:hover,
form button[type='submit']:hover,
form button[type='button']:hover {
  background-color: var(--brand-primary-alt);
  text-decoration: none;
}

a.btn.secondary,
form button.secondary {
  background-color: var(--bg-white);
  color: var(--brand-primary);
}

form button.secondary:hover {
  background-color: var(--bg-white);
  color: var(--brand-primary);
  text-decoration: underline;
}

/* ============================================================================
   FLOATING LABELS (kept for consumers; tokenised)
   ============================================================================ */

.input-container {
  position: relative;
  margin-top: var(--spacing-md);
}

.floating-label {
  position: absolute;
  pointer-events: none;
  left: var(--spacing-sm);
  top: var(--spacing-sm);
  transition: 0.2s ease all;
  opacity: 0.5;
}

input:focus ~ .floating-label,
input:not(:placeholder-shown) ~ .floating-label,
.floating-label.active {
  top: -20px;
  left: var(--spacing-sm);
  font-size: var(--font-size-xs);
  opacity: 1;
}

/* ============================================================================
   DROPDOWN MULTISELECT (kept for consumers; tokenised)
   ============================================================================ */

.dropdown-multiselect {
  position: relative;
  width: 100%;
  margin-top: 0;
}

form .dropdown-multiselect button[type='button'] {
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  margin-top: 0;
}

form .dropdown-multiselect input {
  width: auto;
}

form .dropdown-multiselect label {
  font-weight: var(--font-weight-normal);
}

form .dropdown-multiselect label:hover {
  background: var(--brand-primary);
  color: var(--text-white);
}

.dropdown-toggle {
  width: 100%;
  padding: var(--spacing-sm);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  background: var(--bg-white);
  text-align: left;
  font-size: var(--font-size-base);
  cursor: pointer;
  transition: border-color var(--transition-default);
}

.dropdown-toggle::after {
  content: '\25BC';
  float: right;
  margin-top: 4px;
  font-size: var(--font-size-xs);
  color: var(--text-light);
}

.dropdown-menu {
  display: none;
  position: absolute;
  z-index: var(--z-dropdown);
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  width: 100%;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  margin-top: -1rem;
}

.dropdown-multiselect.open .dropdown-menu {
  display: block;
}

.dropdown-menu label {
  display: flex;
  align-items: center;
  padding: 6px var(--spacing-sm);
  cursor: pointer;
  font-size: var(--font-size-sm);
  margin: 0;
}

.dropdown-menu input[type='checkbox'] {
  margin-right: var(--spacing-xs);
}

.dropdown-multiselect .dropdown-toggle.selected {
  font-weight: var(--font-weight-bold);
  color: var(--brand-primary);
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
  form button[type='submit'],
  form button[type='button'] {
    width: 100%;
    margin-top: var(--spacing-sm);
  }
}
