:root {
  --brand: #1f5fbf;
  --ink: #1d2433;
  --muted: #5b6475;
  --line: #dfe3ea;
  --bg: #f5f7fa;
  --card: #ffffff;
  --ok: #1d7a46;
  --warn: #9a6200;
  --bad: #b3261e;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; line-height: 1.5; font-size: 15px; background: var(--bg); }
a { color: var(--brand); }
h1 { font-size: 1.6rem; margin: 0.2em 0 0.5em; }
h2 { font-size: 1.15rem; margin: 0 0 0.6em; }
h3 { font-size: 1rem; margin: 1.2em 0 0.5em; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
code.warn { background: #fff1d6; }
small, .muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.87rem; font-weight: normal; display: block; margin: 2px 0 4px; }
.warn { color: var(--warn); }
.error { color: var(--bad); }
.ok { color: var(--ok); }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13px; }

.topbar { display: flex; align-items: center; gap: 20px; padding: 10px 24px; background: var(--card); border-bottom: 3px solid var(--brand); flex-wrap: wrap; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.1rem; }
.logo img { max-height: 34px; max-width: 140px; }
.logo small { font-weight: 500; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.mainnav a { padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--ink); }
.mainnav a.active, .mainnav a:hover { background: color-mix(in srgb, var(--brand) 12%, white); color: var(--brand); }
.who { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; }
.who small { display: block; line-height: 1.1; }
.impersonation { background: #fff1d6; padding: 8px 24px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.page { max-width: 1180px; margin: 0 auto; padding: 24px; }
.foot { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 24px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.narrow { max-width: 420px; margin: 40px auto; }
.narrowish { max-width: 680px; }
.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 + section { margin-top: 20px; }
.span2 { grid-column: span 2; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack.tight { gap: 4px; }
.inline { display: inline; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.92rem; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #c8ced8; border-radius: 7px; background: #fff; color: var(--ink); min-width: 0; width: 100%; }
label.check input, input[type="radio"], input[type="checkbox"] { width: auto; }
input[type="color"] { padding: 2px; height: 38px; width: 70px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
textarea { resize: vertical; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 0; }
fieldset.plain { border: 0; padding: 0; }
fieldset.plain:disabled { opacity: 0.85; }
legend { font-weight: 600; padding: 0 6px; }
.w5 { width: 80px; } .w6 { width: 96px; } .w10 { width: 160px; } .w12 { width: 200px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 7px; border: 1px solid var(--brand); color: var(--brand); background: #fff; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: color-mix(in srgb, var(--brand) 8%, white); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: var(--line); color: var(--ink); }
.btn.light { background: #fff; border-color: #ccc; color: var(--ink); }
.btn.danger { border-color: var(--bad); color: #fff; background: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 0.85rem; }
.btn.big { padding: 12px 26px; font-size: 1.05rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font: inherit; font-size: 0.85rem; text-decoration: underline; }
.actions { white-space: nowrap; text-align: right; }
.actions > * { margin-left: 4px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; word-break: break-word; }
.flash.ok { background: #e7f5ec; border-color: #b6e0c5; color: #14532d; }
.flash.error { background: #fdecea; border-color: #f3c0bb; color: #7f1d1d; }
.flash.info { background: #eaf1fd; border-color: #c2d5f5; color: #1e3a8a; }

table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.02em; }
td.num, th.num { text-align: right; }
td.neg { color: var(--bad); } td.pos { color: var(--ok); }
.tablewrap { overflow-x: auto; }
table.edit td { padding: 4px; border-bottom: 0; }
table.edit textarea { min-height: 38px; }
table.compact { width: auto; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
table.heat td.num[style] { background: color-mix(in srgb, var(--brand) calc(var(--v) * 0.55%), white); }

.pill { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #eef1f5; color: var(--muted); text-transform: capitalize; }
.pill.active, .pill.published, .pill.submitted { background: #e7f5ec; color: var(--ok); }
.pill.draft, .pill.in_progress { background: #eaf1fd; color: #1e40af; }
.pill.in_review { background: #fff1d6; color: var(--warn); }
.pill.suspended, .pill.disabled, .pill.retired, .pill.closed { background: #fdecea; color: var(--bad); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi b { display: block; font-size: 1.7rem; line-height: 1.1; }
.kpi span { color: var(--muted); font-size: 0.85rem; }
.kpi.warnbox { border-color: #f0c36d; background: #fffaf0; }
.hbar { display: grid; grid-template-columns: 180px 1fr 50px; gap: 10px; align-items: center; margin: 6px 0; }
.track { height: 10px; background: #e6e9ef; border-radius: 99px; overflow: hidden; }
.fill { height: 100%; background: var(--brand); border-radius: 99px; }
.progress { height: 6px; background: #e6e9ef; border-radius: 99px; overflow: hidden; width: 140px; }
.progress div { height: 100%; background: var(--brand); }
.chips { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li { border: 1px solid var(--line); border-radius: 99px; padding: 4px 12px; }
.filter { margin-bottom: 14px; }
.filter input { width: 280px; }
.filter select, .filter label { width: auto; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.builder { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; align-items: start; }
.builder-side { position: sticky; top: 16px; }
.counts { list-style: none; padding: 0; margin: 0 0 10px; }
.problems { padding-left: 18px; font-size: 0.85rem; max-height: 380px; overflow: auto; }
.section-edit { margin-bottom: 4px; }
.choices { display: grid; gap: 10px; }
.choice { flex-direction: row; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-weight: normal; }
.choice input { margin-top: 4px; }
.choice select { width: auto; padding: 2px 6px; }
.checklist { max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-top: 8px; display: grid; gap: 4px; }
details.danger { margin-top: 20px; border: 1px solid #f3c0bb; border-radius: 8px; padding: 10px 14px; }
details.danger summary { cursor: pointer; color: var(--bad); font-weight: 600; }
details.mail { border-bottom: 1px solid var(--line); padding: 8px 0; }
.mailbody { padding: 10px; background: #fafbfc; border-radius: 6px; margin-top: 6px; }
.auth h1 { font-size: 1.3rem; }
.authlogo { max-height: 50px; margin-bottom: 10px; }

.report-head { display: flex; gap: 16px; align-items: center; border-bottom: 3px solid var(--brand); padding-bottom: 12px; margin-bottom: 14px; }
.report-logo { max-height: 48px; max-width: 150px; }
.report h3 { color: var(--brand); }
.score { margin: 14px 0; }
.score.child { margin-left: 22px; }
.score-top { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.score-name { font-weight: 600; }
.score.child .score-name { font-weight: 500; }
.score-val { color: var(--muted); font-size: 0.9rem; }
.narrative { margin: 6px 0 0; }
.prose { white-space: pre-line; }
.answer { border-left: 3px solid var(--line); padding-left: 10px; margin: 10px 0; }

/* Test player */
.player-body { background: #fff; }
.player-bar { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 24px; border-bottom: 3px solid var(--brand); background: #fff; flex-wrap: wrap; }
.player-status { display: flex; gap: 14px; align-items: center; font-size: 0.9rem; color: var(--muted); }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); background: #eef1f5; padding: 4px 10px; border-radius: 6px; }
.timer.low { background: #fdecea; color: var(--bad); }
.player { max-width: 760px; margin: 0 auto; padding: 24px; }
.sec-title { margin-top: 10px; }
.q { border: 0; padding: 0; margin: 0 0 28px; }
.q legend { padding: 0; margin-bottom: 14px; font-weight: normal; }
.qnum { display: block; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.qtext { font-size: 1.15rem; white-space: pre-line; }
.opts, .likert { display: grid; gap: 8px; }
.opts label, .likert label { flex-direction: row; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; font-weight: normal; cursor: pointer; }
.opts label:has(input:checked), .likert label:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, white); }
.likert { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.likert label { flex-direction: column; text-align: center; gap: 6px; font-size: 0.9rem; }
.player-nav { display: none; }
.player.paged .player-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 10px 0 20px; }
.palette { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.palette button { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--line); background: #fff; font-size: 0.8rem; cursor: pointer; }
.palette button.done { background: color-mix(in srgb, var(--brand) 18%, white); border-color: transparent; }
.palette button.cur { outline: 2px solid var(--brand); }
.submit-row { border-top: 1px solid var(--line); padding-top: 16px; }

@media (max-width: 600px) {
  .player.paged .player-nav { flex-wrap: wrap; }
  .palette { order: -1; width: 100%; }
  .player { padding: 16px; }
}
@media (max-width: 860px) {
  .grid2, .grid3, .builder { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .builder-side { position: static; }
  .page { padding: 16px; }
  .topbar { padding: 10px 16px; gap: 10px; }
  .mainnav { order: 3; flex: 1 1 100%; }
  .who { margin-left: auto; }
  .hbar { grid-template-columns: 110px 1fr 40px; }
  .filter input { width: 100%; }
}
@media print {
  .topbar, .foot, .pagehead .btn, .btn { display: none !important; }
  body, .card { background: #fff; border: 0; }
}
