:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #1d2420;
  --muted: #69736d;
  --line: #dde2dd;
  --accent: #2f5d50;
  --accent-text: #ffffff;
  --ok: #1f7a4a;
  --ok-bg: #e3f3e9;
  --warn: #8a5a00;
  --warn-bg: #fdf1d8;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --radius: 12px;
  --brand-gold: #9a6514;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --card: #1e2421;
    --text: #e6ebe7;
    --muted: #9aa59e;
    --line: #313a35;
    --accent: #6fb39c;
    --accent-text: #0e1a15;
    --ok: #7fd3a2;
    --ok-bg: #1c3326;
    --warn: #f0c46a;
    --warn-bg: #3a2f17;
    --bad: #f2948d;
    --bad-bg: #3d1f1d;
    --brand-gold: #f4c95d;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: .5rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 2rem 0 .75rem; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar form { display: flex; gap: .75rem; align-items: center; margin: 0; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem;
         letter-spacing: -.01em; text-decoration: none; color: var(--text); }
.brand img { display: block; border-radius: 7px; }
.brand-accent { color: var(--brand-gold); }
.login-hero { text-align: center; margin: 7vh 0 1.25rem; }
.login-hero img { display: block; margin: 0 auto .75rem; border-radius: 20px;
                  box-shadow: 0 8px 24px rgba(31, 74, 63, .25); }
