:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --text: #17171a;
  --muted: #6e6e76;
  --line: #e3e3e8;
  --accent: #1c1c1e;
  --ok: #1c7a3e;
  --ok-bg: #e4f4ea;
  --warn: #8a5a00;
  --warn-bg: #fdf0d5;
  --bad: #a11d2c;
  --bad-bg: #fbe3e6;
  --info: #14507d;
  --info-bg: #e5f0f9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131316; --surface: #1d1d21; --text: #f2f2f4; --muted: #9c9ca6;
    --line: #2e2e35; --accent: #f2f2f4;
    --ok: #63d089; --ok-bg: #16311f; --warn: #f0c14b; --warn-bg: #332708;
    --bad: #ff8a95; --bad-bg: #3a1419; --info: #7fbcf0; --info-bg: #102638;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  padding: 0 16px env(safe-area-inset-bottom);
}
h1 { font-size: 20px; margin: 0; letter-spacing: -.2px; }
h2 { font-size: 17px; margin: 0 0 10px; letter-spacing: -.2px; }
a { color: inherit; }
.wrap { max-width: 560px; margin: 0 auto; padding-bottom: 40px; }
.wide { max-width: 1240px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0 14px; }
.top .sub { color: var(--muted); font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
        padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }

.state { text-align: center; padding: 22px 16px; }
.state .big { font-size: 30px; font-weight: 700; letter-spacing: -.6px; margin: 6px 0; }
.state .muted { color: var(--muted); font-size: 14px; }

button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
         background: var(--surface); color: var(--text); padding: 10px 14px; }
