/* ==========================================================================
   Kwizaro — shared design system
   Clean, simple, mobile-first.
   ========================================================================== */

:root {
  --color-bg: #f6f7fb;
  --color-surface: #ffffff;
  --color-border: #e3e6ee;
  --color-text: #1f2430;
  --color-text-muted: #6b7280;
  --color-primary: #4f46e5;
  --color-primary-dark: #4338ca;
  --color-primary-bg: #eef0fd;
  --color-success: #16a34a;
  --color-success-bg: #eafaf0;
  --color-danger: #dc2626;
  --color-danger-bg: #fdecec;
  --color-warning: #d97706;
  --color-warning-bg: #fef3e2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 20, 43, 0.04), 0 4px 12px rgba(20, 20, 43, 0.06);
  --max-width: 760px;
}

* { box-sizing: border-box; }

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

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

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em; font-weight: 700; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }

/* ---------- Layout shell ---------- */

.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-header__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--color-text);
  letter-spacing: -0.02em;
}
.brand:hover { text-decoration: none; }
.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: 0;
  flex-shrink: 0;
}
.brand-kwiz { color: var(--color-primary); }
.brand-aro { color: var(--color-success); }

/* Same brand lockup, centred and a little larger, above the sign-in form. */
.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
.login-brand img {
  width: 36px;
  height: 36px;
  border-radius: 0;
}

