:root {
  --bg: #f3efe6;
  --bg2: #e8e1d4;
  --ink: #1c2430;
  --muted: #5c6673;
  --card: #fffdf8;
  --line: #d5cdbe;
  --accent: #0f6a5a;
  --accent2: #184e77;
  --warn: #9a3412;
  --ok: #166534;
  --bad: #991b1b;
  --shadow: 0 10px 30px rgba(28, 36, 48, 0.08);
  --radius: 16px;
  --font: "Segoe UI", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, #f7f1e2 0%, transparent 40%),
    radial-gradient(circle at 90% 10%, #dceee8 0%, transparent 35%),
    linear-gradient(180deg, var(--bg), var(--bg2));
  min-height: 100vh;
}

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

.wrap { width: min(1100px, calc(100% - 2rem)); margin: 0 auto; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 1rem 0 1.25rem;
}
.brand { font-weight: 800; font-size: 1.25rem; letter-spacing: 0.02em; color: var(--ink); }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.35rem 0.75rem; border-radius: 999px;
  background: rgba(255,255,255,0.7); border: 1px solid var(--line); font-size: 0.9rem;
}

.hero, .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero { padding: 1.5rem; margin-bottom: 1.25rem; }
.hero h1 { margin: 0 0 0.4rem; font-size: clamp(1.5rem, 3vw, 2rem); }
.hero p { margin: 0; color: var(--muted); }

.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.card { padding: 1.1rem 1.2rem; }
.card h2, .card h3 { margin: 0 0 0.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.92rem; }

.btn {
  display: inline-block; border: 0; cursor: pointer;
  background: var(--accent); color: white; font-weight: 700;
  padding: 0.65rem 1rem; border-radius: 12px; font-size: 0.95rem;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; }