button:active { transform: translateY(1px); }
button[disabled] { opacity: .55; cursor: not-allowed; }
.btn-main { width: 100%; padding: 22px; font-size: 21px; font-weight: 700; border: none;
            color: #fff; background: var(--accent); border-radius: 16px; letter-spacing: -.3px; }
.btn-in  { background: #1c7a3e; color: #fff; }
.btn-out { background: #24242a; color: #fff; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-sm { padding: 7px 11px; font-size: 14px; }
.btn-accent { background: var(--accent); color: var(--bg); border-color: var(--accent); }

/* «Ещё ▾» в строке таблицы: редкие действия раскрываются тут же, под
   кнопкой. Не всплывающим окном — его обрезала бы прокрутка таблицы. */
details.acts > summary { list-style: none; cursor: pointer; user-select: none;
                         border: 1px solid var(--line); border-radius: 10px;
                         background: var(--surface); color: var(--text); }
details.acts > summary::-webkit-details-marker { display: none; }
details.acts[open] { flex-basis: 100%; }
details.acts[open] > summary { display: inline-block; background: var(--line); }
/* «По дням» в табеле — та же кнопка-раскрывашка. */
details.days-toggle > summary { list-style: none; cursor: pointer; user-select: none; display: inline-block;
                                border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
details.days-toggle > summary::-webkit-details-marker { display: none; }
details.days-toggle > summary::after { content: ' ▾'; }
details.days-toggle[open] > summary::after { content: ' ▴'; }
.acts-menu { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
/* Надписи на кнопках сотрудника не переносим: «Выдать» и «ПИН» на разных
   строках читаются хуже, чем лишний сантиметр ширины у колонки. */
#people-table .btn-sm { white-space: nowrap; }
@media (min-width: 761px) { #people-table td:last-child { min-width: 270px; } }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; letter-spacing: -.5px; }

.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.tag-ok { background: var(--ok-bg); color: var(--ok); }
.tag-warn { background: var(--warn-bg); color: var(--warn); }
.tag-bad { background: var(--bad-bg); color: var(--bad); }
.tag-info { background: var(--info-bg); color: var(--info); }
.tag-mute { background: var(--line); color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
     color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--info); outline-offset: 1px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
         background: var(--accent); color: var(--bg); padding: 13px 18px; border-radius: 12px;
         box-shadow: var(--shadow); font-weight: 600; max-width: 92vw; text-align: center; z-index: 50; }
.toast.err { background: var(--bad); color: #fff; }
.hide { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 14px; }
.tabs button { white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; margin-right: 6px; }
.daylist { font-size: 14px; }
.daylist div { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.daylist div:last-child { border-bottom: none; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex;
           align-items: center; justify-content: center; padding: 20px; z-index: 60; }
.sheet { background: var(--surface); border-radius: 18px; padding: 22px; width: 100%;
         max-width: 340px; box-shadow: var(--shadow); text-align: center; }
.sheet h3 { margin: 0 0 6px; font-size: 18px; }
.pin-input { font-size: 30px; letter-spacing: 12px; text-align: center; padding: 14px 0 14px 12px; }

.day-btn[aria-selected="true"] { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.day-btn { min-width: 44px; }

/* На телефоне таблицы превращаются в карточки: горизонтальный скролл в
   панели руководителя — худший способ читать доску с телефона. */
@media (max-width: 760px) {
  .wide .scroll { overflow: visible; margin: 0; padding: 0; }
  .wide table, .wide tbody, .wide tr, .wide td { display: block; width: 100%; }
  .wide thead { display: none; }
  .wide tr {
    border: 1px solid var(--line); border-radius: 12px;
    padding: 10px 12px; margin-bottom: 10px; background: var(--surface);
  }
  .wide td {
    border: none; padding: 5px 0; display: flex; gap: 12px;
    align-items: baseline; justify-content: space-between; text-align: right;
  }
  .wide td::before {
    content: attr(data-label); color: var(--muted); font-size: 11.5px;
    text-transform: uppercase; letter-spacing: .3px; text-align: left; flex: 0 0 auto;
  }
  /* Первая ячейка — заголовок карточки: имя не должно ютиться в колонке. */
  .wide tbody td:first-child {
    display: block; text-align: left; font-size: 15px;
    padding: 0 0 8px; margin-bottom: 6px; border-bottom: 1px solid var(--line);
  }
  .wide tbody td:first-child::before { display: none; }
  .wide td:empty { display: none; }
  /* Плитки со счётчиками в панели — по четыре в ряд и мельче: в два
     столбца восемь плиток занимали весь первый экран телефона, и список
     людей начинался только после прокрутки. */
  .wide .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .wide .stat { padding: 7px 8px; border-radius: 10px; }
  /* Строчными: заглавные шире, и «ОПАЗДЫВАЮТ» рвалось посреди слова. */
  .wide .stat .k { font-size: 10.5px; letter-spacing: 0; line-height: 1.2;
                   text-transform: none; hyphens: auto; }
  .wide .stat .v { font-size: 17px; margin-top: 1px; }
  .wide td .btn-row { justify-content: flex-end; }
  /* Карточка сотрудника: полей много, и по одному в ряд она выходила
     в полэкрана. Раскладываем по два: подпись над значением. Имя и
     кнопки — на всю ширину. */
  .wide #people-table tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; }
  .wide #people-table td { display: block; text-align: left; min-width: 0; }
  .wide #people-table td::before { display: block; margin-bottom: 1px; }
  .wide #people-table td:first-child,
  .wide #people-table td:last-child { grid-column: 1 / -1; }
  .wide #people-table td:last-child .btn-row { justify-content: flex-start; }
  .wide #people-table code { overflow-wrap: anywhere; }
  /* Графики: флажок выбора — рядом с именем, а не отдельным «заголовком»
     карточки с чертой под ним; часы, дни и тип — компактно в два столбца. */
  .wide #schedules-table tr { display: grid; grid-template-columns: 26px 1fr 1fr;
                              column-gap: 10px; align-items: start; }
  .wide #schedules-table td { display: block; text-align: left; min-width: 0; }
  .wide #schedules-table td::before { display: block; margin-bottom: 1px; }
  .wide #schedules-table tbody td:first-child { border: none; padding: 6px 0 0; margin: 0; }
  .wide #schedules-table td:nth-child(2) { grid-column: 2 / -1; padding-bottom: 6px; }
  .wide #schedules-table td:nth-child(2)::before { display: none; }
  .wide #schedules-table td:nth-child(3) { grid-column: 2; }
  .wide #schedules-table td:nth-child(4) { grid-column: 3; }
  .wide #schedules-table td:nth-child(5) { grid-column: 2 / -1; }
  .wide #schedules-table td:last-child { grid-column: 1 / -1; }
  .wide #schedules-table td:last-child .btn-row { justify-content: flex-start; }
  /* Раскрытое «Ещё» занимает всю ширину карточки: подпись остаётся сверху,
     а кнопки не выстраиваются по одной в узкий столбик справа от неё. */
  .wide td:has(details.acts[open]) { flex-wrap: wrap; }
  .wide td .btn-row:has(details.acts[open]) { flex-basis: 100%; }
  .wide details.acts[open] { text-align: right; }
  .wide .acts-menu { justify-content: flex-end; }
  .wide .num { text-align: right; }
  .tabs { margin: 0 -16px; padding: 4px 16px 14px; }
  .top { flex-direction: column; align-items: flex-start; gap: 8px; }
  .top .btn-row { flex-wrap: wrap; }
  .row2 { grid-template-columns: 1fr; }
  .sheet { max-height: 88vh; overflow-y: auto; }
}

.brand-row { display: flex; align-items: center; gap: 11px; }
.logo { width: 38px; height: 38px; flex: 0 0 38px; }
@media (max-width: 760px) { .logo { width: 32px; height: 32px; flex-basis: 32px; } }

/* Строка табеля, которую администратор может поправить. */
tr.editable { cursor: pointer; }
tr.editable:hover { background: rgba(255, 255, 255, .05); }
