:root {
  --primary: #1e3a5f;
  --primary-light: #2d5a8a;
  --accent: #e67e22;
  --pass: #27ae60;
  --fail: #c0392b;
  --pending: #f39c12;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1a1a2e;
  --muted: #6b7280;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(30, 58, 95, 0.08);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

#app-main {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 16px;
  padding-bottom: 32px;
}

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--primary);
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transition: transform 0.25s, opacity 0.25s;
  z-index: 1000;
  max-width: 90vw;
  text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

#update-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 999;
  font-size: 14px;
}
#update-banner button {
  background: #fff;
  color: var(--accent);
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}

.brand { text-align: center; margin-bottom: 24px; }
.brand h1 { font-size: 1.4rem; color: var(--primary); margin-top: 12px; }
.brand__icon {
  width: 64px; height: 64px;
  background: var(--primary);
  color: #fff;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.4rem;
}
.brand__icon--sm { width: 32px; height: 32px; font-size: 0.75rem; border-radius: 8px; }

.login-screen { display: flex; align-items: center; justify-content: center; min-height: 80dvh; }
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 8px;
}
.brand-inline { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--primary); }
.top-bar__actions { display: flex; gap: 4px; }

.screen-header { margin-bottom: 20px; }
.screen-header h2 { font-size: 1.25rem; color: var(--primary); margin-top: 8px; }

.dashboard h2 { font-size: 1.1rem; margin-bottom: 16px; }

.card-grid { display: grid; gap: 12px; }
.card-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.card-btn:hover, .card-btn:focus-visible {
  border-color: var(--primary-light);
  box-shadow: var(--shadow);
}
.card-btn--primary { border-color: var(--primary); background: rgba(30, 58, 95, 0.04); }
.card-btn__icon { font-size: 1.5rem; }
.card-btn__title { font-weight: 700; font-size: 1rem; color: var(--primary); }
.card-btn__sub { font-size: 0.85rem; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--primary-light); color: #fff; }
.btn-ghost { background: transparent; color: var(--primary); border: 1px solid var(--border); }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; }
.btn-block { width: 100%; }

.form-stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 0.85rem; font-weight: 600; color: var(--primary); }
.field input, .field select, .field textarea, .question-card textarea, .question-card input[type="text"] {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary-light); outline-offset: 1px; }

.question-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  border-left: 4px solid var(--primary);
}
.question-card legend { font-weight: 700; font-size: 0.9rem; margin-bottom: 8px; }
.radio-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; cursor: pointer; }
.mark-row { display: flex; gap: 16px; margin: 10px 0; }
.mark-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 600; }

.model-answer { background: rgba(30, 58, 95, 0.06); padding: 10px; border-radius: 8px; margin: 8px 0; font-size: 0.9rem; }

.study-module { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.study-module h3 { color: var(--primary); margin-bottom: 4px; }
.study-section { margin-top: 12px; }
.study-section h4 { font-size: 0.95rem; margin-bottom: 4px; }
.study-section p { font-size: 0.9rem; color: var(--text); line-height: 1.65; }
.study-module { margin-bottom: 20px; }
.study-module .muted { margin-bottom: 12px; display: block; font-size: 0.85rem; }
.study-section { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.study-section:first-of-type { border-top: none; padding-top: 0; }
.study-section h4 { color: var(--primary-light); font-size: 0.95rem; margin-bottom: 6px; }

.study-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.study-toc__btn {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
}
.study-toc__btn:hover { border-color: var(--primary); }

.study-module__intro {
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 12px;
  color: var(--text);
}
.study-sources {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  line-height: 1.5;
}

.study-callout {
  margin: 10px 0;
  padding: 10px 12px;
  border-left: 4px solid var(--pending);
  background: rgba(243, 156, 18, 0.1);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.45;
}

.study-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.82rem;
}
.study-table th,
.study-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.study-table th {
  background: rgba(30, 58, 95, 0.08);
  color: var(--primary);
  font-weight: 700;
}

.study-figure {
  margin: 14px 0;
  text-align: center;
}
.study-figure__btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: zoom-in;
  overflow: hidden;
}
.study-figure img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  display: block;
}
.study-figure figcaption {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.study-example {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: rgba(30, 58, 95, 0.06);
  border: 1px dashed var(--border);
}
.study-example__label {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  margin: 0 0 6px;
}
.study-example p { margin: 0; font-size: 0.9rem; line-height: 1.55; }

.study-selfcheck {
  margin: 14px 0 0;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.study-selfcheck__title {
  margin: 0 0 8px;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--primary);
}
.study-selfcheck__item {
  list-style: none;
  margin: 0 0 6px;
}
.study-selfcheck__item details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  line-height: 1.4;
}
.study-selfcheck__answer {
  margin: 8px 0 4px;
  font-size: 0.88rem;
  line-height: 1.5;
}
.study-links { margin-top: 8px; }

