/* ==========================================================================
   Bootstrap-5-compatible grid and form controls, built on our design tokens.

   The class names are Bootstrap's on purpose — row, col-md-6, form-label,
   form-control, form-select, form-check, invalid-feedback — so the markup reads
   exactly like a Bootstrap form and anyone familiar with Bootstrap can work on
   it. The implementation is ours, at roughly 4KB instead of ~160KB, which
   matters on a low-end Android over 3G and keeps the site visually one product
   rather than two.

   Only the subset this form actually uses is implemented.
   ========================================================================== */

/* --- Grid ---------------------------------------------------------------- */

.row {
  display: flex;
  flex-wrap: wrap;
  margin-inline: calc(var(--gutter, var(--space-5)) / -2);
}
/* .row's own `display: flex` is an author rule, so at equal specificity it beats the
   browser's built-in `[hidden] { display: none }` — an author stylesheet always wins
   ties with the user-agent one. Without this, toggling the `hidden` attribute on any
   .row (as the WhatsApp-number row does) removes it from layout in every way except
   the one that matters: it keeps rendering. */
.row[hidden] { display: none; }
.row > * {
  width: 100%;
  padding-inline: calc(var(--gutter, var(--space-5)) / 2);
}

.g-2 { --gutter: var(--space-2); }
.g-3 { --gutter: var(--space-4); }
.g-4 { --gutter: var(--space-5); }

.row > * { margin-bottom: var(--space-4); }

.col-12 { flex: 0 0 100%; max-width: 100%; }

@media (min-width: 768px) {
  .col-md-3  { flex: 0 0 25%;      max-width: 25%; }
  .col-md-4  { flex: 0 0 33.3333%; max-width: 33.3333%; }
  .col-md-6  { flex: 0 0 50%;      max-width: 50%; }
  .col-md-8  { flex: 0 0 66.6667%; max-width: 66.6667%; }
  .col-md-12 { flex: 0 0 100%;     max-width: 100%; }
}

@media (min-width: 992px) {
  .col-lg-2  { flex: 0 0 16.6667%; max-width: 16.6667%; }
  .col-lg-3  { flex: 0 0 25%;      max-width: 25%; }
  .col-lg-4  { flex: 0 0 33.3333%; max-width: 33.3333%; }
  .col-lg-6  { flex: 0 0 50%;      max-width: 50%; }
  .col-lg-8  { flex: 0 0 66.6667%; max-width: 66.6667%; }
}

/* --- Form controls ------------------------------------------------------- */

.form-label {
  display: block;
  font-size: var(--step--1);
  font-weight: 650;
  color: var(--ink);
  margin-bottom: var(--space-2);
  line-height: 1.35;
}

/* Required marker. aria-hidden in the markup — the input's own `required`
   attribute is what conveys this to a screen reader, so the asterisk is purely
   visual and must not be read out as "star" on every field. */
.req {
  color: var(--accent);
  font-weight: 700;
  margin-left: 2px;
}

.optional {
  font-weight: 500;
  color: var(--ink-muted);
  font-size: var(--step--2);
  margin-left: var(--space-2);
}

.form-control,
.form-select {
  display: block;
  width: 100%;
  min-height: var(--touch);
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: var(--step-0);
  color: var(--ink);
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}

.form-control::placeholder { color: var(--ink-faint); }
.form-control:hover, .form-select:hover { border-color: var(--ink-muted); }

.form-control:focus, .form-select:focus {
  border-color: var(--primary-bright);
  box-shadow: 0 0 0 3px rgba(24, 120, 196, 0.18);
  outline: none;
}

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

/* The one icon on the registration form — see the comment beside its markup in
   Start.cshtml for why WhatsApp alone gets one. --success rather than the brand's own
   #25D366 so it stays inside the site's own accessible palette instead of adding an
   off-palette hex for a single glyph. */
.icon-whatsapp { color: var(--success); vertical-align: -3px; margin-right: 4px; }

/* --- Fixed "+91" phone prefix ----------------------------------------------
   Display only: it is not part of the input's value or name, so the field
   still binds and validates as a bare 10-digit number exactly as before —
   OtpService.NormaliseMobile and every sender already assume that shape.
   pointer-events: none keeps it inert; aria-hidden on the span (in the view)
   keeps a screen reader from announcing it as a second, unlabelled field. */
.phone-field { position: relative; }
.phone-field__prefix {
  position: absolute;
  inset-block: 0; left: 0;
  width: 2.75rem;
  display: flex; align-items: center; justify-content: center;
  font-weight: 650;
  color: var(--ink-muted);
  border-right: 1px solid var(--line-strong);
  pointer-events: none;
}
.phone-field .form-control,
.phone-field .input { padding-left: calc(2.75rem + var(--space-2)); }

