/* Campus Forms — Bootstrap 5.3 bridge.
   Load order: bootstrap.css → campus-forms-tokens.css → THIS → campus-forms-components.css

   This file does two jobs and nothing else:
     1. Maps our tokens onto Bootstrap's own --bs-* custom properties, so every
        Bootstrap component inherits the system without being re-skinned one by one.
     2. Restyles the handful of Bootstrap components whose defaults are wrong for a
        public form: form controls, buttons, badges, alerts, checkboxes.

   Do not add app styling here. New rules belong in campus-forms-components.css or
   in the component itself.

   Theme: set data-bs-theme="light" | "dark" on <html>. campus-forms-tokens.css
   answers to both data-bs-theme and data-theme, so one attribute flips both. */

/* ---------------------------------------------------------------
   1. Tokens → Bootstrap variables
   --------------------------------------------------------------- */

:root,
[data-bs-theme="light"],
[data-bs-theme="dark"] {
  /* Surfaces and ink */
  --bs-body-bg: var(--surface-page);
  --bs-body-bg-rgb: var(--surface-page-rgb);
  --bs-body-color: var(--ink);
  --bs-body-color-rgb: var(--ink-rgb);
  --bs-emphasis-color: var(--ink);
  --bs-secondary-color: var(--ink-muted);
  --bs-secondary-bg: var(--surface-sunken);
  --bs-tertiary-color: var(--ink-subtle);
  --bs-tertiary-bg: var(--surface-hover);
  --bs-heading-color: var(--ink);

  /* Type */
  --bs-body-font-family: var(--font-sans);
  --bs-body-font-size: 15px;
  --bs-body-line-height: 1.5333;
  --bs-body-font-weight: 400;

  /* Lines and corners */
  --bs-border-color: var(--line);
  --bs-border-color-translucent: var(--line);
  --bs-border-radius: var(--radius-md);
  --bs-border-radius-sm: var(--radius-sm);
  --bs-border-radius-lg: var(--radius-lg);
  --bs-border-radius-xl: var(--radius-xl);
  --bs-border-radius-pill: var(--radius-pill);

  /* Semantic colours. Only the ones a form uses are mapped; the rest of
     Bootstrap's palette is deliberately left alone — if a screen needs
     .text-info, the screen is using a colour this system has no meaning for. */
  --bs-primary: var(--brand);
  --bs-primary-rgb: var(--brand-rgb);
  --bs-danger: var(--danger);
  --bs-danger-rgb: var(--danger-rgb);
  --bs-success: var(--success-ink);
  --bs-warning: var(--warning-ink);

  --bs-link-color: var(--brand-ink);
  --bs-link-color-rgb: var(--brand-rgb);
  --bs-link-hover-color: var(--brand);
  --bs-link-decoration: underline;

  /* Focus. One ring, everywhere, in both themes. */
  --bs-focus-ring-width: 2px;
  --bs-focus-ring-opacity: 1;
  --bs-focus-ring-color: var(--focus);

  /* Form validation */
  --bs-form-invalid-color: var(--danger-ink);
  --bs-form-invalid-border-color: var(--danger);
  --bs-form-valid-color: var(--success-ink);
  --bs-form-valid-border-color: var(--success-ink);
}

body {
  background: var(--surface-page);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, .h1, .h2, .h3, .h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* One focus treatment for everything Bootstrap or the browser focuses. */
:focus-visible {
  outline: var(--bs-focus-ring-width) solid var(--focus);
  outline-offset: 2px;
  box-shadow: none;
}

/* ---------------------------------------------------------------
   2. Bootstrap components whose defaults are wrong here
   --------------------------------------------------------------- */

/* Inputs, selects, textareas -------------------------------------
   Bootstrap's 38px control is too small for a form filled on a phone.
   Everything a person types into is 44px and sits on surface-card. */
.form-control,
.form-select {
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  font-size: 15px;
  line-height: 20px;
  color: var(--ink);
  background-color: var(--surface-card);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-md);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.form-control::placeholder { color: var(--ink-subtle); opacity: 1; }
.form-control:hover:not(:disabled),
.form-select:hover:not(:disabled) { border-color: var(--ink-muted); }
.form-control:focus,
.form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
  outline: none;
}
.form-control:disabled,
.form-select:disabled {
  background-color: var(--surface-sunken);
  color: var(--ink-subtle);
  cursor: not-allowed;
}
textarea.form-control { min-height: 96px; }

/* An invalid control takes a 2px border AND shows its message. Bootstrap's
   background icon is dropped — it collides with the rupee column and says
   nothing a message does not. */
.form-control.is-invalid,
.form-select.is-invalid,
.was-validated .form-control:invalid {
  border-width: 2px;
  border-color: var(--danger);
  background-image: none;
  padding: calc(var(--space-3) - 1px) calc(var(--space-4) - 1px);
}
.invalid-feedback {
  color: var(--danger-ink);
  font-size: 13px;
  line-height: 19px;
  font-weight: 600;
  margin-top: var(--space-2);
}
.form-text {
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 19px;
  margin-top: var(--space-2);
}
.form-label {
  font-size: 13px;
  line-height: 18px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: var(--space-2);
}

/* Input groups — used for the +91 prefix on a phone field. */
.input-group-text {
  background: var(--surface-sunken);
  border-color: var(--control-border);
  color: var(--ink-muted);
  font-size: 15px;
  padding: 0 var(--space-3);
}

