/* ============================================================
   Charter Meridian Portal — Main Stylesheet
   ============================================================ */

/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:        #0f172a;
  --navy-light:  #1e293b;
  --navy-mid:    #334155;
  --gold:        #d97706;
  --gold-light:  #fbbf24;
  --gold-pale:   #fef3c7;
  --white:       #ffffff;
  --grey-50:     #f8fafc;
  --grey-100:    #f1f5f9;
  --grey-200:    #e2e8f0;
  --grey-400:    #94a3b8;
  --grey-600:    #475569;
  --grey-800:    #1e293b;
  --green:       #16a34a;
  --green-pale:  #dcfce7;
  --red:         #dc2626;
  --red-pale:    #fee2e2;
  --amber:       #d97706;
  --amber-pale:  #fef3c7;
  --blue-pale:   #eff6ff;
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:   'Courier New', Courier, monospace;
  --radius:      8px;
  --radius-sm:   4px;
  --shadow:      0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md:   0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  color: var(--navy);
  background: var(--grey-50);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Utilities ────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.text-muted  { color: var(--grey-400); }
.text-sm     { font-size: .875rem; }
.text-center { text-align: center; }
.text-warning { color: var(--amber); }
.required    { color: var(--red); }
code { font-family: var(--font-mono); font-size: .9em; background: var(--grey-100); padding: 1px 5px; border-radius: 3px; }

/* ── Layout ───────────────────────────────────────────────── */
.container { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; }
.main-content { flex: 1; }

/* ── Site header ──────────────────────────────────────────── */
.site-header {
  background: var(--navy);
  padding: .875rem 0;
  border-bottom: 2px solid var(--gold);
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; }

.logo { display: flex; align-items: center; gap: .6rem; text-decoration: none; }
.logo-mark {
  background: var(--gold);
  color: var(--navy);
  font-weight: 900;
  font-size: .85rem;
  letter-spacing: .05em;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}
.logo-text { color: var(--white); font-weight: 600; font-size: 1rem; }

/* ── Flash messages ───────────────────────────────────────── */
.flash {
  padding: .75rem 1rem;
  font-size: .9rem;
  border-left: 4px solid;
}
.flash--success { background: var(--green-pale); border-color: var(--green); color: #14532d; }
.flash--error   { background: var(--red-pale);   border-color: var(--red);   color: #7f1d1d; }
.flash--warning { background: var(--amber-pale);  border-color: var(--amber); color: #78350f; }
.flash--info    { background: var(--blue-pale);   border-color: #3b82f6;     color: #1e3a5f; }

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
  padding: .875rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .9rem;
}
.alert ul { margin: 0; padding-left: 1.25rem; }
.alert--error   { background: var(--red-pale);   color: #7f1d1d; }
.alert--success { background: var(--green-pale);  color: #14532d; }
.alert--warning { background: var(--amber-pale);  color: #78350f; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: .625rem 1.25rem;
  font-size: .9rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
  transition: filter .15s, box-shadow .15s;
  text-align: center;
}
.btn:hover  { filter: brightness(1.1); }
.btn:active { filter: brightness(.95); }

.btn--primary  { background: var(--gold); color: var(--navy); }
.btn--secondary{ background: var(--navy-light); color: var(--white); }
.btn--ghost    { background: transparent; color: var(--navy-mid); border: 1.5px solid var(--grey-200); }
.btn--ghost:hover { background: var(--grey-100); }
.btn--danger   { background: var(--red); color: var(--white); }
.btn--text     { background: none; border: none; color: var(--gold); padding: 0; font-weight: 500; }
.btn--full     { display: block; width: 100%; }
.btn--sm       { padding: .375rem .875rem; font-size: .8rem; }
.btn--lg       { padding: .875rem 1.75rem; font-size: 1rem; }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-group--checkbox { display: flex; align-items: flex-start; }
.form-label { display: block; font-size: .875rem; font-weight: 600; color: var(--navy-mid); margin-bottom: .375rem; }
.form-hint  { font-size: .8rem; color: var(--grey-400); margin-top: .3rem; }

.form-input {
  display: block;
  width: 100%;
  padding: .625rem .875rem;
  font-size: .95rem;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--navy);
  transition: border-color .15s;
  font-family: var(--font);
}
.form-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(217,119,6,.15);
}
.form-input--textarea { resize: vertical; min-height: 80px; }

/* ── Phone number input group ──────────────────────────────── */
.phone-input-group {
  display: flex;
  gap: 0;
  align-items: stretch;
}
.phone-dial-code {
  flex: 0 0 auto;
  padding: .625rem .5rem;
  font-size: .875rem;
  border: 1.5px solid var(--grey-200);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  background: var(--grey-100);
  color: var(--navy);
  font-family: var(--font);
  cursor: pointer;
  min-width: 100px;
  appearance: auto;
}
.phone-dial-code:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(217,119,6,.15);
  z-index: 1;
  position: relative;
}
.phone-number-input {
  flex: 1 1 auto;
  border-radius: 0 var(--radius) var(--radius) 0 !important;
}
.form-input--otp {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  letter-spacing: .5em;
  text-align: center;
  max-width: 200px;
}
.form-input--sm { padding: .375rem .625rem; font-size: .85rem; }

.checkbox-label { display: flex; align-items: flex-start; gap: .6rem; cursor: pointer; font-size: .9rem; }
.checkbox-label input[type="checkbox"] { margin-top: .15rem; flex-shrink: 0; }

/* ── Auth pages ───────────────────────────────────────────── */
.auth-container { display: flex; justify-content: center; align-items: flex-start; padding: 3rem 1rem 4rem; }
.auth-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem;
  width: 100%;
  max-width: 480px;
  border-top: 3px solid var(--gold);
}
.auth-card--success .auth-card__header { text-align: center; }
.auth-card__header { margin-bottom: 1.75rem; }
.auth-card__header h1 { font-size: 1.5rem; color: var(--navy); margin-bottom: .5rem; }
.auth-card__header p  { color: var(--grey-600); font-size: .95rem; }
.auth-card__footer { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--grey-200); font-size: .85rem; color: var(--grey-400); text-align: center; }
.auth-card__footer a { color: var(--gold); text-decoration: none; }
.auth-card__footer a:hover { text-decoration: underline; }