.site-nav { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.site-nav a { color: var(--color-text-muted); font-weight: 600; font-size: 0.95rem; }
.site-nav a:hover, .site-nav a.active { color: var(--color-primary); text-decoration: none; }

.site-main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.site-footer {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  padding: 2rem 1.25rem 3rem;
}

/* ---------- Building blocks ---------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-list { display: flex; flex-direction: column; gap: 0.75rem; }

.empty-state {
  color: var(--color-text-muted);
  text-align: center;
  padding: 2rem 1rem;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}

.section { margin-bottom: 2rem; }
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.section-title h2 { margin: 0; }
.section-title .count { color: var(--color-text-muted); font-size: 0.9rem; }

/* Stat tiles - small at-a-glance numbers, e.g. test results summaries */
.stat-row { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1rem; }
.stat-tile {
  flex: 1 1 140px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.stat-tile__value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-tile__label { color: var(--color-text-muted); font-size: 0.82rem; margin-top: 0.25rem; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
  transition: background-color .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-outline { background: var(--color-surface); border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover { border-color: var(--color-primary); color: var(--color-primary); }
.btn-block { display: flex; width: 100%; }
.btn[disabled], .btn.is-disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.badge-progress { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-complete { background: var(--color-success-bg); color: var(--color-success); }
.badge-available { background: var(--color-primary-bg); color: var(--color-primary); }
.badge-correct { background: var(--color-success-bg); color: var(--color-success); }
.badge-incorrect { background: var(--color-danger-bg); color: var(--color-danger); }

/* Progress bar */
.progress { background: var(--color-border); border-radius: 999px; height: 8px; overflow: hidden; }
.progress__bar { background: var(--color-primary); height: 100%; border-radius: 999px; transition: width .2s ease; }

/* Test list item */
.test-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.test-item__main { flex: 1 1 220px; min-width: 0; }
.test-item__title { font-weight: 700; margin-bottom: 0.15rem; }
.test-item__meta { color: var(--color-text-muted); font-size: 0.88rem; }
.test-item__progress { margin-top: 0.5rem; max-width: 260px; }
.test-item__action { flex-shrink: 0; }

/* ---------- Forms ---------- */

label, .label { display: block; font-weight: 600; margin-bottom: 0.3rem; font-size: 0.92rem; }

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-bg);
}
textarea { min-height: 5rem; resize: vertical; }

.form-row { margin-bottom: 1.1rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.helper-text { color: var(--color-text-muted); font-size: 0.85rem; margin-top: 0.3rem; }

.message {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-weight: 600;
  font-size: 0.95rem;
}
.message-success { background: var(--color-success-bg); color: var(--color-success); }
.message-error { background: var(--color-danger-bg); color: var(--color-danger); }
.message-info { background: var(--color-primary-bg); color: var(--color-primary); }
.message-warning { background: var(--color-warning-bg); color: var(--color-warning); }

/* ---------- Question / answer UI ---------- */

.question-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; }
.question-intro { color: var(--color-text-muted); margin-bottom: 1rem; white-space: pre-line; }
.question-text { font-size: 1.1rem; font-weight: 600; margin: 1rem 0 1.25rem; white-space: pre-line; }
.question-image { margin: 1rem 0; text-align: center; }
.question-image img { max-height: 320px; }

.answer-list { display: flex; flex-direction: column; gap: 0.6rem; margin: 1rem 0; }

.answer-choice {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1rem;
  transition: border-color .15s ease, background-color .15s ease;
}
.answer-choice:hover { border-color: var(--color-primary); }
.answer-choice input[type="radio"] { width: auto; accent-color: var(--color-primary); transform: scale(1.15); }
.answer-choice input[type="radio"]:checked ~ .answer-choice__label { color: var(--color-primary-dark); }
.answer-choice:has(input[type="radio"]:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary-bg);
}
.answer-choice__key { font-weight: 700; color: var(--color-text-muted); min-width: 1.4em; }

.answer-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 1.05rem;
}
.answer-inline input[type="text"] { width: auto; flex: 1 1 140px; min-width: 100px; }

.question-actions { margin-top: 1.5rem; display: flex; justify-content: flex-end; }

/* ---------- Tables (admin) ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
th { color: var(--color-text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
td .btn { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

/* ---------- Debug ---------- */
.debug-panel {
  margin-top: 2rem;
  padding: 1rem;
  background: #111827;
  color: #9ca3af;
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Code editor (admin/QuestionTemplates.php et al) ---------- */
.code-editor {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  min-height: 420px;
  white-space: pre;
  tab-size: 4;
}

/* ---------- Utilities ---------- */
.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

/* Inline choice pills (used for fill-the-blank style question types) */
.choice-pills { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 1rem 0; }
.choice-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.55rem 1rem;
  border: 1.5px solid var(--color-border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.95rem;
  background: var(--color-surface);
  transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}
.choice-pill:hover { border-color: var(--color-primary); }
.choice-pill input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }
.choice-pill:has(input[type="radio"]:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: #fff;
}

.blank {
  display: inline-block;
  min-width: 3.5em;
  border-bottom: 2px solid var(--color-text-muted);
  text-align: center;
  color: var(--color-text-muted);
  font-weight: 700;
  margin: 0 0.15em;
}

/* Admin: answer pool editor rows */
.answer-pool-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
  align-items: center;
}
.answer-pool-row input { margin: 0; }
@media (max-width: 480px) { .answer-pool-row { grid-template-columns: 90px 1fr; } }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

/* Danger button (destructive actions) */
.btn-danger { background: var(--color-surface); border-color: var(--color-danger); color: var(--color-danger); }
.btn-danger:hover { background: var(--color-danger); color: #fff; }

/* Admin sub-navigation (Questions / Tests tabs) */
.subnav {
  display: flex;
  gap: 1.5rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1.5rem;
  padding-bottom: 0;
}
.subnav a {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.92rem;
  padding-bottom: 0.6rem;
  border-bottom: 2px solid transparent;
}
.subnav a:hover { color: var(--color-primary); text-decoration: none; }
.subnav a.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* Two-column layout (e.g. assigned vs available questions) */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 720px) { .two-col { grid-template-columns: 1fr; } }

/* Small tag list (e.g. which tests a question is used in) */
.tag-list { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: var(--color-primary-bg); color: var(--color-primary); }
.tag-neutral { background: var(--color-border); color: var(--color-text-muted); }
.tag-danger { background: var(--color-danger-bg); color: var(--color-danger); }

