:root {
  /* Без color-scheme нативные элементы (полосы прокрутки, галки, списки)
     остаются светлыми даже в тёмной теме. */
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2f6bd4;
  --accent-soft: #eef3fc;
  --warn: #b4560f;
  --bad: #a8322a;
  --good: #1d7a46;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #15171b;
    --panel: #1c1f24;
    --ink: #e7e9ec;
    --muted: #9aa3ad;
    --line: #2c3038;
    --accent: #6d9bfb;
    --accent-soft: #1e2735;
    --warn: #e0a35c;
    --bad: #e07a72;
    --good: #58c98a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

/* --- шапка --- */
.top {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; color: var(--ink); letter-spacing: .2px; }
.top nav { display: flex; gap: 14px; flex-wrap: wrap; margin-right: auto; }
.top nav a { color: var(--muted); padding: 3px 2px; border-bottom: 2px solid transparent; }
.top nav a.on { color: var(--ink); border-bottom-color: var(--accent); }

main { max-width: 1040px; margin: 0 auto; padding: 24px 20px 72px; }

h1 { font-size: 23px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 30px 0 12px; }
h3 { font-size: 16px; margin: 0 0 6px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }

/* --- панели и плитки --- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 16px 18px; margin-bottom: 16px;
}
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.tile .num { font-size: 26px; font-weight: 700; line-height: 1.2; }
.tile .cap { color: var(--muted); font-size: 13px; }

.overview {
  background: var(--accent-soft); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 14px 18px; white-space: pre-wrap;
}

/* --- таблицы --- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 13px; font-weight: 600; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; white-space: nowrap; }
.wrap { overflow-x: auto; }

/* --- мелочи --- */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tag {
  display: inline-block; padding: 1px 7px; margin: 0 3px 3px 0; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; white-space: nowrap;
}
.tag.off { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.state-good { color: var(--good); }
.state-warn { color: var(--warn); }
.state-bad { color: var(--bad); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }

/* --- карточки материалов --- */
.card { border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; margin-bottom: 12px; background: var(--panel); }
.card .stats { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.card .summary { white-space: pre-wrap; }
.rank { color: var(--muted); font-weight: 700; margin-right: 6px; }

/* --- формы --- */
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 4px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 7px;
}
textarea { min-height: 92px; resize: vertical; font-family: inherit; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; }
.checks label { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--ink); font-size: 14px; }
.checks input { width: auto; }
.numbers { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

button, .btn {
  font: inherit; padding: 8px 14px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
button.ghost, .btn.ghost { background: transparent; color: var(--accent); }
button.quiet, .btn.quiet { background: transparent; color: var(--muted); border-color: var(--line); }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.link { background: none; border: none; color: var(--muted); padding: 0; text-decoration: underline; }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 22px; flex-wrap: wrap; }
form.inline { display: inline; }

.note { border-left: 3px solid var(--good); background: var(--panel); padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.alert { border-left: 3px solid var(--bad); background: var(--panel); padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
code, pre { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: 13px; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 10px 12px; overflow-x: auto; }
details summary { cursor: pointer; color: var(--accent); }
details[open] summary { margin-bottom: 8px; }

/* --- вход --- */
/* В тёмной теме акцент светлее, и белый текст на нём почти не читается
   (контраст 2.7 против нормы 4.5) — на такой кнопке текст тёмный.
   Кнопки-обводки (.ghost, .quiet, .danger) специфичнее и свой цвет сохраняют. */
@media (prefers-color-scheme: dark) {
  button, .btn { color: #10131a; }
}

.login { max-width: 340px; margin: 14vh auto 0; }
.filters { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
.filters label { margin: 0 0 4px; }
.pager { display: flex; gap: 12px; align-items: center; margin-top: 16px; }
