/* Тема (настройка менеджера «Тема», атрибут data-theme корневого
   элемента): light — светлая, dark — тёмная, auto — по системе
   пользователя (prefers-color-scheme). color-scheme переключает и
   встроенные элементы браузера: списки, полосы прокрутки, календари полей. */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #d9dce1;
  --text: #1c1f24;
  --muted: #6b7280;
  --accent: #2b6cb0;
  --accent-contrast: #ffffff;
  --ok-bg: #e6f4ea;
  --ok-text: #1e6b38;
  --err-bg: #fdecea;
  --err-text: #a11212;
  --warn-bg: #fff7e6;
  --warn-text: #8a5a00;
  --running: #1e8e3e;
  --stopped: #6b7280;
  --crashed: #c62828;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #15181d;
    --surface: #1e2227;
    --border: #333a42;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --accent: #5a9bd8;
    --accent-contrast: #0b0d10;
    --ok-bg: #16331f;
    --ok-text: #7fdca0;
    --err-bg: #3a1d1d;
    --err-text: #f0a0a0;
    --warn-bg: #3a2f14;
    --warn-text: #e6c57a;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15181d;
  --surface: #1e2227;
  --border: #333a42;
  --text: #e6e8eb;
  --muted: #9aa3ad;
  --accent: #5a9bd8;
  --accent-contrast: #0b0d10;
  --ok-bg: #16331f;
  --ok-text: #7fdca0;
  --err-bg: #3a1d1d;
  --err-text: #f0a0a0;
  --warn-bg: #3a2f14;
  --warn-text: #e6c57a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.mainnav { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap; }
.mainnav a { color: var(--muted); padding: 0.2rem 0; }
.mainnav a.active, .mainnav a:hover { color: var(--text); text-decoration: none; }
.userbox { display: flex; align-items: center; gap: 0.75rem; }
.inline { display: inline; }
.linkbtn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font: inherit; padding: 0;
}

.content { max-width: 1040px; margin: 1.5rem auto; padding: 0 1.25rem; }
.footer {
  max-width: 1040px; margin: 2rem auto; padding: 1rem 1.25rem;
  display: flex; justify-content: space-between;
  border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem;
}
.muted { color: var(--muted); }

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.75rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.flash { padding: 0.6rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok-text); }
.flash-err { background: var(--err-bg); color: var(--err-text); }
.flash-warn { background: var(--warn-bg); color: var(--warn-text); }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600; color: var(--accent-contrast);
  background: var(--stopped);
}
.badge.running { background: var(--running); }
.badge.stopped { background: var(--stopped); }
.badge.crashed { background: var(--crashed); }
.badge.starting, .badge.stopping { background: var(--accent); }

form.stack { display: flex; flex-direction: column; gap: 0.9rem; max-width: 560px; }
label { font-weight: 600; font-size: 0.9rem; display: block; margin-bottom: 0.25rem; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 0.45rem 0.6rem; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface); color: var(--text); font: inherit;
}
.field-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.field-row > div { flex: 1; min-width: 180px; }
.hint { color: var(--muted); font-size: 0.82rem; margin-top: 0.2rem; }

.btn {
  display: inline-block; padding: 0.45rem 0.9rem; border-radius: 6px;
  border: 1px solid var(--accent); background: var(--accent);
  color: var(--accent-contrast); cursor: pointer; font: inherit; font-weight: 600;
}
.btn:hover { text-decoration: none; opacity: 0.92; }
.btn.secondary { background: transparent; color: var(--accent); }
.btn.danger { background: var(--crashed); border-color: var(--crashed); }
.btn-row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
/* Поля и списки прямо в строке кнопок (фильтры, «Добавить сервер») — по
   содержимому, а не во всю ширину: иначе каждый встаёт отдельной строкой. */
.btn-row > input[type=text], .btn-row > input[type=search], .btn-row > input[type=number], .btn-row > select {
  width: auto; flex: 0 1 auto; min-width: 0;
}

.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.35rem; }
.checks label { font-weight: 400; display: flex; gap: 0.4rem; align-items: flex-start; }
.check-inline { display: flex; gap: 0.4rem; align-items: center; font-weight: 400; }