/* ---------- Question hover preview (admin/addEditTest.php) ---------- */

/* Tables that host a hover preview need their overflow un-clipped so the
   popover isn't cut off by the horizontal-scroll wrapper. */
.table-wrap--overflow-visible { overflow: visible; }

.q-hover {
  position: relative;
  display: inline-block;
  cursor: help;
  border-bottom: 1px dotted var(--color-text-muted);
}
.q-hover:hover, .q-hover:focus { border-bottom-color: var(--color-primary); }

.q-preview-popover {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.5rem;
  width: 300px;
  max-width: min(80vw, 340px);
  z-index: 30;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(20, 20, 43, 0.18);
  padding: 1rem;
  text-align: left;
  white-space: normal;
  cursor: default;
}
.q-hover:hover .q-preview-popover,
.q-hover:focus .q-preview-popover,
.q-hover:focus-within .q-preview-popover {
  display: block;
}

.q-preview { display: flex; flex-direction: column; gap: 0.5rem; }
.q-preview__title { display: block; font-weight: 700; font-size: 0.95rem; }
.q-preview__intro { display: block; color: var(--color-text-muted); font-size: 0.82rem; }
.q-preview__image { display: block; }
.q-preview__image img { max-height: 110px; border-radius: var(--radius-sm); }
.q-preview__text { display: block; font-weight: 600; font-size: 0.9rem; }
.q-preview__answers { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; }
.q-preview__answer { display: block; padding: 0.25rem 0.45rem; border-radius: 6px; background: var(--color-bg); }
.q-preview__answer--correct { background: var(--color-success-bg); color: var(--color-success); font-weight: 700; }
.q-preview__correct {
  display: block;
  font-size: 0.8rem;
  color: var(--color-success);
  font-weight: 700;
  border-top: 1px solid var(--color-border);
  padding-top: 0.4rem;
}

/* Type/category filter bar (admin/addEditTest.php) */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 0.85rem;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}
.filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 0;
}
.filter-bar select {
  min-width: 160px;
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
}
.filter-count {
  margin-left: auto;
  align-self: center;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  font-weight: 600;
}
@media (max-width: 480px) {
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar select { min-width: 0; width: 100%; }
  .filter-count { margin-left: 0; }
}

/* ---------- Header: user area / role badge / agency switcher ---------- */
.user-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.user-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
}
.user-badge__name {
  font-weight: 600;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agency-switcher select {
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}
.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

/* ---------- Login page ---------- */
.login-main {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 360px;
}
.login-card h1 {
  text-align: center;
  margin-bottom: 1.25rem;
}

/* ---------- "View Question" popup (TestResultDetail.php) ---------- */
.btn-link {
  background: none;
  border: none;
  padding: 0;
  margin-left: 0.4rem;
  font-size: 0.85rem;
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: underline;
}
.btn-link:hover { color: var(--color-primary-dark); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 1000;
}
/* The [hidden] attribute is how the popup is shown/hidden (see the inline
   script on TestResultDetail.php). Without this rule, ".modal-overlay"
   above and the browser's built-in "[hidden]{display:none}" rule are the
   same specificity, and ours - loading later - wins, so the popup would
   stay visible (empty, un-closeable) even while "hidden" is set. */
.modal-overlay[hidden] {
  display: none;
}
.modal-box {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1.75rem;
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}
.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.9rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--color-text-muted);
  cursor: pointer;
}
.modal-close:hover { color: var(--color-text); }
.question-modal__options {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.question-modal__options li {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.question-modal__option--correct { border-color: var(--color-success); background: var(--color-success-bg); }
.question-modal__option--theirs { border-color: var(--color-danger); background: var(--color-danger-bg); }
.question-modal__type { margin-bottom: 0.5rem; }
.question-modal__image { display: block; margin: 0.5rem 0; }
