/* ==========================================================================
   DIRECT-SUNLIGHT & WCAG AAA ACCESSIBLE STYLESHEET (7:1+ CONTRAST)
   Fluid Responsive Typography (clamp) + Bottom-Aligned Grid Form Rows
   ========================================================================== */

:root {
  /* High-Contrast Daylight Palette */
  --bg-page: #F1F5F9;
  --bg-surface: #FFFFFF;
  --ink-primary: #090D16;      /* 19.5:1 contrast on white */
  --ink-secondary: #1E293B;    /* 14.6:1 contrast on white */
  --ink-inverse: #FFFFFF;

  /* Thick, Glare-Proof Borders */
  --border-strong: #0F172A;
  --border-subtle: #475569;

  /* Daylight-Safe Action & Status Colors (WCAG AAA Verified) */
  --action-primary: #0039A6;   /* 10.3:1 contrast with white text */
  --action-hover: #002670;
  --focus-ring: #FF9900;

  --status-pass-bg: #E6F4EA;
  --status-pass-ink: #0A361A;
  --status-pass-border: #137333;

  --status-fail-bg: #FCE8E6;
  --status-fail-ink: #7F0000;
  --status-fail-border: #B31412;

  --status-warn-bg: #FEF7E0;
  --status-warn-ink: #5C3C00;
  --status-warn-border: #B06000;

  /* Fluid Responsive Typography Scale (Mobile -> Desktop) */
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.82rem + 0.25vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.3vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1.05rem + 0.4vw, 1.35rem);
  --text-xl: clamp(1.25rem, 1.15rem + 0.6vw, 1.65rem);
  --text-2xl: clamp(1.5rem, 1.3rem + 1vw, 2.25rem);
}

/* 1. Base Reset & Fluid Typography */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--ink-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--text-base);
  line-height: 1.5;
}

h1 {
  font-size: var(--text-2xl);
  line-height: 1.2;
  font-weight: 900;
}

h2 {
  font-size: var(--text-xl);
  line-height: 1.25;
  font-weight: 800;
}

h3 {
  font-size: var(--text-lg);
  line-height: 1.3;
  font-weight: 800;
}

/* 2. High-Visibility Keyboard & Tap Focus Rings */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 4px solid var(--focus-ring);
  outline-offset: 2px;
}

/* 3. Navigation & Sticky Mobile Headers */
nav, header.top-bar {
  background-color: var(--ink-primary);
  color: var(--ink-inverse);
  border-bottom: 4px solid var(--focus-ring);
  padding: clamp(0.75rem, 2vw, 1rem) clamp(0.875rem, 3vw, 1.5rem);
}

nav a:not(.btn), header.top-bar a:not(.btn) {
  color: var(--ink-inverse);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* 4. Containers & Cards */
.container-mobile {
  width: 100%;
  max-width: 36rem;
  margin: 0 auto;
  padding: clamp(0.75rem, 2.5vw, 1.25rem);
}

.container-desktop {
  width: 100%;
  max-width: 78rem;
  margin: 0 auto;
  padding: clamp(0.75rem, 2.5vw, 1.5rem);
}

.card, form > p {
  background-color: var(--bg-surface);
  border: 2px solid var(--border-strong);
  border-radius: 0.625rem;
  padding: clamp(0.875rem, 2.5vw, 1.25rem);
  margin-bottom: 1rem;
}

/* 5. Aligned Multi-Column Form Rows (Fixes Uneven Label Wrapping) */
.form-row,
div[style*="grid-template-columns"] {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  align-items: end; /* Locks input boxes flush along the bottom edge even if one label wraps to 2 lines */
}

.form-row > div,
div[style*="grid-template-columns"] > div {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
  min-width: 0; /* Prevents long inputs/selects from overflowing on narrow screens */
}

/* Stack 2-column inputs cleanly on very narrow phones (< 380px) */
@media (max-width: 380px) {
  .form-row,
  div[style*="grid-template-columns"] {
    grid-template-columns: 1fr;
  }
}

/* 6. Mobile-First Form Inputs (52px+ Touch Targets for Gloved Hands) */
label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 800;
  color: var(--ink-primary);
  margin-bottom: 0.375rem;
  line-height: 1.25;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-width: 0;
  height: 3.25rem;       /* Exact uniform height so adjacent inputs & selects align pixel-for-pixel */
  min-height: 3.25rem;
  padding: 0.625rem 0.875rem;
  font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem); /* >= 16px prevents iOS Safari auto-zoom */
  font-weight: 600;
  color: var(--ink-primary);
  background-color: var(--bg-surface);
  border: 2px solid var(--border-strong);
  border-radius: 0.5rem;
  appearance: none;
  -webkit-appearance: none;
}

