:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --hover: #eef3fd;
  --text: #1d2433;
  --muted: #6b7385;
  --line: #e4e7ed;
  --line-strong: #c4cad6;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --danger: #d43d3d;
  --off-bg: #fdeeee;
  --off-text: #c43b3b;
  --hol-bg: #f8caca;
  --hol-text: #9e1616;
  --short: #e3a008;
  --sel: rgba(47, 111, 222, .38);
  --vac: #2e9d6c;
  --ov: #ee9a1a;
  --crit: #e03b42;
  --head: #2f6fde;
  --lead: #8a57d6;
  --dept: #4a5872;
  --dept-bg: #eceff4;
  --shadow: 0 10px 40px rgba(20, 30, 60, .18);
  --name-w: 330px;
  --cw: 28px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151a;
    --surface: #1b1f26;
    --surface-2: #21262f;
    --hover: #26324a;
    --text: #e6e9ef;
    --muted: #98a1b3;
    --line: #2b313c;
    --line-strong: #414958;
    --accent: #5b8ff0;
    --off-bg: #33232a;
    --off-text: #ff8f88;
    --hol-bg: #552a31;
    --hol-text: #ffb7b0;
    --sel: rgba(91, 143, 240, .45);
    --vac: #3bb27f;
    --ov: #f0a63a;
    --crit: #f2555b;
    --head: #6b9cf5;
    --lead: #a983ee;
  --dept: #7f8ca8;
  --dept-bg: #262c37;
    --dept: #7f8ca8;
    --dept-bg: #262c37;
    --shadow: 0 10px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151a;
  --surface: #1b1f26;
  --surface-2: #21262f;
  --hover: #26324a;
  --text: #e6e9ef;
  --muted: #98a1b3;
  --line: #2b313c;
  --line-strong: #414958;
  --accent: #5b8ff0;
  --off-bg: #33232a;
  --off-text: #ff8f88;
  --hol-bg: #552a31;
  --hol-text: #ffb7b0;
  --sel: rgba(91, 143, 240, .45);
  --vac: #3bb27f;
  --ov: #f0a63a;
  --crit: #f2555b;
  --head: #6b9cf5;
  --lead: #a983ee;
  --dept: #7f8ca8;
  --dept-bg: #262c37;
  --shadow: 0 10px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

button { font: inherit; color: inherit; }

/* ---------- Верхняя панель ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 24px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.year { color: var(--accent); }
.brand .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
  list-style: none;
  user-select: none;
}
.btn::-webkit-details-marker { display: none; }
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .input:focus-visible, .icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger-ghost { border-color: transparent; color: var(--danger); background: transparent; }
.btn.danger-ghost:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }

.input {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  width: 100%;
}
.search { width: 240px; }

.menu { position: relative; }
.menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 50;
  min-width: 250px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.menu-pop button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
.menu-pop button:hover { background: var(--surface-2); }
.menu-pop hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.menu-pop .danger { color: var(--danger); }

/* ---------- Месяцы и легенда ---------- */
.subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.months { display: flex; flex-wrap: wrap; gap: 4px; }
.months button {
  border: 1px solid transparent;
  background: none;
  border-radius: 6px;
  padding: 3px 9px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}
.months button:hover { background: var(--surface-2); color: var(--text); }
.months button.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-weight: 600; }

.legend { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg-sep { width: 1px; height: 16px; background: var(--line-strong); }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--line-strong); }
.sw-off { background: var(--off-bg); }
.sw-hol { background: var(--hol-bg); }
.sw-short { background: var(--surface); position: relative; }
.sw-short::after { content: ''; position: absolute; right: 1px; top: 1px; width: 5px; height: 5px; border-radius: 50%; background: var(--short); }
.sw-wsat { background: var(--surface); border: 1px dashed var(--off-text); }
.sw.bar { border: 0; height: 10px; width: 18px; border-radius: 5px; background: var(--vac); }
.sw.bar.x-over { background: var(--ov); }
.sw.bar.x-crit { background: var(--crit); }