/* --- Password show/hide toggle -------------------------------------------
   .form-control keeps its normal width and focus ring; only its right padding
   moves to clear the icon, so the toggle reads as part of the field rather
   than a control bolted on beside it. */
.password-field { position: relative; }
.password-field .form-control { padding-right: calc(var(--touch) + var(--space-1)); }

.password-toggle {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: var(--touch);              /* matches .form-control's own min-height:
                                        a square tap target, not a sliver. */
  display: flex; align-items: center; justify-content: center;
  background: none; border: 0; padding: 0;
  color: var(--ink-muted);
  cursor: pointer;
}
.password-toggle:hover { color: var(--ink); }
.password-toggle:focus-visible {
  outline: 2px solid var(--primary-bright);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}
.password-toggle svg { width: 20px; height: 20px; }

.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 16 16'%3E%3Cpath fill='none' stroke='%235B6472' stroke-width='1.6' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-7);
}

.form-control[readonly] {
  background: var(--surface-sunk);
  color: var(--ink-muted);
  cursor: default;
}

.form-control:disabled, .form-select:disabled {
  background: var(--surface-sunk);
  color: var(--ink-faint);
  cursor: not-allowed;
}

.form-text {
  display: block;
  font-size: var(--step--1);
  color: var(--ink-muted);
  margin-top: var(--space-2);
}

/* --- Validation ---------------------------------------------------------- */

.invalid-feedback,
.field-validation-error {
  display: block;
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--danger);
  margin-top: var(--space-2);
}
.field-validation-valid { display: none; }

.form-control.input-validation-error,
.form-select.input-validation-error,
.form-control:user-invalid,
.form-select:user-invalid {
  border-color: var(--danger);
  background-color: var(--danger-tint);
}

.validation-summary-errors {
  border: 1px solid #EDBDBF;
  background: var(--danger-tint);
  color: #8C1216;
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-5);
}
.validation-summary-errors ul { margin: 0; padding-left: var(--space-5); }
.validation-summary-valid { display: none; }

/* --- Radios & checkboxes -------------------------------------------------- */

.form-check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-height: var(--touch);
  padding: var(--space-2) 0;
  cursor: pointer;
}
.form-check-input {
  width: 20px; height: 20px; margin: 2px 0 0;
  flex: none; accent-color: var(--primary); cursor: pointer;
}
.form-check-label { cursor: pointer; line-height: 1.4; }

/* Radios laid out in a row on wider screens, stacked on a phone. */
.form-check-inline-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-6);
}
.form-check-inline-group .form-check { padding-block: var(--space-1); }

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend.form-label { padding: 0; }

/* --- Section cards -------------------------------------------------------- */

.form-section {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  margin-bottom: var(--space-6);
  overflow: hidden;
}

.form-section__head {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--surface-sunk);
  border-bottom: 1px solid var(--line-strong);
}

.form-section__num {
  flex: none;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: var(--step--1);
  font-weight: 700;
  align-self: center;
}

.form-section__title {
  font-family: var(--font-body);
  font-size: var(--step-1);
  font-weight: 700;
  letter-spacing: 0.01em;
  margin: 0;
  color: var(--ink);
}

.form-section__hint {
  font-size: var(--step--1);
  color: var(--ink-muted);
  margin-left: auto;
}

.form-section__body { padding: var(--space-5); }
.form-section__body .row:last-child > *:last-child { margin-bottom: 0; }

/* --- Read-only detail pairs (the submitted-application view) --------------
   Same sections as the form, but showing what was answered rather than
   collecting it. auto-fit rather than a fixed two columns so a long address
   is not squeezed into half a phone screen.                                 */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--space-4);
  margin: 0;
}

.detail-grid dt {
  font-size: var(--step--2);
  color: var(--ink-muted, #5B6472);
  margin-bottom: 2px;
}

.detail-grid dd {
  margin: 0;
  font-weight: 500;
  overflow-wrap: anywhere;   /* long emails must wrap, not widen the grid */
}

/* --- Form header (the "official document" masthead) ---------------------- */

.form-masthead {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding-bottom: var(--space-5);
  border-bottom: 3px double var(--line-strong);
  margin-bottom: var(--space-6);
}
.form-masthead__seal { width: 64px; height: 64px; flex: none; }
.form-masthead h1 { font-size: var(--step-2); margin: 0 0 var(--space-1); }
.form-masthead p { margin: 0; font-size: var(--step--1); color: var(--ink-muted); }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding-top: var(--space-5);
  border-top: 1px solid var(--line);
}
.form-actions .btn--primary { margin-left: auto; }
@media (max-width: 599px) {
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; margin-left: 0; }
}

