/* Админка Mirai, этап 1. Один файл стилей: CSP style-src 'self' пускает только его,
   встроенные стили, <style>, внешние шрифты и data:-картинки запрещены.
   Светлая тема, системные шрифты, контраст текста не ниже 4.5:1, области нажатия от 44 px. */

:root {
  --brand: #12b1b9;          /* фирменный — только украшения: полоса шапки, точка логотипа */
  --accent: #0a7479;         /* текст и кнопки: 5.5:1 на белом */
  --accent-strong: #086a6f;
  --accent-soft: #e7f6f7;
  --bar: #0e8f96;            /* столбики по дням: 3.9:1 на белом */
  --bg: #f4f7f8;
  --card: #fff;
  --line: #e1e7ea;
  --line-soft: #eef2f4;
  --text: #1d2329;
  --muted: #596570;          /* 5.5:1 на фоне */
  --error: #b42318;
  --error-bg: #fdecea;
  --warn: #7a4f00;
  --warn-bg: #fff6e0;
  --warn-line: #f0c66b;
  --radius: .75rem;
  --tap: 2.75rem;            /* 44 px */
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-width: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text); background: var(--bg);
}
h1, h2 { line-height: 1.25; color: var(--text); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.0625rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); text-underline-offset: .15em; }
a:hover { color: var(--accent-strong); }
b { font-weight: 650; }

/* видимый фокус с клавиатуры на всех управляющих элементах */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: .35rem; }

.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: .5rem; top: -4rem; z-index: 10;
  padding: .6rem 1rem; background: var(--card); border-radius: .5rem; font-weight: 600;
}
.skip:focus { top: .5rem; }

/* ─── шапка ─────────────────────────────────────────────────────────── */

.top { background: var(--card); border-top: 4px solid var(--brand); border-bottom: 1px solid var(--line); }
.top-in {
  max-width: 60rem; margin: 0 auto; padding: .5rem 1rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem;
}
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.0625rem; min-height: var(--tap); }
.brand-dot { width: .75rem; height: .75rem; border-radius: 50%; background: var(--brand); flex: none; }

.account { order: 2; margin-left: auto; display: flex; align-items: center; gap: .5rem; min-width: 0; }
.who { color: var(--muted); font-size: .9375rem; overflow-wrap: anywhere; }
.logout { margin: 0; }

.menu { display: flex; gap: .25rem; order: 3; width: 100%; }
.menu a {
  flex: 1 1 0; display: flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: .25rem 1rem; border-radius: .5rem;
  color: var(--text); text-decoration: none; font-weight: 600;
  border-bottom: 3px solid transparent;
}
.menu a:hover { background: var(--line-soft); color: var(--text); }
.menu a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); border-bottom-color: var(--brand); }

@media (min-width: 40rem) {
  .menu { order: 1; width: auto; margin-left: 1rem; }
  .menu a { flex: none; }
}

/* ─── каркас страницы ───────────────────────────────────────────────── */

.page { max-width: 60rem; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page-narrow { max-width: 28rem; padding-top: 2.5rem; }
@media (min-width: 40rem) { .page-narrow { padding-top: 4rem; } }

.card, .block {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin: 0 0 1rem; min-width: 0;
}
@media (min-width: 40rem) { .card, .block { padding: 1.25rem 1.5rem; } }

.lead { color: var(--muted); }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: .875rem; margin: .75rem 0 0; }

/* ─── кнопки и поля ─────────────────────────────────────────────────── */

.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: .5rem 1.1rem;
  font: inherit; font-weight: 600; line-height: 1.2; text-decoration: none;
  border: 1px solid var(--accent); border-radius: .5rem; cursor: pointer;
  background: var(--accent); color: #fff;
}
.btn:hover, button:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-ghost { background: var(--card); color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent-strong); }
.btn-wide { width: 100%; }

.field { display: grid; gap: .3rem; min-width: 0; }
label { font-weight: 600; font-size: .9375rem; }
input {
  font: inherit; color: var(--text); background: #fff;
  min-height: var(--tap); width: 100%; max-width: 100%; min-width: 0;
  padding: .5rem .75rem; border: 1px solid #8b969f; border-radius: .5rem;
}
input:focus-visible { outline-offset: 0; border-color: var(--accent); }

