/* ==========================================================================
   Forms
   ========================================================================== */
.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.form__section {
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-xs);
}

.form__section-title {
  font-size: var(--font-size-small);
  font-family: var(--font-family-bold);
  text-transform: uppercase;
  letter-spacing: var(--label-letter-spacing);
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.form__row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  gap: var(--space-4);
}

.form__field {
  display: flex;
  flex-direction: column;
  white-space: nowrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  font-size: var(--font-size-small);
  width: 100%;
}

.form__field > textarea {
  min-height: 100px;
  resize: vertical;
}

.form__field--inline {
  display: flex;
  flex-direction: row;
  gap: var(--space-4);
}

.form__field--centered {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.form__label {
  display: block;
  font-family: var(--font-family-bold);
  font-size: var(--font-size-small);
  color: var(--color-text-muted);
}

.form__input,
.form__select {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--font-size-medium);
  font-family: var(--font-family-base);
  color: var(--color-text);
  background-color: var(--color-surface-sunken);
  transition: border-color var(--transition-fast), background-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.form__field > textarea.form__input,
textarea.form__input {
  height: auto;
  padding: var(--space-2) var(--space-3);
}

.form__input:hover,
.form__select:hover {
  border-color: var(--color-border-strong);
}

.form__input:focus,
.form__select:focus {
  outline: none;
  background-color: var(--color-surface);
  border-color: var(--color-primary-green);
  box-shadow: var(--focus-ring);
}

/* Auto-generated values (e.g. a complaint id or a computed due date) — shown
   for reference, not editable. */
.form__input--readonly,
.form__input--readonly:hover,
.form__input--readonly:focus {
  border-color: var(--color-border);
  background-color: var(--tint-navy-04);
  color: var(--color-text-muted);
  box-shadow: none;
  cursor: default;
}

.form__select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right var(--space-2) center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  padding-right: var(--space-8);
  cursor: pointer;
}

.form__checkbox {
  margin-right: var(--space-2);
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary-green);
}

.form__hint {
  margin-bottom: var(--space-2);
  font-size: var(--font-size-small);
  color: var(--color-text-muted, #64748b);
}

/* Something the form needs to say before it is filled in, rather than about one
   field: that a firm's own adviser is sending their edits for review, say. */
.form__notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background-color: var(--color-surface-sunken);
  color: var(--color-text-muted);
  font-size: var(--font-size-small);
  line-height: 1.5;
}

.form__notice-icon {
  flex-shrink: 0;
  margin-top: 2px;
}

/* A field the user can read but not set — the person a firm's own adviser is
   logging feedback as, say. Sits on the input's line so the form still reads as
   a column of fields rather than a paragraph dropped into one. */
.form__static-value {
  display: flex;
  align-items: center;
  height: 40px;
  font-size: var(--font-size-medium);
  color: var(--color-text);
}

.form__checkbox-group {
  display: grid;
  /* `min(100%, 200px)` rather than a bare 200px: in a drawer narrower than the
     track the column would otherwise overflow the form rather than the grid
     dropping to one column. */
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
  gap: var(--space-2);
}

.form__checkbox-option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  /* A grid track is `minmax(200px, 1fr)`, so an option whose label runs longer
     than that — "Annual Suitability Report (ASR)", and the checklist note under
     it — has to be allowed to wrap rather than push its box open. Flex items
     refuse to shrink below their content width without this. */
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--font-size-small);
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.form__checkbox-option:hover {
  border-color: var(--color-primary-green);
}

.form__checkbox-option:has(.form__checkbox:checked) {
  border-color: var(--color-primary-green);
  background-color: var(--tint-primary-10, rgba(16, 185, 129, 0.08));
}

.form__checkbox-option .form__checkbox {
  margin-right: 0;
  /* The box keeps its size while the label beside it wraps. */
  flex-shrink: 0;
}

/* A recommendation and the checklist it brings with it, stacked so the option
   still reads as one line of list (see cases/_case_type_checkboxes). */
.form__checkbox-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* As above: without `min-width: 0` this refuses to be narrower than its
     longest line, and the text runs out of the option instead of wrapping. */
  min-width: 0;
  overflow-wrap: anywhere;
}