.study-lightbox {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: min(96vw, 900px);
  width: 100%;
  background: #111;
  color: #fff;
  position: relative;
}
.study-lightbox::backdrop { background: rgba(0, 0, 0, 0.75); }
.study-lightbox__close {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 2;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}
.study-lightbox img {
  width: 100%;
  max-height: 80vh;
  object-fit: contain;
  display: block;
}
.study-lightbox__caption {
  margin: 0;
  padding: 10px 14px 14px;
  font-size: 0.85rem;
  color: #ddd;
}

.list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.list-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.list-item--action { cursor: pointer; }
.list-item--action:hover { border-color: var(--primary-light); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  align-self: flex-start;
}
.badge--pass { background: rgba(39, 174, 96, 0.15); color: var(--pass); }
.badge--fail { background: rgba(192, 57, 43, 0.15); color: var(--fail); }
.badge--pending, .badge--pending_review { background: rgba(243, 156, 18, 0.15); color: var(--pending); }

.tag {
  font-size: 0.7rem;
  background: var(--primary);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  font-weight: 600;
}

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.hint { margin-top: 8px; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.section-title { font-size: 1rem; margin: 20px 0 10px; color: var(--primary); }
.placeholder-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  border: 2px dashed var(--border);
  color: var(--muted);
}
.offline-hint { margin-top: 24px; font-size: 0.85rem; color: var(--muted); text-align: center; }

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 8px;
  overflow: hidden;
}
.progress-bar__fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.2s;
}

.wizard-body { margin-bottom: 16px; }
.wizard-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.mode-btn {
  width: 100%;
  text-align: left;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  cursor: pointer;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 8px;
}
.mode-btn--on {
  border-color: var(--primary);
  background: rgba(30, 58, 95, 0.08);
}

.photo-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.photo-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--border);
}

.quoting-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.quoting-header h2 { flex: 1; }

#app-main.route-quoting {
  max-width: none;
  padding: 8px;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}
.quoting-frame-wrap {
  flex: 1;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
}
#quote-frame {
  width: 100%;
  height: 100%;
  min-height: calc(100dvh - 100px);
  border: none;
}

.score-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin: 12px 0;
  padding: 10px 12px;
  background: rgba(30, 58, 95, 0.06);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.assessor-prompt {
  margin: 16px 0;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(30, 58, 95, 0.1), rgba(30, 58, 95, 0.04));
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
}
.assessor-prompt__label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
  margin: 0 0 6px;
}
.assessor-prompt__text {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.45;
  margin: 0 0 8px;
  color: var(--text);
}

.competency-checklist {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.competency-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
}
.competency-item--done {
  border-color: rgba(39, 174, 96, 0.45);
  background: rgba(39, 174, 96, 0.06);
}
.competency-item__label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
}
.competency-item__label input[type="checkbox"] {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--pass);
}
.competency-item__title {
  font-weight: 600;
  line-height: 1.4;
}
.competency-item__ref {
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}
.competency-item__ref summary {
  padding: 8px 14px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}
.competency-item__ref p {
  margin: 0;
  padding: 0 14px 12px;
  color: var(--muted);
  line-height: 1.45;
}

.result-card {
  text-align: center;
  padding: 28px 20px;
  margin: 16px 0 24px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
}
.result-card--pass {
  border-color: var(--pass);
  background: rgba(39, 174, 96, 0.1);
}
.result-card--fail {
  border-color: var(--fail);
  background: rgba(192, 57, 43, 0.08);
}
.result-card__pct {
  font-size: 2.5rem;
  font-weight: 800;
  margin: 0;
  line-height: 1;
}
.result-card--pass .result-card__pct { color: var(--pass); }
.result-card--fail .result-card__pct { color: var(--fail); }
.result-card__label {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 10px 0 8px;
}

@media (min-width: 600px) {
  .card-grid { grid-template-columns: 1fr 1fr; }
  .card-grid .card-btn:first-child { grid-column: 1 / -1; }
}