/* Checkboxes -----------------------------------------------------
   20px, brand fill, our tick. Radios keep Bootstrap's dot. */
.form-check-input {
  width: 20px;
  height: 20px;
  margin-top: 0;
  background-color: var(--surface-card);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
}
.form-check-input:checked {
  background-color: var(--brand);
  border-color: var(--brand);
}
/* The tick is drawn in on-brand, not white. In the dark theme brand lightens,
   so a white tick would disappear — this is the pair that has to move together. */
.form-check-input:checked[type="checkbox"] {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fffcf7' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3e%3c/svg%3e");
}
[data-bs-theme="dark"] .form-check-input:checked[type="checkbox"],
[data-theme="dark"] .form-check-input:checked[type="checkbox"] {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%230b2019' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3e%3c/svg%3e");
}
.form-check-input:focus {
  border-color: var(--brand);
  box-shadow: none;
}
.form-check-input:disabled {
  background-color: var(--surface-sunken);
  border-color: var(--line-strong);
  opacity: 1;
}
.form-check-input[type="radio"] { border-radius: var(--radius-pill); }

/* Buttons --------------------------------------------------------
   Three, and only three. .btn-primary is the one action per screen. */
.btn {
  --bs-btn-font-family: var(--font-sans);
  --bs-btn-font-size: 14px;
  --bs-btn-font-weight: 600;
  --bs-btn-line-height: 18px;
  --bs-btn-padding-y: 12px;
  --bs-btn-padding-x: var(--space-6);
  --bs-btn-border-radius: var(--radius-md);
  --bs-btn-focus-box-shadow: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}
.btn-lg { --bs-btn-font-size: 15px; --bs-btn-padding-x: var(--space-8); min-height: 52px; }
.btn-sm { --bs-btn-font-size: 13px; --bs-btn-padding-y: 8px; --bs-btn-padding-x: var(--space-4); min-height: 36px; }

.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-color: var(--on-brand);
  --bs-btn-hover-bg: var(--brand-hover);
  --bs-btn-hover-border-color: var(--brand-hover);
  --bs-btn-hover-color: var(--on-brand);
  --bs-btn-active-bg: var(--brand-hover);
  --bs-btn-active-border-color: var(--brand-hover);
  --bs-btn-active-color: var(--on-brand);
  --bs-btn-disabled-bg: var(--brand);
  --bs-btn-disabled-border-color: var(--brand);
  --bs-btn-disabled-color: var(--on-brand);
  --bs-btn-disabled-opacity: .55;
}

/* Bootstrap's .btn-outline-secondary is the wrong grey here. This is the
   system's secondary button; use it, not an outline variant. */
.btn-secondary {
  --bs-btn-bg: var(--surface-card);
  --bs-btn-border-color: var(--control-border);
  --bs-btn-color: var(--ink);
  --bs-btn-hover-bg: var(--surface-hover);
  --bs-btn-hover-border-color: var(--control-border);
  --bs-btn-hover-color: var(--ink);
  --bs-btn-active-bg: var(--surface-hover);
  --bs-btn-active-border-color: var(--control-border);
  --bs-btn-active-color: var(--ink);
  --bs-btn-disabled-bg: var(--surface-card);
  --bs-btn-disabled-border-color: var(--line-strong);
  --bs-btn-disabled-color: var(--ink-subtle);
}

.btn-ghost {
  --bs-btn-bg: transparent;
  --bs-btn-border-color: transparent;
  --bs-btn-color: var(--brand-ink);
  --bs-btn-hover-bg: var(--surface-hover);
  --bs-btn-hover-border-color: transparent;
  --bs-btn-hover-color: var(--brand-ink);
  --bs-btn-active-bg: var(--surface-hover);
  --bs-btn-active-border-color: transparent;
  --bs-btn-active-color: var(--brand-ink);
  --bs-btn-padding-x: var(--space-3);
}

/* Cards ----------------------------------------------------------
   Bootstrap's card is the right element; its defaults are not. */
.card {
  --bs-card-bg: var(--surface-card);
  --bs-card-border-color: var(--line-strong);
  --bs-card-border-radius: var(--radius-lg);
  --bs-card-inner-border-radius: var(--radius-lg);
  --bs-card-spacer-y: var(--space-8);
  --bs-card-spacer-x: var(--space-8);
  box-shadow: var(--shadow-card);
}
@media (max-width: 767.98px) {
  .card { --bs-card-spacer-y: var(--space-6); --bs-card-spacer-x: var(--space-6); }
}

/* Badges ---------------------------------------------------------
   Bootstrap's .bg-* classes do not carry a readable ink, so the system
   ships its own tones in campus-forms-components.css (.cf-badge).
   These two exist only because .badge is so often reached for. */
.badge {
  --bs-badge-font-size: 12px;
  --bs-badge-font-weight: 600;
  --bs-badge-padding-y: 3px;
  --bs-badge-padding-x: var(--space-3);
  --bs-badge-border-radius: var(--radius-pill);
}

/* Alerts — the Bootstrap element behind a Callout. */
.alert {
  --bs-alert-border-radius: var(--radius-lg);
  --bs-alert-padding-y: var(--space-4);
  --bs-alert-padding-x: var(--space-5);
  --bs-alert-border: 1px solid transparent;
  font-size: 13px;
  line-height: 19px;
}

/* Bootstrap's .table, .modal, .dropdown and the rest are unstyled by this
   system. A public form does not need them. If one turns up, tokenise it here
   in the same shape as the blocks above rather than writing loose CSS. */