textarea {
  height: auto;
  min-height: 5.5rem;
}

input::placeholder,
textarea::placeholder {
  color: #475569;
  font-weight: 500;
}

/* Custom High-Contrast Pull-Down Menu Symbol (Pure CSS - Firefox Safe) */
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  cursor: pointer;
  padding-right: 3.5rem;
  text-overflow: ellipsis;
  background-color: var(--bg-surface);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-inverse) 50%),
    linear-gradient(135deg, var(--ink-inverse) 50%, transparent 50%),
    linear-gradient(to right, var(--ink-primary), var(--ink-primary)) !important;
  background-position:
    calc(100% - 1.35rem) center,
    calc(100% - 0.85rem) center,
    right 0 top 0 !important;
  background-size:
    0.5rem 0.5rem,
    0.5rem 0.5rem,
    2.65rem 100% !important;
  background-repeat: no-repeat !important;
}

select:hover {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-inverse) 50%),
    linear-gradient(135deg, var(--ink-inverse) 50%, transparent 50%),
    linear-gradient(to right, var(--action-primary), var(--action-primary)) !important;
}

@media (forced-colors: active) {
  select {
    -webkit-appearance: auto;
    -moz-appearance: auto;
    appearance: auto;
    background-image: none !important;
    padding-right: 0.875rem;
  }
}


/* 7. Oversized Radio & Checkbox Cards */
.radio-card {
  display: flex;
  align-items: center;
  min-height: 3.5rem;
  padding: 0.875rem 1rem;
  margin-bottom: 0.5rem;
  background-color: var(--bg-surface);
  border: 2px solid var(--border-strong);
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: var(--text-base);
  font-weight: 700;
}

.radio-card input[type="radio"],
.radio-card input[type="checkbox"] {
  width: 1.5rem;
  height: 1.5rem;
  min-height: 1.5rem;
  margin-right: 0.875rem;
  accent-color: var(--action-primary);
  flex-shrink: 0;
}

.radio-card:has(input:checked) {
  background-color: #E8F0FE;
  border-width: 3px;
  border-color: var(--action-primary);
}

.radio-card.pass-option:has(input:checked) {
  background-color: var(--status-pass-bg);
  border-color: var(--status-pass-border);
  color: var(--status-pass-ink);
}

.radio-card.fail-option:has(input:checked) {
  background-color: var(--status-fail-bg);
  border-color: var(--status-fail-border);
  color: var(--status-fail-ink);
}

/* 8. Primary & Secondary Buttons */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3.25rem;
  padding: 0.75rem 1.25rem;
  font-size: var(--text-base);
  font-weight: 800;
  text-decoration: none;
  border-radius: 0.5rem;
  border: 2px solid var(--border-strong);
  cursor: pointer;
  transition: background-color 0.12s ease;
}

button[type="submit"],
.btn-primary {
  width: 100%;
  background-color: var(--action-primary);
  color: var(--ink-inverse);
  border-color: var(--ink-primary);
}

button[type="submit"]:hover,
.btn-primary:hover {
  background-color: var(--action-hover);
}

