:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --line: #dde3ea;
  --text: #17212b;
  --muted: #5d6b7a;
  --brand: #0f766e;
  --brand-2: #115e59;
  --brand-soft: #e2f3f1;
  --accent: #d97706;
  --accent-soft: #fdf1dc;
  --ok: #15803d;
  --ok-soft: #e3f5e8;
  --bad: #b91c1c;
  --bad-soft: #fbe5e5;
  --warn: #b45309;
  --warn-soft: #fdf0d8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .05);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  /* цвета предметов */
  --s-math: #2563eb; --s-reading: #9333ea; --s-physics: #0891b2;
  --s-chemistry: #db2777; --s-geography: #16a34a; --s-biology: #ca8a04;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 var(--font); -webkit-text-size-adjust: 100%; }
img { max-width: 100%; height: auto; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.1rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ---------- шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 56px;
}
.topbar .brand { font-weight: 700; color: var(--brand-2); display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who { color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo-dot { width: 28px; height: 28px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: .8rem; flex: none; }
.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.lang button { border: 0; background: transparent; padding: 6px 10px; font: inherit; font-size: .8rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.lang button.on { background: var(--brand); color: #fff; }

/* ---------- элементы ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); padding: 9px 16px; border-radius: 10px; font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; min-height: 40px; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn.lg { padding: 14px 28px; font-size: 1.1rem; min-height: 52px; border-radius: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
.field + .field { margin-top: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 18px; height: 18px; }
.err { color: var(--bad); background: var(--bad-soft); border-radius: 8px; padding: 8px 12px; font-size: .9rem; }
.note { background: var(--brand-soft); border-radius: 10px; padding: 12px 14px; }
.note.warn { background: var(--warn-soft); }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.brand { background: var(--brand-soft); color: var(--brand-2); border-color: transparent; }

/* ---------- вход ---------- */
.login-wrap { min-height: calc(100vh - 56px); display: flex; flex-direction: column; align-items: center; padding: 28px 16px; }
.school-title { text-align: center; margin: 12px 0 24px; }
.school-title h1 { font-size: clamp(1.4rem, 4vw, 2rem); color: var(--brand-2); }
.school-title p { margin: 0; color: var(--muted); }
.login-card { width: 100%; max-width: 420px; }

/* ---------- главная ученика ---------- */
.subjects { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.subject-card { display: flex; gap: 14px; align-items: center; padding: 16px; border-left: 5px solid var(--sc, var(--brand)); }
.subject-ico { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.4rem; background: color-mix(in srgb, var(--sc) 14%, white); flex: none; }
.group-label { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
.rules li + li { margin-top: 6px; }
.start-box { text-align: center; padding: 28px 20px; }

/* ---------- тест ---------- */
body.testing { user-select: none; -webkit-user-select: none; background: #eef2f5; }
body.testing textarea { user-select: text; -webkit-user-select: text; }
.test-head { position: sticky; top: 0; z-index: 40; background: var(--surface); border-bottom: 1px solid var(--line); }
.test-head .bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem; padding: 6px 12px; border-radius: 8px; background: var(--brand-soft); color: var(--brand-2); white-space: nowrap; }
.timer.low { background: var(--bad-soft); color: var(--bad); }
.save-state { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.save-state.bad { color: var(--bad); font-weight: 600; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 0 12px 8px; scrollbar-width: thin; }
.tab {
  flex: none; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 7px 12px;
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; color: var(--text); display: flex; gap: 8px; align-items: center;
  border-bottom: 3px solid var(--sc, var(--line));
}
.tab.on { background: var(--sc); color: #fff; border-color: var(--sc); }
.tab .cnt { font-size: .75rem; font-weight: 700; opacity: .85; }
.qnav { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.qnav button {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font: inherit; font-weight: 700; cursor: pointer;
}
.qnav button.done { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-2); }
.qnav button.cur { outline: 2px solid var(--accent); outline-offset: 1px; }
.test-body { max-width: 1400px; margin: 0 auto; padding: 14px 12px 90px; display: grid; gap: 14px; grid-template-columns: 1fr; }
.test-body.split { grid-template-columns: 1fr; }
@media (min-width: 1000px) {
  .test-body.split { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; }
  .test-body.split .stimulus { position: sticky; top: 130px; max-height: calc(100vh - 150px); overflow: auto; }
}
.stimulus { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.stimulus .st-title { font-weight: 700; color: var(--brand-2); margin-bottom: 8px; }
.qcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.qhead { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 10px; }
.qnum { font-weight: 800; color: var(--muted); font-size: .9rem; text-transform: uppercase; letter-spacing: .03em; }
.hint { font-size: .9rem; color: var(--warn); background: var(--warn-soft); border-radius: 8px; padding: 8px 12px; margin: 12px 0; }
.rich { overflow-wrap: anywhere; }
.rich table { border-collapse: collapse; margin: 10px 0; max-width: 100%; display: block; overflow-x: auto; }
.rich td, .rich th { border: 1px solid #9aa7b4; padding: 6px 10px; vertical-align: top; overflow-wrap: normal; word-break: normal; hyphens: auto; }
.rich th { background: var(--surface-2); }
.rich p { margin: .5em 0; }
.rich .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.opts { display: grid; gap: 8px; margin-top: 8px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; border: 1.5px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer;
  background: var(--surface); transition: border-color .12s, background .12s;
}
.opt:hover { border-color: #b8c4cf; }
.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.disabled { opacity: .5; cursor: not-allowed; }
.opt input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--brand); }
.opt .letter { font-weight: 800; color: var(--muted); min-width: 1.2em; }
.opt .otext { flex: 1; min-width: 0; }
.opt img, .match-row img { max-height: 180px; display: block; margin-top: 6px; }
.match { display: grid; gap: 10px; }
.match-row { display: grid; grid-template-columns: 1fr; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
@media (min-width: 700px) { .match-row { grid-template-columns: 1fr 1fr; align-items: center; } }
.match-legend { display: grid; gap: 6px; margin: 10px 0; padding: 12px; background: var(--surface-2); border-radius: 10px; }
.open-input { min-height: 140px; font-size: 1rem; }
.test-foot {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line);
  padding: 10px 12px; display: flex; gap: 10px; justify-content: space-between; z-index: 40;
}

/* ---------- модальные окна ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 1000; display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; padding: 22px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); margin: auto 0; }
.modal.wide { max-width: 1320px; }
.modal h2 { margin-bottom: 12px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.gate { position: fixed; inset: 0; background: var(--bg); z-index: 900; display: flex; align-items: center; justify-content: center; padding: 20px; }
.gate .card { max-width: 520px; text-align: center; }
.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 2000; font-size: .95rem; box-shadow: var(--shadow); max-width: 90vw; }

/* ---------- результаты ---------- */
.score-big { font-size: 2.6rem; font-weight: 800; color: var(--brand-2); line-height: 1; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-size: 1.6rem; font-weight: 800; }
.kpi .l { color: var(--muted); font-size: .85rem; }
.pbar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.pbar > i { display: block; height: 100%; background: var(--sc, var(--brand)); }
.res-subj { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.res-q { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--surface); }
.res-q + .res-q { margin-top: 10px; }
.res-q.ok { border-left: 5px solid var(--ok); }
.res-q.bad { border-left: 5px solid var(--bad); }
.res-q.part { border-left: 5px solid var(--warn); }
.res-q.pend { border-left: 5px solid var(--muted); }
.ans-line { margin-top: 8px; padding: 8px 12px; border-radius: 8px; background: var(--surface-2); }
.ans-line.good { background: var(--ok-soft); }
.teacher-note { margin-top: 8px; font-size: .9rem; font-style: italic; color: var(--muted); }
details.stim { margin: 8px 0; }
details.stim summary { cursor: pointer; color: var(--brand); font-weight: 600; }

/* ---------- кабинет ---------- */
.staff-tabs { display: flex; gap: 4px; overflow-x: auto; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 56px; z-index: 45; }
.staff-tabs button { border: 0; background: transparent; padding: 12px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.staff-tabs button.on { color: var(--brand-2); border-bottom-color: var(--brand); }
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); max-height: 70vh; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.grid th { background: #eef2f6; position: sticky; top: 0; z-index: 2; cursor: pointer; font-weight: 700; }
table.grid tfoot td { background: #f1f5f9; font-weight: 700; position: sticky; bottom: 0; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tr:hover td { background: #f8fafc; }
.heat { display: inline-block; min-width: 52px; text-align: center; padding: 2px 6px; border-radius: 6px; font-weight: 700; }
.chart-box { position: relative; height: 300px; }
.charts { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 900px) { .charts { grid-template-columns: 1fr 1fr; } }
.unit { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.unit + .unit { margin-top: 14px; }
.unit-head { display: flex; gap: 8px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; flex-wrap: wrap; }
.unit-stim { padding: 12px 14px; max-height: 260px; overflow: auto; border-bottom: 1px dashed var(--line); }
.q-item { display: flex; gap: 10px; padding: 12px 14px; align-items: flex-start; border-bottom: 1px solid var(--line); }
.q-item:last-child { border-bottom: 0; }
.q-item .qprev { flex: 1; min-width: 0; max-height: 120px; overflow: hidden; }
.opt-edit { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: start; padding: 8px; border: 1px solid var(--line); border-radius: 10px; }
.opt-edit + .opt-edit { margin-top: 8px; }
.opt-edit textarea { min-height: 44px; }
.opt-edit .tools { display: flex; flex-direction: column; gap: 4px; }
.editor-grid { display: grid; grid-template-columns: 1fr; gap: 18px; }
@media (min-width: 1100px) { .editor-grid { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); } }
.preview-box { background: #eef2f5; border-radius: var(--radius); padding: 12px; }
.tex-btns { display: flex; flex-wrap: wrap; gap: 4px; }
.tex-btns button { min-width: 42px; }
.tex-preview { min-height: 60px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; background: var(--surface-2); font-size: 1.2rem; overflow-x: auto; }
.thumb { max-height: 60px; border-radius: 6px; border: 1px solid var(--line); }
.cards-print { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.pcard { border: 1px dashed #999; padding: 14px; page-break-inside: avoid; break-inside: avoid; font-size: 14px; }
.pcard .pschool { font-size: 11px; color: #555; }
.pcard .pname { font-weight: 700; font-size: 15px; margin: 4px 0 8px; }
.pcard .pval { font-family: Consolas, monospace; font-size: 16px; font-weight: 700; }
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .container { padding: 0; max-width: none; }
}
@media (max-width: 600px) {
  .card { padding: 16px; }
  .topbar .who { display: none; }
  .test-foot .btn { flex: 1; }
}

/* ---------- редактор вопросов (как в конспектах myent.kz) ---------- */
.ed-step { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.ed-step + .ed-step { margin-top: 12px; }
.ed-h { font-weight: 800; margin-bottom: 8px; color: var(--brand-2); }
.ed-prev { align-self: start; }
@media (min-width: 1100px) { .ed-prev { position: sticky; top: 0; max-height: calc(100vh - 160px); overflow: auto; } }
.type-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.type-tile { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; text-align: left; border: 2px solid var(--line); background: var(--surface);
  border-radius: 12px; padding: 10px 12px; font: inherit; cursor: pointer; }
.type-tile .ti { font-size: 1.3rem; line-height: 1; }
.type-tile.on { border-color: var(--brand); background: var(--brand-soft); }
.mdf { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; }
.mdf-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px; border-bottom: 1px solid var(--line); background: #f3f6f9; }
.mdf textarea { border: 0; border-radius: 0; min-height: 0; font-size: .95rem; line-height: 1.55; }
.mdf textarea:focus { outline: none; box-shadow: inset 0 0 0 2px var(--brand); }
.corr { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); padding: 4px 6px; border-radius: 8px; cursor: pointer; margin: 0; }
.corr b { font-size: 1rem; color: var(--text); }
.corr.on { background: var(--ok-soft); color: var(--ok); }
.corr input { width: 18px; height: 18px; accent-color: var(--ok); }
.rich img { max-height: 480px; border-radius: 6px; display: block; margin: 8px 0; }
.preview-banner { background: var(--accent-soft); color: #7a4400; padding: 8px 12px; font-size: .9rem; font-weight: 600; text-align: center; }