.success-icon { font-size: 3rem; color: var(--green); margin-bottom: .5rem; }

/* ── Credential summary (signup success) ──────────────────── */
.credential-summary { margin: 1.5rem 0; }
.credential-item {
  display: flex; flex-direction: column; gap: .25rem;
  padding: 1rem;
  background: var(--grey-50);
  border-radius: var(--radius);
  border-left: 3px solid var(--gold);
  margin-bottom: .75rem;
}
.credential-label { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--grey-400); }
.credential-value { font-family: var(--font-mono); font-size: 1.2rem; font-weight: 700; letter-spacing: 2px; color: var(--navy); }
.credential-note  { font-size: .8rem; color: var(--grey-400); }

/* ── Info boxes ───────────────────────────────────────────── */
.info-box { background: var(--blue-pale); border-radius: var(--radius); padding: 1rem 1.25rem; margin: 1rem 0; font-size: .9rem; }
.info-box h3 { font-size: .9rem; margin-bottom: .5rem; }
.info-box ol, .info-box ul { margin: 0; padding-left: 1.25rem; }
.info-box li { margin-bottom: .25rem; }
.info-box--neutral { background: var(--grey-100); color: var(--grey-600); }

/* ── Option cards (signup-existing) ──────────────────────── */
.option-group { display: flex; flex-direction: column; gap: 1rem; margin: 1.5rem 0; }
.option-card { padding: 1.25rem; border: 1.5px solid var(--grey-200); border-radius: var(--radius); }
.option-card h2 { font-size: 1rem; margin-bottom: .5rem; }
.option-card p  { font-size: .9rem; color: var(--grey-600); margin-bottom: 1rem; }

/* ── Site footer ──────────────────────────────────────────── */
.site-footer {
  background: var(--navy);
  color: var(--grey-400);
  padding: 1.25rem 0;
  font-size: .8rem;
  margin-top: auto;
}

/* ── Questionnaire ────────────────────────────────────────── */
.questionnaire-body .site-header { position: sticky; top: 0; z-index: 100; }
.questionnaire-header-actions { display: flex; gap: .5rem; }

.questionnaire-container { max-width: 720px; margin: 0 auto; padding: 2rem 1rem 4rem; }

/* Stage indicator */
.stage-indicator { margin-bottom: 2rem; }
.stage-indicator__stages { display: flex; gap: 0; overflow: hidden; }
.stage-indicator__stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  position: relative;
  padding: .5rem .25rem;
}
.stage-indicator__stage::before {
  content: '';
  position: absolute;
  top: 50%;
  right: -50%;
  width: 100%;
  height: 2px;
  background: var(--grey-200);
  z-index: 0;
}
.stage-indicator__stage:last-child::before { display: none; }
.stage-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--grey-200);
  border: 2px solid var(--grey-200);
  z-index: 1;
}
.stage-indicator__stage--active .stage-dot { background: var(--gold); border-color: var(--gold); }
.stage-label { font-size: .7rem; color: var(--grey-400); text-align: center; }
.stage-indicator__stage--active .stage-label { color: var(--gold); font-weight: 600; }