.login-name { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.login-hero .muted { margin: .25rem 0 0; }
.narrow.login-card { margin-top: 0; }
.who { color: var(--muted); }

.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.narrow { max-width: 380px; margin: 10vh auto 0; }
.muted { color: var(--muted); }

/* Формы */
label { display: block; margin-bottom: 1rem; font-weight: 600; }
input, select, textarea {
  display: block; width: 100%; margin-top: .35rem; padding: .7rem .8rem;
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
legend { font-weight: 600; margin-bottom: .5rem; }
.pw-wrap { position: relative; display: block; margin-top: .35rem; }
.pw-wrap input { margin-top: 0; padding-right: 3.25rem; }
.eye {
  position: absolute; right: 0; top: 0; bottom: 0; width: 3rem; padding: 0;
  display: grid; place-items: center; background: none; border: 0; color: var(--muted);
}
.eye svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8;
           stroke-linecap: round; stroke-linejoin: round; }
.eye .eye-closed, .eye[aria-pressed="true"] .eye-open { display: none; }
.eye[aria-pressed="true"] .eye-closed { display: block; }
.eye:focus-visible { outline: 2px solid var(--accent); border-radius: 8px; }
.hint { display: block; font-weight: 400; font-size: .875rem; color: var(--muted); margin-top: .35rem; }
.errorlist { list-style: none; margin: -.5rem 0 1rem; padding: 0; color: var(--bad); font-size: .9rem; }

button, .primary, .secondary {
  font: inherit; cursor: pointer; border-radius: 10px; padding: .7rem 1rem;
  border: 1px solid transparent; text-align: center; text-decoration: none; display: inline-block;
}
.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.secondary { background: transparent; color: var(--accent); border-color: var(--accent); }
.wide { display: block; width: 100%; }
.big { padding: 1rem; font-size: 1.05rem; margin: 1rem 0; }
button:disabled { opacity: .6; cursor: wait; }
.link { background: none; border: 0; padding: 0; color: var(--accent); }
.danger { color: var(--bad); }
.back { display: inline-block; margin-bottom: .5rem; text-decoration: none; }

.flash { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.flash.success { background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--bad-bg); color: var(--bad); }

/* Баланс */
.balance { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; min-width: 0;
}
.tile.main { grid-column: 1 / -1; background: var(--accent); color: var(--accent-text); border: 0; }
.tile .label { font-size: .8rem; opacity: .8; }
.tile .value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile.main .value { font-size: 2rem; }

/* Оценки */
.mark {
  display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 8px;
  font-weight: 700; background: var(--bg);
}
.m5 { --c: var(--ok); } .m4 { --c: var(--accent); } .m3 { --c: var(--warn); }
.m2, .m1 { --c: var(--bad); }
.mark { color: var(--c); border: 1.5px solid var(--c); }

.submission header { display: flex; justify-content: space-between; margin-bottom: .5rem; }
.grades { list-style: none; margin: 0; padding: 0; }
.grades li {
  display: grid; grid-template-columns: 2rem 1fr auto; gap: 2px 10px; align-items: center;
  padding: .5rem 0; border-top: 1px solid var(--line);
}
.grades .sum { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.grades .status { grid-column: 2 / -1; font-size: .8rem; }
.grades .reason { grid-column: 2 / -1; font-size: .875rem; color: var(--bad); }
.grades .pending .status { color: var(--warn); }
.grades .approved .status { color: var(--ok); }
.grades .rejected .status { color: var(--bad); }
.grades .rejected .subj, .grades .rejected .sum { text-decoration: line-through; color: var(--muted); }
.comment { margin: .5rem 0 0; color: var(--muted); font-style: italic; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin: .5rem 0; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

.pager { display: flex; justify-content: space-between; align-items: center; margin: 1rem 0; }
.payouts { list-style: none; padding: 0 16px; }
.payouts li {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 1rem;
  padding: .6rem 0; border-top: 1px solid var(--line);
}
.payouts li:first-child { border-top: 0; }

/* Строка оценки в форме */
.grade-row { padding: .75rem 0; border-top: 1px solid var(--line); }
.grade-row:first-child { border-top: 0; }
.row-head { display: flex; gap: .5rem; align-items: center; }
.row-head select { margin: 0; }
.remove-row { font-size: 1.1rem; padding: .5rem; }
.chips { display: flex; gap: 6px; align-items: center; margin-top: .5rem; }
.chip { margin: 0; font-weight: 700; }
.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip span {
  display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: 10px;
  border: 1.5px solid var(--line); color: var(--c); background: var(--bg); cursor: pointer;
}
.chip input:checked + span { background: var(--c); color: var(--card); border-color: var(--c); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.row-sum { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.total { margin-top: 1rem; }
.photo-pick input { padding: .6rem; }

/* ===== Интерфейс проверяющего ===== */
body.wide .wrap { max-width: 1100px; }
.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 0 12px;
  background: var(--card); border-bottom: 1px solid var(--line); scrollbar-width: none;
}
.tabs a {
  padding: .7rem .8rem; text-decoration: none; color: var(--text); white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tabs a[aria-current="page"] { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
.tabs a.muted { margin-left: auto; color: var(--muted); }
.badge {
  display: inline-block; min-width: 1.4em; padding: 0 .4em; border-radius: 99px;
  background: var(--bad); color: #fff; font-size: .75rem; font-weight: 700; text-align: center;
}
.badge.warn { background: var(--warn-bg); color: var(--warn); }

/* Сообщения наблюдателя о проблемах в заявке */
.report-flag { margin-left: auto; padding: 0 .5em; border-radius: 99px; background: var(--warn-bg);
               color: var(--warn); font-size: .8rem; font-weight: 600; white-space: nowrap; }
.reports { border-left: 4px solid var(--warn); }
.reports h2 { margin-top: 0; font-size: 1.05rem; }
.report-item { padding: .6rem 0; border-top: 1px solid var(--line); }
.report-item:first-of-type { border-top: 0; }
.report-item p { margin: 0 0 .3rem; }
.report-item.resolved { opacity: .65; }
.report-item .open { color: var(--warn); }
.report-item form { margin-top: .4rem; }
.small { font-size: .85rem; }
.report-form summary { cursor: pointer; font-weight: 600; color: var(--warn); }
.report-form form { margin-top: .8rem; }
.report-form textarea { width: 100%; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 1rem; }
.segmented a { padding: .5rem 1rem; text-decoration: none; color: var(--text); }
.segmented a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }

.queue-item { display: flex; gap: 14px; text-decoration: none; color: inherit; }
.queue-item:hover { border-color: var(--accent); }
.queue-photo { position: relative; flex: 0 0 96px; height: 96px; border-radius: 8px; overflow: hidden;
               background: var(--bg); display: grid; place-items: center; }
.queue-photo img { width: 100%; height: 100%; object-fit: cover; }
.queue-photo .more { position: absolute; right: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff;
                     font-size: .75rem; padding: 0 .35rem; border-radius: 6px; }
.queue-body { min-width: 0; flex: 1; }
.queue-head { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.mini-grades { list-style: none; padding: 0; margin: .4rem 0 0; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.mini-grades li { display: flex; align-items: center; gap: 6px; font-size: .9rem; }
.mini-grades .mark { width: 1.6rem; height: 1.6rem; font-size: .85rem; }
.mini-grades .rejected { text-decoration: line-through; color: var(--muted); }
.mini-grades .approved::after { content: "✓"; color: var(--ok); font-weight: 700; }
.empty { text-align: center; padding: 3rem 1rem; font-size: 1.1rem; color: var(--muted); }

.review-head h1 { margin-bottom: .2rem; }
.review-head { margin-bottom: 1rem; }
.review-grid { display: grid; gap: 16px; }
@media (min-width: 860px) {
  .review-grid { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; }
  .review-grid .photos { position: sticky; top: 4.5rem; max-height: calc(100vh - 5.5rem); overflow-y: auto; }
}
.photos img { display: block; width: 100%; border-radius: var(--radius); border: 1px solid var(--line); margin-bottom: 10px; }

.review-row { padding: .9rem 0; border-top: 1px solid var(--line); }
.review-row:first-of-type { border-top: 0; }
.review-row[data-decision="approved"] { --row: var(--ok); }
.review-row[data-decision="rejected"] { --row: var(--bad); }
.review-fields { display: grid; grid-template-columns: 1fr 4.5rem auto; gap: 8px; align-items: center; }
.review-fields select { margin: 0; }
.review-fields .row-sum { min-width: 4.5rem; text-align: right; color: var(--row, var(--muted)); }
.decision { display: flex; gap: 6px; margin-top: .5rem; }
.dec { margin: 0; flex: 1; font-weight: 600; }
.dec input { position: absolute; opacity: 0; width: 0; height: 0; }
.dec span { display: block; text-align: center; padding: .55rem .4rem; border-radius: 10px;
            border: 1.5px solid var(--line); cursor: pointer; font-size: .9rem; }
.dec-approved input:checked + span { background: var(--ok); border-color: var(--ok); color: var(--card); }
.dec-rejected input:checked + span { background: var(--bad); border-color: var(--bad); color: var(--card); }
.dec-pending input:checked + span { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.dec input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.reason input { margin-top: .5rem; }
.reviewed { font-size: .8rem; margin: .4rem 0 0; }
.review-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 1rem; }
.review-actions.top { margin: 0 0 .25rem; justify-content: flex-end; }
.review-actions .primary { flex: 1; }

.balances { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.student-balance dl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: .75rem 0 0; }
.student-balance dt { font-size: .8rem; color: var(--muted); }
.student-balance dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.big-num { font-size: 1.5rem; color: var(--accent); }

.form-grid { display: grid; gap: 0 16px; grid-template-columns: 1fr 1fr; }
.form-grid h2 { grid-column: 1 / -1; margin-top: 0; }
.form-grid.four { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.span-2 { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.table-wrap { overflow-x: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: .55rem .75rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th { font-size: .8rem; color: var(--muted); font-weight: 600; }
tfoot th { border-bottom: 0; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
.center { text-align: center; }
.neg { color: var(--bad); }
th .mark { width: 1.5rem; height: 1.5rem; font-size: .8rem; }
table input, table select { margin: 0; padding: .45rem .55rem; }
table.subjects .num-input { width: 5.5rem; }
.num-input { font-variant-numeric: tabular-nums; }
table.subjects input[type=checkbox] { width: 1.2rem; height: 1.2rem; margin: 0 auto; }
.new-row td { background: var(--bg); }

.filters { display: flex; gap: 8px; margin-bottom: 1rem; }
.filters select { width: auto; margin: 0; }
.stat-row { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* ===== Журнал ===== */
.month-nav { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-bottom: .75rem; }
.month-nav a { text-decoration: none; font-size: 1.3rem; padding: .2rem .8rem; border-radius: 8px;
               border: 1px solid var(--line); background: var(--card); }
.month-nav strong { min-width: 9rem; text-align: center; }
.journal th, .journal td { padding: .4rem .45rem; }
.journal .sticky { position: sticky; left: 0; z-index: 1; background: var(--card); text-align: left;
                   font-weight: 500; max-width: 11rem; overflow: hidden; text-overflow: ellipsis; }
.journal thead .sticky, .journal tfoot .sticky { font-weight: 600; }
.journal .day { text-align: center; min-width: 2.4rem; }
.journal th.day span { display: block; font-size: .95rem; color: var(--text); }
.journal th.day small { font-size: .7rem; color: var(--muted); font-weight: 400; }
.journal td.day { white-space: nowrap; }
.jm {
  display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; margin: 1px;
  border-radius: 6px; font-weight: 700; font-size: .9rem; text-decoration: none;
  color: var(--c); border: 1.5px solid var(--c);
}
.jm.approved { background: var(--c); color: var(--card); }
.jm.pending { border-style: dashed; }
.jm.rejected { color: var(--muted); border-color: var(--line); text-decoration: line-through; }
a.jm:hover { outline: 2px solid var(--accent); outline-offset: 1px; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: .85rem; }
.legend .jm { width: 1.4rem; height: 1.4rem; font-size: .75rem; }

/* ===== Запросы выплаты ===== */
.action-row { display: flex; gap: 8px; margin-top: -.25rem; }
.action-row a { flex: 1; }
.request-status { display: flex; justify-content: space-between; align-items: center; gap: 1rem;
                  border-color: var(--warn); background: var(--warn-bg); }
.request-status span { display: block; font-size: .85rem; }
.request-status form { margin: 0; }
.payout-request { border-color: var(--warn); }
.pr-head { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.pr-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; margin-top: .75rem; }
.pr-actions details { flex: 1; min-width: 200px; }
.pr-actions summary { list-style: none; display: inline-block; }
.pr-actions summary::-webkit-details-marker { display: none; }
.pr-decline { display: flex; gap: 8px; margin-top: 8px; }
.pr-decline input { margin: 0; }
.danger-btn { color: var(--bad); border-color: var(--bad); }

.bell { text-decoration: none; font-size: 1.1rem; }
.backup-status.warn { border-color: var(--warn); background: var(--warn-bg); }
.backup-status p:first-child { margin-top: 0; }
.st-ok { color: var(--ok); font-weight: 600; }
.st-failed { color: var(--bad); font-weight: 600; }
.st-running, .st-queued { color: var(--warn); }
td.wrap-text { white-space: normal; min-width: 12rem; }

/* ===== Анализ ===== */
.filters { flex-wrap: wrap; align-items: center; }
.filters .segmented { margin: 0; }
.analysis th[scope=row] { font-weight: 500; }
.bar-col { min-width: 9.5rem; }
.avg-meter {
  position: relative; display: inline-block; vertical-align: middle;
  width: 5.5rem; height: 8px; border-radius: 4px; background: var(--line);
}
.avg-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--accent); }
.avg-ref { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px;
           background: var(--text); border-radius: 1px; }
.avg-num { margin-left: .4rem; font-variant-numeric: tabular-nums; }
.st-row-weak th, .st-row-weak td { background: var(--warn-bg); }
.status { font-weight: 600; font-size: .85rem; white-space: nowrap; }
.status.weak { color: var(--warn); }
.status.strong { color: var(--ok); }
.status.ok { color: var(--muted); }
.status-cell { cursor: help; }
.trend.up { color: var(--ok); }
.trend.down { color: var(--bad); }
.apply { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; white-space: nowrap; }
.apply input[type=checkbox] { width: 1.1rem; height: 1.1rem; margin: 0; }
.diff-input { width: 3rem; display: inline-block; margin: 0; padding: .3rem .4rem; text-align: center; }
.recommend { margin-top: 1rem; border-color: var(--warn); }
.recommend h2 { margin-top: 0; }
.recommend ul { padding-left: 1.2rem; }
.rules summary { cursor: pointer; font-weight: 600; }
.rules ul { padding-left: 1.2rem; margin-bottom: 0; }

/* ===== Расценки ===== */
.prices .sticky { position: sticky; left: 0; background: var(--card); font-weight: 500; }
.prices td.pos { color: var(--ok); }
.diff-dots { display: block; width: 4rem; height: 4px; margin-top: 4px; border-radius: 2px; background: var(--line); }
.diff-dots span { display: block; height: 100%; border-radius: 2px; background: var(--accent); }
.action-row { flex-wrap: wrap; }

/* ===== Бот ===== */
td.actions { display: flex; gap: 12px; justify-content: flex-end; align-items: center; }
td.actions form { margin: 0; }
.blocked-row td { background: var(--bad-bg); }
.tag { display: inline-block; font-size: .75rem; padding: 0 .4rem; border-radius: 6px; margin-left: .3rem; }
.tag.bad { background: var(--bad); color: #fff; }
.bot-log { padding: 0; }
.log-row { padding: .6rem 1rem; border-top: 1px solid var(--line); }
.log-row:first-child { border-top: 0; }
.log-row.in { border-left: 3px solid var(--accent); }
.log-row.out { border-left: 3px solid var(--line); background: var(--bg); }
.log-row.ignored { border-left-color: var(--bad); opacity: .7; }
.log-meta { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; font-size: .8rem; }
.log-text { margin-top: .2rem; white-space: normal; overflow-wrap: anywhere; }
.delete-form { text-align: right; margin-top: .5rem; }
.danger-zone { border-color: var(--bad); margin-top: 2rem; }
#bot { margin-top: 2rem; }
#bot h2 { margin-top: 0; }
.bot-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.bot-form .pw-wrap { flex: 1; min-width: 240px; margin: 0; }
code { background: var(--bg); padding: 0 .3em; border-radius: 4px; font-size: .9em; }
.danger-zone h2 { margin-top: 0; color: var(--bad); }

@media (max-width: 360px) {
  .balance { grid-template-columns: 1fr 1fr; }
  .chip span { width: 2.4rem; height: 2.4rem; }
}
