/* Mobile-first. Small screens are the default; min-width media queries add
   desktop affordances. Target: 320px+ phones work without horizontal scroll;
   tap targets ≥ 44px; no hover-only interactions. */

:root {
  --fg: #1f2330;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --bg: #f8fafc;
  --card: #fff;
  --border: #e5e7eb;
  --danger: #b91c1c;
  --danger-dark: #7f1d1d;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
  font-size: 16px;                 /* prevents iOS zoom on inputs */
  -webkit-tap-highlight-color: rgba(79, 70, 229, 0.15);
}

/* ---------- Header / top nav ---------- */
.topnav {
  padding: 0.6rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 500;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1rem;
}
.brand {
  font-weight: 700;
  color: var(--fg);
  text-decoration: none;
  font-size: 1.05rem;
}
.topnav-links {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
  flex-wrap: wrap;
}
.topnav-links a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.95rem;
}
.topnav-links a:hover { color: var(--fg); background: #f1f5f9; }
.topnav-links a.active { color: var(--accent); background: #eef2ff; }
.topnav-links .nav-gear {
  font-size: 1.1rem;
  padding: 0.35rem 0.55rem;
  line-height: 1;
}

/* Public (signed-out) top-nav variants */
.topnav-public-link {
  font-weight: 600;
  color: #4b5563 !important;
}
.topnav-public-cta {
  font-weight: 700;
  color: #fff !important;
  background: var(--accent, #4f46e5);
  border-radius: 6px;
  padding: 0.4rem 0.9rem !important;
}
.topnav-public-cta:hover { background: #4338ca !important; }

/* ---------- Public landing page ---------------------------------------- */
.public-hero {
  max-width: 840px;
  margin: 3.5rem auto 2rem;
  padding: 0 1.5rem;
  text-align: center;
}
.public-hero-title {
  font-size: 2.4rem;
  line-height: 1.15;
  margin: 0 0 1rem;
  color: #1f2330;
  letter-spacing: -0.02em;
}
.public-hero-lede {
  font-size: 1.1rem;
  line-height: 1.55;
  color: #4b5563;
  max-width: 680px;
  margin: 0 auto 1.75rem;
}
.public-cta-row {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}
.public-cta {
  display: inline-block;
  padding: 0.7rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 0.1s, transform 0.1s, box-shadow 0.1s;
}
.public-cta-primary {
  background: var(--accent, #4f46e5);
  color: #fff !important;
  box-shadow: 0 3px 10px rgba(79, 70, 229, 0.25);
}
.public-cta-primary:hover { background: #4338ca; box-shadow: 0 5px 14px rgba(79, 70, 229, 0.35); }
.public-cta-secondary {
  background: #fff;
  color: var(--accent, #4f46e5) !important;
  border-color: var(--accent, #4f46e5);
}
.public-cta-secondary:hover { background: #eef2ff; }
.public-cta-wide { display: block; width: 100%; max-width: 320px; text-align: center; margin: 1rem auto; }

.public-features {
  max-width: 1040px;
  margin: 3rem auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}
.public-feature {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
}
.public-feature-emoji { font-size: 2.2rem; margin-bottom: 0.5rem; }
.public-feature h2 { font-size: 1.1rem; margin: 0.25rem 0 0.5rem; color: #1f2330; }
.public-feature p { margin: 0; color: #4b5563; line-height: 1.55; font-size: 0.95rem; }

.public-explainer {
  max-width: 720px;
  margin: 3rem auto 2rem;
  padding: 0 1.5rem;
}
.public-explainer h2 {
  font-size: 1.3rem;
  margin-bottom: 0.75rem;
  text-align: center;
  color: #1f2330;
}
.public-steps {
  counter-reset: step;
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.public-steps li {
  counter-increment: step;
  padding: 0.85rem 1rem 0.85rem 3.25rem;
  background: #f8fafc;
  border-left: 3px solid var(--accent, #4f46e5);
  border-radius: 8px;
  position: relative;
  line-height: 1.5;
  color: #374151;
}
.public-steps li::before {
  content: counter(step);
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.8rem;
  height: 1.8rem;
  background: var(--accent, #4f46e5);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.public-footer {
  max-width: 720px;
  margin: 3rem auto 2rem;
  padding: 1.5rem 1.5rem 0;
  text-align: center;
  border-top: 1px solid #e5e7eb;
}

/* Auth stubs (login / register) */
.public-auth {
  max-width: 480px;
  margin: 4rem auto;
  padding: 2.5rem 2rem;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.04);
}
.public-auth h1 { font-size: 1.6rem; margin: 0 0 1rem; color: #1f2330; }
.public-auth-note {
  color: #4b5563;
  line-height: 1.6;
  margin: 0 0 1.5rem;
}
.public-auth-footer { margin-top: 1.25rem; }
.public-auth-footer a { color: var(--accent, #4f46e5); font-weight: 600; }

/* Subtle banner shown on /settings */
.settings-banner {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
  color: #78350f;
}
.settings-banner b { margin-right: 0.4rem; }

/* ---------- Layout ---------- */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: 5rem;            /* breathing room above mobile browser chrome */
}

/* Embedded mode: pages rendered inside the settings iframe strip their chrome. */
body.embed main {
  max-width: none;
  padding: 0.75rem;
  padding-bottom: 1rem;
}

/* Narrow-page utility (history lookup, etc.) */
.narrow-page { max-width: 600px; }
.lookup-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin: 1rem 0;
}
.lookup-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-weight: 600;
}
.lookup-form input {
  padding: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  min-height: 44px;
}
.cta-primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cta-primary:hover { background: var(--accent-dark); }

h1 { font-size: 1.4rem; line-height: 1.25; margin: 0.5rem 0; }
h2 { font-size: 1.15rem; line-height: 1.3; margin: 1rem 0 0.5rem; }
h3 { font-size: 1.05rem; line-height: 1.3; }
p  { margin: 0.5rem 0; }
.meta { color: var(--muted); font-size: 0.9rem; }

/* ---------- Home: two-column layout (left panel + main) ---------- */
.layout {
  display: flex;
  flex-direction: column;         /* stack on mobile */
  gap: 1rem;
}
.side-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
}
.side-panel-title {
  font-size: 1rem;
  margin: 0 0 0.5rem;
  padding: 0 0.25rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.test-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.test-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  min-height: 44px;
  transition: border-color 0.1s, background 0.1s;
}
a.test-item { text-decoration: none; color: inherit; }
.test-item:hover { border-color: var(--accent); }
.test-item.active {
  background: #eef2ff;
  border-color: var(--accent);
}
.test-emoji { font-size: 1.5rem; flex-shrink: 0; }
.test-item-body { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.test-name { font-weight: 600; }
.test-meta { color: var(--muted); font-size: 0.85rem; }

/* Main panel */
.main-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  min-height: 60vh;
}
.file-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  min-height: 40px;
}
.file-item:hover { border-color: var(--accent); }
.file-item.active {
  background: #eef2ff;
  border-color: var(--accent);
}
.file-emoji { flex-shrink: 0; font-size: 1.1rem; }
.file-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.1rem; }
.file-label { font-weight: 600; font-size: 0.92rem; }
.file-path {
  color: var(--muted);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-bytes { color: var(--muted); font-size: 0.75rem; flex-shrink: 0; }

.file-list-compact .file-item {
  padding: 0.35rem 0.55rem;
  min-height: 32px;
}
.file-list-compact .file-label { font-size: 0.85rem; }

/* ---------- Template-editor cards ------------------------------------
   All four cards share the Templates group's palette (purple/violet).
   Previously each had its own color (blue/green/orange/pink); they're now
   unified so the Templates group reads as one coherent section rather
   than four competing items. Deeper shade picked so they stand out from
   the pale group background. */
.questionnaire-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: linear-gradient(135deg, #6d28d9 0%, #7c3aed 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
  text-align: left;
  width: 100%;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 2px 6px rgba(109, 40, 217, 0.2);
  transition: transform 0.1s, box-shadow 0.1s;
  margin-bottom: 0.4rem;
}
.questionnaire-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(109, 40, 217, 0.35);
}
.questionnaire-card:active { transform: translateY(1px); }
.questionnaire-card-emoji { font-size: 1rem; flex-shrink: 0; }
.questionnaire-card-title { flex: 1; }
.questionnaire-card-arrow {
  font-size: 1rem;
  opacity: 0.85;
  flex-shrink: 0;
}

/* profiles/scoring/report-card kept as classes in markup for structural
   identification; visually they now inherit from .questionnaire-card. */
.profiles-card, .scoring-card, .report-card { /* same palette as base card */ }

/* Saved items page */
.saved-sections { display: flex; flex-direction: column; gap: 1.25rem; }
.saved-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}
.saved-section h2 { margin: 0 0 0.3rem; font-size: 1.1rem; }
.saved-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin: 0.3rem 0 0.7rem;
  padding: 0;
  list-style: none;
}
.saved-empty {
  padding: 0.5rem 0.65rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-style: italic;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: #fff;
}
.saved-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  flex-wrap: wrap;
}
.saved-item-info { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; flex: 1; }
.saved-item-info b { font-size: 0.9rem; word-break: break-all; }
.saved-item-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

.btn-sm {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.7rem;
  border-radius: 5px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  min-height: 32px;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
}
.btn-sm:hover { opacity: 0.9; }
.btn-sm-outline {
  background: #fff;
  color: var(--accent);
}
.btn-sm-outline:hover { background: #eef2ff; }

/* Per-card color variants removed — all cards now share the Templates
   palette set by .questionnaire-card. The class names still exist in the
   markup so JS hooks keep working, but no color overrides. */

/* Scoring editor */
.scoring-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.scoring-section h3 { margin: 0 0 0.25rem; font-size: 1.05rem; }
.radio-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.6rem; }
.radio-row {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: #fff;
}
.radio-row:has(input:checked) {
  background: #eef2ff;
  border-color: var(--accent);
}
.radio-row input { margin-top: 0.2rem; }
.radio-label { font-size: 0.95rem; line-height: 1.4; }
.radio-label code {
  font-size: 0.78rem;
  color: var(--muted);
  background: transparent;
}

.dim-list { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.5rem; }
.dim-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
}
.dim-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}
.dim-row label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.dim-row input {
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  min-height: 32px;
}
.dim-id { width: 5rem; }
.dim-pole-a, .dim-pole-b { width: 4rem; text-align: center; font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; }
.dim-usage { font-size: 0.72rem; color: var(--muted); min-height: 1em; }
.dim-actions { margin-left: auto; display: flex; gap: 0.25rem; }
.dim-actions button {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  font-size: 0.9rem;
  min-height: 32px;
}
.dim-actions .delete-btn { color: var(--danger); }
.dim-actions .delete-btn:hover { background: #fef2f2; border-color: var(--danger); }
.dim-label-wrap { display: flex; flex-direction: column; gap: 0.2rem; margin-top: 0.5rem; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.dim-label-wrap input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  font-weight: normal;
  color: var(--fg);
  min-height: 36px;
}

/* How-it-works explainer steps */
.how-it-works { background: #fefce8; border-color: #fef08a; }
.hiw-steps {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.hiw-step {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}
.hiw-step-num {
  background: var(--accent);
  color: #fff;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
}
.hiw-step-body { flex: 1; line-height: 1.55; font-size: 0.95rem; }
.hiw-step-body code {
  background: #fff;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.88em;
  border: 1px solid var(--border);
}

/* Points table */
.points-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0 0.5rem;
}
.points-table thead {
  background: #f8fafc;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.points-table th, .points-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.points-table th.pt-val, .points-table td.pt-val { width: 6rem; }
.points-table th.pt-actions, .points-table td.pt-actions { width: 7rem; text-align: right; }
.points-table input.pt-label {
  width: 100%;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
}
.points-table input.pt-value {
  width: 4.5rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  text-align: center;
}
.points-table .pt-actions button {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  min-height: 30px;
  margin-left: 0.15rem;
}
.points-table .pt-actions .delete-btn { color: var(--danger); }
.points-table .pt-actions .delete-btn:hover { background: #fef2f2; border-color: var(--danger); }

/* Profile filter grid */
.profile-filter {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
  position: sticky;
  top: 3.5rem;
  z-index: 50;
}
.profile-filter-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.55rem;
  font-size: 0.95rem;
}
.profile-filter-head .meta { margin-left: auto; }
.filter-clear {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}
.filter-clear:hover { background: #f1f5f9; }

.profile-filter-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}
.filter-btn {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.4rem;
  cursor: pointer;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: 0.88rem;
  min-height: 40px;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.filter-btn:hover { border-color: var(--accent); }
.filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-dark);
}

@media (min-width: 640px) {
  .profile-filter-grid { grid-template-columns: repeat(8, 1fr); }
}

/* Profile editor cards */
.profile-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.9rem;
}
.profile-card-head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}
.profile-code {
  background: #1f2330;
  color: #fff;
  padding: 0.2rem 0.65rem;
  border-radius: 4px;
  font-size: 0.82rem;
  font-weight: 700;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.profile-label { font-size: 1.05rem; font-weight: 600; }

.profile-field { margin-bottom: 0.75rem; }
.profile-field-label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.profile-field-input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 0.95rem;
  background: #fff;
  resize: vertical;
}
.profile-field-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.profile-list-items {
  list-style: none;
  padding: 0;
  margin: 0 0 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.profile-list-items li {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
.profile-list-input {
  flex: 1;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 0.93rem;
  background: #fff;
}
.profile-list-del {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--danger);
  padding: 0.35rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  min-height: 32px;
}
.profile-list-del:hover { background: #fef2f2; border-color: var(--danger); }
.profile-list-add {
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}
.profile-list-add:hover { border-color: var(--accent); color: var(--accent); background: #eef2ff; }

/* File viewer header (sits above the iframe) */
.file-view-head {
  background: #1e293b;
  color: #e2e8f0;
  padding: 0.4rem 0.75rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  border-radius: 8px 8px 0 0;
}
.file-view-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-view-head .meta { color: #94a3b8; }
.file-view-head a.meta { text-decoration: underline; }

/* Preview / Raw toggle in the file-view header */
.file-view-head-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.edit-btn {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 0.3rem 0.7rem;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 6px;
}
.edit-btn:hover { background: var(--accent-dark); }
.view-toggle {
  display: inline-flex;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  overflow: hidden;
}
.view-toggle-btn {
  background: transparent;
  color: #cbd5e1;
  border: 0;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-weight: 600;
}
.view-toggle-btn.active { background: #4f46e5; color: #fff; }
.view-toggle-btn:not(.active):hover { background: #1e293b; color: #fff; }

/* ---------- Friendly questionnaire preview ---------- */
.preview-view {
  background: var(--card);
  padding: 1rem;
  max-height: 70vh;
  overflow-y: auto;
}
.preview-summary { color: var(--muted); margin-bottom: 0.75rem; font-size: 0.95rem; }

.preview-pole-section { margin-bottom: 1.25rem; }
.preview-pole-section h4 {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.5rem 0;
  font-size: 1rem;
}
.pole-dim-label { font-weight: 600; }

.q-table, .q-options-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  font-size: 0.92rem;
}
.q-table thead, .q-options-table thead {
  background: #f8fafc;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.q-table th, .q-table td,
.q-options-table th, .q-options-table td {
  padding: 0.5rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.q-table tr:last-child td,
.q-options-table tr:last-child td { border-bottom: 0; }
.q-table td.q-num, .q-table th.q-num {
  width: 2.5rem;
  color: var(--muted);
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.q-table td.q-trait, .q-table th.q-trait { width: 4rem; text-align: center; }
.q-options-table td.opt-id, .q-options-table th.opt-id {
  width: 2.5rem;
  color: var(--muted);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  text-align: center;
}
.q-options-table td.opt-cat, .q-options-table th.opt-cat { width: 5rem; text-align: center; }

/* Pole chips — one color per pole, paired across each dimension */
.pole-chip {
  display: inline-block;
  min-width: 1.5rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  text-align: center;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.pole-E { background: #2563eb; }   /* EI — blue */
.pole-I { background: #6366f1; }
.pole-S { background: #059669; }   /* SN — green */
.pole-N { background: #10b981; }
.pole-T { background: #d97706; }   /* TF — amber */
.pole-F { background: #f59e0b; }
.pole-J { background: #dc2626; }   /* JP — red */
.pole-P { background: #ef4444; }

/* Enneagram category chip */
.cat-chip {
  display: inline-block;
  min-width: 1.5rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: #6366f1;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  text-align: center;
}

/* Enneagram full-options preview cards */
.preview-question-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}
.preview-question-card h4 {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin: 0 0 0.6rem;
  font-size: 1rem;
  line-height: 1.3;
}
.q-num-circle {
  background: var(--accent);
  color: #fff;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}
.preview-question-card .q-options-table { background: #fff; }

/* ---------- Test page header ---------- */
.test-header { margin-bottom: 1rem; padding-right: 7rem; /* space for fixed button */ }
.test-header h1 { margin: 0 0 0.3rem 0; }
.test-header p { margin: 0.25rem 0; }

/* ---------- Auto-fill button (fixed top-right) ---------- */
.test-actions {
  position: fixed;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1000;
}
.autofill-btn {
  background: var(--danger);
  color: #fff;
  border: 2px solid var(--danger-dark);
  padding: 0.6rem 0.9rem;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(185, 28, 28, 0.45);
  letter-spacing: 0.02em;
  min-height: 44px;                /* tap target */
}
.autofill-btn:active {
  background: var(--danger-dark);
  transform: translateY(1px);
}

/* ---------- Form: identity block ---------- */
.test-form fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 1rem;
  background: var(--card);
}
.test-form fieldset legend { padding: 0 0.4rem; font-weight: 600; font-size: 0.95rem; }
.test-form .id-block label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0.5rem 0;
  font-size: 0.92rem;
}
.test-form .id-block input {
  width: 100%;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;                 /* keep 16px to prevent iOS zoom */
  min-height: 44px;
}

/* ---------- Form: question sections ---------- */
.test-form section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 1rem;
}
.test-form .question {
  margin: 0.75rem 0;
  padding-bottom: 0.75rem;
  border-bottom: 1px dashed var(--border);
}
.test-form .question:last-child { border-bottom: none; padding-bottom: 0; }
.test-form .q-text { margin: 0 0 0.5rem 0; }

/* Options: stack full-width on mobile so they're easy to tap */
.test-form .q-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.4rem;
}
.test-form .opt {
  display: flex;
  align-items: center;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  min-height: 44px;                /* tap target */
  font-size: 0.98rem;
}
.test-form .opt input {
  margin-right: 0.6rem;
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
}
.test-form .opt:active { background: #f1f5f9; }
.test-form .opt:has(input:checked) {
  border-color: var(--accent);
  background: #eef2ff;
  font-weight: 600;
}

/* Bottom action bar: draft buttons + submit */
.form-bottom-bar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.form-bottom-left {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Submit button: full-width on mobile */
button.submit {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 0.95rem 1.5rem;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
  min-height: 48px;
}
button.submit:active { background: var(--accent-dark); }

/* Draft buttons */
.btn-draft {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.55rem 0.85rem;
  border-radius: 6px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}
.btn-draft:active { opacity: 0.85; }
.btn-draft-outline {
  background: #fff;
  color: var(--accent);
}
.btn-draft-outline:hover { background: #eef2ff; }
.btn-draft-sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; min-height: 32px; }

/* --- Disabled-state for the Download report anchor ------------------------ */
.btn-draft[disabled],
.btn-draft-outline.is-disabled,
.btn-draft.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: auto;        /* still receive hover for the tooltip */
}
.btn-draft-outline.is-disabled { color: #888; background: #f3f4f6; border-color: #d0d0d0; }

/* --- Full-screen submit overlay ------------------------------------------- */
#submit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 24, 0.82);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: inherit;
}
#submit-overlay[hidden] { display: none; }
.submit-overlay-body {
  background: #1f2230;
  border-radius: 12px;
  padding: 2.25rem 2.5rem;
  max-width: 440px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}
.submit-overlay-body h2 { margin: 0.5rem 0 0.75rem; color: #fff; }
.submit-overlay-body p { margin: 0.35rem 0; color: #d4d7e0; }
.submit-overlay-body .meta { color: #8a8fa0; margin-top: 1rem; }
.ai-spinner-big {
  display: inline-block;
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255,255,255,0.25);
  border-top-color: #7b8cff;
  border-radius: 50%;
  animation: ai-spin 0.9s linear infinite;
  margin-bottom: 0.5rem;
}

/* --- Per-row action buttons on working-list items ------------------------ */
.file-item-row {
  display: flex !important;
  align-items: stretch;
  gap: 0.25rem;
}
.file-item-row .file-item { flex: 1; min-width: 0; }
.file-item-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.15rem 0.1rem;
}
.row-icon-btn {
  border: 1px solid transparent;
  background: transparent;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
  border-radius: 5px;
  cursor: pointer;
  color: #555;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.75rem;
  min-height: 1.6rem;
}
.row-icon-btn svg { display: block; }
.row-icon-btn:hover { background: rgba(0,0,0,0.06); border-color: rgba(0,0,0,0.08); }
.row-icon-btn.row-icon-danger { color: #b33; font-weight: 600; }
.row-icon-btn.row-icon-danger:hover { background: #fee; border-color: #f4c0c0; }

/* Direction-tinted action buttons on file rows. The button's background
   matches the destination section's color, so at a glance you know where
   a click will send the file. Emoji glyphs ignore CSS `color`, so we tint
   with background + border instead. */
.row-icon-btn.row-icon-promote {
  /* Promote: working → saved. Matches the My Journey section's palette
     (bg #ecfdf5 + border #10b981) so the button visually belongs to the
     destination. */
  background: #ecfdf5;
  border-color: #10b981;
  color: #065f46;
  font-weight: 700;
}
.row-icon-btn.row-icon-promote:hover {
  background: #d1fae5;
  border-color: #059669;
}
.row-icon-btn.row-icon-demote {
  /* Demote: saved → working. Matches the Recent Runs section's palette
     (bg #eef2ff + border #6366f1) so the button visually belongs to the
     destination. */
  background: #eef2ff;
  border-color: #6366f1;
  color: #3730a3;
  font-weight: 700;
}
.row-icon-btn.row-icon-demote:hover {
  background: #e0e7ff;
  border-color: #4f46e5;
}

/* --- Save-to-journey modal (My Personality — Saved) ---------------------- */
.journey-replace-row {
  display: flex !important;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.5rem 0.25rem;
  border-top: 1px solid #eee;
}
.journey-replace-row input[type=radio] { margin-top: 0.3rem; }
.journey-replace-row:first-child { border-top: none; }

/* --- AI narrative loading state ------------------------------------------- */
.ai-narrative-loading {
  border: 1px dashed #d0d4df;
  background: #f7f8fb;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  color: #4b5563;
}
.ai-narrative-loading .error { color: #b33; }
.ai-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #c8ccd6;
  border-top-color: var(--accent, #4f46e5);
  border-radius: 50%;
  animation: ai-spin 0.9s linear infinite;
  vertical-align: -2px;
  margin-right: 0.35rem;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }

/* Server drafts list */
#server-drafts {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-top: 1rem;
}
#server-drafts h3 { margin: 0 0 0.6rem; }
.draft-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.draft-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.draft-item-info { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.draft-item-info b { font-size: 0.92rem; }

/* ---------- Result / report ---------- */
.report {
  background: var(--card);
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  line-height: 1.6;
}
.report h1 { font-size: 1.5rem; margin: 0.75rem 0 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.report h2 { font-size: 1.15rem; margin: 1.25rem 0 0.5rem; color: var(--fg); }
.report h3 { font-size: 1rem; margin: 1rem 0 0.4rem; }
.report p { margin: 0.4rem 0; }
.report ul { padding-left: 1.25rem; margin: 0.4rem 0; }
.report li { margin: 0.2rem 0; }
.report strong { color: var(--fg); }
.report em { color: var(--muted); font-size: 0.9rem; }
.report code { background: #f1f5f9; padding: 0.1rem 0.35rem; border-radius: 3px; font-size: 0.88em; }
.report table { width: 100%; border-collapse: collapse; margin: 0.75rem 0; font-size: 0.92rem; }
.report th, .report td { padding: 0.5rem 0.65rem; border: 1px solid var(--border); text-align: left; }
.report th { background: #f8fafc; font-weight: 600; font-size: 0.85rem; }
.report tr:hover { background: #fafbfc; }
@media (max-width: 640px) {
  .report { padding: 0.85rem; }
  .report h1 { font-size: 1.25rem; }
  .report table { font-size: 0.85rem; }
}
/* Report action bar */
.report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.75rem 0;
}

#saved-reports-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-top: 0.75rem;
}
#saved-reports-panel h3 { margin: 0 0 0.6rem; }

.summary-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  margin-top: 1rem;
}
.summary-box pre {
  background: #f1f5f9;
  padding: 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: auto;
}

/* ---------- Questionnaire editor ---------- */
.editor-header { margin-bottom: 1rem; }
.editor-header h1 { margin: 0.25rem 0 0.5rem; }
.back-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}
.back-link:hover { text-decoration: underline; }

.editor-status {
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  white-space: pre-wrap;
  font-size: 0.95rem;
  border: 1px solid;
}
.editor-status.error { background: #fef2f2; border-color: #fca5a5; color: #7f1d1d; }
.editor-status.success { background: #f0fdf4; border-color: #86efac; color: #14532d; }

.editor-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  position: sticky;
  top: 4rem;
  z-index: 100;
  background: var(--bg);
  padding: 0.5rem 0;
}
/* When embedded in the settings iframe, stick to the iframe's top (no outer nav). */
body.embed .editor-actions {
  top: 0;
  padding: 0.5rem 0.75rem;
  margin: -0.75rem -0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: #fff;
}
.cta-secondary {
  background: #fff;
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 0.7rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
}
.cta-secondary:hover { background: #f1f5f9; }

.editor-body { display: flex; flex-direction: column; gap: 1rem; }

/* Generic file editor */
.file-edit-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}
.file-edit-bar-left { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; min-width: 0; }
.file-edit-bar-left b { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem; word-break: break-all; }
.file-edit-bar-right { display: flex; gap: 0.4rem; }
.file-edit-textarea {
  width: 100%;
  min-height: 65vh;
  padding: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.45;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  tab-size: 2;
  resize: vertical;
  box-sizing: border-box;
}
.file-edit-textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ====== Settings layout: left sidebar (picker + cards + files) + right iframe ====== */
.settings-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: stretch;
  min-height: calc(100vh - 160px);
}
@media (min-width: 900px) {
  .settings-layout { grid-template-columns: 300px 1fr; }
}
.settings-side {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-self: start;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  position: sticky;
  top: 4.5rem;
}
.settings-main { display: flex; flex-direction: column; min-width: 0; }
.side-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.test-picker {
  width: 100%;
  padding: 0.5rem 0.6rem;
  font: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  margin-bottom: 0.4rem;
}
.side-test-meta {
  padding: 0.55rem 0.65rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 7px;
  margin-bottom: 0.5rem;
}
.side-test-meta p { margin: 0 0 0.3rem; font-size: 0.8rem; }
.side-test-meta p:last-child { margin-bottom: 0; }
.side-test-meta code { font-size: 0.75rem; }
.side-take-test {
  display: inline-flex;
  align-items: center;
  margin-top: 0.35rem;
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
  min-height: 30px;
}
.side-section-title {
  margin: 0;
  padding: 0.5rem 0.6rem 0.25rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}
.side-section-title .meta { font-size: 0.7rem; text-transform: none; letter-spacing: normal; }
.side-section-hint {
  margin: 0 0 0.35rem;
  padding: 0 0.6rem;
  font-size: 0.78rem;
}

/* Role-based visibility.
   Source of truth today: `document.documentElement.dataset.role` set by the
   <head> script in base.html. Admin is default; ?role=user or the toggle
   button flips it. When real auth arrives, the server will write the role
   server-side and the toggle goes away. */
html[data-role="user"] .admin-only { display: none !important; }

/* Dev-only role preview pills (under "Take the test" on the settings sidebar).
   Two buttons side by side; active one is filled, inactive is outlined.
   Entire block auto-hides once real auth replaces this preview mechanism. */
.role-preview-box {
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px dashed #d0d4df;
}
.role-preview-caption {
  margin: 0 0 0.3rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}
.role-preview-buttons {
  display: flex;
  gap: 0.35rem;
}
.role-preview-btn {
  flex: 1;
  font-size: 0.78rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid #d0d4df;
  background: #fff;
  color: #374151;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.3;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.role-preview-btn:hover { background: #f3f4f6; }
.role-preview-btn.active[data-set-role="admin"] {
  background: #6d28d9;                 /* violet — matches Templates palette */
  border-color: #6d28d9;
  color: #fff;
}
.role-preview-btn.active[data-set-role="user"] {
  background: #10b981;                 /* green — matches Journey palette */
  border-color: #10b981;
  color: #fff;
}

/* Dev-only role toggle in the top nav. */
.nav-role-toggle {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border: 1px solid #d0d4df;
  background: #f7f8fb;
  color: #374151;
  border-radius: 6px;
  cursor: pointer;
  margin-left: 0.35rem;
  font-family: inherit;
  line-height: 1.4;
}
.nav-role-toggle:hover { background: #eef2ff; border-color: #6366f1; color: #3730a3; }
.nav-role-toggle[data-role="user"] { background: #ecfdf5; border-color: #10b981; color: #065f46; }

/* Settings-page admin groups. Same colored-panel system as the three
   collections — each group has its own palette so the eye can tell them
   apart at a glance. */
.settings-group {
  border: 1px solid transparent;
  border-left-width: 3px;
  border-radius: 10px;
  padding: 0.4rem 0.3rem 0.6rem;
  margin-bottom: 0.9rem;
}
.side-section-title-plain {
  padding: 0.35rem 0.6rem 0.25rem;
}

/* Templates group — purple/violet */
.settings-group-templates {
  background: #f5f3ff;                /* pale lavender */
  border-color: #7c3aed;               /* violet */
}
.settings-group-templates .side-section-title-plain { color: #5b21b6 !important; }

/* Template files group — amber/warm */
.settings-group-files {
  background: #fffbeb;                /* pale amber */
  border-color: #d97706;              /* amber */
}
.settings-group-files .side-section-title-plain { color: #92400e !important; }
.settings-group-files .file-list .file-item { background: #fffdf4; }

/* --- Section color bands --------------------------------------------------
   Each sidebar section gets its own subtle palette so items are
   unmistakable at a glance. Same visual structure, different hue.
--------------------------------------------------------------------------- */
.side-section {
  border-radius: 10px;
  border: 1px solid transparent;
  border-left-width: 3px;
  padding: 0.15rem 0 0.5rem;
  margin-bottom: 0.9rem;
}
.side-section .saved-list { margin: 0.1rem 0; padding: 0 0.4rem; }
.side-section .saved-bulk-actions { padding: 0.3rem 0.6rem 0; }

/* Saved / Journey — green ("keep this") */
.side-section-saved {
  background: #ecfdf5;
  border-color: #10b981;
}
.side-section-saved .side-section-title { color: #065f46; }
.side-section-saved .file-item.active {
  background: #d1fae5;
  border-color: #10b981;
}
.side-section-saved .file-emoji { filter: saturate(1.2); }

/* Working / Recent runs — indigo */
.side-section-working {
  background: #eef2ff;
  border-color: #6366f1;
}
.side-section-working .side-section-title { color: #3730a3; }
.side-section-working .file-item.active {
  background: #e0e7ff;
  border-color: #6366f1;
}

/* Drafts — slate */
.side-section-drafts {
  background: #f1f5f9;
  border-color: #64748b;
}
.side-section-drafts .side-section-title { color: #334155; }
.side-section-drafts .file-item.active {
  background: #e2e8f0;
  border-color: #64748b;
}

/* Settings embedded viewer/editor iframe — fills remaining viewport height */
.file-view-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 130px);
}
.file-view-iframe {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: #fff;
}
.file-view-empty {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  color: var(--meta);
  border: 1px dashed var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: #fff;
  min-height: 520px;
}
.file-view-empty[hidden] { display: none; }
.editor-group {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
}
.editor-group-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.q-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
}
.q-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.q-num-badge {
  background: var(--accent);
  color: #fff;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.q-trait-wrap { font-size: 0.9rem; color: var(--muted); display: inline-flex; align-items: center; gap: 0.4rem; }
.q-trait-wrap select {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  min-height: 32px;
}
.q-card-actions { margin-left: auto; display: flex; gap: 0.25rem; }
.q-card-actions button {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  font-size: 0.9rem;
  min-height: 32px;
}
.q-card-actions button:hover { background: #f1f5f9; }
.q-card-actions .delete-btn { color: var(--danger); }
.q-card-actions .delete-btn:hover { background: #fef2f2; border-color: var(--danger); }

.q-text {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 0.95rem;
  resize: vertical;
  min-height: 44px;
  background: #fff;
}
.q-text:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.add-q-btn {
  width: 100%;
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 0.6rem;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  margin-top: 0.4rem;
}
.add-q-btn:hover { border-color: var(--accent); color: var(--accent); background: #eef2ff; }

.editor-options-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-top: 0.4rem;
}
.editor-options-table th, .editor-options-table td {
  padding: 0.3rem 0.45rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.editor-options-table th { background: #eef2ff; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; }
.editor-options-table .opt-label-in {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  font-size: 0.9rem;
}
.editor-options-table .opt-cat-in {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
}

/* ---------- Report template editor ---------- */
.rpt-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.75rem;
}
.rpt-card-disabled { opacity: 0.6; }
.rpt-card-head {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}
.rpt-toggle { flex-shrink: 0; padding-top: 0.15rem; cursor: pointer; }
.rpt-toggle input { width: 1.1rem; height: 1.1rem; cursor: pointer; }
.rpt-card-emoji { font-size: 1.3rem; flex-shrink: 0; }
.rpt-card-info { flex: 1; min-width: 0; }
.rpt-card-info b { display: block; font-size: 1rem; }
.rpt-card-info .meta { display: block; margin-top: 0.15rem; }

.rpt-config {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.rpt-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
}
.rpt-checkbox input { width: 1.05rem; height: 1.05rem; cursor: pointer; }
.rpt-field { display: flex; flex-direction: column; gap: 0.2rem; }
.rpt-field label { font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.rpt-text-input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  min-height: 40px;
}
.rpt-textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  min-height: 80px;
  resize: vertical;
}

.rpt-add-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.rpt-add-label { font-weight: 600; color: var(--muted); font-size: 0.9rem; }
.rpt-add-btn {
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
}
.rpt-add-btn:hover { border-color: var(--accent); color: var(--accent); background: #eef2ff; }

/* ---------- Excel-verify details block ---------- */
.excel-verify {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-top: 1rem;
}
.excel-verify summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 1.02rem;
  padding: 0.25rem 0;
}
.excel-verify .excel-body p { font-size: 0.95rem; }
.excel-verify code {
  background: #f1f5f9;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.9em;
}
.btn-secondary {
  display: inline-block;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--fg);
  background: #fff;
  margin-right: 0.4rem;
  margin-bottom: 0.4rem;
  min-height: 44px;
  font-size: 0.95rem;
}
.btn-secondary:active { background: #f1f5f9; }

.paste-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.paste-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  background: #fafbfc;
}
.paste-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
}
.paste-block textarea {
  width: 100%;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  resize: vertical;
}
.copy-btn {
  margin-left: auto;
  padding: 0.4rem 0.75rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  min-height: 36px;
}
.copy-btn:active { background: var(--accent-dark); }

@media (min-width: 640px) {
  .paste-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- History table: turn into stacked cards on mobile ---------- */
table.history {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
}
table.history thead { display: none; }
table.history tr {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
}
table.history td {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 0;
  border: none;
  font-size: 0.95rem;
}
table.history td::before {
  content: attr(data-label);
  color: var(--muted);
  font-weight: 600;
}

/* ==========================================================
   Tablet + ( ≥ 640 px )
   ========================================================== */
@media (min-width: 640px) {
  .topnav { padding: 0.75rem 1.5rem; }
  main { padding: 1.5rem; }
  h1 { font-size: 1.7rem; }
  h2 { font-size: 1.3rem; }

  .test-header { padding-right: 9rem; }
  .test-actions { top: 0.75rem; right: 1rem; }
  .autofill-btn { padding: 0.7rem 1.1rem; font-size: 1rem; }

  .form-bottom-bar { flex-direction: row; align-items: center; justify-content: space-between; }
  button.submit { width: auto; }

  /* Options side-by-side on wider screens (common case: 3 likert choices) */
  .test-form .q-options { flex-direction: row; flex-wrap: wrap; }
  .test-form .opt { flex: 1 1 auto; min-width: 140px; }

  .test-form section { padding: 1rem 1.25rem; }
  .test-form fieldset { padding: 1rem; }
  .test-form .id-block label { flex-direction: row; align-items: center; gap: 0.5rem; }
  .test-form .id-block input { width: auto; min-width: 260px; }

  /* History reverts to a real table on wider screens */
  table.history { background: var(--card); border: 1px solid var(--border);
                  border-radius: 10px; overflow: hidden; }
  table.history thead { display: table-header-group; }
  table.history tr { display: table-row; background: transparent;
                     border: none; border-bottom: 1px solid var(--border);
                     border-radius: 0; padding: 0; margin: 0; }
  table.history th, table.history td { display: table-cell;
                                       padding: 0.6rem; text-align: left; }
  table.history td { border: none; justify-content: flex-start; }
  table.history td::before { content: none; }
}

/* ==========================================================
   Wide ( ≥ 900 px ): two-column home layout
   ========================================================== */
@media (min-width: 900px) {
  .layout {
    flex-direction: row;
    align-items: flex-start;
  }
  .side-panel {
    flex: 0 0 260px;
    position: sticky;
    top: 5rem;                       /* below the top nav */
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
  }
  .main-panel { flex: 1; min-width: 0; }
}

/* ==========================================================
   Desktop ( ≥ 960 px )
   ========================================================== */
@media (min-width: 960px) {
  main { padding: 2rem; }
  .topnav { padding: 1rem 2rem; }

  .test-header { padding-right: 10rem; }
  .test-actions { top: 1rem; right: 1.25rem; }
  .autofill-btn {
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    box-shadow: 0 4px 14px rgba(185, 28, 28, 0.45);
  }
  .autofill-btn:hover {
    background: #991b1b;
    box-shadow: 0 6px 18px rgba(185, 28, 28, 0.55);
    transform: translateY(-1px);
  }

  .test-item { transition: transform 0.1s, border-color 0.1s; }
  .test-item:hover:not(.active) { transform: translateY(-1px); }
  .test-form .opt:hover { border-color: var(--accent); }
  button.submit:hover { background: var(--accent-dark); }
}
