/* Theme tokens. The app UI is dark; the report (.report) and printing use the light tokens further below. */
:root {
  color-scheme: dark;
  --bg: #0f141a;
  --surface: #161d25;
  --surface-2: #1c2530;
  --field: #11181f;
  --ink: #e6ecf2;
  --muted: #a3b1be;
  --faint: #66737f;
  --line: #2a3542;
  --line-strong: #3a4756;
  --track: #24303b;
  --cover: #3d4b59;
  --brand: #62b6d6;
  --brand-btn: #2a7c9c;
  --brand-btn-hover: #3389ab;
  --brand-soft: rgba(98, 182, 214, .13);
  --brand-line: rgba(98, 182, 214, .38);
  --accent: #dcae63;
  --danger: #ef8189;
  --danger-btn: #b3434b;
  --danger-soft: rgba(239, 129, 137, .13);
  --ok: #62cb9a;
  --ok-soft: rgba(98, 203, 154, .13);
  --warn: #e9b65f;
  --warn-soft: rgba(233, 182, 95, .12);
  --warn-line: rgba(233, 182, 95, .35);
  --warn-ink: #f2d39b;
  --violet: #c9a3dc;
  --violet-soft: rgba(201, 163, 220, .12);
  --violet-line: rgba(201, 163, 220, .32);
  --yes: #2f86a8;
  --no: #5f6d7a;
  --skip: #b9852c;
  --yes-soft: rgba(47, 134, 168, .16);
  --skip-soft: rgba(185, 133, 44, .13);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .18);
  --font: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, 'Noto Sans Arabic', Arial, sans-serif;
}

