:root {
  --bg: #f5f6f8; --card: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e2e5eb; --brand: #1f5fbf; --brand-ink: #fff;
  --ok: #1e7b45; --ok-bg: #e8f5ee; --err: #b42318; --err-bg: #fdecea; --warn: #8a5a00; --warn-bg: #fff6e0;
  --add: #e6f6ec; --rem: #fdecea; --mov: #e8f0fd; --hit: #fff3c4; --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; } h2 { font-size: 15px; margin: 0 0 8px; } h3 { font-size: 14px; margin: 12px 0 8px; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: #f0f2f5; padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--muted); font-weight: normal; } .small { font-size: 12px; } .pad { padding: 8px; } .hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
input, select, textarea, button, .btn { font: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #b8cdf0; border-color: var(--brand); }
button, .btn { cursor: pointer; display: inline-block; white-space: nowrap; }
button:hover, .btn:hover { background: #f3f5f8; text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.primary:hover, .btn.primary:hover { background: #194f9f; }
button.small, .btn.small { padding: 2px 7px; font-size: 12px; }
button.link { border: 0; background: none; color: var(--brand); padding: 2px 4px; }
.danger { color: var(--err) !important; }
label { display: block; font-size: 13px; color: var(--muted); }
label input, label select, label textarea { display: block; width: 100%; margin-top: 3px; color: var(--ink); }
label.inline { display: inline-flex; gap: 6px; align-items: center; } label.inline input { width: auto; margin: 0; }

header.top { display: flex; align-items: center; gap: 18px; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--ink); }
header nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
header nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); }
header nav a.on { background: #eaf0fb; color: var(--brand); }
.logout { margin: 0; }
main { max-width: 1200px; margin: 0 auto; padding: 18px 20px 60px; }
body.wide main { max-width: none; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; overflow-x: auto; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.login form > * { margin-bottom: 12px; } .login button { width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; } .row.wrap { flex-wrap: wrap; } .row form { margin: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; } @media (max-width: 900px) { .two { grid-template-columns: 1fr; } }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; align-items: end; }
.form-grid .full { grid-column: 1 / -1; }
.flash { padding: 10px 12px; border-radius: 6px; margin: 0 0 12px; background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); } .flash.warn { background: var(--warn-bg); color: var(--warn); }
.ok-line { color: var(--ok); margin: 4px 0 8px; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; color: var(--muted); font-size: 12px; }
.stat b { display: block; font-size: 18px; color: var(--ink); } .stat.on { border-color: var(--brand); }
table.grid { width: 100%; border-collapse: collapse; margin-top: 10px; }
table.grid th, table.grid td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.grid input { padding: 3px 6px; }
.pill { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 99px; background: #eef0f4; color: var(--muted); }
.pill.published { background: #e8f0fd; color: var(--brand); } .pill.finalized { background: var(--ok-bg); color: var(--ok); } .pill.draft { background: var(--warn-bg); color: var(--warn); }
.changes { list-style: none; padding: 0; } .changes li { padding: 5px 8px; border-radius: 5px; margin-bottom: 4px; }
.changes .added { background: var(--add); } .changes .removed { background: var(--rem); } .changes .moved { background: var(--mov); }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---------- builder ---------- */
.builder-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.notes { background: var(--warn-bg); padding: 8px 12px; border-radius: 6px; margin-bottom: 10px; }
.panels { display: grid; grid-template-columns: minmax(300px, 1.1fr) minmax(220px, .7fr) minmax(380px, 1.4fr); gap: 12px; height: calc(100vh - 170px); min-height: 520px; }
@media (max-width: 1100px) { .panels { grid-template-columns: 1fr; height: auto; } .panel { height: 70vh; } }
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.panel-head { padding: 10px 12px 0; } .panel-body { overflow-y: auto; flex: 1; min-height: 0; margin: 0; padding: 0 8px 8px; }
.filters { padding: 8px 12px; display: grid; gap: 6px; } .filters input { width: 100%; } .filters select { max-width: 48%; flex: 1; padding: 4px 6px; }
.bulk { padding: 4px 12px 8px; border-bottom: 1px solid var(--line); }
.college { border-bottom: 1px solid var(--line); padding: 8px 4px; }
.college-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; margin-bottom: 4px; }
.choice { display: flex; gap: 6px; align-items: center; padding: 2px 4px; color: var(--ink); border-radius: 4px; cursor: pointer; }
.choice:hover { background: #f5f7fa; } .choice.in { color: var(--muted); } .choice input { width: auto; margin: 0; }
.tag { font-size: 11px; background: #eef0f4; border-radius: 4px; padding: 0 5px; color: var(--muted); }
.choice-list { list-style: none; } .choice-list li { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-bottom: 1px solid #f0f1f4; background: #fff; }
.choice-list li.empty { color: var(--muted); padding: 16px 8px; border: 0; }
.grip { cursor: grab; color: #aab; user-select: none; padding: 0 2px; }
.ranked li .pos { width: 30px; text-align: right; font-weight: 700; color: var(--brand); flex: none; }
.ranked li .what { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 0 6px; align-items: baseline; }
.ranked li .what > span:last-child { width: 100%; }
.ranked li .acts { display: flex; gap: 2px; align-items: center; flex: none; opacity: .55; } .ranked li:hover .acts { opacity: 1; }
.ranked li .moveto { width: 42px; padding: 2px 4px; font-size: 12px; }
.ranked li.locked { background: #f7f8fb; } .ranked li.locked .grip { cursor: not-allowed; color: #dde; }
.ranked li.hit { background: var(--hit); } .ranked li.bad, .pv li.bad { background: var(--err-bg); }
.ranked li .tick { width: auto; margin: 0; }
.sortable-ghost { opacity: .4; background: #e8f0fd !important; }
#validation { padding: 0 12px; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 25, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: min(860px, 100%); box-shadow: 0 10px 40px rgba(0,0,0,.2); display: flex; flex-direction: column; max-height: 92vh; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head .close { font-size: 22px; line-height: 1; }
.modal-body { padding: 14px 18px; overflow-y: auto; } .modal-body > div > * { margin-bottom: 10px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.tpl-opt { display: block; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px; color: var(--ink); cursor: pointer; }
.tpl-opt input { display: inline; width: auto; }
.row-btn { display: block; width: 100%; text-align: left; margin-bottom: 4px; } .row-btn.on { border-color: var(--brand); background: #eef3fc; }
.copy-results { max-height: 220px; overflow-y: auto; }
ol.pv { max-height: 50vh; overflow-y: auto; padding-left: 36px; margin: 0; } ol.pv li { padding: 2px 0; }
ol.pv li.pv-block { list-style: none; margin: 10px 0 4px -26px; font-weight: 600; color: var(--brand); } ol.pv li.pv-block.empty { color: var(--warn); }
.rules-modal .rules-pv { position: sticky; bottom: 0; background: #fff; padding: 8px 0; border-top: 1px solid var(--line); }
.rules-only .blocks { display: none; }

/* ---------- rule editor ---------- */
.block { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; background: #fbfcfd; }
.block-head { display: flex; gap: 6px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.block-head .num { font-weight: 700; color: var(--brand); } .block-head .bname { font-weight: 600; flex: 1; }
.block-body { padding: 8px 10px; }
.sec { margin-bottom: 10px; } .sub { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.toggles { display: flex; flex-wrap: wrap; gap: 4px; } .toggles.compact { max-height: 82px; overflow-y: auto; }
.tog { padding: 2px 8px; font-size: 12px; border-radius: 99px; } .tog.on { background: #e3ecfb; border-color: var(--brand); color: var(--brand); }
.picker .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.chip { background: #eef3fc; border-radius: 99px; padding: 1px 4px 1px 9px; font-size: 12px; }
.chip button { border: 0; background: none; padding: 0 4px; cursor: pointer; }
.pick-search { position: relative; } .pick-search input { width: 100%; }
.pick-results { position: absolute; z-index: 20; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.12); max-height: 260px; overflow-y: auto; }
.pick-results button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid #f1f2f5; border-radius: 0; }
.overrides, .global { margin-top: 8px; } .ov { border: 1px dashed var(--line); border-radius: 6px; padding: 8px; margin-bottom: 6px; background: #fff; }
.ov-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.pl { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 0; border-bottom: 1px solid #f0f1f4; } .pl .n { width: 64px; }
.tpl-layout { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.tpl-layout .preview { position: sticky; top: 10px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; }
.tpl-layout .preview ol { max-height: none; flex: 1; }
@media (max-width: 1000px) { .tpl-layout { grid-template-columns: 1fr; } .tpl-layout .preview { position: static; } }

/* ---------- student ---------- */
.student { max-width: 760px; margin: 0 auto; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.summary .label { display: block; font-size: 12px; color: var(--muted); }
.student #s-filter { width: 100%; margin: 6px 0 10px; }
.s-list { list-style: none; padding: 0; margin: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.s-list li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-bottom: 1px solid #f0f1f4; }
.s-list .pos { font-weight: 700; color: var(--brand); min-width: 28px; text-align: right; }
.s-list .what { flex: 1; min-width: 0; } .s-list .what b, .s-list .what span { display: block; } .s-list .what span { color: var(--muted); }
@media (max-width: 600px) { main { padding: 12px; } header.top { padding: 8px 12px; gap: 8px; } .s-list code { display: none; } }
/* Phase 2: change requests */
.pill.pending { background: var(--warn-bg); color: var(--warn); } .pill.approved { background: var(--ok-bg); color: var(--ok); }
.pill.partially_approved { background: #e8f0fd; color: var(--brand); } .pill.rejected { background: #fdecec; color: #b42318; }
.op-add { color: var(--ok); } .op-remove { color: #b42318; } .op-move { color: var(--brand); }
.diff-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.diff-cols ol { margin: 0; padding-left: 0; list-style: none; font-size: 13px; max-height: 70vh; overflow: auto; }
.diff-cols li { padding: 3px 6px; border-bottom: 1px solid #f0f1f4; display: flex; gap: 8px; }
.diff-cols li .pos { width: 30px; color: var(--muted); text-align: right; flex: none; }
.diff-cols li.changed { background: #fff8e6; } .diff-cols li.added { background: var(--ok-bg); } .diff-cols li.removed { background: #fdecec; text-decoration: line-through; }
.items td:first-child { width: 28px; }
.s-edit li { gap: 6px; } .s-edit .tools { display: flex; gap: 4px; flex: none; }
.s-edit .tools button { padding: 4px 8px; min-width: 32px; }
.s-edit li.moved { background: #fff8e6; } .s-edit li.new { background: var(--ok-bg); }
.s-bar { position: sticky; bottom: 0; z-index: 5; background: #fff; border-top: 1px solid #e3e6ec; padding: 10px 0; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.s-removed { margin-top: 12px; }
@media (max-width: 700px) { .diff-cols { grid-template-columns: 1fr; } }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; } .tabs a { padding: 4px 10px; border-radius: 99px; background: #eef0f4; color: var(--ink); font-size: 13px; }
.tabs a.on { background: var(--brand); color: #fff; }
@media (max-width: 600px) { .s-bar #s-summary { flex-basis: 100%; } .s-edit .tools button { padding: 4px 6px; min-width: 30px; } }
/* Questionnaire */
.q-two { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.q-preview { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; }
.q-form .q { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.q-form .q.sub { margin-left: 18px; border-left: 3px solid var(--brand); }
.q-form .q h3 { margin: 0 0 4px; font-size: 14px; } .q-form .q .help { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.q-form .opts { display: flex; flex-direction: column; gap: 6px; } .q-form .opts.inline { flex-direction: row; flex-wrap: wrap; gap: 6px 14px; }
.q-form label.opt { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; } .q-form label.opt input { margin-top: 3px; }
.q-form .ord { display: inline-block; min-width: 18px; font-weight: 700; color: var(--brand); }
.q-form .tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 0 6px; margin-left: 4px; }
.q-form .row-edit { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.q-form .ex { background: #f7f8fa; border-radius: 6px; padding: 6px 8px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.q-issue { padding: 6px 8px; border-radius: 6px; margin: 4px 0; font-size: 13px; }
.q-issue.ask { background: var(--warn-bg); color: var(--warn); } .q-issue.review { background: #e8f0fd; color: var(--brand); } .q-issue.info { background: #f2f3f5; color: var(--muted); }
.q-preview ol { padding-left: 0; list-style: none; font-size: 12px; } .q-preview li { padding: 2px 0; border-bottom: 1px solid #f0f1f4; display: flex; gap: 6px; }
.q-preview li .pos { width: 28px; text-align: right; color: var(--muted); flex: none; } .q-preview .blk { font-weight: 700; margin-top: 8px; color: var(--brand); }
@media (max-width: 900px) { .q-two { grid-template-columns: 1fr; } .q-preview { position: static; max-height: none; } }
/* questionnaire form (questionnaire.js) */
.q-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px 12px; margin: 0 0 10px; min-width: 0; }
.q-item legend { font-weight: 700; padding: 0 4px; }
.q-item p { margin: 0 0 8px; }
.q-no { display: inline-block; min-width: 26px; text-align: center; background: var(--mov); color: var(--brand); border-radius: 99px; font-size: 12px; padding: 0 6px; }
.q-opts { display: flex; flex-direction: column; gap: 6px; } .q-opts.cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr)); gap: 4px 12px; }
.q-opt { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; color: var(--ink); font-size: 14px; min-width: 0; } .q-opt input { width: auto; margin: 3px 0 0; flex: none; }
.q-ordered .chips, .q-form .picker .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.q-form .chip button { border: 0; background: none; padding: 0 3px; }
.q-sub { border-left: 3px solid var(--line); padding: 6px 0 6px 10px; margin: 8px 0; display: flex; flex-direction: column; gap: 6px; }
.q-row { flex-direction: row; flex-wrap: wrap; align-items: center; }
.q-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--ink); } .q-inline select, .q-inline input { width: auto; max-width: 100%; margin: 0; }
.q-form select { max-width: 100%; } .q-form textarea { width: 100%; }
.q-adv { border: 1px dashed var(--brand); border-radius: var(--radius); padding: 8px 12px; margin-top: 14px; }
.q-adv > summary { cursor: pointer; font-weight: 700; color: var(--brand); margin-bottom: 8px; }
.q-follow { margin-top: 12px; } .q-follow .q-issue { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.q-apply { margin: 10px 0; }