/* ---------- Таблица ---------- */
.grid-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
  background: var(--surface);
}

.grid {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  user-select: none;
  font-size: 12px;
}
.grid th, .grid td {
  box-sizing: border-box;
  width: var(--cw);
  min-width: var(--cw);
  max-width: var(--cw);
  padding: 0;
  text-align: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-weight: 400;
}

/* Шапка */
.grid thead th { position: sticky; z-index: 3; background: var(--surface-2); }
.grid thead .r1 th { top: 0; height: 30px; }
.grid thead .r2 th { top: 30px; height: 22px; font-weight: 600; }
.grid thead .r3 th { top: 52px; height: 20px; color: var(--muted); font-size: 10.5px; }
.grid thead .r2 th, .grid thead .r3 th { cursor: default; }
.grid thead th.month { text-align: left; font-weight: 600; font-size: 13px; }
.month-label { position: sticky; left: calc(var(--name-w) + 8px); padding: 0 8px; white-space: nowrap; }
.month-label .muted { color: var(--muted); font-weight: 400; font-size: 11.5px; margin-left: 4px; }
.grid thead th.off { color: var(--off-text); background: var(--off-bg); }
.grid thead th.hol { color: var(--hol-text); background: var(--hol-bg); font-weight: 700; }
.grid thead th.wsat { box-shadow: inset 0 0 0 1px var(--off-text); }
.grid thead .r2 th.short { position: sticky; }
.grid thead .r2 th.short::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--short);
}

/* Липкая колонка с именами */
.grid .name-col {
  position: sticky;
  left: 0;
  z-index: 2;
  width: var(--name-w);
  min-width: var(--name-w);
  max-width: var(--name-w);
  padding: 0 8px;
  text-align: left;
  background: var(--surface);
  border-right: 1px solid var(--line-strong);
}
.grid thead .corner { z-index: 5; top: 0; vertical-align: bottom; padding-bottom: 4px; }
.corner-inner { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; font-size: 12.5px; }
.corner-inner .muted { color: var(--muted); font-weight: 400; font-size: 11px; }

/* Ячейки дней */
.grid td { height: 30px; position: relative; background: var(--surface); }
.grid td.off { background: var(--off-bg); }
.grid td.hol { background: var(--hol-bg); }
.grid .ms { box-shadow: inset 2px 0 0 var(--line-strong); }

/* Строка команды */
.grid tr.team-row > * { background: var(--surface-2); height: 34px; border-bottom-color: var(--line-strong); }
.grid tr.team-row > .name-col { box-shadow: inset 4px 0 0 var(--team); }
.grid tr.team-row td.off { background: color-mix(in srgb, var(--off-bg) 70%, var(--surface-2)); }
.grid tr.team-row td.hol { background: color-mix(in srgb, var(--hol-bg) 70%, var(--surface-2)); }
.grid tr.team-row td { font-size: 11px; font-weight: 650; }
.grid tr.team-row td.cnt {
  background: color-mix(in srgb, var(--team) var(--a), var(--surface-2));
  color: #fff;
  text-shadow: 0 0 2px rgba(0, 0, 0, .35);
}
.grid tr.team-row td.cnt.over { background: var(--ov); }
.grid tr.team-row td.cnt.crit { background: var(--crit); }

/* Строка отдела */
.grid tr.dept-row > * { background: var(--dept-bg); height: 38px; border-bottom-color: var(--line-strong); }
.grid tr.dept-row > .name-col { box-shadow: inset 4px 0 0 var(--dept); }
.grid tr.dept-row td.off { background: color-mix(in srgb, var(--off-bg) 65%, var(--dept-bg)); }
.grid tr.dept-row td.hol { background: color-mix(in srgb, var(--hol-bg) 65%, var(--dept-bg)); }
.grid tr.dept-row td { font-size: 11px; font-weight: 700; }
.grid tr.dept-row td.cnt {
  background: color-mix(in srgb, var(--dept) var(--a), var(--dept-bg));
  color: #fff;
  text-shadow: 0 0 2px rgba(0, 0, 0, .35);
}
.grid tr.dept-row td.cnt.crit { background: var(--crit); }
.dept-name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.dept-name:hover { text-decoration: underline; }
.dept-row .badge { background: color-mix(in srgb, var(--dept) 18%, transparent); }

