:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #7a8394;
  --line: #d9dde4;
  --accent: #e8890c;
  --accent-soft: #fff3e0;
  --weekend: #e6e8ec;
  --sum: #fff7d6;
  --pay: #eaf3ea;
  --sep: #1d2330;
  --ok: #d8f3dc;
  --err: #ffd9d9;
  --today: #fde7c3;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --text: #e6e9ee;
    --muted: #8b93a3;
    --line: #2f3540;
    --accent: #f0a03a;
    --accent-soft: #3a2c18;
    --weekend: #262b33;
    --sum: #34301c;
    --pay: #1f3324;
    --sep: #e6e9ee;
    --ok: #1f4a2a;
    --err: #5a2424;
    --today: #4a3a1c;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
button, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
input {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 6px;
  padding: 6px 8px;
}
.muted { color: var(--muted); }
.pad { padding: 0 16px; }
.r { text-align: right; }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chk { display: inline-flex; gap: 6px; align-items: center; }

header {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; }
.month-nav { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.month-nav b { min-width: 130px; text-align: center; font-size: 16px; }
.month-nav button { padding: 4px 10px; background: transparent; color: var(--text); border-color: var(--line); }

.tabs { display: flex; gap: 4px; padding: 8px 16px 0; flex-wrap: wrap; }
.tabs button { background: transparent; color: var(--text); border-color: transparent; border-radius: 8px 8px 0 0; }
.tabs button.on { background: var(--panel); border-color: var(--line); border-bottom-color: var(--panel); font-weight: 600; }
.tabs #logout { margin-left: auto; border-radius: 8px; border-color: var(--line); }

main { padding: 12px 16px 40px; }
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--panel); color: var(--text); }
.seg button.on { background: var(--accent); color: #fff; }

/* ── сетка табеля ── */
.grid-wrap { overflow: auto; max-height: calc(100vh - 170px); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.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: 2; background: var(--panel); padding: 4px 2px; font-weight: 600; }
.grid thead tr:nth-child(2) th { top: 27px; font-weight: 400; color: var(--muted); }
.grid .name {
  position: sticky; left: 0; z-index: 1; background: var(--panel);
  text-align: left; padding: 4px 10px; min-width: 190px; max-width: 240px; overflow: hidden; text-overflow: ellipsis;
}
.grid thead .name { z-index: 3; }
.grid .item { font-style: italic; padding-left: 18px; }
.grid tr.emp td { border-top: 3px solid var(--sep); font-weight: 700; }
.grid tr.emp .name { font-size: 14px; }
.grid .day { min-width: 38px; }
.grid .we, .grid thead .we { background: var(--weekend); }
.grid thead .today { background: var(--today); }
.grid td.today { box-shadow: inset 0 0 0 1px var(--accent); }
.grid .sum { background: var(--sum); min-width: 62px; padding: 4px 6px; font-weight: 600; }
.grid .pay { background: var(--pay); min-width: 92px; padding: 4px 8px; text-align: right; font-variant-numeric: tabular-nums; }
.grid thead .sum, .grid thead .pay { background: var(--sum); }
.grid thead .pay { background: var(--pay); }
.grid .sep { background: var(--sep); min-width: 4px; width: 4px; padding: 0; }
.grid input {
  -webkit-touch-callout: none; -webkit-user-select: text;
  width: 38px; border: 0; border-radius: 0; background: transparent;
  padding: 5px 2px; text-align: center; font-variant-numeric: tabular-nums;
}
.grid input:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--panel); }
.grid input.ok { background: var(--ok); transition: background .2s; }
.grid input.err { background: var(--err); }
.half-1 .h2, .half-1 .sep, .half-2 .h1, .half-2 .sep { display: none; }

/* ── карточки админки ── */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.card.row input:first-child { flex: 1; min-width: 200px; }
.emp-card .name-in { font-weight: 700; font-size: 15px; min-width: 200px; }
.inactive { opacity: .55; }
table.list, table.mini { width: 100%; border-collapse: collapse; }
table.list th, table.list td, table.mini th, table.mini td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.list th.r, table.list td.r, table.mini th.r, table.mini td.r { text-align: right; }
table.list thead th, table.mini th { color: var(--muted); font-weight: 500; }
table.list tfoot td { font-weight: 700; border-top: 2px solid var(--text); border-bottom: 0; }
table.mini { margin: 8px 0; }
.mini input.rate, .items input.rate { width: 90px; text-align: right; }
.items input.n { width: 100%; min-width: 160px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--accent-soft); }
tr.detail > td { background: var(--bg); }

