/* График смен — вид, максимально близкий к Excel, но приятнее и без зума страницы. */
:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #182230;
  --muted: #6b7686;
  --line: #d8e0ea;
  --line-soft: #eef2f7;
  --head: #eaf0f7;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --weekend: #fbf1f1;
  --today: #fff6d8;
  --after: #fff0f0;
  --after-ink: #b3261e;
  --ok: #1a7f37;
  --radius: 10px;
  --cell: 34px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.35 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

/* Шапка */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(14px, env(safe-area-inset-left)) 10px max(14px, env(safe-area-inset-right));
  background: linear-gradient(180deg, #ffffff 0%, #f9fbfe 100%);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 15px;
  flex: 0 0 auto;
}
.brand-text { font-weight: 650; letter-spacing: .2px; white-space: nowrap; }
.who { color: var(--muted); font-size: 13px; text-align: right; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who b { color: var(--ink); font-weight: 600; }

main {
  padding: 12px max(10px, env(safe-area-inset-left)) calc(18px + env(safe-area-inset-bottom))
          max(10px, env(safe-area-inset-right));
  max-width: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* Вход */
.gate {
  max-width: 420px; margin: 6vh auto 0;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 22px;
  box-shadow: 0 6px 24px rgba(24, 34, 48, .06);
}
.gate h1 { font-size: 20px; margin: 0 0 6px; }
.gate-form { display: grid; gap: 12px; margin-top: 16px; }
.gate-form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, button { font: inherit; color: inherit; }
input, select {
  min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; width: 100%;
}
input:focus, select:focus { outline: 2px solid rgba(31,111,235,.35); border-color: var(--accent); }
.err { color: #b3261e; font-size: 13px; min-height: 18px; margin: 0; }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 7px 13px;
  border: 1px solid var(--line); border-radius: 9px;
  background: #fff; cursor: pointer;
  white-space: nowrap; font-size: 14px;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: #f2f6fc; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.icon { min-width: 38px; padding: 4px 10px; font-size: 20px; line-height: 1; }

/* Панель месяца */
.board-head {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-title {
  font-size: 17px; font-weight: 650; min-width: 150px; text-align: center;
  text-transform: capitalize;
}
.board-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
.search { min-width: 160px; max-width: 220px; }
.team-filter { min-width: 130px; max-width: 190px; }

.hint { color: var(--muted); font-size: 12.5px; margin: 8px 2px 0; }

/* Лента забора */
.take-banner {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid #f3d8a8; background: #fff8e8;
  border-radius: 10px; font-size: 13.5px; color: #6b4a09;
}
.take-banner.alert { border-color: #f2c3c3; background: var(--after); color: var(--after-ink); }

/* Сетка: прокрутка только внутри листа */
.sheet-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 2px 10px rgba(24,34,48,.04);
  max-height: calc(100dvh - 190px);
}
.sheet {
  display: grid;
  grid-auto-rows: var(--cell);
  font-variant-numeric: tabular-nums;
  min-width: 0;
}

/* Заголовок: ФИО/регион/итого закреплены слева */
.cell {
  display: flex; align-items: center; justify-content: center;
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  position: relative;
  min-width: 0;
}
.cell.head {
  background: var(--head); font-weight: 620; font-size: 11.5px;
  color: #3c4a5c; position: sticky; top: 0; z-index: 5;
}
.cell.head.wkd { background: #f6e3e3; }
.cell.day { color: #22303f; }
.cell.day.wkd { background: var(--weekend); }
.cell.day.today { background: var(--today); box-shadow: inset 0 0 0 2px #f0c14b; }
.cell.day.editable { cursor: pointer; }
.cell.day.editable:hover { background: #eef5ff; }
.cell.day.editable::after {
  content: ""; position: absolute; inset: 0; border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(31,111,235,.18);
  opacity: 0; transition: opacity .1s;
}
.cell.day.editable:hover::after { opacity: 1; }
.cell.day.other { color: #9aa6b5; background: #f8fafc; }
.cell.day.mine { font-weight: 600; }

/* Слева: ФИО / регион / итого */
.cell.name, .cell.region, .cell.team, .cell.total {
  position: sticky; z-index: 6; background: var(--panel);
  justify-content: flex-start; padding: 0 8px; font-size: 13px;
  border-right: 1px solid var(--line);
}
.cell.head.name, .cell.head.region, .cell.head.team, .cell.head.total {
  z-index: 8; background: var(--head); justify-content: center; padding: 0 4px;
}
.cell.name { left: 0; }
.cell.region { left: var(--w-name); }
.cell.total { left: calc(var(--w-name) + var(--w-region)); }
.cell.name { width: var(--w-name); min-width: var(--w-name); max-width: var(--w-name);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; }
.cell.region { width: var(--w-region); min-width: var(--w-region); max-width: var(--w-region);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.cell.total { width: var(--w-total); min-width: var(--w-total); max-width: var(--w-total);
  justify-content: center; font-weight: 650; }
.cell.day { width: var(--w-day); min-width: var(--w-day);}
.cell.head.day { width: var(--w-day); min-width: var(--w-day); flex-direction: column; gap: 0; line-height: 1.05; }
.cell.head.day small { font-size: 9.5px; color: var(--muted); font-weight: 500; }

.row-mine .cell.name { background: #eef6ff; box-shadow: inset 3px 0 0 var(--accent); }
.row-inactive { opacity: .55; }
.cell.day.after-take { box-shadow: inset 0 0 0 1px rgba(179,38,30,.35); }

.legend { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
}
.legend-item b { font-weight: 650; }

/* Модальные окна */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(16, 24, 36, .38);
  padding: 0;
}
.modal-box {
  background: #fff; width: min(560px, 100%);
  border-radius: 14px 14px 0 0;
  padding: 16px max(16px, env(safe-area-inset-left)) calc(16px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow: auto;
  box-shadow: 0 -8px 30px rgba(16,24,36,.2);
}
.modal-box.wide { width: min(760px, 100%); }
.modal h3 { margin: 0 0 10px; font-size: 16px; }
.slot-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.slot {
  min-width: 62px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; cursor: pointer; text-align: center;
}
.slot:hover { background: #eef5ff; border-color: #b9d3f8; }
.slot b { display: block; font-size: 15px; }
.slot small { color: var(--muted); font-size: 11px; }
.slot.nonwork b { color: #8a6d3b; }
.range-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 0; border-top: 1px solid var(--line-soft); font-size: 13px; color: var(--muted);
}
.range-row input { width: 64px; min-height: 36px; text-align: center; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.log-filters { margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.log-list { display: grid; gap: 6px; max-height: 54dvh; overflow: auto; }
.log-item {
  display: grid; grid-template-columns: 108px 1fr auto; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--line-soft); border-radius: 8px;
  font-size: 13px; align-items: center;
}
.log-item .ts { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.log-item .who { font-weight: 600; }
.log-item .chg { font-variant-numeric: tabular-nums; color: #3c4a5c; }
.log-item.after { border-color: #f2c3c3; background: var(--after); }
.log-item.after .chg { color: var(--after-ink); }
.log-empty { color: var(--muted); padding: 12px; text-align: center; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  background: #17212e; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 13.5px; z-index: 80; max-width: 90vw; text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.err { background: #8c1d18; }
.toast.ok { background: #1a7f37; }

/* Телефон: сетка остаётся сеткой, но плотнее; прокрутка только внутри листа */
@media (max-width: 780px) {
  :root {
    --cell: 32px;
    --w-name: 136px;
    --w-region: 92px;
    --w-total: 52px;
    --w-day: 34px;
  }
  .brand-text { font-size: 14px; }
  .board-head { gap: 8px; }
  .month-title { font-size: 15px; min-width: 120px; }
  .board-actions { width: 100%; }
  .search { flex: 1 1 130px; max-width: none; }
  .team-filter { flex: 1 1 120px; max-width: none; }
  .board-actions .btn { flex: 0 0 auto; }
  .sheet-wrap { max-height: calc(100dvh - 250px); }
  .cell.name { font-size: 12px; }
  .cell.region { display: none; }
  .cell.head.region { display: none; }
  .cell.total { left: var(--w-name); }
  .log-item { grid-template-columns: 1fr auto; }
  .log-item .ts { grid-column: 1 / -1; }
}

@media (max-width: 420px) {
  :root { --w-name: 118px; --w-total: 46px; --w-day: 32px; --cell: 31px; }
  .who { font-size: 12px; }
}

/* Печать: лист как в Excel */
@media print {
  .topbar, .board-head, .hint, .take-banner, .modal, .toast { display: none !important; }
  .sheet-wrap { max-height: none; overflow: visible; border: 0; box-shadow: none; }
  .cell.head { position: static; }
}

/* Админ-панель */
.admin-sec { border-top: 1px solid var(--line-soft); padding: 14px 0; }
.admin-sec:first-of-type { border-top: 0; padding-top: 4px; }
.admin-sec h4 { margin: 0 0 4px; font-size: 14px; }
.small { font-size: 12.5px; margin: 0 0 10px; }
.admin-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.admin-form input, .admin-form select { flex: 1 1 130px; min-width: 0; min-height: 36px; }
.admin-form .btn { flex: 0 0 auto; }
.slot-admin { display: flex; flex-wrap: wrap; gap: 6px; }
.slot-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px 4px 10px;
  font-size: 13px; background: #fff;
}
.slot-chip input { width: 56px; min-height: 28px; padding: 2px 6px; text-align: center; }
.slot-chip button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 0 4px; }
.chief-list, .people-list { display: grid; gap: 4px; max-height: 190px; overflow: auto; }
.chief-row, .people-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center;
  font-size: 13px; padding: 5px 8px; border: 1px solid var(--line-soft); border-radius: 7px;
}
.people-row { grid-template-columns: 1fr 1fr auto; }
.people-row .link { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people-row .btn { min-height: 28px; padding: 2px 8px; font-size: 12px; }