/* Question card */
.question-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem;
  border-top: 3px solid var(--gold);
}
.question-number { font-size: .8rem; font-weight: 600; color: var(--grey-400); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .75rem; }
.question-text { font-size: 1.25rem; font-weight: 600; color: var(--navy); margin-bottom: 1.75rem; line-height: 1.4; }

.edit-banner {
  background: var(--amber-pale);
  border-left: 3px solid var(--amber);
  padding: .625rem .875rem;
  font-size: .875rem;
  margin-bottom: 1.25rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Options */
.options-fieldset { border: none; margin-bottom: 1.5rem; }
.option-label {
  display: flex;
  align-items: flex-start;
  gap: .875rem;
  padding: .875rem 1rem;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: .5rem;
  transition: border-color .15s, background .15s;
}
.option-label:hover { border-color: var(--gold); background: var(--gold-pale); }
.option-label input { margin-top: .2rem; flex-shrink: 0; accent-color: var(--gold); }
.option-text { font-size: .95rem; }

/* Context section */
.context-section { margin-bottom: 1.5rem; }
.context-field { margin-top: .75rem; }
.char-count { font-size: .75rem; color: var(--grey-400); display: block; margin-top: .25rem; text-align: right; }

/* Question actions */
.question-actions { display: flex; gap: .75rem; flex-wrap: wrap; border-top: 1px solid var(--grey-200); padding-top: 1.5rem; }

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
  background: var(--grey-100);
  color: var(--grey-600);
  text-transform: lowercase;
}
.badge--adaptive { background: var(--amber-pale); color: var(--amber); }
.badge--skipped  { background: var(--grey-100); color: var(--grey-400); }
.badge--fixed_onboarding { background: var(--blue-pale); color: #1d4ed8; }
.badge--ai_generated { background: var(--amber-pale); color: var(--amber); }
.badge--active   { background: var(--green-pale); color: var(--green); }

/* ── Review page ──────────────────────────────────────────── */
.review-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 2.5rem; border-top: 3px solid var(--gold); }
.review-card__title { font-size: 1.5rem; margin-bottom: .5rem; }
.review-card__subtitle { color: var(--grey-600); font-size: .9rem; margin-bottom: 2rem; }

.answers-list { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 2rem; }
.answer-row {
  padding: 1rem 1.25rem;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
}
.answer-row__header { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.answer-seq { font-size: .75rem; font-weight: 700; color: var(--gold); text-transform: uppercase; }
.answer-stage { font-size: .75rem; color: var(--grey-400); }
.answer-question { font-weight: 600; margin-bottom: .35rem; font-size: .9rem; }
.answer-value { font-size: .9rem; color: var(--grey-600); margin-bottom: .35rem; }
.answer-context { font-size: .85rem; color: var(--grey-400); font-style: italic; }

.review-submit-section, .review-continue-section { border-top: 1px solid var(--grey-200); padding-top: 1.5rem; margin-top: 1rem; }
.review-submit-section h2 { font-size: 1.1rem; margin-bottom: .5rem; }
.review-submit-section p { font-size: .9rem; color: var(--grey-600); margin-bottom: 1rem; }

/* ── Admin layout ─────────────────────────────────────────── */
.admin-body { background: var(--grey-100); }
.admin-layout { display: flex; min-height: 100vh; }

.admin-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.admin-sidebar__brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid var(--navy-mid);
  margin-bottom: .5rem;
}
.admin-sidebar__brand .logo-text { font-size: .9rem; }

.admin-nav { list-style: none; padding: .5rem 0; flex: 1; }
.admin-nav li + li { margin-top: 2px; }
.admin-nav__link {
  display: block;
  padding: .625rem 1rem;
  font-size: .875rem;
  color: var(--grey-400);
  text-decoration: none;
  border-radius: var(--radius-sm);
  margin: 0 .5rem;
  transition: background .15s, color .15s;
}
.admin-nav__link:hover, .admin-nav__link--active {
  background: var(--navy-light);
  color: var(--white);
}
.admin-nav__link--active { color: var(--gold-light); }

.admin-sidebar__footer { padding: 1rem; border-top: 1px solid var(--navy-mid); }
.admin-user-info { font-size: .8rem; color: var(--grey-400); margin-bottom: .5rem; }