.login { max-width: 320px; margin: 15vh auto; display: flex; flex-direction: column; gap: 10px; padding: 0 16px; }
.login h1 { margin: 0 0 8px; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: all .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: #c0392b; color: #fff; }

@media (max-width: 600px) {
  .month-nav { margin-left: 0; width: 100%; justify-content: space-between; }
  .grid .name { min-width: 140px; max-width: 160px; }
}

/* премия */
small.bonus { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
.grid .pay small.bonus { line-height: 1.1; }
tr.bonus-row td { background: var(--accent-soft); }

/* авто-строки (доплата за день) */
.grid tr.auto-row td { background: var(--accent-soft); color: var(--muted); font-style: italic; }
.grid td.auto { font-size: 11px; }
select.trig { border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; background: var(--panel); color: inherit; max-width: 180px; }

/* строка с именем — не для ввода: штриховка, чтобы не путали с ячейками дней */
.grid tr.emp td:not(.name):not(.pay):not(.sep) {
  background: repeating-linear-gradient(135deg, var(--weekend) 0 3px, var(--panel) 3px 7px);
  cursor: not-allowed;
}

/* комментарии к ячейкам */
.grid td[data-c] { position: relative; }
.grid td.noted::after {
  content: ''; position: absolute; top: 0; right: 0;
  border-style: solid; border-width: 0 8px 8px 0; border-color: transparent var(--accent) transparent transparent;
  pointer-events: none;
}
.note-pop {
  position: fixed; z-index: 20; width: 280px; padding: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); display: flex; flex-direction: column; gap: 8px; font-size: 13px;
}
.note-pop textarea { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; background: var(--panel); color: inherit; }

/* ── режим «по дню» (телефон) ── */
.daynav {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px; padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.daynav.we { background: var(--weekend); }
.daynav button { padding: 10px 16px; font-size: 16px; background: transparent; color: var(--text); border-color: var(--line); }
.dlabel { flex: 1; text-align: center; display: flex; flex-direction: column; line-height: 1.2; }
.dlabel b { font-size: 17px; }
.dcard { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; overflow: hidden; }
.dcard summary { list-style: none; cursor: pointer; padding: 12px 14px 12px 32px; font-weight: 700; font-size: 15px; display: flex; flex-direction: column; gap: 2px; position: relative; }
.dcard summary::-webkit-details-marker { display: none; }
.dcard summary::before { content: '▸'; position: absolute; left: 14px; top: 12px; color: var(--muted); }
.dcard[open] summary::before { content: '▾'; }
.dsum { font-weight: 400; font-size: 12px; color: var(--muted); }
.drows { border-top: 1px solid var(--line); }
.drow { display: grid; grid-template-columns: 1fr 96px 40px; align-items: center; gap: 8px; padding: 6px 10px 6px 14px; border-bottom: 1px solid var(--line); }
.drow:last-child { border-bottom: 0; }
.drow label { font-style: italic; }
.drow input { height: 44px; font-size: 18px; text-align: right; padding: 6px 10px; }
.drow input.ok { background: var(--ok); }
.drow input.err { background: var(--err); }
.note-btn { height: 40px; width: 40px; padding: 0; font-size: 16px; opacity: .45; border-color: transparent; }
.note-btn.has { opacity: 1; border-color: var(--accent); background: var(--accent-soft); }
@media (max-width: 600px) {
  main { padding: 10px 10px 40px; }
  .toolbar .muted { display: none; }
  .drow { grid-template-columns: 1fr 88px 36px; }
  .note-pop { left: 8px !important; right: 8px; width: auto; }
  .grid input { width: 44px; padding: 10px 2px; font-size: 15px; }
  .grid .day { min-width: 44px; }
}

/* ── статистика ── */
.card.stats { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: center; }
.donut-wrap { max-width: 300px; margin: 0 auto; }
.donut { width: 100%; height: auto; }
.donut path { transition: opacity .15s, transform .15s; transform-origin: 130px 130px; cursor: pointer; }
.donut path.dim { opacity: .35; }
.donut path.hl { opacity: 1; transform: scale(1.03); }
.slice-label { fill: #fff; font-size: 11px; font-weight: 600; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.donut-total { fill: var(--text); font-size: 20px; font-weight: 700; text-anchor: middle; }
.donut-sub { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.legend tr[data-i] { cursor: default; }
.legend tr.hl td { background: var(--accent-soft); }
.legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend td.bar { width: 28%; }
.legend td.bar div { height: 8px; border-radius: 4px; min-width: 2px; }
.legend .small { font-size: 11px; }
@media (max-width: 760px) { .card.stats { grid-template-columns: 1fr; } .legend td.bar { display: none; } .legend th:last-child { display: none; } }