.form__checkbox-note {
  color: var(--color-text-muted);
  font-size: 11px;
  line-height: 1.3;
}

.form__actions {
  margin-top: var(--space-6);
  display: flex;
  gap: var(--space-3);
}

/* --- Validation error summary --- */
.form__error-summary {
  border: 1px solid var(--tint-danger-16);
  border-left: 3px solid var(--color-danger);
  border-radius: var(--radius-md);
  background-color: var(--tint-danger-10);
  color: var(--color-danger);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
}

.form__error-summary h3 {
  font-size: var(--font-size-medium);
  color: var(--color-danger);
  margin-bottom: var(--space-2);
}

.form__error-summary ul {
  margin: 0;
  padding-left: var(--space-4);
  font-size: var(--font-size-small);
}

/* --- Yes/No radio switch --- */
.form__radio-switch {
  position: relative;
  width: 100%;
}

.form__radio-group {
  display: flex;
  background-color: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 3px;
  position: relative;
  width: 120px;
}

.form__radio-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.form__radio-label {
  flex: 1;
  text-align: center;
  padding: var(--space-1) var(--space-3);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: var(--font-size-small);
  transition: all var(--transition-base);
  user-select: none;
  z-index: 1;
  color: var(--color-text-muted);
}

.form__radio-label:hover {
  background-color: var(--tint-navy-06);
}

.form__radio-label--yes.selected,
.form__radio-input:checked + .form__radio-label--yes {
  background-color: var(--color-success) !important;
  color: var(--color-white) !important;
}

.form__radio-label--no.selected,
.form__radio-input:checked + .form__radio-label--no {
  background-color: var(--color-text-muted) !important;
  color: var(--color-white) !important;
}

.form__radio-input:focus-visible + .form__radio-label {
  box-shadow: var(--focus-ring);
}

.form__radio-label--yes.selected:hover,
.form__radio-input:checked + .form__radio-label--yes:hover {
  background-color: var(--color-success-dark) !important;
}

/* --- Grid helpers --- */
.form__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

.form__field--full {
  grid-column: 1 / -1;
}

.form__field--date {
  width: 100%;
}

/* --- Duration inputs --- */
.form__duration-inputs {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
}

.form__duration-inputs--labeled {
  flex-wrap: wrap;
}

.form__duration-input-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.form__duration-separator {
  color: var(--color-text-muted);
  font-weight: 500;
  padding-bottom: var(--space-2);
}

/* --- Currency / percentage affixes --- */
.form__input-wrapper {
  position: relative;
  display: inline-block;
}

.form__input-wrapper--currency::before {
  content: "£";
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
}

.form__input-wrapper--percentage::after {
  content: "%";
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
}

.form__input--currency {
  padding-left: var(--space-6);
}

.form__input--percentage {
  padding-right: var(--space-6);
}

/* --- File upload --- */
.form__file-upload {
  margin-bottom: var(--space-4);
}

.form__input--file {
  width: 100%;
  height: auto;
  padding: var(--space-3);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  background-color: var(--color-surface-sunken);
  cursor: pointer;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.form__input--file:hover {
  border-color: var(--color-primary-green);
  background-color: var(--tint-green-10);
}

.form__preview {
  margin-top: var(--space-2);
}

.form__preview-image {
  max-width: 200px;
  max-height: 200px;
  object-fit: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

/* --- Static (read-only) radio switch --- */
.form__radio-label--static {
  flex: 1;
  text-align: center;
  padding: var(--space-1) var(--space-3);
  cursor: default;
  border-radius: var(--radius-sm);
  font-weight: 500;
  user-select: none;
  z-index: 1;
  width: 50%;
}

.form__radio-switch--static {
  width: 120px;
}

.form__radio-switch--static .form__radio-label {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-small);
  cursor: default;
}

.form__radio-label--yes.form__radio-label--selected {
  background-color: var(--color-success);
  color: var(--color-white);
}

.form__radio-label--no.form__radio-label--selected {
  background-color: var(--color-text-muted);
  color: var(--color-white);
}
