/*
 * Precheck UI layer.
 *
 * Loaded last on every page, after Bootstrap and the ported PHP stylesheets, so the shared
 * components look the same everywhere: inputs, radios and checkboxes, switches, modals, alerts,
 * tables, badges and menus. Buttons and tabs are deliberately left as they were. It changes how
 * components look, never page layout.
 *
 * Bootstrap 5.3 components read CSS variables, so most of this sets those variables instead of
 * fighting specificity. Brand colour and font are unchanged (#1E7EF2, Gilroy).
 */

:root {
  --pc-brand: #1e7ef2;
  --pc-brand-hover: #1669d8;
  --pc-brand-active: #1259bb;
  --pc-brand-soft: #eaf3fe;
  --pc-brand-border: #bcd7fb;
  --pc-ring: 0 0 0 4px rgba(30, 126, 242, 0.2);

  --pc-ink: #16181d;
  --pc-muted: #5b6472;
  --pc-subtle: #8a93a3;
  --pc-border: #e3e7ee;
  --pc-border-strong: #cbd2dc;
  --pc-surface: #ffffff;
  --pc-surface-2: #f6f8fb;
  --pc-surface-3: #eef1f6;

  --pc-danger: #e5484d;
  --pc-danger-hover: #d13a3f;

  --pc-radius-sm: 8px;
  --pc-radius: 12px;
  --pc-radius-lg: 16px;
  --pc-radius-xl: 20px;
  --pc-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --pc-shadow: 0 10px 30px -12px rgba(16, 24, 40, 0.22);
  --pc-shadow-lg: 0 24px 60px -20px rgba(16, 24, 40, 0.35);
  --pc-control-h: 44px;
  --pc-ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  /* Bootstrap reads these. */
  --bs-primary: #1e7ef2;
  --bs-primary-rgb: 30, 126, 242;
  --bs-link-color: #1e7ef2;
  --bs-link-color-rgb: 30, 126, 242;
  --bs-link-hover-color: #1259bb;
  --bs-link-hover-color-rgb: 18, 89, 187;
  --bs-border-color: #e3e7ee;
  --bs-focus-ring-color: rgba(30, 126, 242, 0.2);
}

::selection {
  background: rgba(30, 126, 242, 0.18);
}

/* Keyboard focus is always visible; mouse clicks do not leave rings behind. */
a:focus-visible,
button:focus-visible,
summary:focus-visible,
[role='button']:focus-visible,
[tabindex]:not([tabindex='-1']):focus-visible {
  outline: 2px solid var(--pc-brand);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ */
/* Text inputs, selects, textareas                                    */
/* ------------------------------------------------------------------ */

.form-control,
.form-select,
.form-input input {
  min-height: var(--pc-control-h);
  padding: 0.6rem 0.9rem;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--pc-ink);
  background-color: #fff;
  border: 1.5px solid var(--pc-border);
  border-radius: var(--pc-radius);
  transition:
    border-color 0.15s var(--pc-ease),
    box-shadow 0.15s var(--pc-ease),
    background-color 0.15s var(--pc-ease);
}
.form-control:hover,
.form-select:hover,
.form-input input:hover {
  border-color: var(--pc-border-strong);
}
.form-control:focus,
.form-select:focus,
.form-input input:focus {
  border-color: var(--pc-brand);
  box-shadow: var(--pc-ring);
  outline: 0;
}
.form-control::placeholder,
.form-input input::placeholder {
  color: var(--pc-subtle);
  opacity: 1;
}
.form-control:disabled,
.form-control[readonly],
.form-select:disabled,
.form-input input:disabled {
  background-color: var(--pc-surface-2);
  color: var(--pc-muted);
  border-color: var(--pc-border);
}
textarea.form-control {
  min-height: 110px;
  resize: vertical;
}
.form-control-sm,
.form-select-sm {
  min-height: 36px;
  padding: 0.35rem 0.7rem;
  font-size: 0.875rem;
  border-radius: 10px;
}
.form-control[type='number'] {
  font-variant-numeric: tabular-nums;
}

.form-label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--pc-ink);
  margin-bottom: 0.4rem;
}
.form-label.form-text {
  color: var(--pc-muted);
}
.form-text {
  color: var(--pc-muted);
}

/* Input groups: one continuous control, with the add-on in a quieter tone. */
.input-group-text {
  min-height: var(--pc-control-h);
  padding: 0.6rem 0.85rem;
  font-weight: 600;
  color: var(--pc-muted);
  background-color: var(--pc-surface-2);
  border: 1.5px solid var(--pc-border);
  border-radius: var(--pc-radius);
}
.input-group:focus-within .input-group-text {
  border-color: var(--pc-brand);
  color: var(--pc-brand);
}
.input-group > .form-control:focus {
  z-index: 3;
}

/* ------------------------------------------------------------------ */
/* Radios, checkboxes, switches                                       */
/* ------------------------------------------------------------------ */