.logbox {
  background: #0d1117; color: #d6dee8; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.82rem; padding: 0.75rem; border-radius: 6px; height: 420px;
  overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
/* Дашборд: таблица серверов (6 столбцов) шире карточки сессии входа. */
.grid-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1rem; }
@media (max-width: 760px) {
  .grid-main { grid-template-columns: minmax(0, 1fr); }
}
.kv { display: flex; justify-content: space-between; gap: 1rem; padding: 0.2rem 0; }
.kv span:first-child { color: var(--muted); }
.onetime { font-family: ui-monospace, monospace; font-weight: 700; }
.tag { font-size: 0.78rem; color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Широкие формы (entry list, BoP) и повторяемые строки. */
form.stack.wide { max-width: none; }
form.stack.wide > div:not(.table-scroll):not(.btn-row):not(.flash) { max-width: 760px; }
.table-scroll { overflow-x: auto; }
table.entrants th, table.entrants td { padding: 0.3rem 0.35rem; vertical-align: middle; }
table.entrants input[type=text], table.entrants select { padding: 0.3rem 0.4rem; min-width: 7rem; }
table.entrants input.w-steam { min-width: 11.5rem; font-family: ui-monospace, Menlo, Consolas, monospace; }
table.entrants input.w-num { min-width: 4.5rem; width: 5rem; }
.center { text-align: center; }
ul.problems { margin: 0.35rem 0 0; padding-left: 1.2rem; }
.badge.vip { background: #b7791f; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }

/* Чемпионаты: вкладки, прогресс, обзор по этапам, карточки этапов. */
.tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin: 1rem 0; }
.tabs a { padding: 0.45rem 0.8rem; border: 1px solid transparent; border-bottom: none; border-radius: 6px 6px 0 0; color: var(--muted); }
.tabs a.active { border-color: var(--border); background: var(--surface); color: var(--text); font-weight: 600; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--text); }
progress.progress {
  -webkit-appearance: none; appearance: none; display: block; width: 100%;
  height: 0.5rem; border: 0; border-radius: 999px; overflow: hidden;
  background: var(--border); color: var(--accent); margin: 0.35rem 0;
}
progress.progress::-webkit-progress-bar { background: var(--border); }
progress.progress::-webkit-progress-value { background: var(--accent); }
progress.progress::-moz-progress-bar { background: var(--accent); }
progress.progress.small { height: 0.35rem; min-width: 6rem; }
table.overview td, table.overview th { text-align: center; padding: 0.35rem 0.4rem; }
table.overview td.left, table.overview th.left { text-align: left; }
.cell-p1 { background: #f6d55c; color: #1c1f24; }
.cell-p2 { background: #d5d9df; color: #1c1f24; }
.cell-p3 { background: #e0a96d; color: #1c1f24; }
.cell-p4_10 { background: #cfe8d5; color: #1c1f24; }
.cell-p11 { background: #e6eef8; color: #1c1f24; }
.cell-nopoints { background: #eeeeee; color: #555; }
.cell-dq { background: #f2b8b5; color: #5c0b0b; }
.cell-ignored { text-decoration: line-through; opacity: 0.55; }
.legend { display: flex; flex-wrap: wrap; gap: 0.5rem; font-size: 0.8rem; margin-top: 0.6rem; }
.legend span { padding: 0.1rem 0.5rem; border-radius: 4px; }
.event-card { border-left: 4px solid var(--border); }
.event-card.running { border-left-color: var(--running); }
.event-card.completed { border-left-color: var(--accent); }
.event-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: baseline; }
.event-head h3 { margin: 0; font-size: 1.05rem; }
.pill { display: inline-block; padding: 0.05rem 0.45rem; border-radius: 999px; border: 1px solid var(--border); font-size: 0.78rem; margin-right: 0.25rem; }
.pill.ok { border-color: var(--running); color: var(--running); }
.badge.warn { background: #b7791f; }
.badge.fl { background: #6b46c1; }
.badge.pole { background: #2c7a7b; }
.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; }
.inline-form > div { min-width: 8rem; }
.inline-form input[type=text], .inline-form input[type=number], .inline-form select { width: auto; min-width: 7rem; }
.desc p { margin: 0 0 0.6rem; white-space: pre-line; }
.mine td { font-weight: 700; }
input[type=datetime-local] {
  width: 100%; padding: 0.45rem 0.6rem; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface); color: var(--text); font: inherit;
}

/* Колокольчик уведомлений (PLT-057). */
.bell { position: relative; display: inline-flex; align-items: center; color: var(--muted); padding: 0.15rem; }
.bell:hover, .bell.active { color: var(--text); text-decoration: none; }
.bell-count {
  position: absolute; top: -0.35rem; right: -0.55rem; min-width: 1.15rem; padding: 0 0.25rem;
  border-radius: 999px; background: var(--crashed); color: #fff; font-size: 0.7rem; font-weight: 700;
  line-height: 1.15rem; text-align: center;
}
ul.notes { list-style: none; margin: 0; padding: 0; }
.note { padding: 0.7rem 0; border-bottom: 1px solid var(--border); }
.note:last-child { border-bottom: none; }
.note.unread { border-left: 3px solid var(--accent); padding-left: 0.6rem; }
.note.quiet { opacity: 0.85; }
.note-head { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; flex-wrap: wrap; }
.note-text { white-space: pre-line; margin: 0.25rem 0; }
.note-actions { gap: 1rem; font-size: 0.88rem; }

/* Календарь (EVT-150). */
.calendar { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.cal-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-head div { padding: 0.35rem 0.5rem; font-size: 0.8rem; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); }
.cal-day { min-height: 6.5rem; padding: 0.3rem 0.35rem; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); overflow: hidden; }
.cal-row .cal-day:last-child { border-right: none; }
.cal-day.other { background: var(--bg); color: var(--muted); }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-date { font-size: 0.8rem; font-weight: 600; margin-bottom: 0.2rem; }
.cal-item { font-size: 0.76rem; line-height: 1.25; padding: 0.1rem 0.3rem; margin-bottom: 0.2rem; border-radius: 4px; border-left: 3px solid var(--accent); background: var(--bg); overflow-wrap: anywhere; }
.cal-item.kind-championship { border-left-color: #6b46c1; }
.cal-time { font-weight: 700; margin-right: 0.2rem; }
.cal-flag { color: var(--running); font-size: 0.65rem; }
.legend .cal-item { display: inline-block; margin: 0; }
.pill.kind-championship { border-color: #6b46c1; color: #6b46c1; }
.pill.kind-preset { border-color: var(--accent); color: var(--accent); }
h3.cal-list-day { font-size: 0.98rem; margin: 1rem 0 0.3rem; }
h3.cal-list-day.today { color: var(--accent); }
fieldset.card { max-width: 560px; }
fieldset.card legend { font-weight: 600; padding: 0 0.3rem; }
@media (max-width: 720px) {
  .cal-day { min-height: 4.5rem; }
  .cal-item .cal-time { display: block; }
}

/* Журнал аудита, круги результата, применённый конфиг, обслуживание. */
input[type=date] {
  width: 100%; padding: 0.45rem 0.6rem; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface); color: var(--text); font: inherit;
}
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0.6rem; align-items: end; }
.filters label { font-size: 0.82rem; }
details.more summary { cursor: pointer; color: var(--accent); font-size: 0.85rem; }
details.more[open] summary { margin-bottom: 0.35rem; }
pre.block {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.6rem;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.8rem;
  white-space: pre-wrap; word-break: break-word; margin: 0.35rem 0; max-height: 540px; overflow: auto;
}
.btn.small { padding: 0.15rem 0.55rem; font-size: 0.8rem; font-weight: 600; }
table.laps th, table.laps td { padding: 0.25rem 0.45rem; font-size: 0.86rem; vertical-align: middle; }
tr.lap-invalid td.lap-time { text-decoration: line-through; color: var(--muted); }
.lap-form { display: inline-flex; gap: 0.3rem; align-items: center; flex-wrap: wrap; }
.lap-form input[type=text] { width: 13rem; padding: 0.2rem 0.4rem; font-size: 0.82rem; }
.danger-zone { border-color: var(--crashed); }
.progress-label { font-size: 0.85rem; color: var(--muted); }

/* Утилиты вместо встроенных стилей: политика CSP (PLT-054) запрещает
   атрибут style. !important сохраняет приоритет, который был у атрибута. */
[hidden] { display: none !important; }
.m-0 { margin: 0 !important; }
.mt-0 { margin-top: 0 !important; }
.mt-06 { margin-top: 0.6rem !important; }
.mt-075 { margin-top: 0.75rem !important; }
.mt-1 { margin-top: 1rem !important; }
.mb-04 { margin-bottom: 0.4rem !important; }
.mb-05 { margin-bottom: 0.5rem !important; }
.mb-1 { margin-bottom: 1rem !important; }
.my-025 { margin: 0.25rem 0 !important; }
.my-05 { margin: 0.5rem 0 !important; }
.justify-between { justify-content: space-between !important; }
.text-danger { color: var(--crashed) !important; }
.text-warn { color: var(--warn-text) !important; }
.break-all { word-break: break-all !important; }
.pre-line { white-space: pre-line !important; }
.d-block { display: block !important; }
.w-6rem { width: 6rem !important; }
.maxw-280 { max-width: 280px !important; }
.maxw-320 { max-width: 320px !important; }
.maxw-360 { max-width: 360px !important; }
.maxw-560 { max-width: 560px !important; }
.maxw-760 { max-width: 760px !important; }
.maxw-860 { max-width: 860px !important; }
.card-center-420 { max-width: 420px !important; margin: 3rem auto !important; }
.card-center-460 { max-width: 460px !important; margin: 2rem auto !important; }
.card-center-520 { max-width: 520px !important; margin: 3rem auto !important; text-align: center !important; }
.error-code { font-size: 2.5rem !important; margin-bottom: 0 !important; }