.btn.secondary { background: var(--accent2); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.warn { background: var(--warn); }
.btn.block { display: block; width: 100%; text-align: center; }

.flash {
  padding: 0.8rem 1rem; border-radius: 12px; margin-bottom: 1rem;
  border: 1px solid var(--line); background: #fff;
}
.flash.ok { border-color: #86efac; background: #f0fdf4; color: var(--ok); }
.flash.err { border-color: #fecaca; background: #fef2f2; color: var(--bad); }

.login-box { max-width: 420px; margin: 4rem auto; padding: 1.5rem; }

body.page-login {
  background:
    linear-gradient(105deg, rgba(12, 28, 32, 0.72) 0%, rgba(12, 28, 32, 0.35) 42%, rgba(12, 28, 32, 0.18) 100%),
    url("../img/login-study-bg.jpg") center / cover no-repeat fixed;
  color: #f4f7f6;
}
body.page-login .wrap {
  width: min(1100px, calc(100% - 2rem));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding: 1.5rem 0;
}
body.page-login .flash {
  width: min(380px, 100%);
  margin: 0 0 0.75rem auto;
}
.login-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
  gap: 2rem;
  align-items: center;
}
.login-copy {
  max-width: 22rem;
  padding: 0.25rem 0;
}
.login-brand {
  margin: 0;
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  font-size: clamp(2.4rem, 5vw, 3.4rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: #f7faf9;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.25);
}
.login-brand span { color: #7dcec0; }
.login-tag {
  margin: 0.7rem 0 0;
  color: rgba(244, 247, 246, 0.82);
  font-size: 1.02rem;
  letter-spacing: 0.01em;
}
body.page-login .login-box {
  margin: 0 0 0 auto;
  width: 100%;
  background: rgba(255, 252, 247, 0.96);
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(6px);
}
body.page-login .login-box h1 {
  margin: 0 0 0.35rem;
  font-size: 1.55rem;
}
.login-actions { margin-top: 1.2rem; }

@media (max-width: 760px) {
  .login-stage {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }
  body.page-login .login-box,
  body.page-login .flash {
    margin-left: 0;
    margin-right: 0;
  }
  .login-brand { font-size: 2.2rem; }
}
label { display: block; margin: 0.8rem 0 0.3rem; font-weight: 600; }
input[type=text], input[type=password], input[type=file], textarea, select {
  width: 100%; padding: 0.7rem 0.8rem; border-radius: 12px;
  border: 1px solid var(--line); background: #fff; font: inherit;
}
textarea { min-height: 110px; resize: vertical; }

.q {
  border: 1px solid var(--line); border-radius: 14px; padding: 1rem;
  margin: 1rem 0; background: #fffcf7;
}
.q .meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.4rem; }
.choices label { font-weight: 500; display: flex; gap: 0.5rem; align-items: flex-start; margin: 0.45rem 0; }
.choices input { width: auto; margin-top: 0.25rem; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.65rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.badge {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px;
  font-size: 0.8rem; font-weight: 700; background: #e2e8f0;
}
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.wait { background: #ffedd5; color: var(--warn); }
.badge.done { background: #dbeafe; color: var(--accent2); }

.photo-grid { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.photo-grid img {
  width: 100%; height: 160px; object-fit: cover; border-radius: 12px;
  border: 1px solid var(--line); background: #eee;
}
.file-list { margin: 0.5rem 0 0; padding-left: 1.35rem; }
.file-list li { margin: 0.45rem 0; line-height: 1.4; }

/* Формулы KaTeX — читаемые дроби и корни */
.katex { font-size: 1.12em; }
.q p strong .katex,
.q-prompt .katex { font-size: 1.18em; }
.q .katex-display { margin: 0.6rem 0; overflow-x: auto; }
.choices label .katex { font-size: 1.12em; }
.feedback-math .katex-display {
  margin: 0.45rem 0;
  overflow-x: auto;
  text-align: left;
}
.feedback-math .katex { font-size: 1.15em; }
.feedback-box .feedback-math { line-height: 1.55; }
.katex .frac-line { border-bottom-width: 0.06em; }

/* Зона вставки фото из буфера */
.paste-zone {
  margin-top: 0.6rem;
  padding: 1rem 1.1rem;
  border: 2px dashed #0f6a5a;
  border-radius: 14px;
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(15, 106, 90, 0.06),
      rgba(15, 106, 90, 0.06) 8px,
      rgba(15, 106, 90, 0.12) 8px,
      rgba(15, 106, 90, 0.12) 16px
    ),
    #e7f3ef;
  cursor: pointer;
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(15, 106, 90, 0.15);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.paste-zone:hover, .paste-zone.paste-active {
  border-color: #0a4f43;
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(15, 106, 90, 0.1),
      rgba(15, 106, 90, 0.1) 8px,
      rgba(15, 106, 90, 0.18) 8px,
      rgba(15, 106, 90, 0.18) 16px
    ),
    #d8eee8;
  box-shadow: inset 0 0 0 1px rgba(15, 106, 90, 0.25), 0 0 0 3px rgba(15, 106, 90, 0.12);
}
.paste-zone.has-image {
  border-style: solid;
  background: #eef8f5;
}
.paste-zone p { margin: 0.25rem 0; color: #0f3d36; }
.paste-zone .small.muted { color: #3d6b62 !important; }
.paste-preview {
  display: block;
  margin-top: 0.6rem;
  max-width: 100%;
  max-height: 220px;
  border-radius: 10px;
  border: 1px solid #9bc4bb;
  object-fit: contain;
  background: #fff;
}
.photo-upload input[type=file] {
  margin-bottom: 0.45rem;
}
.paste-actions {
  display: flex !important;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid rgba(15, 106, 90, 0.25);
}
.paste-actions .btn {
  padding: 0.55rem 0.9rem;
  font-size: 0.92rem;
  font-weight: 700;
}
.q-figure {
  margin: 0.75rem 0 1rem;
  padding: 0.6rem;
  background: #fff;
  border: 1px solid var(--line, #ddd);
  border-radius: 10px;
  max-width: 520px;
}
.q-figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
}
.q-figure figcaption {
  margin-top: 0.4rem;
}

/* Admin assign */
.assign-layout {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(0, 1.6fr) minmax(220px, 0.9fr);
  align-items: start;
}
.assign-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.assign-toolbar input[type=search] {
  width: min(320px, 100%);
  margin: 0;
}
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}
.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.th-sort {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.th-sort:hover { color: var(--accent); }
.th-sort.active { color: var(--accent); }
.th-sort-ind { font-size: 0.85em; opacity: 0.75; }
.assign-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}
.test-picker {
  max-height: min(62vh, 640px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f3efe6;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.test-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffcf7;
  padding: 0.15rem 0.25rem 0.45rem;
  box-shadow: 0 1px 0 rgba(28, 36, 48, 0.04);
}
.test-group > summary {
  cursor: pointer;
  font-weight: 750;
  font-size: 1.02rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.55rem;
  list-style: none;
  border-radius: 10px;
  background: rgba(15, 106, 90, 0.06);
}
.test-group > summary::-webkit-details-marker { display: none; }
.test-group > summary::before {
  content: "▸";
  color: var(--accent);
  font-size: 0.85em;
  width: 1em;
  flex-shrink: 0;
}
.test-group[open] > summary::before { content: "▾"; }
.test-group[open] > summary {
  background: rgba(15, 106, 90, 0.1);
  margin-bottom: 0.35rem;
}
.test-group .summary-label {
  flex: 1;
  min-width: 0;
}
/* классы — явно внутри предмета */
.test-group-body {
  padding: 0 0.35rem 0.25rem 1.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  border-left: 3px solid rgba(15, 106, 90, 0.28);
  margin: 0 0.4rem 0.25rem 0.85rem;
}
.test-grade {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.1rem 0.2rem 0.25rem;
}
.test-grade > summary {
  cursor: pointer;
  font-weight: 650;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.45rem;
  list-style: none;
  color: var(--muted);
}
.test-grade > summary::-webkit-details-marker { display: none; }
.test-grade > summary::before {
  content: "▸";
  font-size: 0.8em;
  width: 1em;
  flex-shrink: 0;
  color: var(--muted);
}
.test-grade[open] > summary::before { content: "▾"; }
.test-grade[open] > summary { color: var(--ink); }
/* список тестов — ещё глубже */
.test-list {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.15rem 0.2rem 0.3rem 1.1rem;
  margin: 0 0.25rem 0.15rem 0.55rem;
  border-left: 2px dashed rgba(28, 36, 48, 0.18);
}
.test-row, .student-row {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  margin: 0;
  padding: 0.45rem 0.5rem;
  border-radius: 10px;
  font-weight: 500;
  cursor: pointer;
}
.test-row:hover, .student-row:hover { background: rgba(15, 106, 90, 0.07); }
.test-row input, .student-row input { width: auto; margin-top: 0.2rem; flex-shrink: 0; }
.test-row-body { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.test-row-title { font-weight: 650; line-height: 1.25; }
.student-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 1rem;
}
.assign-submit-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  position: sticky;
  bottom: 0.5rem;
  padding-top: 0.5rem;
  background: linear-gradient(180deg, transparent, var(--card) 30%);
}

.hidden { display: none !important; }
.progress-wrap { margin: 0.5rem 0; }
.progress-label { font-size: 0.92rem; color: var(--muted); margin-bottom: 0.35rem; }
.progress-track {
  height: 8px; border-radius: 999px; background: var(--bg2); overflow: hidden;
  border: 1px solid var(--line);
}
.progress-fill {
  height: 100%; background: var(--accent); width: 0; transition: width 0.2s ease;
}
.practice-nav {
  display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; align-items: center;
}
.practice-choices .practice-opt {
  display: flex; gap: 0.5rem; align-items: flex-start;
  padding: 0.55rem 0.65rem; border-radius: 10px; border: 1px solid transparent;
  margin: 0.35rem 0; cursor: pointer; font-weight: 500;
}
.practice-choices .practice-opt:hover { background: rgba(15, 106, 90, 0.06); }
.practice-choices .practice-opt.is-correct {
  border-color: #86efac; background: #f0fdf4;
}
.practice-choices .practice-opt.is-wrong {
  border-color: #fecaca; background: #fef2f2;
}
.feedback {
  margin-top: 0.75rem; padding: 0.7rem 0.85rem; border-radius: 10px;
  border: 1px solid var(--line); font-weight: 600;
}
.feedback.ok { background: #f0fdf4; border-color: #86efac; color: var(--ok); }
.feedback.bad { background: #fef2f2; border-color: #fecaca; color: var(--bad); }

/* ЛК: три цветовые зоны */
:root {
  --lk-books: #3b6ea5;
  --lk-books-bg: #eef4fb;
  --lk-books-border: #b7cce3;
  --lk-tests: #0f6a5a;
  --lk-tests-bg: #eef7f4;
  --lk-tests-border: #a9d0c5;
  --lk-done: #7a4f9a;
  --lk-done-bg: #f5effa;
  --lk-done-border: #d4c0e4;
}

.dash-section-live {
  background: linear-gradient(180deg, #f3faf7 0%, #e5f4ee 100%);
  border-color: #9fcbbd;
}
.dash-section-live h2 { color: #0f6a5a; }
.live-row td { vertical-align: top; }
.dash-section-books h2 { color: var(--lk-books); }
.dash-book {
  background: #fff;
  border: 1px solid var(--lk-books-border) !important;
  border-left: 4px solid var(--lk-books) !important;
}
.btn-book {
  background: var(--lk-books) !important;
}
.btn-book:hover { filter: brightness(1.06); }

.dash-section-tests {
  background: linear-gradient(180deg, #f7fcfa 0%, var(--lk-tests-bg) 100%);
  border-color: var(--lk-tests-border);
}
.dash-section-tests h2 { color: var(--lk-tests); }
.dash-test {
  background: #fff;
  border: 1px solid var(--lk-tests-border) !important;
  border-left: 4px solid var(--lk-tests) !important;
  padding-top: 0.85rem !important;
  padding-bottom: 0.9rem !important;
}
.dash-test h3 {
  margin-bottom: 0.35rem;
  font-size: 1.02rem;
  line-height: 1.35;
}
.dash-test-meta { margin: 0 0 0.75rem; color: var(--ink); }
.dash-test .btn { background: var(--lk-tests); }

.dash-section-results {
  background: linear-gradient(180deg, #f8f3fc 0%, #efe4f8 100%);
  border-color: #c9a9e0;
}
.dash-section-results h2 { color: var(--lk-done); }
.dash-done {
  background: #fff;
  border: 1px solid #c9a9e0 !important;
  border-left: 5px solid #7a4f9a !important;
  padding-top: 0.85rem !important;
  padding-bottom: 0.9rem !important;
}
.dash-done.is-waiting {
  background: linear-gradient(180deg, #fffdf8 0%, #fff4e5 100%);
  border-color: #f0c48a !important;
  border-left-color: #c2410c !important;
}
.dash-done.is-checked {
  background: linear-gradient(180deg, #fbf7ff 0%, #f0e6fa 100%);
  border-color: #c9a9e0 !important;
  border-left-color: #7a4f9a !important;
}
.dash-done h3 {
  margin-bottom: 0.35rem;
  font-size: 1.02rem;
  line-height: 1.35;
}
.btn-done {
  background: #7a4f9a !important;
}
.dash-done.is-waiting .btn-done {
  background: #c2410c !important;
}
.btn-done:hover { filter: brightness(1.06); text-decoration: none; }

.test-source {
  margin: 0.35rem 0 0.65rem !important;
  color: var(--ink) !important;
  font-size: 0.98rem;
  line-height: 1.45;
  padding: 0.65rem 0.85rem;
  background: rgba(15, 106, 90, 0.07);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
}

@media (max-width: 900px) {
  .assign-layout { grid-template-columns: 1fr; }
  .test-picker { max-height: 50vh; }
}

@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; }
}