.team-head { display: flex; align-items: center; gap: 6px; padding-left: 4px; }
.team-head.lvl1 { padding-left: 20px; }
.team-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.team-name:hover { text-decoration: underline; }
.badge {
  flex: none;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--team) 18%, transparent);
  color: var(--text);
  font-size: 11px;
  text-align: center;
  line-height: 18px;
}
.spacer { flex: 1; }

.icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.icon:hover { background: color-mix(in srgb, var(--text) 9%, transparent); color: var(--text); }
.toggle { transition: transform .15s; }
.collapsed .toggle { transform: rotate(-90deg); }

/* Строка сотрудника */
.emp { display: flex; align-items: center; gap: 6px; padding-left: 26px; }
.emp.lvl1 { padding-left: 28px; }
.emp.lvl2 { padding-left: 50px; }
.grid tr.head-row > .name-col { background: color-mix(in srgb, var(--head) 5%, var(--surface)); }
.link { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; }
.link:hover { text-decoration: underline; }
.empty-head .muted { color: var(--muted); font-size: 12.5px; }
.emp-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.emp-name:hover { text-decoration: underline; }
.icon.del:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.icon svg { width: 15px; height: 15px; }
.role {
  flex: none;
  padding: 0 6px;
  border-radius: 9px;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 17px;
}
.role-head { color: var(--head); background: color-mix(in srgb, var(--head) 14%, transparent); }
.role-lead { color: var(--lead); background: color-mix(in srgb, var(--lead) 14%, transparent); }
.stat {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--muted);
  padding: 1px 6px;
  border-radius: 6px;
}
.stat.full { color: var(--vac); background: color-mix(in srgb, var(--vac) 12%, transparent); }
.stat.over { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.grid tr.emp-row:hover > .name-col { background: var(--hover); }
.grid tr.emp-row > .name-col .icon { opacity: .3; }
.grid tr.emp-row:hover > .name-col .icon, .grid tr.emp-row > .name-col .icon:focus-visible { opacity: 1; }
.grid tr.emp-row td { cursor: cell; }

/* Отпуск — полоса поверх ячейки; цвет зависит от пересечений */
.grid td.vac { cursor: pointer; --vc: var(--vac); }
.grid td.vac.x-over { --vc: var(--ov); }
.grid td.vac.x-crit { --vc: var(--crit); }
.grid td.vac::before {
  content: '';
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 0;
  right: 0;
  background: var(--vc);
}
.grid td.vac.hol::before {
  background: repeating-linear-gradient(135deg, var(--vc) 0 3px, color-mix(in srgb, var(--vc) 45%, transparent) 3px 6px);
}
.grid td.vs::before { left: 3px; border-radius: 6px 0 0 6px; }
.grid td.ve::before { right: 3px; border-radius: 0 6px 6px 0; }
.grid td.vs.ve::before { border-radius: 6px; }
.grid td.vac:hover::before { filter: brightness(1.12); }

.grid td.sel::after {
  content: '';
  position: absolute;
  inset: 3px 0;
  background: var(--sel);
}

/* Пусто */
.empty {
  position: absolute;
  inset: 80px 0 auto 0;
  text-align: center;
  color: var(--muted);
}

.hint {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

/* ---------- Диалоги ---------- */
.dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(15, 20, 30, .45); }
.dialog form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dialog h2 { margin: 0 0 2px; font-size: 18px; font-weight: 650; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
.field .input { color: var(--text); font-size: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.calc {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
  line-height: 1.6;
}
.calc:empty { display: none; }
.calc b { font-variant-numeric: tabular-nums; }
.calc .neg { color: var(--danger); }
.error { color: var(--danger); font-size: 13px; }
.field-note { margin: -6px 0 0; color: var(--muted); font-size: 12.5px; }
.field-note:empty { display: none; }

/* Пересечения в диалоге отпуска */
.overlap:empty { display: none; }
.overlap {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.55;
  border-left: 4px solid var(--ov);
  background: color-mix(in srgb, var(--ov) 12%, var(--surface));
}
.overlap.crit { border-left-color: var(--crit); background: color-mix(in srgb, var(--crit) 12%, var(--surface)); }
.overlap b { font-weight: 650; }
.overlap ul { margin: 4px 0 0; padding-left: 18px; }
.overlap li.crit { color: var(--crit); font-weight: 600; }

/* Кнопка и список конфликтов */
.btn.conflicts.has { border-color: var(--crit); color: var(--crit); background: color-mix(in srgb, var(--crit) 10%, var(--surface)); font-weight: 600; }
.btn.conflicts.none { color: var(--vac); }
.dialog.wide { width: min(640px, calc(100vw - 32px)); }
.dlg-sub { margin: -8px 0 0; color: var(--muted); font-size: 13px; }
.conflicts-list { display: flex; flex-direction: column; gap: 6px; max-height: 55vh; overflow: auto; }
.conflicts-list .empty-note { color: var(--muted); padding: 12px 0; }
.conflict {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-left: 4px solid var(--crit);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}
.conflict:hover { background: var(--surface-2); }
.conflict .who { font-weight: 600; }
.conflict .team { color: var(--muted); font-size: 12px; }
.conflict .when { grid-row: 1 / span 2; grid-column: 2; text-align: right; font-variant-numeric: tabular-nums; }
.conflict .when small { display: block; color: var(--muted); font-size: 12px; }

/* Кратковременная подсветка дня после перехода */
.grid .flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 40% { outline: 2px solid var(--crit); outline-offset: -2px; } 100% { outline-color: transparent; } }
.error:empty { display: none; }
.dlg-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches label { position: relative; cursor: pointer; }
.swatches input { position: absolute; opacity: 0; }
.swatches span {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line-strong);
}
.swatches input:checked + span { box-shadow: 0 0 0 2px var(--text); }
.swatches input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Узкие экраны ---------- */
@media (max-width: 720px) {
  .row2 { grid-template-columns: 1fr; }
}

@media print {
  .topbar .actions, .hint, .months { display: none; }
  .grid-wrap { overflow: visible; }
}

/* ---------- Приложение и вход ---------- */
.app { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.auth-card {
  width: min(440px, 100%);
  padding: 28px 24px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0; font-size: 22px; font-weight: 650; }
.auth-sub { margin: 4px 0 18px; color: var(--muted); font-size: 13px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 18px; background: var(--surface-2); border-radius: 10px; }
.tab { height: 32px; border: 0; border-radius: 7px; background: none; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.btn.wide { width: 100%; justify-content: center; height: 38px; }
.note-first {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border-left: 4px solid var(--accent);
}

/* Меню пользователя */
.user-btn { max-width: 260px; }
.user-btn #userName { overflow: hidden; text-overflow: ellipsis; }
.app-role {
  flex: none;
  padding: 0 6px;
  border-radius: 9px;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 17px;
  color: var(--muted);
  background: var(--surface-2);
}
.app-role.admin { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
body:not(.is-admin) .admin-only { display: none !important; }

/* Своя строка */
.grid tr.me-row > .name-col { box-shadow: inset 3px 0 0 var(--accent); }
.grid tr.me-row .emp-name { font-weight: 650; }
.grid tr.emp-row.ro td { cursor: default; }
.grid tr.emp-row.ro td.vac { cursor: help; }
.acc-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--vac); }

/* Группа «Не распределены» */
.grid tr.dept-row.unassigned > .name-col { box-shadow: inset 4px 0 0 var(--line-strong); }
.grid tr.dept-row.unassigned .dept-name { color: var(--muted); cursor: default; }
.grid tr.dept-row.unassigned .dept-name:hover { text-decoration: none; }

/* Доступ в карточке сотрудника */
.access { margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; gap: 12px; }
.access legend { padding: 0 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.input:disabled { opacity: .6; cursor: not-allowed; }

/* Уведомление */
.toast {
  position: fixed;
  left: 50%;
  bottom: 56px;
  z-index: 100;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--surface);
  font-size: 13.5px;
  box-shadow: var(--shadow);
}
.toast.err { background: var(--danger); color: #fff; }

/* Подтверждение */
.confirm-dialog { width: min(440px, calc(100vw - 32px)); }
.confirm-text { margin: 0; white-space: pre-line; line-height: 1.5; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(1.07); }

/* Перетаскивание сотрудников */
.grip { flex: none; margin-left: -14px; width: 10px; color: var(--muted); opacity: .45; cursor: grab; font-size: 13px; line-height: 1; }
.grid tr.emp-row:hover .grip { opacity: 1; }
.grid th[draggable="true"] { cursor: grab; }
.grid th[draggable="true"]:active { cursor: grabbing; }
.grid tr.drag-src > .name-col { opacity: .45; }
.grid tr.drop-target > .name-col {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface)) !important;
  box-shadow: inset 0 0 0 2px var(--accent) !important;
}
.grid tr.drop-target > td { background-color: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
/* Во время перетаскивания подсказываем, куда можно отпустить */
body.dnd .grid tr.team-row > .name-col,
body.dnd .grid tr.empty-head > .name-col,
body.dnd .grid tr.head-row > .name-col,
body.dnd .grid tr.dept-row.unassigned > .name-col { outline: 1px dashed var(--accent); outline-offset: -3px; }

/* Коды приглашения */
.code-input { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .12em; text-transform: uppercase; }
.invite-team {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  background: color-mix(in srgb, var(--vac) 12%, var(--surface));
  border-left: 4px solid var(--vac);
}
.row3 { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 12px; }
.inv-create { display: flex; flex-direction: column; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.inv-row { display: flex; align-items: flex-end; gap: 12px; }
.inv-row .grow { flex: 1; }
.inv-new {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.inv-code { font: 700 26px/1.2 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .14em; }
.inv-link { font-size: 12.5px; color: var(--muted); word-break: break-all; user-select: all; }
.inv-new-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.inv-list { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow: auto; }
.inv-list .empty-note { color: var(--muted); font-size: 13px; padding: 4px 0; }
.inv-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 2px 12px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.inv-item.inactive { opacity: .55; }
.inv-item .code { font: 600 14px ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .1em; grid-row: 1 / span 2; }
.inv-item .meta { font-size: 12.5px; color: var(--muted); }
.inv-item .what { font-size: 13px; }
.inv-item .acts { grid-row: 1 / span 2; grid-column: 3; display: flex; gap: 4px; }
.inv-item .acts .btn { height: 28px; padding: 0 10px; font-size: 12.5px; }
.status { font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 8px; margin-left: 6px; }
.status.on { color: var(--vac); background: color-mix(in srgb, var(--vac) 14%, transparent); }
.status.off { color: var(--muted); background: var(--surface-2); }
@media (max-width: 720px) {
  .row3 { grid-template-columns: 1fr; }
  .inv-row { flex-direction: column; align-items: stretch; }
  .inv-item { grid-template-columns: 1fr; }
  .inv-item .code, .inv-item .acts { grid-row: auto; grid-column: auto; }
}

/* ---------- Переключатели: вид и масштаб ---------- */
.seg {
  display: inline-flex;
  flex: none;
  padding: 3px;
  gap: 2px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.seg button {
  border: 0;
  background: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
body.view-my .table-only { display: none !important; }
.mobile-only { display: none !important; }

/* ---------- Масштаб таблицы ---------- */
.grid.z-week { --cw: 10px; }
.grid.z-month { --cw: 4px; }
.grid.z-week thead .r2 th, .grid.z-month thead .r2 th { font-size: 0; height: 10px; }
.grid.z-week thead .r2 th.short::after, .grid.z-month thead .r2 th.short::after { display: none; }
.grid.z-week thead .r3, .grid.z-month thead .r3 { display: none; }
.grid.z-week td.cnt, .grid.z-month td.cnt { font-size: 0; }
.grid.z-week td.vs::before, .grid.z-month td.vs::before { left: 1px; border-radius: 4px 0 0 4px; }
.grid.z-week td.ve::before, .grid.z-month td.ve::before { right: 1px; border-radius: 0 4px 4px 0; }
.grid.z-week td.vs.ve::before, .grid.z-month td.vs.ve::before { border-radius: 4px; }
.grid.z-month th, .grid.z-month td { border-right-width: 0; }
.grid.z-month .name-col { border-right-width: 1px; }
.grid.z-month .ms { box-shadow: inset 1px 0 0 var(--line-strong); }
.grid.z-month .month-label .muted { display: none; }
.grid.z-week td.sel::after, .grid.z-month td.sel::after { inset: 2px 0; }

/* ---------- Мой отпуск ---------- */
.my-view { flex: 1; overflow: auto; background: var(--bg); }
.my-inner { max-width: 640px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.my-card { padding: 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.my-card h2 { margin: 0; font-size: 18px; }
.my-card .place { color: var(--muted); font-size: 13px; margin-top: 2px; }
.my-card .nums { display: flex; justify-content: space-between; align-items: baseline; margin-top: 14px; font-size: 13.5px; }
.my-card .nums b { font-size: 22px; font-variant-numeric: tabular-nums; }
.my-card .nums .rest.neg b { color: var(--danger); }
.progress { height: 8px; margin-top: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: 4px; background: var(--vac); }
.progress.over i { background: var(--danger); }
.my-list { display: flex; flex-direction: column; gap: 8px; }
.my-list .empty-note { color: var(--muted); text-align: center; padding: 24px 8px; font-size: 14px; }
.vac-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--vac);
  background: var(--surface);
  cursor: pointer;
}
.vac-card:hover { background: var(--surface-2); }
.vac-card.over { border-left-color: var(--ov); }
.vac-card.crit { border-left-color: var(--crit); }
.vac-card .dates { font-size: 16px; font-weight: 650; }
.vac-card .meta { margin-top: 2px; font-size: 13px; color: var(--muted); }
.vac-card .note { margin-top: 6px; font-size: 13.5px; }
.vac-card .chips { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.chip { font-size: 12.5px; padding: 4px 8px; border-radius: 6px; }
.chip.over { background: color-mix(in srgb, var(--ov) 14%, transparent); }
.chip.crit { background: color-mix(in srgb, var(--crit) 14%, transparent); color: var(--crit); font-weight: 600; }

/* ---------- Меню на телефоне ---------- */
.dialog.sheet { width: min(420px, calc(100vw - 24px)); }
.sheet form { gap: 12px; }
.sheet-head { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.mm-group { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.mm-item {
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  text-align: left;
  font-size: 15px;
  cursor: pointer;
}
.mm-item:last-child { border-bottom: 0; }
.mm-item:hover { background: var(--surface-2); }
.mm-item.danger { color: var(--danger); }
.mm-help summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
.mm-help .legend { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin: 10px 0; }
.mm-help .lg-sep { display: none; }
.nm-short { display: none; }
.toast { white-space: pre-line; cursor: pointer; }

/* ---------- Телефон ---------- */
@media (max-width: 720px) {
  :root { --name-w: 118px; --cw: 24px; }
  .desk-only { display: none !important; }
  .mobile-only { display: inline-flex !important; }

  .topbar { flex-wrap: nowrap; padding: 8px 12px; gap: 8px; }
  .brand { min-width: 0; }
  .brand h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .actions { flex-wrap: nowrap; gap: 6px; }
  .actions .btn { height: 34px; padding: 0 10px; }
  .menu-btn { font-size: 18px; padding: 0 12px; }
  .conflicts .cf-full { display: none; }
  .conflicts .cf-short { display: inline; }

  .subbar { padding: 6px 12px; gap: 6px; }
  .seg button { padding: 4px 8px; font-size: 12.5px; }
  .months { flex-wrap: nowrap; overflow-x: auto; width: 100%; scrollbar-width: none; }
  .months::-webkit-scrollbar { display: none; }
  .months button { flex: none; }

  /* Узкая колонка имён */
  .corner-inner .muted { display: none; }
  .nm-full { display: none; }
  .nm-short { display: inline; }
  .grip, .acc-dot, .grid tr.emp-row > .name-col .icon, .team-head .icon:not(.toggle) { display: none !important; }
  .grid .name-col { padding: 0 4px 0 6px; }
  .emp { flex-wrap: wrap; row-gap: 0; column-gap: 4px; align-content: center; height: 100%; }
  .emp, .emp.lvl1 { padding-left: 4px; }
  .emp.lvl2 { padding-left: 10px; }
  .emp .spacer { display: none; }
  .emp-name { max-width: 100%; font-size: 12px; line-height: 1.15; }
  .emp .role { font-size: 9.5px; line-height: 14px; padding: 0 4px; }
  .emp .stat { flex-basis: 100%; padding: 0; font-size: 10px; line-height: 1.1; background: none !important; }
  .grid td, .grid tr.emp-row > th { height: 34px; }
  .team-head, .team-head.lvl1 { padding-left: 0; gap: 4px; }
  .team-name, .dept-name {
    font-size: 11.5px;
    line-height: 1.15;
    white-space: normal;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .badge { min-width: 16px; padding: 0 4px; font-size: 10px; }
  .toggle { width: 20px; }

  .my-inner { padding: 12px; }
}
@media (min-width: 721px) {
  .conflicts .cf-short { display: none; }
}

/* ---------- Инструкция ---------- */
.help-link { display: block; margin: -8px 0 16px; font-size: 13px; text-align: left; }
.dialog.help-dialog { width: min(780px, calc(100vw - 24px)); max-height: calc(100vh - 32px); display: none; flex-direction: column; overflow: hidden; }
.dialog.help-dialog[open] { display: flex; }
.help-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px 8px; }
.help-head h2 { margin: 0; flex: 1; font-size: 19px; }
.help-toc { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 20px 12px; border-bottom: 1px solid var(--line); }
.help-toc button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 12.5px;
  cursor: pointer;
}
.help-toc button:hover { border-color: var(--accent); color: var(--accent); }
.help-head, .help-toc { flex: none; }
.help-body { flex: 1; min-height: 0; overflow: auto; padding: 4px 20px 20px; line-height: 1.55; font-size: 14px; }
.help-body section { padding-top: 12px; scroll-margin-top: 8px; }
.help-body h3 { margin: 6px 0 8px; font-size: 16px; }
.help-body p { margin: 8px 0; }
.help-body ul, .help-body ol { margin: 6px 0; padding-left: 22px; }
.help-body li { margin: 4px 0; }
.help-body code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.help-body dt { font-weight: 650; margin-top: 10px; }
.help-body dd { margin: 2px 0 0; color: var(--muted); }
.help-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; margin: 10px 0; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: 13px; }
@media (max-width: 720px) {
  .dialog.help-dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .help-head { padding: 12px 14px 6px; }
  .help-head h2 { font-size: 17px; }
  .help-toc { flex-wrap: nowrap; overflow-x: auto; padding: 4px 14px 10px; scrollbar-width: none; }
  .help-toc button { flex: none; }
  .help-body { padding: 0 14px 24px; font-size: 14.5px; }
  .help-legend { grid-template-columns: 1fr; }
}
