/* КПП: тёмная тема, mobile-first, крупные элементы (не меньше 48 px). */

:root {
  --bg: #111418;
  --surface: #1b2027;
  --surface-2: #252c35;
  --border: #3a4350;
  --text: #f2f4f7;
  --muted: #a9b3c1;
  --primary: #2f80ed;
  --entry: #1e9e55;
  --exit: #2f6fd6;
  --danger: #d93636;
  --success-bg: #123d26;
  --error-bg: #4a1717;
  --focus: #ffd34d;
  --radius: 12px;
  --tap: 48px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

a { color: #8ab8ff; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.page { max-width: 960px; margin: 0 auto; padding: 16px; }

/* Верхняя панель */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar__brand { font-weight: 700; color: var(--text); text-decoration: none; min-height: var(--tap); display: flex; align-items: center; }
.topbar__user { color: var(--muted); flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__nav { display: flex; align-items: center; gap: 4px 16px; flex-wrap: wrap; }
.topbar__nav a, .link-button {
  min-height: var(--tap); display: inline-flex; align-items: center;
  color: #8ab8ff; background: none; border: 0; padding: 0; font: inherit; cursor: pointer; text-decoration: underline;
}
.topbar__nav form { margin: 0; }

/* Карточки */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 16px; }
.card--narrow { max-width: 420px; margin: 24px auto; }
.title { margin: 0 0 16px; font-size: 1.6rem; line-height: 1.2; }
.muted { color: var(--muted); }

/* Формы */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-weight: 600; }
.field__help { color: var(--muted); font-size: 0.9rem; }
.field__error, .form__error { color: #ffb3b3; }
.form__error { background: var(--error-bg); border-radius: 8px; padding: 12px; }

.field input, .field select, .field textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  background: var(--surface-2); color: var(--text);
  border: 2px solid var(--border); border-radius: 8px; font: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); outline: none; }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 10px 20px; border-radius: 10px;
  border: 2px solid transparent; font: inherit; font-weight: 700;
  text-decoration: none; cursor: pointer; color: #fff;
  touch-action: manipulation;
}
.btn--block { width: 100%; }
.btn--primary { background: var(--primary); }
.btn--entry { background: var(--entry); }
.btn--exit { background: var(--exit); }
.btn--danger { background: var(--danger); }
.btn--secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn.is-active { border-color: var(--focus); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.form .btn + .btn { margin-top: -4px; }

/* Переключатель языка */
.lang-switch { margin: 20px 0; }
.lang-switch__label { display: block; color: var(--muted); margin-bottom: 8px; }
.lang-switch__buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Свойства профиля */
.props { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0 0 8px; }
.props dt { color: var(--muted); }
.props dd { margin: 0; overflow-wrap: anywhere; }

/* Сообщения */
.messages { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.message { padding: 12px 16px; border-radius: 8px; background: var(--surface-2); }
.message--success { background: var(--success-bg); }
.message--error { background: var(--error-bg); }

/* Служебное */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }
.btn--big { min-height: 64px; font-size: 1.2rem; }
.btn--huge { min-height: 112px; font-size: 1.8rem; letter-spacing: 0.04em; }

/* Главный экран охранника */
.guard-head {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px;
  margin-bottom: 16px;
}
.guard-head__name { font-weight: 700; font-size: 1.1rem; }
.guard-head__inside { font-size: 1.25rem; }
.guard-head__inside strong { font-size: 1.6rem; }
.direction-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }

.recent__title { font-size: 1.2rem; margin: 0 0 12px; }
.ops { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.op { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.op__main { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.op__time { font-weight: 700; font-variant-numeric: tabular-nums; margin-right: 4px; }
.op__details { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 4px; overflow-wrap: anywhere; }
.op__details:empty { display: none; }
.op__reason { margin-top: 4px; overflow-wrap: anywhere; }
.op__actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; margin-top: 10px; }
.op--cancelled .op__main, .op--cancelled .op__details { opacity: 0.6; }
.op--cancelled .op__time { text-decoration: line-through; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 0.85rem; font-weight: 700; }
.badge--entry { background: var(--entry); }
.badge--exit { background: var(--exit); }
.badge--allowed { background: var(--success-bg); color: #9be3b8; }
.badge--denied { background: var(--error-bg); color: #ffb3b3; }
.badge--cancelled { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.cancel { flex: 1 1 100%; }
.cancel > summary { list-style: none; width: max-content; }
.cancel > summary::-webkit-details-marker { display: none; }
.cancel[open] > summary { border-color: var(--focus); }
.cancel__form { margin-top: 10px; }

/* Форма операции */
.op-form { display: flex; flex-direction: column; gap: 20px; padding-bottom: 96px; }
.op-form__head { display: flex; align-items: center; gap: 12px; }
.op-form__direction { margin: 0; font-size: 2rem; letter-spacing: 0.05em; flex: 1; text-align: center; padding: 8px 0; border-radius: var(--radius); }
.op-form--entry .op-form__direction { background: var(--entry); }
.op-form--exit .op-form__direction { background: var(--exit); }
.block { margin: 0; padding: 0; border: 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.form__error-list { margin: 0 0 8px; padding-left: 20px; }
.form__error-list:empty { display: none; }

.photo { display: flex; flex-direction: column; gap: 8px; }
.photo__img { width: 100%; max-height: 50vh; object-fit: contain; background: #000; border-radius: var(--radius); }
.photo__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile { position: relative; display: block; cursor: pointer; }
.tile input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tile__face {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 64px; height: 100%; padding: 8px; border-radius: 10px;
  background: var(--surface-2); border: 3px solid var(--border); font-weight: 600;
}
.tile input:checked + .tile__face { background: #1f3b63; border-color: var(--focus); }
.tile input:focus-visible + .tile__face { outline: 3px solid var(--focus); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: var(--tap); padding: 8px 14px; border-radius: 24px; font: inherit;
  background: var(--surface-2); color: var(--text); border: 2px solid var(--border); cursor: pointer;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  touch-action: manipulation;
}
.chip.is-active { border-color: var(--focus); background: #1f3b63; }
.suggest { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.suggest__item {
  display: block; width: 100%; min-height: var(--tap); padding: 10px 12px; text-align: left;
  background: var(--surface); color: var(--text); border: 0; border-bottom: 1px solid var(--border); font: inherit; cursor: pointer;
}
.suggest li:last-child .suggest__item { border-bottom: 0; }
.counter { align-self: flex-end; font-variant-numeric: tabular-nums; }

.op-form__actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--border);
}
@media (min-width: 992px) {
  .op-form__actions { left: 50%; right: auto; width: 960px; transform: translateX(-50%); }
}

/* Журнал (компьютер; на телефоне таблица прокручивается внутри своего блока) */
.page--wide { max-width: 1440px; }
.home-links { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.journal-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 16px; }
.journal-head .title { margin: 0; }
.filters { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; padding: 16px; }
.filters__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.filters .field__label { font-size: 0.9rem; }
.filters__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.filters__actions .check { margin-right: auto; }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; }
.check input { width: 24px; height: 24px; accent-color: var(--primary); }
.journal-count { margin: 8px 0; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.table th, .table td { padding: 8px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.table th { position: sticky; top: 0; background: var(--surface-2); font-weight: 700; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #20262e; }
.table .wrap { min-width: 160px; max-width: 320px; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.small { font-size: 0.8rem; margin-top: 4px; }
.row--cancelled td { color: var(--muted); }
.row--cancelled td:first-child { text-decoration: line-through; }
.btn--small { min-height: 36px; padding: 4px 12px; font-size: 0.85rem; }
@media (pointer: coarse) { .btn--small { min-height: var(--tap); } }

.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 16px 0; }
.pager .btn { min-width: var(--tap); padding: 8px 12px; }
.pager__gap { padding: 0 4px; color: var(--muted); }

.photo-dialog { padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(96vw, 1060px); }
.photo-dialog::backdrop { background: rgba(0, 0, 0, 0.75); }
.photo-dialog__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 8px 8px 16px; }
.photo-dialog__img { display: block; max-width: 100%; max-height: calc(90vh - 72px); margin: 0 auto; background: #000; }

/* Отчёты */
.report-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.report-tabs__item {
  min-height: var(--tap); display: inline-flex; align-items: center; padding: 8px 16px;
  border-radius: 10px; border: 2px solid var(--border); background: var(--surface);
  color: var(--text); text-decoration: none; font-weight: 600;
}
.report-tabs__item.is-current { border-color: var(--focus); background: #1f3b63; }
.report-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.report-card {
  display: flex; flex-direction: column; gap: 8px; padding: 20px 16px; min-height: 140px;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
}
.report-card:hover { border-color: var(--primary); }
.report-card__title { font-weight: 700; font-size: 1.15rem; }
.report-card__value { font-size: 2.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.report-card__text { color: var(--muted); font-size: 0.95rem; }
.filters__row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.filters__row .field { flex: 0 1 220px; }
.quick-periods { display: flex; flex-wrap: wrap; gap: 8px; }
.report-period { margin: 8px 0 12px; font-weight: 600; }
.report-note { margin: 12px 0 0; font-size: 0.95rem; max-width: 80ch; }
.report-note--warning { color: #ffcf8a; }

.table--report { font-size: 0.95rem; }
.table--report th { position: static; white-space: normal; }
.table--report td.num, .table--report th + td, .table--report thead th:not(:first-child) { text-align: right; }
.table--report tbody td:first-child { text-align: left; }
.table--report .th-group { text-align: center !important; border-bottom-color: var(--border); }
.table--report tfoot th, .table--report tfoot td { background: var(--surface-2); font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
.table--report .strong { font-weight: 700; }
.table--report .is-negative, .inside-summary__value.is-negative { color: #ff9c9c; }
.neg-mark { margin-left: 2px; cursor: help; }

.inside-summary { display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 4px 16px; margin-bottom: 16px; }
.inside-summary__label { font-size: 1.2rem; }
.inside-summary__value { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.inside-summary__baseline { grid-column: 1 / -1; margin: 0; }

/* Столбчатый график (inline SVG, без JS). Цвета проверены на контраст и цветослепоту. */
.chart { margin: 0 0 16px; padding: 12px 16px 8px; }
.chart__legend { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; margin-bottom: 8px; font-size: 0.95rem; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; }
.legend-item__swatch { width: 14px; height: 14px; border-radius: 3px; }
.legend-item__swatch--entry, .chart__bar--entry { background: #2fae62; fill: #2fae62; }
.legend-item__swatch--exit, .chart__bar--exit { background: #4a8af4; fill: #4a8af4; }
.chart__scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart__svg { display: block; width: 100%; min-width: 720px; height: auto; }
.chart__grid { stroke: var(--border); stroke-width: 1; }
.chart__grid--base { stroke: var(--muted); }
.chart__tick, .chart__hour { fill: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.chart__tick { text-anchor: end; }
.chart__hour { text-anchor: middle; }
.chart__hit { fill: transparent; }
.chart__hit:hover { fill: rgba(255, 255, 255, 0.06); }