/* ─── вход и ошибки ─────────────────────────────────────────────────── */

.login { display: grid; gap: 1rem; margin-top: .25rem; }
.login-card h1, .error-card h1 { margin-bottom: 1.25rem; }
.error-card .error-title { font-size: 1.25rem; }
.error-card p:last-child { margin: 0; }

.alert { border-radius: .5rem; padding: .75rem 1rem; margin: 0 0 1rem; font-weight: 600; border: 1px solid; }
.alert-error { color: var(--error); background: var(--error-bg); border-color: #f4b4ad; }
.alert-warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }

/* ─── отчёты: выбор периода ─────────────────────────────────────────── */

.controls { display: grid; gap: .75rem; margin: 0 0 1rem; }

.periods { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.periods a {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 3rem; padding: .5rem; border-radius: .5rem;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  font-weight: 600; text-decoration: none;
}
.periods a:hover { border-color: var(--accent); color: var(--accent); }
.periods a[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (min-width: 40rem) { .periods { grid-template-columns: repeat(3, minmax(0, 10rem)); } }

.custom { background: var(--card); border: 1px solid var(--line); border-radius: .5rem; }
.custom summary {
  display: flex; align-items: center; gap: .5rem; min-height: var(--tap);
  padding: .5rem 1rem; cursor: pointer; font-weight: 600; list-style: none;
}
.custom summary::-webkit-details-marker { display: none; }
.custom summary::before {
  content: ""; width: .5rem; height: .5rem; flex: none;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s;
}
.custom[open] summary::before { transform: rotate(45deg); }
.custom summary.is-active { color: var(--accent); }
.period-form { display: grid; gap: .75rem; padding: 0 1rem 1rem; }
@media (min-width: 40rem) {
  .period-form { grid-template-columns: 1fr 1fr auto; align-items: end; }
}

.toggle {
  display: inline-flex; align-items: center; gap: .6rem; justify-self: start;
  min-height: var(--tap); padding: .25rem .25rem .25rem 0;
  color: var(--text); font-weight: 600; text-decoration: none;
}
.toggle:hover { color: var(--accent); }
.toggle-box {
  position: relative; width: 2.75rem; height: 1.5rem; flex: none;
  border-radius: 1rem; background: #c4ccd2; transition: background .15s;
}
.toggle-box::after {
  content: ""; position: absolute; top: .1875rem; left: .1875rem;
  width: 1.125rem; height: 1.125rem; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s;
}
.toggle.is-on .toggle-box { background: var(--accent); }
.toggle.is-on .toggle-box::after { transform: translateX(1.25rem); }

.period-line { color: var(--muted); }
.period-line b { color: var(--text); }
.tag {
  display: inline-block; margin-left: .25rem; padding: .05rem .5rem; border-radius: 1rem;
  background: var(--warn-bg); color: var(--warn); font-size: .875rem; font-weight: 600;
}

/* ─── отчёты: сводка ────────────────────────────────────────────────── */

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; margin: 0; }
.tile {
  display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: .15rem;
  padding: .75rem; border-radius: .5rem; background: var(--bg); border: 1px solid var(--line-soft); min-width: 0;
}
.tile dt { color: var(--muted); font-size: .875rem; line-height: 1.3; overflow-wrap: anywhere; }
.tile dd { margin: 0; font-size: 1.875rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-total { grid-column: 1 / -1; background: var(--accent-soft); border-color: #bfe5e7; }
.tile-total dd { font-size: 2.5rem; color: var(--accent); }
.tile-warn { background: var(--warn-bg); border-color: var(--warn-line); }
.tile-warn dd { color: var(--warn); }
/* в HTML подпись идёт первой (dt, затем dd); column-reverse показывает число над подписью */
@media (min-width: 40rem) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tile-total { grid-column: auto; }
}

.tests { margin: .75rem 0 0; color: var(--muted); font-size: .9375rem; }
.tests b { color: var(--text); }

/* ─── таблицы ───────────────────────────────────────────────────────── */

table { border-collapse: collapse; width: 100%; }
.list { table-layout: fixed; }
.list th, .list td {
  text-align: left; vertical-align: top; padding: .55rem .5rem;
  border-bottom: 1px solid var(--line-soft); overflow-wrap: anywhere;
}
.list thead th {
  font-size: .8125rem; font-weight: 600; color: var(--muted);
  border-bottom: 1px solid var(--line); padding-top: 0;
}
.list tbody tr:last-child > * { border-bottom: 0; }
.list th:first-child, .list td:first-child { padding-left: 0; }
.list th:last-child, .list td:last-child { padding-right: 0; }
.list .n {
  width: 4.5rem; text-align: right; white-space: nowrap;
  font-variant-numeric: tabular-nums; font-weight: 600;
}
.list .key { overflow-wrap: anywhere; word-break: normal; }
.others td { color: var(--muted); font-style: italic; }
.others .n { font-weight: 600; }

/* заявки по дням: подпись, столбик, число */
.days tbody th { font-weight: 500; width: 6.5rem; white-space: nowrap; }
.days thead th:first-child { width: 6.5rem; }
.days .bar-cell { vertical-align: middle; }
.days .n { width: 3.5rem; }
.days .zero th, .days .zero .n { color: var(--muted); font-weight: 400; }
.bar { display: block; height: .75rem; border-radius: .375rem; background: var(--bar); min-width: 0; }
.bar.w-0 { width: 0; }
.w-5 { width: 5%; }   .w-10 { width: 10%; } .w-15 { width: 15%; } .w-20 { width: 20%; }
.w-25 { width: 25%; } .w-30 { width: 30%; } .w-35 { width: 35%; } .w-40 { width: 40%; }
.w-45 { width: 45%; } .w-50 { width: 50%; } .w-55 { width: 55%; } .w-60 { width: 60%; }
.w-65 { width: 65%; } .w-70 { width: 70%; } .w-75 { width: 75%; } .w-80 { width: 80%; }
.w-85 { width: 85%; } .w-90 { width: 90%; } .w-95 { width: 95%; } .w-100 { width: 100%; }

.empty {
  margin: 0; padding: 1rem; text-align: center; color: var(--muted);
  background: var(--bg); border: 1px dashed #c4ccd2; border-radius: .5rem;
}

/* ─── журнал ────────────────────────────────────────────────────────── */

.journal { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); border-collapse: separate; border-spacing: 0; }
.journal th, .journal td { padding: .6rem .75rem; }
.journal th:first-child, .journal td:first-child { padding-left: 1rem; }
.journal th:last-child, .journal td:last-child { padding-right: 1rem; }
.journal thead th { padding-top: .75rem; }
.journal .when { white-space: nowrap; font-variant-numeric: tabular-nums; }
.journal thead th:nth-child(1) { width: 11rem; }
.journal thead th:nth-child(2) { width: 6rem; }
.journal thead th:nth-child(5) { width: 8.5rem; }
.journal .actor { font-weight: 600; }
.journal .tag-cell { color: var(--muted); font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .875rem; }

/* на узком экране строка журнала — карточка с подписями полей */
@media (max-width: 47.99rem) {
  .journal, .journal tbody, .journal tr, .journal td { display: block; width: auto; }
  .journal { border: 0; background: none; }
  .journal thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .journal tr {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: .5rem 1rem; margin: 0 0 .5rem;
  }
  .journal td, .journal td:first-child, .journal td:last-child {
    display: grid; grid-template-columns: 6.5rem minmax(0, 1fr); gap: .75rem;
    padding: .2rem 0; border: 0; white-space: normal;
  }
  .journal .when { width: auto; }
  .journal td::before {
    content: attr(data-label); color: var(--muted); font-size: .875rem; font-weight: 400;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  }
  .journal .what { font-weight: 600; }
}

.pager { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .5rem; margin: 1rem 0; }
.pager > :first-child { justify-self: start; }
.pager > :last-child { justify-self: end; }
.pager .btn { min-width: 7.5rem; }
.pager-no { color: var(--muted); text-align: center; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