.admin-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.admin-topbar {
  background: var(--white);
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--grey-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.admin-page-title { font-size: 1.25rem; font-weight: 700; }

.admin-content { padding: 1.5rem; flex: 1; }
.admin-section { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; margin-bottom: 1.5rem; }
.admin-section__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.admin-section__header h2 { font-size: 1rem; }

/* Stats */
.stats-row { display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.stat-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem 1.5rem; border-left: 3px solid var(--gold); min-width: 140px; }
.stat-card__value { font-size: 2rem; font-weight: 700; color: var(--navy); line-height: 1; }
.stat-card__label { font-size: .8rem; color: var(--grey-400); margin-top: .25rem; }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th {
  text-align: left;
  padding: .625rem .75rem;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--grey-400);
  border-bottom: 2px solid var(--grey-200);
  white-space: nowrap;
}
.data-table td {
  padding: .75rem;
  border-bottom: 1px solid var(--grey-100);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--grey-50); }

/* Search form */
.search-form { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.inline-form { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 1rem; justify-content: center; padding: 1rem; font-size: .875rem; }

/* Detail pages */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.5rem; }
.detail-section { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; }
.detail-section h2 { font-size: 1rem; margin-bottom: 1rem; border-bottom: 1px solid var(--grey-200); padding-bottom: .5rem; }
.detail-section h3 { font-size: .9rem; margin-bottom: .5rem; }

.detail-list { display: grid; grid-template-columns: auto 1fr; gap: .5rem 1rem; font-size: .875rem; }
.detail-list dt { font-weight: 600; color: var(--grey-600); white-space: nowrap; }
.detail-list dd { color: var(--navy); }

/* Q&A list */
.qa-list { display: flex; flex-direction: column; gap: .875rem; }
.qa-item { padding: 1rem 1.25rem; border: 1.5px solid var(--grey-200); border-radius: var(--radius); }
.qa-item--skipped { opacity: .7; }
.qa-item__header { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.qa-seq { font-weight: 700; font-size: .8rem; color: var(--gold); }
.qa-stage { font-size: .75rem; color: var(--grey-400); }
.qa-question { font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
.qa-answer   { font-size: .875rem; color: var(--grey-600); }
.qa-context  { font-size: .8rem; color: var(--grey-400); font-style: italic; margin-top: .25rem; }
.qa-meta     { margin-top: .5rem; }

/* Audit list */
.audit-list { list-style: none; display: flex; flex-direction: column; gap: .5rem; }
.audit-item { display: flex; align-items: baseline; gap: 1rem; font-size: .85rem; padding: .5rem 0; border-bottom: 1px solid var(--grey-100); }
.audit-time  { white-space: nowrap; min-width: 160px; }
.audit-event { font-family: var(--font-mono); font-size: .8rem; color: var(--navy-mid); flex: 1; }
.audit-ip    { white-space: nowrap; }

/* Danger zone */
.danger-zone { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--grey-200); }
.danger-zone h3 { font-size: .875rem; margin-bottom: .35rem; }

/* Action blocks */
.action-block { margin-bottom: 1.25rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--grey-100); }
.action-block:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

/* Quick links */
.quick-links { display: flex; gap: .75rem; flex-wrap: wrap; }
.quick-link-card {
  background: var(--grey-50);
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  padding: .875rem 1.25rem;
  text-decoration: none;
  font-weight: 600;
  font-size: .875rem;
  color: var(--navy);
  transition: border-color .15s, background .15s;
}
.quick-link-card:hover { border-color: var(--gold); background: var(--gold-pale); }

/* TOTP setup */
.totp-setup h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.qr-code-container { display: flex; justify-content: center; padding: 1rem; background: var(--white); border: 1.5px solid var(--grey-200); border-radius: var(--radius); margin: 1rem 0; }
.qr-code { max-width: 200px; }
.manual-code { background: var(--grey-50); padding: .875rem; border-radius: var(--radius); margin-top: .5rem; }
.secret-code { display: block; font-size: 1rem; letter-spacing: .1em; word-break: break-all; margin: .5rem 0; color: var(--navy); }
details summary { cursor: pointer; font-size: .875rem; color: var(--gold); margin-top: .5rem; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .admin-layout { flex-direction: column; }
  .admin-sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; }
  .admin-nav { display: flex; flex-direction: row; padding: 0; }
  .admin-nav__link { padding: .5rem .75rem; }
  .admin-sidebar__brand { padding: .75rem 1rem; }
  .admin-sidebar__footer { display: none; }

  .question-card { padding: 1.5rem; }
  .question-text { font-size: 1.1rem; }

  .auth-card { padding: 1.75rem; }
  .detail-grid { grid-template-columns: 1fr; }
}
