:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1c2530;
  --muted: #6b7885;
  --line: #dde3e9;
  --brand: #1f3864;
  --brand-soft: #e8eef7;
  --ok: #1e7d44;
  --ok-bg: #d9f2e2;
  --warn: #9a5b00;
  --warn-bg: #ffeccc;
  --bad: #a32020;
  --bad-bg: #ffdede;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

a { color: var(--brand); }

/* ---------------- шапка ---------------- */
.top {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--brand);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 16px; }
.brand span { font-weight: 400; opacity: .75; }
.top nav { display: flex; gap: 18px; margin-left: 8px; }
.top nav a { color: #fff; text-decoration: none; opacity: .85; font-size: 14px; }
.top nav a:hover { opacity: 1; text-decoration: underline; }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 13px; }
.who .fio { font-weight: 600; }
.who .role { opacity: .7; }
.who .exit { color: #fff; opacity: .8; }

main { padding: 22px 20px 60px; }

/* ---------------- заголовок страницы ---------------- */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
h1 { margin: 0 0 4px; font-size: 22px; }
.norm { margin: 0; color: var(--muted); font-size: 14px; }
.return-note { margin: 6px 0 0; color: var(--warn); font-size: 14px; }

.period { display: flex; gap: 8px; }
.period select {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
}

/* ---------------- значки ---------------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
}
.badge.ok { background: var(--ok-bg); color: #16613a; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.draft { background: #e9edf2; color: var(--muted); }
.badge.closed { background: #e0e4e9; color: #4a5560; }

/* ---------------- карточки отделов ---------------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-decoration: none;
  color: inherit;
  transition: box-shadow .15s, transform .15s;
}
.card:hover { box-shadow: 0 4px 16px rgba(20,40,70,.12); transform: translateY(-1px); }
.card.submitted { border-left: 4px solid #2e9e63; }
.card.returned { border-left: 4px solid #e0a13a; }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card-top .dept { font-weight: 600; }
.card-body { margin: 10px 0 4px; display: flex; align-items: baseline; gap: 6px; }
.card-body .count { font-size: 28px; font-weight: 700; color: var(--brand); }
.card-body .count-label { color: var(--muted); font-size: 13px; }
.card-foot { font-size: 12px; color: var(--muted); }
.card-foot.warn-text { color: var(--warn); }

/* ---------------- палитра кодов ---------------- */
.palette {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  position: sticky;
  top: 52px;
  z-index: 40;
}
.palette-label { font-size: 13px; color: var(--muted); margin-right: 4px; }
.palette-hint { font-size: 12px; color: var(--muted); margin-left: 8px; }
.chip {
  min-width: 40px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--chip, #fff);
  font: 600 13px/1 inherit;
  cursor: pointer;
}
.chip:hover { border-color: var(--brand); }
.chip.active { outline: 2px solid var(--brand); outline-offset: 1px; }

/* ---------------- сетка табеля ---------------- */
.grid-wrap {
  overflow: auto;
  max-height: calc(100vh - 260px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table.grid { border-collapse: separate; border-spacing: 0; font-size: 13px; }
.grid th, .grid td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0;
  text-align: center;
  white-space: nowrap;
}
.grid thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--brand-soft);
  font-weight: 600;
  padding: 4px 6px;
  color: #24354f;
}
.grid thead th.weekend { background: #dfe3e8; color: #8a2020; }
.grid th.day { min-width: 30px; }
.grid th.day .dnum { display: block; font-size: 13px; }
.grid th.day .dwd { display: block; font-size: 10px; font-weight: 400; opacity: .7; }

.sticky-l { position: sticky; background: var(--panel); z-index: 15; }
.grid thead .sticky-l { z-index: 30; background: var(--brand-soft); }
.num { left: 0; width: 34px; color: var(--muted); }
.fio {
  left: 34px;
  min-width: 200px;
  max-width: 240px;
  text-align: left;
  padding: 4px 8px !important;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  border-right: 1px solid var(--line);
}
.pos {
  min-width: 150px;
  max-width: 190px;
  text-align: left;
  padding: 4px 8px !important;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}

td.cell {
  width: 30px;
  height: 30px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
td.cell:hover { outline: 2px solid var(--brand); outline-offset: -2px; }
td.cell.empty { background: repeating-linear-gradient(45deg, #fff, #fff 4px, #ffe9e9 4px, #ffe9e9 8px); }
td.cell.saved { animation: pulse .7s ease-out; }
td.cell.failed { outline: 2px solid var(--bad); outline-offset: -2px; }
@keyframes pulse { from { box-shadow: inset 0 0 0 2px #2e9e63; } to { box-shadow: none; } }

.tot {
  background: #f7f9fb;
  font-weight: 600;
  min-width: 52px;
  padding: 4px 8px !important;
  font-size: 12px;
}
.grid tbody tr:hover td:not(.sticky-l) { background-color: rgba(31,56,100,.04); }

/* ---------------- прочее ---------------- */
.note {
  background: #fff8e6;
  border: 1px solid #f0dca8;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 14px;
}
.problems {
  margin-top: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid #e0a13a;
  border-radius: var(--radius);
  padding: 12px 18px;
}
.problems h2 { margin: 0 0 8px; font-size: 15px; color: var(--warn); }
.problems ul { margin: 0; padding-left: 20px; font-size: 13px; color: #55606b; }

.actions { margin-top: 18px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn {
  display: inline-block;
  padding: 9px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  font: 600 14px/1.2 inherit;
  cursor: pointer;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:disabled { background: #b9c2cd; border-color: #b9c2cd; cursor: not-allowed; }
.hint { font-size: 13px; color: var(--muted); }
.return-form input {
  flex: 1;
  min-width: 260px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

/* ---------------- вход ---------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 30px 28px;
  box-shadow: 0 8px 30px rgba(20,40,70,.08);
}
.login h1 { font-size: 19px; margin: 0 0 2px; }
.login .sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.login label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.login input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: 15px inherit;
}
.login button {
  width: 100%;
  padding: 11px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font: 600 15px inherit;
  cursor: pointer;
}
.login .hint { display: block; margin: 14px 0 0; text-align: center; }
.err {
  background: #ffe2e2;
  border: 1px solid #f0b4b4;
  color: #8d1f1f;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: #2b3440;
  color: #fff;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================= телефоны и планшеты ================= */
/* Многие руководители работают удалённо и заполняют табель с телефона. */

@media (max-width: 900px) {
  .top { flex-wrap: wrap; gap: 10px 16px; padding: 9px 14px; }
  .top nav { order: 3; width: 100%; margin: 0; gap: 14px; }
  .who { font-size: 12px; gap: 8px; }
  .who .role { display: none; }

  main { padding: 16px 12px 48px; }
  h1 { font-size: 19px; }

  .page-head { gap: 12px; }
  .period { width: 100%; }
  .period select { flex: 1; padding: 9px 10px; font-size: 15px; }

  .cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .card { padding: 12px; }
  .card-body .count { font-size: 22px; }

  /* Палитра — одной прокручиваемой строкой, чтобы не занимала пол-экрана */
  .palette {
    top: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 8px;
    padding: 10px;
    -webkit-overflow-scrolling: touch;
  }
  .palette-label, .palette-hint { display: none; }
  .chip { flex: 0 0 auto; min-width: 46px; padding: 10px 12px; font-size: 15px; }

  /* Должность на узком экране не помещается — она есть в своде */
  .pos, th.pos { display: none; }

  .grid-wrap { max-height: calc(100vh - 210px); border-radius: 8px; }
  .fio { min-width: 128px; max-width: 128px; font-size: 12px; }
  td.cell { width: 38px; height: 40px; font-size: 13px; }  /* палец, не курсор */
  .grid th.day { min-width: 38px; }
  .tot { min-width: 46px; font-size: 11px; }

  .actions { flex-direction: column; align-items: stretch; }
  .btn { text-align: center; padding: 12px 18px; }
  .return-form input { min-width: 0; }
}

@media (max-width: 560px) {
  .num, th.num { display: none; }
  .fio { left: 0; min-width: 108px; max-width: 108px; }
  .brand span { display: none; }
  /* Из итогов на телефоне оставляем главное — дни и часы */
  .t-vac, .t-sick, .t-ctrl,
  .grid thead th:nth-last-child(-n+3) { display: none; }
}

/* Не даём странице ехать вбок: прокручивается только таблица */
html, body { max-width: 100%; overflow-x: hidden; }

/* ---------------- свод ---------------- */
h2.sec { font-size: 15px; margin: 22px 0 10px; color: #3b4754; }
table.grid.plain td, table.grid.plain th { padding: 6px 10px; font-size: 13px; }
table.grid.plain td.l, table.grid.plain th.l { text-align: left; }
table.grid.plain td.muted { color: var(--muted); font-size: 12px; }
table.grid.plain td.zero { color: #c3cad2; }
table.grid.plain td.has { font-weight: 600; }
table.grid.plain tfoot td { background: var(--brand-soft); position: sticky; bottom: 0; }
.bad { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.inline-return { display: flex; gap: 6px; }
.inline-return input {
  width: 150px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: 12px inherit;
}
@media (max-width: 900px) {
  table.grid.plain td, table.grid.plain th { padding: 8px 8px; font-size: 12px; }
  .inline-return { flex-direction: column; }
  .inline-return input { width: 110px; }
}

/* ---------------- сотрудники ---------------- */
tr.dimmed td { opacity: .45; }
.small { font-size: 11px; }
.nowrap { white-space: nowrap; }
.chip-static {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--brand-soft);
  font-weight: 600;
  font-size: 12px;
}
dialog.editor {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px 26px;
  width: min(560px, calc(100vw - 32px));
  box-shadow: 0 24px 60px -20px rgba(20,40,70,.5);
}
dialog.editor::backdrop { background: rgba(20,30,45,.45); }
dialog.editor h2 { margin: 0 0 18px; font-size: 18px; }
dialog.editor label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}
dialog.editor input, dialog.editor select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: 15px inherit;
  background: #fff;
  color: var(--ink);
}
dialog.editor .two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
dialog.editor .hint { margin: 4px 0 0; font-size: 12px; line-height: 1.5; }
dialog.editor .actions { margin-top: 18px; }

/* День с часами, хотя код не «явка»: подработка в отпуске, выход в выходной */
td.cell.off-schedule::after {
  content: "";
  position: absolute;
  right: 1px; bottom: 1px;
  border: 4px solid transparent;
  border-right-color: #1f3864;
  border-bottom-color: #1f3864;
}
td.cell { position: relative; }

/* Переключатель периода в своде: месяц / первая половина / вторая */
.halves { display: flex; gap: 0; margin-bottom: 14px; flex-wrap: wrap; }
.halves .half {
  padding: 8px 16px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.halves .half:first-child { border-radius: 8px 0 0 8px; }
.halves .half:last-child { border-radius: 0 8px 8px 0; }
.halves .half + .half { border-left: 0; }
.halves .half.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------------- памятка ---------------- */
.doc { max-width: 800px; }
.doc h2 { font-size: 17px; margin: 30px 0 10px; color: #24354f; }
.doc h2:first-child { margin-top: 0; }
.doc p { margin: 0 0 12px; }
.doc .muted { color: var(--muted); font-size: 14px; }
.doc table.deadlines { width: 100%; margin-bottom: 16px; }
.doc ol.steps-list { margin: 0 0 12px; padding-left: 22px; }
.doc ol.steps-list li { margin-bottom: 7px; }

.codes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 7px;
  margin-bottom: 14px;
}
.code-item { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.code-badge {
  flex: 0 0 auto;
  min-width: 38px;
  text-align: center;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-weight: 700;
  font-size: 13px;
}

dl.cases { margin: 0; }
dl.cases dt {
  font-weight: 600;
  margin-top: 16px;
  padding-left: 12px;
  border-left: 3px solid var(--brand);
}
dl.cases dd { margin: 5px 0 0 15px; color: #45505c; }