/* Light "paper" tokens for the report preview and the printed PDF. */
.report {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f5f6f8;
  --field: #ffffff;
  --ink: #1c2631;
  --muted: #5f6b78;
  --faint: #9aa4ae;
  --line: #e2e6eb;
  --line-strong: #cfd6de;
  --track: #edf0f3;
  --cover: #d9e0e6;
  --brand: #1f5f7a;
  --brand-soft: #e7f0f4;
  --brand-line: #cfe0e8;
  --danger: #b3434b;
  --ok: #2f7d5b;
  --ok-soft: #e7f4ee;
  --warn: #9a6516;
  --warn-soft: #fbf2e3;
  --warn-line: #f0e0c4;
  --warn-ink: #6d4e1c;
  --violet: #7a4e8c;
  --violet-soft: #f3ecf7;
  --yes: #1f5f7a;
  --no: #5c6773;
  --skip: #9a6516;
  --shadow: 0 1px 2px rgba(20, 30, 40, .05), 0 2px 8px rgba(20, 30, 40, .04);
  color: var(--ink);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.7; color: var(--ink); background: var(--bg);
  display: flex; flex-direction: column; min-height: 100vh;
}
h1, h2, h3, h4 { line-height: 1.35; margin: 0 0 .4em; font-weight: 700; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.08rem; }
h4 { font-size: .98rem; }
p { margin: 0 0 .6em; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 16px; }
main.wrap { flex: 1; padding-top: 20px; padding-bottom: 32px; outline: none; }
.mono, code { font-family: ui-monospace, Consolas, monospace; font-size: .85em; direction: ltr; unicode-bidi: isolate; }
.muted, .muted-text { color: var(--muted); }
.muted-text { font-size: .9rem; }
.note { color: var(--muted); font-size: .88rem; }
.note.small, .small-note { font-size: .8rem; color: var(--muted); }
.warn-text { color: var(--warn); }
.danger-text { color: var(--danger) !important; }
.alert { background: var(--danger-soft); color: var(--danger); padding: 10px 14px; border-radius: 8px; }
.ic { width: 18px; height: 18px; flex: none; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* header / footer */
.app-header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-logo { height: 40px; width: auto; max-width: 140px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text small { color: var(--muted); font-size: .75rem; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { text-decoration: none; color: var(--muted); padding: 8px 14px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
.app-footer { border-top: 1px solid var(--line); background: var(--surface); padding: 16px 0; text-align: center; font-size: .9rem; }
.app-footer a { color: var(--brand); text-decoration: none; font-weight: 600; }
.app-footer a:hover { text-decoration: underline; }

/* cards & buttons */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.narrow { max-width: 640px; margin-inline: auto; }
.card-title { font-size: 1rem; margin-bottom: .3em; }
.card-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.eyebrow { font-size: .78rem; color: var(--muted); font-weight: 600; }
.page-head { margin-bottom: 16px; }
.admin-login { max-width: 380px; margin: 48px auto; }
.admin-login form { display: grid; gap: 12px; }
.empty-state { text-align: center; color: var(--muted); padding: 32px 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface-2); cursor: pointer; font-weight: 500; text-decoration: none; color: var(--ink);
  min-height: 38px; white-space: nowrap;
}
.btn:hover { border-color: var(--faint); background: var(--track); }
.btn.primary { background: var(--brand-btn); border-color: var(--brand-btn); color: #fff; }
.btn.primary:hover { background: var(--brand-btn-hover); }
.btn.danger { background: var(--danger-btn); border-color: var(--danger-btn); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: .86rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible, .ans-btn:focus-visible, .trait-head:focus-visible, .nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--track); color: var(--ink); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.icon-btn.ph { visibility: hidden; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* forms */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-weight: 500; font-size: .9rem; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; }
.field small { color: var(--muted); font-size: .8rem; }
.req { color: var(--danger); font-weight: 400; }
input[type="text"], input[type="password"], input:not([type]), textarea, select {
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; background: var(--field); color: var(--ink); width: 100%; min-height: 38px;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
select { width: auto; }
option { background: var(--surface); color: var(--ink); }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[type="checkbox"] { accent-color: var(--brand-btn); }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: .9rem; margin: 6px 0; }
.input-row { display: flex; gap: 4px; align-items: center; }
.input-row input { flex: 1; min-width: 0; }

/* dialogs & toasts */
.dialog { border: 1px solid var(--line-strong); border-radius: 14px; padding: 20px; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog-msg { white-space: pre-line; }
.dialog-actions { display: flex; gap: 8px; margin-top: 14px; }
.toasts { position: fixed; bottom: 16px; inset-inline-start: 16px; inset-inline-end: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 100; pointer-events: none; }
.toast { pointer-events: auto; background: #2a3542; color: #f1f5f9; border: 1px solid var(--line-strong); padding: 10px 16px; border-radius: 10px; max-width: 560px; box-shadow: var(--shadow); transition: opacity .3s; font-size: .92rem; }
.toast.success { background: #1d6a4a; border-color: #2a8460; color: #fff; }
.toast.error { background: #9e3a43; border-color: #b8505a; color: #fff; }
.toast.out { opacity: 0; }

/* chips & tags */
.chip { display: inline-block; font-size: .75rem; padding: 1px 9px; border-radius: 999px; background: var(--track); color: var(--muted); white-space: nowrap; font-weight: 500; }
.st-confirmed { background: var(--brand-soft); color: var(--brand); }
.st-absent { background: var(--track); color: var(--muted); }
.st-partial { background: var(--warn-soft); color: var(--warn); }
.st-unassessed, .st-empty { background: transparent; color: var(--muted); border: 1px dashed var(--line-strong); }
.tag { font-size: .7rem; padding: 0 7px; border-radius: 4px; font-weight: 600; vertical-align: middle; }
.tag.ai { background: var(--violet-soft); color: var(--violet); }
.tag.new { background: var(--ok-soft); color: var(--ok); }
.tag.free { background: var(--warn-soft); color: var(--warn); }
.tag.rec { background: var(--brand-soft); color: var(--brand); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* session head */
.session-head .sh-top { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.session-head h2 { margin-bottom: 0; }
.meta { font-size: .85rem; color: var(--muted); }
.sh-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-start; }
.problem { margin-top: 10px; background: var(--surface-2); border-radius: 8px; padding: 8px 12px; }
.problem summary { cursor: pointer; font-weight: 500; }
.problem p { white-space: pre-wrap; margin: 8px 0 0; }
.progress { margin-top: 12px; display: flex; align-items: center; gap: 10px; }
.progress-bar { flex: 1; height: 6px; background: var(--track); border-radius: 99px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--brand); }
.progress small { color: var(--muted); white-space: nowrap; }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; inset-inline-end: 0; top: 100%; margin-top: 4px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.45); min-width: 260px; z-index: 18; padding: 4px; } /* above the pinned indicators (15), below the header (20) */
.menu-list button { display: block; width: 100%; text-align: start; padding: 9px 12px; border: 0; background: none; border-radius: 6px; cursor: pointer; color: var(--ink); }
.menu-list button:hover { background: var(--surface-2); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { border: 0; background: none; padding: 10px 16px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }

/* assessment layout */
.assess-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
/* Indicators stay pinned and fully visible while the questions scroll; the panel scrolls on its own if taller than the screen. */
.assess-side {
  position: sticky; top: calc(var(--header-h, 64px) + 12px);
  max-height: calc(100vh - var(--header-h, 64px) - 24px); overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin;
}
.assess-side .card { margin-bottom: 12px; padding: 14px 16px; }
.assess-side .card:last-child { margin-bottom: 0; }

/* Compact pinned indicators for narrow screens */
.ind-strip {
  display: none; position: sticky; top: calc(var(--header-h, 64px) - 1px); z-index: 15; margin: 0 -16px 16px; padding: 8px 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line-strong); box-shadow: 0 6px 16px rgba(0, 0, 0, .35);
}
.strip-head { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; padding: 2px 0 6px; cursor: pointer; color: var(--ink); text-align: start; }
.strip-legend { flex: 1; font-size: .78rem; color: var(--muted); }
.strip-head .chev { transform: rotate(-90deg); transition: transform .15s; }
.ind-strip.collapsed .strip-head .chev { transform: rotate(90deg); }
.ind-strip.collapsed .strip-head { padding-bottom: 0; }
.strip-sum { font-size: .82rem; color: var(--muted); }
.strip-row { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.3fr) 56px; align-items: center; gap: 10px; font-size: .85rem; padding: 2px 0; }
.strip-row.muted .strip-name { color: var(--muted); }
.strip-cols { font-size: .72rem; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-bottom: 2px; }
.strip-name { display: flex; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strip-a { display: flex; align-items: center; gap: 8px; }
.strip-a b, .strip-b b { direction: ltr; font-size: .85rem; }
.strip-b { text-align: end; }
.mini { flex: 1; height: 8px; background: var(--track); border-radius: 99px; overflow: hidden; display: block; }
.mini span { display: block; height: 100%; border-radius: 99px; }
.strength { font-size: .75rem; color: var(--brand); font-weight: 600; direction: ltr; }
.r-strength { font-size: .75rem; color: var(--muted); }
.results-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; align-items: start; }
.cat-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: 999px; cursor: pointer; user-select: none; }
.cat-chip input { accent-color: var(--c); margin: 0; }
.cat-chip b { font-size: .8rem; color: var(--muted); font-weight: 600; }
.cat-chip.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); }
.cat-card { border-top: 3px solid var(--c); }
.cat-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.cat-pct { text-align: center; flex: none; }
.cat-pct b { display: block; font-size: 1.5rem; color: var(--c); line-height: 1.1; }
.cat-pct small { color: var(--muted); font-size: .75rem; }

.trait { border: 1px solid var(--line); border-radius: 10px; margin-top: 8px; }
.trait.open { border-color: var(--line-strong); }
.trait-head { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; padding: 10px 12px; cursor: pointer; text-align: start; border-radius: 10px; color: var(--ink); }
.trait-head:hover { background: var(--surface-2); }
.chev { display: inline-flex; color: var(--muted); transition: transform .15s; }
.trait.open .chev { transform: rotate(-90deg); }
.trait-name { flex: 1; font-weight: 600; }
.trait-head .count { font-size: .8rem; color: var(--muted); direction: ltr; }
.trait-body { padding: 0 12px 12px; }
.qns { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.qn { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); border-inline-start: 3px solid transparent; flex-wrap: wrap; }
.qn.unanswered { background: transparent; border: 1px dashed var(--line-strong); border-inline-start: 3px dashed var(--line-strong); }
.qn.a-yes { border-inline-start-color: var(--yes); background: var(--yes-soft); }
.qn.a-no { border-inline-start-color: var(--no); }
.qn.a-skip { border-inline-start-color: var(--skip); background: var(--skip-soft); }
.qn-text { flex: 1 1 260px; }
.ans { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: var(--field); flex: none; }
.ans-btn { border: 0; background: none; padding: 6px 12px; cursor: pointer; font-size: .85rem; color: var(--muted); border-inline-start: 1px solid var(--line-strong); min-height: 34px; }
.ans-btn:first-child { border-inline-start: 0; }
.ans-btn:hover { background: var(--track); color: var(--ink); }
.ans-btn.a-yes.active { background: var(--yes); color: #fff; }
.ans-btn.a-no.active { background: var(--no); color: #fff; }
.ans-btn.a-skip.active { background: var(--skip); color: #fff; }

.drafts { margin-top: 12px; border: 1px solid var(--violet-line); background: var(--violet-soft); border-radius: 10px; padding: 12px; }
.drafts-head { display: flex; flex-direction: column; margin-bottom: 6px; }
.drafts-head small { color: var(--muted); }
.drafts ul { list-style: none; padding: 0; margin: 0 0 10px; }
.drafts li label { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; cursor: pointer; }
.drafts li input { margin-top: 6px; accent-color: var(--violet); }

/* indicators */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 38%) 1fr 48px; align-items: center; gap: 8px; }
.bar-row.muted .bar-label { color: var(--muted); }
.bar-label { display: flex; align-items: center; gap: 6px; font-size: .88rem; min-width: 0; }
.bar-track { position: relative; height: 12px; background: var(--track); border-radius: 99px; overflow: hidden; }
.bar-cover { position: absolute; inset-block: 0; inset-inline-start: 0; background: var(--cover); border-radius: 99px; }
.bar-fill { position: absolute; inset-block: 0; inset-inline-start: 0; border-radius: 99px; }
.bar-val { font-weight: 700; font-size: .9rem; text-align: end; direction: ltr; }
.bar-detail { grid-column: 1 / -1; font-size: .78rem; color: var(--muted); margin-top: -6px; }
.dist { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.donut { flex: none; }
.donut-num { font-size: 8px; font-weight: 700; fill: var(--ink); font-family: var(--font); }
.donut-cap { font-size: 3.2px; fill: var(--muted); font-family: var(--font); }
.legend { list-style: none; padding: 0; margin: 0; flex: 1; min-width: 150px; display: flex; flex-direction: column; gap: 4px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.legend .lg-name { flex: 1; }
.legend b { direction: ltr; }
.method { margin: 0; padding-inline-start: 18px; font-size: .86rem; color: var(--muted); }
.method b { color: var(--ink); }
.method li { margin-bottom: 4px; }
.method-card summary { cursor: pointer; font-weight: 600; }
.method-card[open] summary { margin-bottom: 8px; }

/* guidance */
.reminder { display: flex; gap: 10px; background: var(--warn-soft); border: 1px solid var(--warn-line); color: var(--warn-ink); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: .9rem; }
.reminder p { margin: 0; }
.reminder .ic { margin-top: 3px; }
.gd-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.gd-cat { border: 1px solid var(--line); border-inline-start: 4px solid var(--c); border-radius: 10px; padding: 12px 14px; break-inside: avoid; }
.gd-head { display: flex; align-items: center; gap: 10px; }
.gd-head h4 { flex: 1; margin: 0; }
.gd-rank { width: 26px; height: 26px; border-radius: 50%; background: var(--c); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; flex: none; }
.gd-pct { font-weight: 700; font-size: 1.15rem; color: var(--c); direction: ltr; }
.gd-meta { font-size: .8rem; color: var(--muted); margin: 2px 0 6px; }
.gd-items { margin: 0; padding-inline-start: 20px; }
.gd-items li { margin-bottom: 3px; }

/* admin */
.admin-grid { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 16px; align-items: start; }
.adm-side { position: sticky; top: calc(var(--header-h, 64px) + 12px); }
.adm-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.adm-item { display: flex; align-items: center; gap: 4px; border-radius: 8px; border: 1px solid transparent; }
.adm-item.active { background: var(--brand-soft); border-color: var(--brand-line); }
.adm-item.empty { border: 1px dashed var(--warn-line); }
.adm-side .adm-pick small { white-space: normal; }
.session-qs { margin: 0 0 12px; border: 1px solid var(--violet-line); background: var(--violet-soft); border-radius: 10px; padding: 12px; }
.session-qs .adm-rows { margin: 6px 0 10px; }
.session-qs .adm-row { align-items: center; }
.adm-pick { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; text-align: start; background: none; border: 0; padding: 8px; cursor: pointer; border-radius: 8px; color: var(--ink); }
.adm-pick small { width: 100%; color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adm-name { font-weight: 600; }
.adm-tools { display: inline-flex; align-items: center; flex: none; }
.move { display: inline-flex; }
.adm-rows { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 4px; }
.adm-row { display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px; border-radius: 8px; background: var(--surface-2); }
.adm-row .num { color: var(--muted); font-size: .8rem; min-width: 18px; padding-top: 3px; }
.adm-text { flex: 1; padding-top: 2px; }
.adm-lib { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.q-add { border-top: 1px solid var(--line); padding-top: 12px; }

/* AI settings */
.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.settings-grid > .card:last-child { grid-column: 1 / -1; }
.key-form { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.key-form .btn { margin-top: 27px; }
.keys { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 8px; }
.key-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; flex-wrap: wrap; }
.key-row.active { border-color: var(--brand-line); background: var(--brand-soft); }
.key-row small { display: block; color: var(--muted); }
.step { margin: 14px 0 8px; color: var(--brand); }
.search { margin-bottom: 10px; }
.or-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.or-co { display: flex; flex-direction: column; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface-2); cursor: pointer; text-align: start; color: var(--ink); }
.or-co:hover { border-color: var(--brand); background: var(--brand-soft); }
.or-co small { color: var(--muted); }
.model-controls { margin: 10px 0; }
.models { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.model { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; background: var(--surface-2); }
.model.selected { border-color: var(--brand); background: var(--brand-soft); }
.model code { color: var(--muted); overflow-wrap: anywhere; text-align: start; }
.m-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.m-price { font-size: .85rem; }
.m-price small { color: var(--muted); }
.m-caps { display: flex; flex-wrap: wrap; gap: 4px; }
.m-h { font-size: .78rem; color: var(--muted); }
.m-h .off { color: var(--line-strong); }
.m-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 4px; }
.m-foot small { color: var(--muted); }

/* report (screen preview on light paper) */
.report-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.report-toolbar small { color: var(--muted); flex-basis: 100%; }
.report { background: var(--surface); max-width: 860px; margin: 0 auto; padding: 36px 40px; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0, 0, 0, .35); }
.r-header { display: flex; align-items: center; gap: 16px; border-bottom: 3px solid var(--brand); padding-bottom: 14px; margin-bottom: 16px; }
.r-logo { height: 54px; width: auto; max-width: 160px; object-fit: contain; }
.r-header h1 { font-size: 1.6rem; color: var(--brand); margin: 0; }
.r-header p { margin: 0; color: var(--muted); }
.r-info { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 20px; margin-bottom: 14px; }
.r-info div { display: flex; flex-direction: column; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.r-info span { font-size: .78rem; color: var(--muted); }
.r-disclaimer { background: var(--brand-soft); border-inline-start: 4px solid var(--brand); padding: 10px 14px; border-radius: 6px; font-size: .9rem; margin-bottom: 18px; }
.r-sec { margin-bottom: 22px; }
.r-sec > h2, .r-chart > h2 { font-size: 1.12rem; color: var(--brand); border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-bottom: 10px; }
.r-problem { white-space: pre-wrap; }
.r-kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.r-kpis div { background: var(--bg); border-radius: 8px; padding: 10px; text-align: center; }
.r-kpis b { display: block; font-size: 1.35rem; color: var(--brand); direction: ltr; }
.r-kpis span { font-size: .78rem; color: var(--muted); }
.r-charts { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
.r-interp p { text-align: justify; }
.r-cat { border-top: 3px solid var(--c); padding-top: 10px; margin-bottom: 18px; }
.r-cat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.r-cat-head h3 { color: var(--c); margin: 0; }
.r-cat-nums { display: flex; gap: 14px; font-size: .85rem; color: var(--muted); }
.r-cat-nums b { color: var(--ink); direction: ltr; display: inline-block; }
.r-sum { font-size: .82rem; color: var(--muted); }
.r-trait { margin-bottom: 10px; break-inside: avoid; }
.r-trait-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.r-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.r-table th, .r-table td { border: 1px solid var(--line); padding: 5px 8px; text-align: start; vertical-align: top; }
.r-table th { background: var(--bg); font-weight: 600; }
.r-table th:last-child, .r-table td:last-child { width: 110px; white-space: nowrap; }
.r-table tr { break-inside: avoid; }
.ans-yes { color: var(--yes); font-weight: 700; }
.ans-no { color: var(--no); }
.ans-skip { color: var(--skip); }
.ans-none { color: var(--faint); }
.r-footer { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; text-align: center; font-size: .8rem; color: var(--muted); }

/* responsive */
@media (max-width: 1000px) {
  .assess-grid, .results-grid, .admin-grid, .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .adm-side { position: static; }
  .assess-side { display: none; }
  .ind-strip { display: block; }
  .settings-grid > .card:last-child { grid-column: auto; }
}
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .card { padding: 14px; }
  .header-inner { padding-block: 8px; }
  .brand-logo { height: 34px; }
  .nav { width: 100%; }
  .nav a { flex: 1; text-align: center; padding: 6px 8px; font-size: .9rem; }
  .sh-actions { width: 100%; }
  .sh-actions .btn { flex: 1; }
  /* The ⋯ menu gets its own full-width row; its list opens inside the screen instead of past the edge. */
  .sh-actions .menu { flex: 1 1 100%; }
  .sh-actions .menu summary { width: 100%; }
  .sh-actions .menu-list { inset-inline-end: auto; inset-inline-start: 0; width: 100%; min-width: 0; }
  .qn { flex-direction: column; align-items: stretch; }
  .qn-text { flex: none; }
  .ans { width: 100%; }
  .ans-btn { flex: 1; }
  .report { padding: 18px 14px; }
  .r-info, .r-charts { grid-template-columns: minmax(0, 1fr); }
  .r-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Key, provider and save button each take a full row so the key field stays usable. */
  .key-form { flex-direction: column; align-items: stretch; gap: 0; }
  .key-form select { width: 100%; }
  .key-form .btn { margin-top: 0; width: 100%; }
  .models { grid-template-columns: minmax(0, 1fr); }
}

/* print: only the report, on white paper */
@page {
  size: A4;
  margin: 14mm 13mm 16mm;
  @bottom-right { content: "\202B بَصَائِر - insight\202C"; font-family: 'IBM Plex Sans Arabic', Tahoma, sans-serif; font-size: 9pt; color: #667380; }
  @bottom-left { content: counter(page) " / " counter(pages); font-family: 'IBM Plex Sans Arabic', Tahoma, sans-serif; font-size: 9pt; color: #667380; }
}
@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  :root { color-scheme: light; --bg: #ffffff; }
  html, body { background: #fff; color: #1c2631; }
  body { font-size: 10.5pt; display: block; }
  .app-header, .app-footer, .toasts, .no-print { display: none !important; }
  main.wrap { padding: 0; max-width: none; }
  body:not([data-route="report"]) main { display: none; }
  .report { border: 0; box-shadow: none; padding: 0; max-width: none; border-radius: 0; }
  .r-sec > h2, .r-chart > h2, .r-cat-head { break-after: avoid; }
  .r-details { break-before: page; }
  .r-charts, .r-kpis, .gd-cat, .r-trait, .r-disclaimer, .reminder { break-inside: avoid; }
  .r-cat-head { break-inside: avoid; }
  p { orphans: 3; widows: 3; }
}
