:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #d6d9df;
  --accent: #2f5bd3;
  --danger: #c0392b;
  --duty-bg: #ffd9a8;
  --duty-fg: #8a4b00;
  --sleep-bg: #d9e8ff;
  --sleep-fg: #1f4f9a;
  --off-bg: #dff3e1;
  --off-fg: #23703a;
  --abs-bg: #e7e1f5;
  --abs-fg: #5b3d99;
  --weekend: #f1f2f6;
  --warn: #ffe1e1;
  --sticky-w1: 150px;
  --sticky-w2: 230px;
}

* { box-sizing: border-box; }

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

button, .btn, input, select {
  font: inherit;
}

button, .btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; }
button.link.danger { color: var(--danger); }

input, select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  background: #fff;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: #1f2a44;
  color: #fff;
}
.topbar h1 { font-size: 18px; margin: 0; }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tab { background: transparent; color: #cdd5ea; border-color: transparent; }
.tab.active { background: #fff; color: #1f2a44; }
.io { display: flex; gap: 6px; }
.io button:disabled { opacity: .45; cursor: default; }

main { padding: 12px 16px; }
.panel { display: none; }
.panel.active { display: block; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.check { display: inline-flex; align-items: center; gap: 4px; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.legend b { display: inline-block; min-width: 22px; text-align: center; border-radius: 3px; padding: 0 3px; }
.c-duty { background: var(--duty-bg); color: var(--duty-fg); }
.c-sleep { background: var(--sleep-bg); color: var(--sleep-fg); }
.c-off { background: var(--off-bg); color: var(--off-fg); }
.c-abs { background: var(--abs-bg); color: var(--abs-fg); }
.c-busy { color: #9aa1ad; }
.manual-mark { display: inline-block; width: 8px; height: 8px; border-top: 8px solid var(--accent); border-left: 8px solid transparent; vertical-align: middle; }

.grid-wrap {
  overflow: auto;
  max-height: calc(100vh - 170px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

table.grid {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}
.grid th, .grid td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0;
  text-align: center;
  height: 24px;
}
.grid thead th {
  position: sticky;
  top: 0;
  background: #eef0f4;
  z-index: 2;
  min-width: 30px;
  font-weight: 600;
  cursor: pointer;
}
.grid thead th small { display: block; font-weight: 400; color: var(--muted); font-size: 10px; }
.grid thead th.weekend { background: #e3e6ee; color: var(--danger); }
.grid thead th.today { box-shadow: inset 0 -3px 0 var(--accent); }
.grid .sticky1, .grid .sticky2 {
  position: sticky;
  background: var(--panel);
  z-index: 1;
  text-align: left;
  padding: 0 6px;
  white-space: nowrap;
}
.grid .sticky1 { left: 0; min-width: var(--sticky-w1); max-width: var(--sticky-w1); overflow: hidden; text-overflow: ellipsis; }
.grid .sticky2 { left: var(--sticky-w1); min-width: var(--sticky-w2); max-width: var(--sticky-w2); overflow: hidden; text-overflow: ellipsis; }
.grid thead .sticky1, .grid thead .sticky2 { z-index: 3; cursor: default; }
.grid th.total, .grid td.total { min-width: 34px; font-weight: 600; background: #fafbfc; }

.grid tr.post-head td {
  background: #1f2a44;
  color: #fff;
  font-weight: 600;
  text-align: left;
  padding: 0 6px;
}
.grid tr.post-head td.sticky1 { background: #1f2a44; }
.grid tr.post-head .rule { font-weight: 400; color: #b8c2dc; margin-left: 8px; }
.grid tr.empty td { color: var(--muted); font-style: italic; text-align: left; padding: 0 6px; }
.grid tr.cover td { background: #fafbfc; color: var(--muted); font-size: 11px; }
.grid tr.cover td.miss { background: var(--warn); color: var(--danger); font-weight: 700; }
.grid tr.cover td.multi { background: #fff4d6; color: #8a6d00; font-weight: 700; }
.grid tr.post-end td { border-bottom: 2px solid #9aa3b5; }

.grid td.cell { cursor: pointer; position: relative; min-width: 30px; }
.grid td.cell:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid td.weekend { background: var(--weekend); }
.grid td.code-Ч { background: var(--duty-bg); color: var(--duty-fg); font-weight: 700; }
.grid td.code-О { background: var(--sleep-bg); color: var(--sleep-fg); }
.grid td.code-В { background: var(--off-bg); color: var(--off-fg); }
.grid td.abs { background: var(--abs-bg); color: var(--abs-fg); font-size: 10px; }
.grid td.busy { color: #9aa1ad; }
.grid td.cell.sel { box-shadow: inset 0 0 0 2px var(--accent); background-image: linear-gradient(rgba(47, 91, 211, .14), rgba(47, 91, 211, .14)); }
#grid-wrap.dragging { user-select: none; cursor: cell; }
.grid td.cell.in-range { outline: 2px solid var(--accent); outline-offset: -2px; background-color: #e3ebff; }
.field { display: block; }
.field select, .field input { display: block; width: 100%; margin-top: 2px; margin-bottom: 8px; }
.meta-box { margin-top: 8px; font-size: 13px; }
.meta-box .warn { color: #8a6d00; }
.grid td.shift-off { background: repeating-linear-gradient(135deg, #eef8ef 0 4px, #f8fcf8 4px 8px); }
.grid tr.post-head .move { display: inline-flex; gap: 2px; margin-right: 6px; vertical-align: middle; }
.grid tr.post-head .move button { padding: 0 4px; font-size: 10px; line-height: 16px; border-radius: 3px; background: #33415f; border-color: #4a5878; color: #dfe5f3; }
.grid tr.post-head .move button:disabled { opacity: .35; cursor: default; }
.grid td.trip { box-shadow: inset 0 -3px 0 var(--abs-fg); }
.grid td.trip-idle { background: var(--abs-bg); color: var(--abs-fg); font-size: 10px; opacity: .75; }
.grid td.manual::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  border-top: 6px solid var(--accent);
  border-left: 6px solid transparent;
}

.cell-menu {
  position: fixed;
  z-index: 100;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
  padding: 6px;
  min-width: 200px;
}
.cell-menu .menu-title { font-size: 12px; color: var(--muted); padding: 2px 6px 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.cell-menu button { display: flex; width: 100%; gap: 8px; border: 0; text-align: left; padding: 5px 6px; }
.cell-menu button:hover { background: #eef2fd; }
.cell-menu button b { min-width: 24px; text-align: center; border-radius: 3px; }
.cell-menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

.report { margin-top: 8px; color: var(--danger); font-size: 13px; }
.report.ok { color: var(--off-fg); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 10px; }
.hint { color: var(--muted); margin-top: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.row.end { justify-content: flex-end; }
.row h3 { margin: 0; flex: 1; }

.people-layout { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.people-layout form { width: 320px; flex: none; }
.people-layout .grow { flex: 1; min-width: 320px; }
#person-form label { display: block; margin-bottom: 8px; }
#person-form label input { display: block; width: 100%; margin-top: 2px; }
fieldset { border: 1px solid var(--border); border-radius: 6px; margin: 0; }
.post-checks { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
.post-checks label { display: flex !important; gap: 4px; align-items: center; margin: 0 !important; }
.post-checks label input { width: auto !important; display: inline !important; margin: 0 !important; }

table.list { width: 100%; border-collapse: collapse; }
.list th, .list td { border-bottom: 1px solid var(--border); padding: 6px; text-align: left; vertical-align: top; }
.list th { color: var(--muted); font-weight: 600; font-size: 12px; }
.tag { display: inline-block; background: #eef0f4; border-radius: 10px; padding: 0 8px; margin: 1px 2px; font-size: 12px; }
.tag.abs { background: var(--abs-bg); color: var(--abs-fg); }
.list input.rule { width: 90px; }
.list input.slots { width: 52px; }

.day-view { max-width: 900px; }
.report-head { display: flex; align-items: baseline; gap: 12px; }
.report-head h2 { margin: 4px 0 10px; }
.report-miss { background: var(--warn); color: var(--danger); border-radius: 6px; padding: 6px 10px; margin-bottom: 10px; }
.report-section + .report-section { margin-top: 14px; }
.report-section h3 { margin: 0 0 4px; font-size: 15px; padding-left: 8px; border-left: 4px solid var(--border); }
.report-section h3 .count { color: var(--muted); font-weight: 400; }
.report-section ol { margin: 0; padding-left: 36px; }
.report-section li { padding: 3px 0; border-bottom: 1px dashed var(--border); }
.report-section li:last-child { border-bottom: 0; }
.report-section .ri { display: flex; justify-content: space-between; gap: 16px; }
.report-section .ri .post { color: var(--muted); text-align: right; white-space: nowrap; }
.s-duty h3 { border-color: var(--duty-fg); }
.s-ВП h3, .s-ВД h3, .s-Х h3 { border-color: var(--abs-fg); }
.s-off h3 { border-color: var(--off-fg); }
.s-sleep h3 { border-color: var(--sleep-fg); }
.s-work h3 { border-color: var(--accent); }

dialog { border: 1px solid var(--border); border-radius: 10px; padding: 16px; min-width: 520px; }
dialog.wide { width: min(900px, 96vw); }
dialog textarea { width: 100%; box-sizing: border-box; font: inherit; }
.raport-preview { max-height: 40vh; overflow: auto; border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; margin: 8px 0; font-family: "Times New Roman", serif; font-size: 15px; }
.raport-preview p { margin: 0 0 4px; text-align: justify; }
.raport-preview .k-addressee { margin-left: 50%; font-weight: bold; margin-bottom: 0; }
.raport-preview .k-title { text-align: center; font-weight: bold; margin: 8px 0; }
.raport-preview .k-intro, .raport-preview .k-outro { text-indent: 2em; }
.raport-preview .k-person { text-indent: 2.4em; }
.raport-preview .k-signer { font-weight: bold; white-space: pre; }
.pay-flags label { display: block; white-space: nowrap; }
.raport-numbers { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.raport-numbers label { display: flex; flex-direction: column; font-size: 13px; }
.raport-numbers input { width: 140px; }
.raport-numbers input.missing { border-color: #b00020; background: #fff3f4; }
.raport-numbers .hint { font-size: 12px; }
.raport-preview .missing-number { background: #ffe1e4; color: #b00020; }
.raport-check td.bad { color: #b00020; }
.raport-check td.ok { color: #1b7f3b; }
dialog::backdrop { background: rgba(0, 0, 0, .3); }
#absence-list .item { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; border-bottom: 1px dashed var(--border); }

.sheet { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.sheet h4 { margin: 0 0 6px; display: flex; gap: 8px; align-items: center; }
.sheet .meta { color: var(--muted); font-size: 12px; }
.sheet ul { margin: 4px 0; padding-left: 18px; max-height: 140px; overflow: auto; }
.sheet .warn { color: #8a6d00; }
.sheet.unknown { opacity: .6; }

#text-input { width: 100%; font: 13px/1.5 ui-monospace, Consolas, monospace; border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.text-table { border-collapse: collapse; margin-top: 8px; font-size: 12px; }
.text-table td, .text-table th { border: 1px solid var(--border); padding: 2px 6px; text-align: left; }

.strength-day { margin-bottom: 18px; page-break-inside: avoid; }
.strength-day h3 { margin: 0 0 6px; }
table.strength { border-collapse: collapse; background: var(--panel); font-size: 13px; }
.strength th, .strength td { border: 1px solid #8f96a3; padding: 4px 8px; text-align: center; }
.strength th { font-weight: 600; font-size: 12px; max-width: 120px; background: #eef0f4; }
.strength td:first-child, .strength th:first-child { text-align: left; white-space: nowrap; max-width: none; }
#person-form label select { display: block; width: 100%; margin-top: 2px; }
.strength tr.total td { font-weight: 700; background: #f6f7f9; }
.strength tr.unknown td { color: #8a6d00; background: #fff8e1; }
.strength td.has-names { cursor: help; }
.strength td.has-names:hover { background: #e3ebff; }
.names-tip { position: fixed; z-index: 120; background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15); padding: 8px 10px; max-width: 460px; max-height: 60vh; overflow: auto; font-size: 12px; pointer-events: none; }
.names-tip[hidden] { display: none; }
.names-tip .names-title { font-weight: 600; margin-bottom: 4px; }
.names-tip ol { margin: 0; padding-left: 22px; }
.names-tip li { padding: 1px 0; }
.names-tip .post { color: var(--muted); }
.names-tip .rank-group + .rank-group { margin-top: 6px; padding-top: 4px; border-top: 1px solid var(--border); }
.names-tip .rank-head { font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.staff-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 14px; margin-top: 10px; }
.staff-grid label { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 13px; }
.staff-grid input { width: 80px; }
.staff-grid .wide { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
table.numbers td.left { text-align: left; }
table.numbers td.hdr { font-weight: 600; background: #eef0f4; font-size: 12px; }
table.numbers td.vert { writing-mode: vertical-rl; transform: rotate(180deg); }
.strength-day .form-title { text-align: center; font-weight: 700; margin: 0 0 6px; }
.strength-warn { background: #fff8e1; color: #8a6d00; border-radius: 6px; padding: 6px 10px; margin-bottom: 10px; }
.list select.cat, .list input.rank { font-size: 12px; padding: 2px 4px; }
.list input.rank { width: 150px; }

.grid td.name-cell { position: sticky; padding-right: 22px; }
.grid td.name-cell .row-remove { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); display: none;
  border: 0; background: none; color: var(--danger); padding: 0 4px; font-size: 12px; }
.grid tr:hover td.name-cell .row-remove { display: inline-block; }
.grid tr.post-head .add-person { margin-left: 8px; padding: 0 6px; font-size: 11px; line-height: 16px; border-radius: 3px;
  background: #33415f; border-color: #4a5878; color: #dfe5f3; font-weight: 400; }
.cell-menu.wide { width: 380px; }
.cell-menu input[type=search] { width: 100%; margin: 4px 0; }
.pick-list { max-height: 50vh; overflow: auto; }
.pick-list button { justify-content: space-between; }
.pick-list button .post { color: var(--muted); font-size: 11px; white-space: nowrap; }
.list td.duty-count { text-align: center; font-weight: 600; }
.list td.has-names { cursor: help; }

.staff-group { margin-bottom: 14px; }
.staff-group .group-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.staff-group .group-head input.group-name { font-weight: 700; font-size: 15px; min-width: 260px; }
.staff-group .group-head .counts { color: var(--muted); font-size: 13px; }
.staff-group .group-head .counts b { color: var(--text); }
table.staff { width: 100%; border-collapse: collapse; font-size: 13px; }
.staff th, .staff td { border: 1px solid var(--border); padding: 3px 5px; vertical-align: middle; }
.staff th { background: #eef0f4; font-size: 12px; text-align: left; }
.staff td input, .staff td select { width: 100%; border-color: transparent; background: transparent; padding: 2px 4px; }
.staff td input:hover, .staff td select:hover, .staff td input:focus, .staff td select:focus { border-color: var(--border); background: #fff; }
.staff td.num { width: 32px; text-align: center; color: var(--muted); }
.staff td input.slot-title { min-width: 190px; }
.staff td input[list=ranks] { min-width: 130px; }
.staff td select { min-width: 120px; }
.staff td:nth-child(5) select { min-width: 220px; max-width: 280px; }
.staff td.vacant select { color: var(--danger); font-style: italic; }
.staff td.mismatch input { background: #fff8e1; }
.staff td.actions { white-space: nowrap; width: 1%; }
.staff tr.vacant-row td:not(.actions) { background-color: #fdf7f7; }
.staff-free { color: var(--muted); font-size: 13px; }
.staff-free .tag { cursor: default; }

/* ---------- Sign-in, users, roles ---------- */

[hidden] { display: none !important; }
body.locked .topbar, body.locked main { display: none; }
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { margin: 0 0 8px; }
.login-error { color: var(--danger); min-height: 1.4em; white-space: pre-line; }
.login-quick { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; }
.login-quick button { display: flex; justify-content: space-between; gap: 8px; width: 100%; margin-top: 4px; text-align: left; }
.login-quick .role { color: var(--muted); font-size: 12px; }
.userbox { display: flex; gap: 8px; align-items: center; color: #cdd5ea; }
.userbox #user-name { font-size: 13px; }
.grid td.cell.ro { cursor: default; }
.tag.role-superadmin { background: #fde2e2; }
.tag.role-admin { background: #fff1d6; }
.tag.status-disabled { color: var(--danger); }
.tag.status-invited { color: var(--muted); }
.perm-table td:not(:first-child), .perm-table th:not(:first-child) { text-align: center; width: 120px; }
.perm-table .only { color: var(--muted); font-size: 12px; }
#audit-body td:first-child { white-space: nowrap; }
#audit-body td:last-child { white-space: pre-line; }
#audit-body tr.alert-row td { background: var(--warn); }
#audit-devices .meta-box { margin: 8px 0; }
.list input.vpn { width: 120px; font-size: 12px; }
.users-posts { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 4px; }

.print-only { display: none; }

@media print {
  @page { size: A4 landscape; margin: 8mm; }
  body { background: #fff; font-size: 10px; }
  .no-print, .topbar, .names-tip { display: none !important; }
  .print-only { display: block; font-size: 14px; margin: 0 0 6px; }
  main { padding: 0; }
  .grid-wrap { max-height: none; overflow: visible; border: 0; }
  .grid { font-size: 9px; }
  .grid th, .grid td { height: 16px; border-color: #999; }
  .grid thead th { min-width: 18px; }
  .grid td.cell { min-width: 18px; }
  .grid .sticky1, .grid .sticky2, .grid thead th { position: static; }
  .grid td.manual::after { display: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
#tab-posts .card { overflow-x: auto; }
.vpn-qr { display: flex; justify-content: center; padding: 8px; background: #fff; }
.vpn-qr img { width: 280px; height: 280px; }
#vpn-tools { margin-left: auto; }
#vpn-dialog { width: min(520px, 96vw); min-width: 0; }
.group-tail { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.group-tail input { width: 340px; font-size: 12px; }
@media print { .group-tail { display: none; } }

/* Server mode: sign-in, activation, 2FA, backup codes, account */
#server-auth { width: 100%; max-width: 420px; }
#server-auth .login-card { max-width: 420px; margin: 0 auto; }
.code-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .08em; text-transform: uppercase; }
.steps { padding-left: 18px; margin: 4px 0 8px; }
.totp-qr { display: flex; justify-content: center; margin: 8px 0; }
.totp-qr img { width: 200px; height: 200px; image-rendering: pixelated; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.totp-key { text-align: center; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.totp-key code { color: var(--text); user-select: all; word-break: break-all; }
.backup-list { columns: 2; column-gap: 20px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13.5px; margin: 8px 0; padding-left: 26px; }
.backup-list li { margin: 2px 0; user-select: all; white-space: nowrap; }
.sync-status { font-size: 12px; color: #cdd5ea; }
.sync-status.error { color: #ffb4a8; font-weight: 600; }
.code-dialog { max-width: 560px; }
.code-box { border: 1px dashed var(--border); border-radius: 8px; padding: 12px; margin: 8px 0; text-align: center; }
.code-big { font: 600 22px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .06em; user-select: all; word-break: break-all; }
.account-dialog form { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; }
.account-dialog h4 { margin: 4px 0 8px; }