.form-check-input {
  width: 1.2em;
  height: 1.2em;
  margin-top: 0.15em;
  border: 1.5px solid var(--pc-border-strong);
  background-color: #fff;
  cursor: pointer;
  transition:
    background-color 0.15s var(--pc-ease),
    border-color 0.15s var(--pc-ease),
    box-shadow 0.15s var(--pc-ease);
}
.form-check-input[type='checkbox'] {
  border-radius: 6px;
}
.form-check-input:hover {
  border-color: var(--pc-brand);
}
.form-check-input:focus {
  border-color: var(--pc-brand);
  box-shadow: var(--pc-ring);
}
.form-check-input:checked {
  background-color: var(--pc-brand);
  border-color: var(--pc-brand);
}
.form-check-input:disabled {
  opacity: 0.5;
}
.form-check-label {
  cursor: pointer;
  color: var(--pc-ink);
}
.form-check {
  min-height: 1.6rem;
}

/* Switches: a grey track with a white knob that turns blue when on. */
.form-switch .form-check-input,
.form-switch .form-check-input:focus {
  width: 2.5em;
  height: 1.4em;
  margin-top: 0.05em;
  border-radius: 2em;
  border-color: var(--pc-border-strong);
  background-color: var(--pc-border-strong);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3.2' fill='%23fff'/%3e%3c/svg%3e");
}
.form-switch .form-check-input:checked {
  background-color: var(--pc-brand);
  border-color: var(--pc-brand);
}
.form-switch .form-check-input:hover {
  border-color: var(--pc-brand);
}

/* Plain radios and checkboxes that are not Bootstrap-styled still use the brand colour. */
input[type='radio']:not(.form-check-input),
input[type='checkbox']:not(.form-check-input) {
  accent-color: var(--pc-brand);
  width: 1.1em;
  height: 1.1em;
  cursor: pointer;
}


/* ------------------------------------------------------------------ */
/* Modals, cards, menus                                               */
/* ------------------------------------------------------------------ */

.modal-content {
  border: 0;
  border-radius: var(--pc-radius-xl);
  box-shadow: var(--pc-shadow-lg);
}
.modal-header {
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--pc-border);
}
.modal-header .modal-title {
  margin-bottom: 0;
  font-weight: 700;
}
.modal-body {
  padding: 1.4rem;
}
.modal-footer {
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--pc-border);
}
.modal-backdrop.show {
  opacity: 0.45;
}

.card {
  border: 1px solid var(--pc-border);
  border-radius: var(--pc-radius-lg);
  box-shadow: var(--pc-shadow-sm);
}

.dropdown-menu {
  padding: 0.4rem;
  border: 1px solid var(--pc-border);
  border-radius: var(--pc-radius);
  box-shadow: var(--pc-shadow);
}
.dropdown-item {
  border-radius: var(--pc-radius-sm);
  padding: 0.5rem 0.75rem;
  font-weight: 500;
}
.dropdown-item:active {
  background-color: var(--pc-brand);
}

/* ------------------------------------------------------------------ */
/* Alerts, badges, tables                                             */
/* ------------------------------------------------------------------ */

.alert {
  border: 1px solid transparent;
  border-radius: var(--pc-radius);
  padding: 0.85rem 1.1rem;
  font-weight: 500;
}
.alert-warning {
  color: #7a4d00;
  background-color: #fff8e6;
  border-color: #fde7b0;
}
.alert-danger {
  color: #9f1c22;
  background-color: #fdecec;
  border-color: #f7c9cb;
}
.alert-success {
  color: #146c3c;
  background-color: #e9f8ef;
  border-color: #bfe8cf;
}
.alert-info,
.alert-primary {
  color: #0f4c9a;
  background-color: var(--pc-brand-soft);
  border-color: #cfe2fd;
}
.alert-secondary,
.alert-light {
  color: var(--pc-muted);
  background-color: var(--pc-surface-2);
  border-color: var(--pc-border);
}

.badge {
  padding: 0.38em 0.72em;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.table {
  --bs-table-color: var(--pc-ink);
  --bs-table-border-color: var(--pc-border);
  margin-bottom: 0;
}
.table > :not(caption) > * > * {
  padding: 0.75rem 0.9rem;
}
.table > thead th {
  --bs-table-bg: var(--pc-surface-2);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--pc-muted);
  border-bottom-width: 1px;
  white-space: nowrap;
}
.table > tbody > tr {
  transition: background-color 0.12s;
}
.table > tbody > tr:hover > * {
  --bs-table-bg-state: var(--pc-surface-2);
}
.table-responsive {
  border-radius: var(--pc-radius);
}

/* ------------------------------------------------------------------ */
/* Sign-in and sign-up forms (their own markup, already rounded)      */
/* ------------------------------------------------------------------ */

.p-form .input-wrap input {
  border-width: 1.5px;
  transition:
    border-color 0.15s var(--pc-ease),
    box-shadow 0.15s var(--pc-ease);
}
.p-form .input-wrap input:hover {
  border-color: var(--pc-border-strong);
}
.p-form .input-wrap input:focus {
  border-color: var(--pc-brand);
  box-shadow: var(--pc-ring);
  outline: 0;
}
/* A thumbnail that could not load shows the neutral placeholder, filling its frame. */
img.img-fallback {
  object-fit: cover;
  background-color: #eef1f5;
}

/* Links in body copy get a proper underline on hover. */
.form-text a,
.small a,
p a {
  text-underline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {

  .form-select,
  .form-check-input {
    transition: none;
  }
}
