/* ===============================================
   QUESTIONNAIRE STYLES (css/questionnaire.css)
   =============================================== */

:root {
  --blue: #0d1c61;
  --white: #fff;
  --ink: #0b1025;
  --accent: #8ac0dc;
  --error-color: #ffb3b3;
  --error-outline: #ff6b6b;
  --success-color: #a7ffb4; /* Light green for ticks */
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  color: var(--white);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: #0d1c61;
  background-image: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.08),
    rgba(13, 28, 97, 0) 30%
  );
  background-repeat: repeat-x;
  background-position: left top;
  background-size: 100% auto;
  line-height: 1.5;
}

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 16px 2vw; backdrop-filter: blur(4px);
}

.title {
  margin: 0; 
  grid-column: 2;
  text-align: center;
  font-weight: 900; 
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  line-height: 1.1;
  letter-spacing: -0.5px;
  text-transform: uppercase;
}

.title .subtitle {
  display: block;
  font-size: clamp(0.75rem, 2vw, 0.9rem);
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 4px;
  opacity: 0.9;
}

.logo-img {
  height: 68px; width: auto;
  grid-column: 3;
  justify-self: end;
}

/* Page layout */
.wrap { width: min(1100px, 92vw); margin: 24px auto 80px; }

.intro {
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 14px; padding: 16px 18px; margin-bottom: 18px;
  font-size: 15px;
  line-height: 1.6;
}

/* --- Input Wrap Styles --- */
.input-wrap { margin-bottom: 16px; }
.input-wrap label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 14px;
}

.input-wrap input[type="text"],
.input-wrap input[type="email"],
.input-wrap select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, .28);
  background: rgba(255, 255, 255, .08);
  color: var(--white);
  font-size: 14px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  font-family: inherit;
}

.input-wrap input::placeholder { color: rgba(255, 255, 255, 0.6); opacity: 1; }

.input-wrap select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23ffffff'%3E%3Cpath fill-rule='evenodd' d='M4.22 6.22a.75.75 0 0 1 1.06 0L8 8.94l2.72-2.72a.75.75 0 1 1 1.06 1.06l-3.25 3.25a.75.75 0 0 1-1.06 0L4.22 7.28a.75.75 0 0 1 0-1.06Z' clip-rule='evenodd' /%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 36px;
  cursor: pointer;
}

.input-wrap select option { background: var(--white); color: var(--blue); }

.input-error {
  display: none;
  color: var(--error-color);
  font-size: .9rem;
  margin-top: 6px;
}

.input-wrap.invalid input,
.input-wrap.invalid select {
  outline: 2px solid var(--error-outline);
  border-color: transparent;
}

.input-wrap.invalid .input-error { display: block; }

/* --- Grid layout for details section --- */
.details-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; }
.details-grid .span-two { grid-column: span 2; }

@media (max-width: 640px) {
  .details-grid { grid-template-columns: 1fr; }
  .details-grid .span-two { grid-column: span 1; }
}

/* --- Tabs Styles --- */
.tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  padding-bottom: 12px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.5);
  font-weight: 700;
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  transition: all 0.2s ease;
}

.tab-btn:hover { color: rgba(255,255,255,0.8); background: rgba(255,255,255,0.05); }
.tab-btn.active { background: rgba(255,255,255,0.15); color: var(--white); box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Sections / cards --- */
details.section {
  scroll-margin-top: 140px; 
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  margin: 14px 0;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

details.section[open] {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.25);
}

/* --- Summary style with arrow (FIXED ALIGNMENT) --- */
summary {
  cursor: pointer;
  padding: 16px 18px 16px 44px; /* Left padding makes room for the arrow */
  list-style: none;
  outline: none;
  position: relative;
  
  /* Forces the header to act as a row with space between items */
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: space-between !important;
  width: 100% !important;
}

/* Hide the default browser arrow/bullet */
summary::-webkit-details-marker { display: none; }

/* The Section Title (Left-aligned) */
summary span:first-of-type {
  text-align: left;
  display: inline-block;
}

/* The Instructional Text (Pushed far right) */
summary span:last-of-type {
  margin-left: auto;   /* Force pushes it to the right boundary */
  text-align: right;
  opacity: 0.6;
  font-size: 12px;     /* Matches your 'retrieve' text size */
  font-weight: 500;
  white-space: nowrap; /* Prevent wrapping */
  flex-shrink: 0;      /* Don't let title squash me */
  color: var(--white);
}

/* Arrow for summary */
summary::before {
  content: '►';
  font-size: 0.8em;
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  transition: transform 0.2s ease-in-out;
  color: var(--accent);
}

details[open] > summary::before { transform: translateY(-50%) rotate(90deg); }

/* --- Checkmark for completed sections --- */
details.section-complete > summary span:first-child::after {
  content: '✓';
  color: var(--success-color);
  font-size: 1em;
  margin-left: 10px;
  font-weight: bold;
}

.sec-body { padding: 8px 18px 16px 18px; }

/* --- Questions --- */
fieldset.q {
  border: 0;
  margin: 20px 0;
  padding: 16px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: all 0.3s ease;
}

fieldset.q:hover { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 255, 255, 0.1); }
.q legend { 
   color: rgba(255,255,255,0.9);
   padding-top: 60px;
   font-weight: 800; 
   font-size: 15px; 
   margin-bottom: 8px; }

.opts { display: grid; gap: 10px; }

.opt { 
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.9); 
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px; 
  padding: 12px 14px; 
  display: flex; 
  gap: 12px; 
  align-items: flex-start; 
  cursor: pointer;
  transition: all 0.2s ease;
}