/* ==========================================================================
   A4 print
   The completed form has to survive being printed, signed and filed — several
   districts will keep a paper copy regardless of what the database says.
   ========================================================================== */

@media print {
  @page { size: A4 portrait; margin: 14mm 12mm; }

  html, body {
    background: #fff !important;
    color: #000 !important;
    font-size: 10.5pt;
  }

  /* Screen chrome has no place on a filed document. */
  .site-header, .site-footer, .skip-link, .form-actions,
  .no-print, .alert, .stepper, .form-text, .g-recaptcha { display: none !important; }

  .print-only { display: block !important; }

  .container, .container--tight { max-width: 100% !important; padding: 0 !important; }
  .section { padding-block: 0 !important; }

  /* The seal must survive printing — several districts will keep a signed paper
     copy, and a masthead with a blank square where the seal should be does not
     look like an official document. Browsers drop background images when printing
     but keep <img>, which is one reason the seal is an image rather than CSS. */
  .form-masthead {
    break-inside: avoid;
    page-break-after: avoid;
    border-bottom: 1.5pt double #000 !important;
    padding-bottom: 3mm !important;
    margin-bottom: 5mm !important;
  }
  .form-masthead__seal {
    width: 18mm !important; height: 18mm !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .form-masthead h1 { font-size: 14pt !important; }
  .form-masthead p  { font-size: 9pt !important; color: #000 !important; }

  .form-section {
    border: 1pt solid #000 !important;
    border-radius: 0 !important;
    margin-bottom: 6mm !important;
    /* Never split a section across a page break — a signature block orphaned on
       page 3 is exactly what makes a printed form get rejected. */
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .form-section__head {
    background: #e8e8e8 !important;
    border-bottom: 1pt solid #000 !important;
    padding: 2mm 3mm !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .form-section__num {
    background: #000 !important; color: #fff !important;
    width: 20px; height: 20px; font-size: 9pt;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .form-section__body { padding: 3mm !important; }

  .row > * { margin-bottom: 3mm !important; }
  .form-label { font-size: 8.5pt; margin-bottom: 1mm; color: #000 !important; }
  .req { color: #000 !important; }

  /* Values are what matter on paper, so inputs print as ruled lines rather than
     boxes — and readonly/disabled shading would waste toner. */
  .form-control, .form-select {
    border: 0 !important;
    border-bottom: 0.5pt solid #000 !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: #000 !important;
    min-height: 0 !important;
    padding: 0 0 1mm !important;
    font-size: 10pt;
  }
  textarea.form-control { min-height: 14mm !important; }

  .form-check-input { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  a { text-decoration: none !important; color: #000 !important; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 8pt; }

  .print-signature {
    display: flex !important;
    justify-content: space-between;
    gap: 10mm;
    margin-top: 10mm;
    break-inside: avoid;
  }
  .print-signature div {
    flex: 1;
    border-top: 0.5pt solid #000;
    padding-top: 2mm;
    font-size: 9pt;
  }
}

.print-only { display: none; }

/* --- Preferred exam location picker ------------------------------------
   A state filter, then that state's towns as tickable rows. Ticking assigns
   the next rank; the arrows reorder. Rows stay tall enough to hit on a phone. */
.exam-pref__state { border: 0; padding: 0; margin: var(--space-3) 0 0; min-width: 0; }
.exam-pref__legend {
  font-size: var(--step--1); font-weight: 650; color: var(--ink-muted);
  padding: 0; margin-bottom: var(--space-2);
}
.exam-pref__list {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-1) var(--space-3);
}
.exam-pref__item {
  display: flex; align-items: center; gap: var(--space-2);
  min-height: 44px; padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm, 6px);
}
.exam-pref__item[data-rank]:not([data-rank=""]) { background: var(--primary-tint); }
.exam-pref__choice { display: flex; align-items: center; gap: var(--space-2); flex: 1; cursor: pointer; min-width: 0; }
.exam-pref__choice .form-check-input { margin: 0; flex: none; }
.exam-pref__rank {
  flex: none; min-width: 2.4em; text-align: center;
  font-size: var(--step--2); font-weight: 700; color: var(--primary-deep);
}
.exam-pref__rank:empty { visibility: hidden; }
.exam-pref__name { overflow-wrap: anywhere; }
.exam-pref__move { display: inline-flex; gap: 2px; flex: none; }
.exam-pref__arrow {
  width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--ink-muted); font-size: 11px; line-height: 1; cursor: pointer;
}
.exam-pref__arrow:disabled { opacity: .35; cursor: default; }
.exam-pref__arrow:hover:not(:disabled) { color: var(--primary-deep); border-color: var(--primary-deep); }
