:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #d9dce1;
  --line-soft: #e8eaee;
  --accent: #2f5fd0;
  --accent-soft: #e7eefc;
  --off: #f4cccc;
  --off-head: #c00000;
  --under: #e06666;
  --under-soft: #fde2e2;
  --over: #f6b26b;
  --ok: #6aa84f;
  --today: #2f5fd0;
  --warn: #d93025;
  --vac: #cfe2f3;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.bad { color: var(--warn); }
.good { color: var(--ok); }

/* шапка */
.top { display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 52px; background: #1f2a44; color: #fff; position: sticky; top: 0; z-index: 30; }
.top .brand { color: #fff; font-weight: 700; font-size: 16px; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.top .brand:hover { text-decoration: none; }
.top .brand .logo { width: 30px; height: 30px; filter: drop-shadow(0 0 1px rgba(255,255,255,.7)); }
.login-logo { display: block; width: 64px; height: 64px; margin: 0 auto 8px; }
.login h1 { text-align: center; }
.top nav { display: flex; gap: 4px; flex: 1; }
.top nav a { color: #c9d3ea; padding: 6px 12px; border-radius: 6px; white-space: nowrap; }
.top nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.top nav a.on { background: rgba(255,255,255,.16); color: #fff; }
.top .me { display: flex; align-items: center; gap: 10px; }
.top .me a { color: #fff; }
.top .me .muted { color: #9aa6c2; font-size: 12px; }
.top .me form { margin: 0; }
.top .me .link { color: #c9d3ea; }

main.page { max-width: 1200px; margin: 0 auto; padding: 20px; }
main.page.wide { max-width: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 440px; }

/* формы */
label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
label input, label select, label textarea { display: block; width: 100%; margin-top: 4px; color: var(--text); }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 120px; resize: vertical; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; margin: 0; }
button, .btn { font: inherit; padding: 7px 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); cursor: pointer; display: inline-block; }
button:hover, .btn:hover { border-color: #b8bdc6; text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #264fb0; }
button.danger { color: var(--warn); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.link.danger { color: var(--warn); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.inline { display: inline; margin: 0; }
fieldset { border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 14px; }
legend { padding: 0 6px; font-weight: 600; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; background: #e6f4ea; border: 1px solid #b7dfc3; }
.flash.err { background: var(--under-soft); border-color: #f2b8b5; }

/* вход */
main.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login button { width: 100%; margin-top: 6px; }

/* таблицы */
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.list tr.inactive td { color: var(--muted); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--line-soft); }
.badge.ok { background: #e6f4ea; color: #1e6b35; }
.badge.err { background: var(--under-soft); color: #a50e0e; }
.actions { white-space: nowrap; text-align: right; }
.actions form { display: inline; }

/* график */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav h1 { margin: 0 6px; min-width: 170px; text-align: center; color: var(--off-head); }
.month-nav > button { padding: 4px 12px; font-size: 18px; line-height: 1.2; }
.month-nav #today { font-size: 14px; }
.brush { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.brush #brush-marks { display: contents; }
.brush button { padding: 4px 10px; }
.brush button[style] { background: var(--c); }
.brush button.on { outline: 2px solid var(--accent); outline-offset: 1px; font-weight: 700; }
body.painting td.editable { cursor: crosshair; }
.summary { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 10px; padding: 8px 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }

.grid-wrap { overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); max-height: calc(100vh - 230px); }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 13px; width: 100%; table-layout: fixed; }
.grid th, .grid td { border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
.grid thead th { position: sticky; background: var(--card); z-index: 2; }
.grid thead tr.cov th { top: 0; height: 38px; }
.grid thead tr.dates th { top: 38px; border-bottom: 2px solid var(--line); }
.grid .sticky { position: sticky; left: 0; z-index: 3; background: var(--card); border-right: 2px solid var(--line); }
.grid thead .sticky { z-index: 4; }
.grid th.name { text-align: left; padding: 4px 10px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid th.month { color: var(--off-head); font-size: 16px; font-weight: 700; }
.grid th.day { text-align: center; font-weight: 700; padding: 3px 0; position: sticky; overflow: hidden; }
.grid th.day small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.grid tr.dates th.off { color: var(--off-head); background: var(--off); }
.grid tr.dates th.pre small::after { content: " ·"; }
.grid tr.dates th.today { box-shadow: inset 0 -3px 0 var(--today); }
.grid th.clickable { cursor: pointer; }
.grid th.clickable:hover { filter: brightness(.95); }
.grid .star { color: var(--accent); font-style: normal; position: absolute; top: 1px; right: 3px; font-size: 12px; }
.grid tr.cov th.day { font-size: 11px; font-weight: 600; line-height: 1.25; }
.grid tr.cov th.day span { display: block; }
.grid tr.cov th.day .lack { color: #8b0000; }
.grid .cov-under { background: var(--under) !important; color: #fff; }
.grid .cov-under .lack { color: #fff !important; text-decoration: underline; }
.grid .cov-over { background: var(--over) !important; }
.grid .cov-ok { background: #d9ead3 !important; }
.grid .dot { position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%; background: #1f2a44; }
.grid td.cell { height: 28px; text-align: center; font-weight: 600; font-size: 12px; position: relative; padding: 0; overflow: hidden; white-space: nowrap; }
.grid td.off { background: var(--off); }
.grid td.today { box-shadow: inset 2px 0 0 var(--today), inset -2px 0 0 var(--today); }
.grid td.editable { cursor: pointer; }
.grid td.editable:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid td.warn::before { content: ""; position: absolute; inset: 1px; border: 2px dashed var(--warn); pointer-events: none; }
.grid td.bday::after { content: "🎂"; position: absolute; top: -1px; right: 1px; font-size: 10px; }
.grid .tot { text-align: center; padding: 0 2px; font-weight: 600; background: #fafbfc; overflow: hidden; white-space: nowrap; }
/* компактный вид */
.grid.compact { font-size: 12px; }
.grid.compact td.cell { font-size: 11px; height: 26px; }
.grid.compact th.name { padding: 3px 6px; font-size: 12px; }
.grid.compact tr.cov th.day { font-size: 10px; letter-spacing: -0.2px; }
.grid.compact th.day small { font-size: 10px; }
.grid.compact td.bday::after { font-size: 8px; }
.grid thead .tot { font-size: 12px; color: var(--muted); }
.grid td.empty { padding: 30px; text-align: center; color: var(--muted); }
.grid tbody tr:hover th.name { background: var(--accent-soft); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 20px; font-style: normal; font-weight: 700; font-size: 11px; color: var(--text); border: 1px solid var(--line); border-radius: 3px; }
.legend .lg-off { background: var(--off); }
.legend .lg-warn { border: 2px dashed var(--warn); }
.legend .lg-bday { border: 0; }

.menu { position: absolute; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 4px; min-width: 240px; }
.menu button { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; text-align: left; padding: 6px 8px; font-weight: 600; }
.menu button:hover { background: var(--accent-soft); }
.menu button i { width: 16px; height: 16px; border-radius: 3px; border: 1px solid var(--line); }
.menu button .muted { font-weight: 400; font-size: 12px; }

dialog { border: 1px solid var(--line); border-radius: 10px; padding: 20px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 16px 48px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(20,24,35,.35); }
dialog fieldset[hidden] { display: none; }
.pw-row { display: flex; gap: 6px; margin-top: 4px; }
.pw-row input { margin-top: 0; flex: 1; min-width: 0; }
.pw-row button { white-space: nowrap; padding: 6px 10px; font-size: 13px; }
.invite-row[hidden], .invite-note[hidden] { display: none; }
input[readonly] { background: #f2f3f5; }
input:disabled { background: #f2f3f5; color: var(--muted); }
.dlg-actions { display: flex; justify-content: flex-end; align-items: center; gap: 14px; }

/* сотрудники / пользователи */
.cols { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.bday-list { list-style: none; margin: 0; padding: 0; }
.bday-list li > span:last-child { white-space: nowrap; }
.bday-list li { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.bday-list li.today { font-weight: 700; color: var(--off-head); }
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; margin: 8px 0 12px; }
details.edit > summary { cursor: pointer; color: var(--accent); list-style: none; }
details.edit > summary::-webkit-details-marker { display: none; }
details.edit[open] { background: #fafbfc; padding: 12px; border-radius: var(--radius); border: 1px solid var(--line-soft); }

/* отделы */
.dept-list { list-style: none; margin: 0; padding: 0; }
.dept-list li { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line-soft); }
.dept-row { display: flex; align-items: center; gap: 8px; flex: 1; margin: 0; }
.dept-row input[name=name] { flex: 1; min-width: 0; padding: 5px 8px; }

/* отпуска */
.vac-list { list-style: none; margin: 14px 0 0; padding: 0; }
.vac-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line-soft); }
.vac-list li.now b { color: #1c4f8a; }
.grid td.vac { background: var(--vac); color: #1c4f8a; }
.grid td.vac.vac-first { box-shadow: inset 3px 0 0 #6fa8dc; }
.menu hr { border: 0; border-top: 1px solid var(--line-soft); margin: 4px 0; }
.menu .lg-vac { background: var(--vac); }
.legend .lg-vacmark { background: #ffff00; box-shadow: inset 0 -4px 0 #6fa8dc; }
.legend .lg-vac { background: var(--vac); color: #1c4f8a; }

/* дежурство во время отпуска: голубая полоска снизу */
.grid td.vac-mark { box-shadow: inset 0 -4px 0 #6fa8dc; }
/* события */
.grid tr.dates th .ev { display: block; font-size: 11px; line-height: 1; margin-top: 1px; }
.grid tr.dates th.has-ev { background-image: linear-gradient(to top, rgba(47,95,208,.10), transparent 60%); }
.events { margin-top: 14px; }
.events h3 { font-size: 14px; margin: 0 0 6px; }
.events ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 4px 20px; }
.events li { padding: 4px 0; cursor: pointer; }
.events li:hover b { color: var(--accent); }
.ev-ico { display: inline-block; width: 20px; }
.ev-list { list-style: none; margin: 0 0 10px; padding: 0; }
.ev-list li { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
#ev-add[hidden], #day-save[hidden] { display: none; }
dialog { max-height: calc(100vh - 40px); overflow: auto; }

/* группы сотрудников */
.grid tr.group th, .grid tr.group td { background: #eef1f6; font-weight: 700; height: 26px; }
.grid tr.group-europe th, .grid tr.group-europe td { background: #fdf0e3; }
.grid tr.group th.name { color: #1f2a44; }
.summary .teams { display: flex; gap: 18px; flex-wrap: wrap; width: 100%; padding-top: 6px; border-top: 1px dashed var(--line-soft); }
.summary .team-europe b { color: #b45f06; }
.badge.eu { background: #fdf0e3; color: #b45f06; }

@media (max-width: 860px) {
  .cols, .row3 { grid-template-columns: 1fr; }
  .top { gap: 10px; padding: 0 10px; overflow-x: auto; }
  .top .brand { font-size: 0; gap: 0; }

  .grid tr.cov th.name { font-size: 10px; white-space: normal; }
  .top nav a { white-space: nowrap; }
  main.page { padding: 12px; }
}