.opt:hover { background: rgba(255, 255, 255, 0.1); border-color: var(--accent); }

.opt:has(input:checked) {
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid #ffffff;
  color: #ffffff;
}

.opt input { accent-color: var(--accent); transform: translateY(2px); cursor: pointer; }
.opt .lbl { line-height: 1.4; font-size: 14px; font-weight: 500; }
.help { font-size: 12px; opacity: .85; margin: 6px 0 2px 2px; }

/* --- Invalid state highlighting --- */
details.section.invalid-section > summary { color: var(--error-color); }
details.section.invalid { box-shadow: 0 0 0 2px rgba(231,76,60,.35) inset; border-color: rgba(231,76,60,.55); }
.q.invalid { outline: 2px solid var(--error-outline); background: rgba(231, 76, 60, 0.05); border-radius: 14px; padding: 12px; }
.q.invalid legend { color: var(--error-color); }

/* --- Submit Button Style --- */
.btn { cursor: pointer; border: 0; background: var(--accent); color: #0e1740; font-weight: 800; padding: 12px 24px; border-radius: 12px; box-shadow: 0 10px 20px rgba(0,0,0,.22); transition: opacity .15s, filter .15s; font-family: inherit; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: grayscale(.2); }

/* Progress counter */
.progress {
  position: sticky; top: 86px; z-index: 5; margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px; padding: 6px 12px;
  width: max-content; font-size: 13px; font-weight: 600;
  backdrop-filter: blur(4px);
}

.hidden { display: none !important; }

/* --- Styles for New Consent Box --- */
.consent-box { background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .18); border-radius: 14px; padding: 16px 18px; margin-top: 24px; margin-bottom: 18px; font-size: 14px; line-height: 1.5; }
.consent-box h4 { margin-top: 0; margin-bottom: 12px; font-weight: 700; font-size: 16px; }
.consent-box .consent-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.consent-check { display: flex; align-items: flex-start; gap: 8px; font-weight: bold; font-size: 14px; cursor: pointer; padding: 4px; }
.consent-check input[type="checkbox"] { margin-top: 3px; flex-shrink: 0; accent-color: var(--accent); }

/* --- Validation List Styles --- */
.submit-action { display: flex; justify-content: flex-end; align-items: center; gap: 20px; margin-top: 18px; }
.validation-list { display: none; font-size: 12px; opacity: 0.9; padding: 8px 12px; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.1); border-radius: 8px; align-self: stretch; align-items: center; }
.validation-list.show { display: flex; }
.validation-list ul { margin: 0; padding: 0; list-style: none; }
.validation-list li { padding-left: 20px; position: relative; line-height: 1.6; }
.validation-list li.valid-item { color: var(--success-color); }
.validation-list li.valid-item::before { content: '✓'; position: absolute; left: 0; color: var(--success-color); font-weight: bold; }
.validation-list li.invalid-item { color: var(--error-color); }
.validation-list li.invalid-item::before { content: '✗'; position: absolute; left: 0; color: var(--error-color); font-weight: bold; }

/* Mobile Hiding of Subtitles to save space */
@media (max-width: 480px) {
  summary span:last-child { display: none; }
}

/* The Section Title (Left) */
.tab-title {
  text-align: left;
  display: inline-block;
  font-weight: 800;
  font-size: 18px;
}

/* The Instructional Text (Far Right) */
.tab-instruction {
  margin-left: auto;   /* This is the magic "push" to the right */
  text-align: right;
  opacity: 0.6;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap; /* Prevents text from breaking into two lines */
  flex-shrink: 0;      /* Ensures the text doesn't get squashed */
}

/* ===============================================
   LOADING SCREEN VISIBILITY FIX
   Ensures the loader is physically removed from 
   view until the '.show' class is applied.
   =============================================== */

.loading {
  position: fixed;
  inset: 0;
  z-index: 9999; /* Higher than topbar and progress bar */
  background: rgba(11, 16, 37, 0.98);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  
  /* 1. PHYSICALLY HIDDEN BY DEFAULT */
  visibility: hidden;
  opacity: 0;
  
  /* 2. PREVENT MOUSE INTERACTION */
  pointer-events: none;
  
  /* 3. SMOOTH TRANSITION (Optional) */
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* THE TRIGGER CLASS */
.loading.show {
  visibility: visible;
  opacity: 1;
  pointer-events: auto; /* Re-enable interaction when visible */
}

/* Ensure spinner is centered and sized correctly */
.spinner {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 6px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- LOGOUT BUTTON STYLING --- */
.logout-btn {
  grid-column: 1; /* Places it in the left column of your topbar grid */
  justify-self: start;
  background: transparent;
  border: 1px solid var(--accent); /* Matches the 'Diagnostic Portal' text color */
  color: var(--accent);            /* Matches the 'Diagnostic Portal' text color */
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: all 0.2s ease;
}

.logout-btn:hover {
  background: var(--accent);
  color: var(--blue);
  box-shadow: 0 0 15px rgba(138, 192, 220, 0.4);
}

/* Adjust button size for small mobile screens */
@media (max-width: 600px) {
    .logout-btn {
        padding: 6px 10px;
        font-size: 10px;
    }
}

.logo-img { 
  grid-column: 1; 
  justify-self: start; 
}

/* Logout on far right */
.logout-btn {
  grid-column: 3;
  justify-self: end;
  border: 1px solid var(--accent); /* Light blue (#8ac0dc) */
  color: var(--accent);
}