.btn-secondary {
  background-color: var(--bg-surface);
  color: var(--ink-primary);
  border: 2px solid var(--border-strong);
}

.btn-secondary:hover {
  background-color: #E2E8F0;
  color: var(--ink-primary);
}

.btn-danger {
  background-color: var(--status-fail-border);
  color: var(--ink-inverse);
  border-color: var(--ink-primary);
}

/* Sticky Mobile Action Bar */
.sticky-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: var(--bg-surface);
  border-top: 3px solid var(--border-strong);
  padding: 0.75rem 1rem;
  z-index: 50;
}

/* 9. Daylight-Safe Status Badges & Legal Alerts */
.badge-pass {
  display: inline-block;
  background-color: var(--status-pass-bg);
  color: var(--status-pass-ink);
  border: 2px solid var(--status-pass-border);
  font-weight: 800;
  font-size: var(--text-xs);
  padding: 0.25rem 0.625rem;
  border-radius: 0.375rem;
}

.badge-fail {
  display: inline-block;
  background-color: var(--status-fail-bg);
  color: var(--status-fail-ink);
  border: 2px solid var(--status-fail-border);
  font-weight: 800;
  font-size: var(--text-xs);
  padding: 0.25rem 0.625rem;
  border-radius: 0.375rem;
}

.alert-legal-fail {
  background-color: var(--status-fail-bg);
  color: var(--status-fail-ink);
  border: 3px solid var(--status-fail-border);
  padding: 1rem;
  border-radius: 0.5rem;
  font-weight: 700;
  font-size: var(--text-sm);
}

.alert-expiry-warn {
  background-color: var(--status-warn-bg);
  color: var(--status-warn-ink);
  border: 3px solid var(--status-warn-border);
  padding: 1rem;
  border-radius: 0.5rem;
  font-weight: 700;
  font-size: var(--text-sm);
}

ul.errorlist {
  list-style: none;
  margin: 0 0 0.5rem 0;
  padding: 0.625rem 0.75rem;
  background-color: var(--status-fail-bg);
  color: var(--status-fail-ink);
  border: 2px solid var(--status-fail-border);
  border-radius: 0.375rem;
  font-weight: 700;
  font-size: var(--text-sm);
}

/* 10. High-Contrast Responsive Tables */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  border: 2px solid var(--border-strong);
  border-radius: 0.5rem;
  background-color: var(--bg-surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: var(--text-sm);
}

thead th {
  background-color: var(--ink-primary);
  color: var(--ink-inverse);
  font-weight: 800;
  padding: 0.875rem 0.75rem;
  border-bottom: 2px solid var(--border-strong);
}

tbody td {
  padding: 0.875rem 0.75rem;
  border-bottom: 1.5px solid var(--border-subtle);
  color: var(--ink-primary);
  font-weight: 500;
}

tbody tr:nth-child(even) {
  background-color: #F8FAFC;
}

/* Accessible FAQ Accordion (<details> / <summary>) */
.faq-item {
  border: 2px solid var(--border-strong);
  border-radius: 0.5rem;
  margin-bottom: 0.75rem;
  background-color: var(--bg-surface);
  overflow: hidden;
}

.faq-item summary {
  list-style: none;
  cursor: pointer;
  min-height: 3.25rem;
  padding: 0.875rem 1rem;
  font-size: var(--text-base);
  font-weight: 800;
  color: var(--ink-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.faq-item summary::-webkit-details-marker {
  display: none;
}

.faq-item summary::after {
  content: "+";
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--action-primary);
  flex-shrink: 0;
}

.faq-item[open] summary {
  background-color: #F8FAFC;
  border-bottom: 2px solid #CBD5E1;
}

.faq-item[open] summary::after {
  content: "−";
}

.faq-item summary:focus-visible {
  outline: 4px solid var(--focus-ring);
  outline-offset: -4px;
}

.faq-item p {
  margin: 0;
  padding: 1rem;
  color: var(--ink-secondary);
}
