:root {
  /* Тёмная тема + фирменный оранжевый (Летай) */
  --bg: #14161c;
  --card-bg: #1c1f28;
  --card-bg-2: #20242e;
  --border: #2c303c;
  --text: #e7e9ee;
  --text-muted: #97a0af;
  --accent: #ff7a1a;
  --accent-dark: #e0620a;
  --accent-soft: rgba(255, 122, 26, 0.16);
  --completed: #22c55e;
  --over: #b91c1c;
  --header-bg: #20242e;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* ---- Login ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1a1206, #402302);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 32px 36px;
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.45);
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card h1 {
  margin: 0;
  font-size: 20px;
  color: var(--text);
}

.login-card .hint {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.login-card input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--card-bg-2);
  color: var(--text);
}
.login-card input::placeholder { color: var(--text-muted); }

.login-card button {
  margin-top: 6px;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #2a1200;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.login-card button:hover { background: var(--accent-dark); color: #fff; }

.error {
  color: #f87171;
  font-size: 13px;
  min-height: 16px;
}

/* ---- App shell ---- */
.app {
  max-width: 1900px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.topbar h1 {
  font-size: 22px;
  margin: 0;
  color: var(--text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

/* Закреплённая шапка (заголовок + фильтры + статус выгрузки) - остаётся
   наверху при прокрутке таблицы вниз. */
.sticky-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  padding-top: 24px;
  margin: 0 -20px;
  padding-left: 20px;
  padding-right: 20px;
  box-shadow: 0 4px 14px -6px rgba(0, 0, 0, 0.5);
}

/* ---- Legend над таблицей ---- */
.legend-top {
  margin: 16px 0 12px;
  padding: 12px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
}

.legend-top .legend-title {
  font-weight: 700;
  color: var(--text);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-bar {
  display: inline-block;
  width: 30px;
  height: 6px;
  border-radius: 3px;
  vertical-align: middle;
}
.legend-bar-assigned { background: linear-gradient(to right, rgb(148,154,166), var(--accent)); }
.legend-bar-completed { background: linear-gradient(to right, rgb(148,154,166), var(--completed)); }

.legend-swatch-over {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--over);
  vertical-align: middle;
}

/* ---- Filters ---- */
.filters {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-end;
  margin-bottom: 12px;
}

.filter-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-block label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.filter-block select,
.filter-block input[type=date] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  min-width: 160px;
  background: var(--card-bg-2);
  color: var(--text);
  color-scheme: dark;
}

.check-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.check-row label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 400;
  text-transform: none;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 9px;
  border-radius: 999px;
  cursor: pointer;
  background: var(--card-bg-2);
}

.actions {
  flex-direction: row;
  gap: 10px;
}

.primary-btn, .ghost-btn {
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}

.primary-btn {
  background: var(--accent);
  color: #2a1200;
}
.primary-btn:hover { background: var(--accent-dark); color: #fff; }

.ghost-btn {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.ghost-btn:hover { background: var(--card-bg-2); }

/* Кнопка "Обновить данные" - крупная, оранжевая (фирменный цвет), с
   анимацией загрузки внутри самой кнопки. Пока идёт выгрузка - никаких
   подписей нигде, только спиннер. */
.refresh-btn-big {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 26px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid var(--accent-dark);
  background: linear-gradient(180deg, #ff9d47, var(--accent));
  color: #2a1200;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(255, 122, 26, 0.35);
  transition: transform 0.05s ease, box-shadow 0.15s ease;
}
.refresh-btn-big:hover {
  background: linear-gradient(180deg, #ffb066, var(--accent));
  box-shadow: 0 3px 14px rgba(255, 122, 26, 0.5);
}
.refresh-btn-big:active {
  transform: translateY(1px);
}
.refresh-btn-big:disabled {
  background: #33363f;
  border-color: var(--border);
  color: var(--text-muted);
  box-shadow: none;
  cursor: default;
}

.refresh-status {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
  min-height: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Спиннер - крутится и на кнопке "Обновить данные" во время выгрузки, и
   (если понадобится) в статусной строке. */
.spinner {
  width: 16px;
  height: 16px;
  border: 3px solid rgba(42, 18, 0, 0.35);
  border-top-color: #2a1200;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Table ---- */
/* main - собственная прокручиваемая область для таблицы (и по горизонтали,
   и по вертикали). ВАЖНО: overflow-x:auto без явного overflow-y браузер
   сам трактует как overflow-y:auto тоже (так работает спецификация CSS) -
   то есть main в любом случае становится отдельным контейнером прокрутки.
   Раньше это не было учтено: position:sticky у thead пытался прилипать
   "top" относительно страницы, а реально считался относительно main -
   из-за этого шапка таблицы наезжала на середину списка сотрудников при
   прокрутке. Явно делаем main ограниченной по высоте прокручиваемой
   панелью и прижимаем thead к top:0 ИМЕННО ВНУТРИ main - тогда it always
   и работает предсказуемо. Высота вычисляется в app.js (updateStickyOffset)
   от суммарной высоты закреплённой шапки + легенды над таблицей. */
main {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: calc(100vh - var(--content-offset, 320px));
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}

thead th {
  background: var(--header-bg);
  text-align: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  /* top:0 ОТНОСИТЕЛЬНО main (см. комментарий у main выше) - именно так
     нужно, а не относительно страницы. */
  top: 0;
  font-size: 13px;
  color: var(--text);
  z-index: 20;
}

thead th.emp-col {
  text-align: left;
}

/* Разделитель между тайм-слотами (9-13 / 13-17 / 17-20). */
.slot-boundary {
  border-right: 2px solid #4b5163 !important;
}

tbody td {
  padding: 10px 12px;
  text-align: center;
  border-bottom: 1px solid #262a34;
}

/* Ячейка с числами нарядов. */
tbody td.count-cell {
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* Режим "Все" - назначено/выполнено в одной ячейке через слэш. */
.count-assigned {
  color: var(--text-muted);
  font-weight: 500;
}
.count-sep {
  color: #545a68;
  margin: 0 1px;
  font-weight: 400;
}
.count-completed {
  color: var(--text);
  font-weight: 700;
}

tbody td.emp-col {
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text);
}

.new-badge {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #ffb066;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  vertical-align: middle;
}

tbody tr.group-row td {
  background: var(--card-bg-2);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
}

/* ---- Индикаторы загрузки в ячейке (по времени) ----
   Верхняя полоска - назначено, нижняя - выполнено. Обе считаются по
   суммарному времени нарядов этой категории в этом тайм-слоте
   относительно длины слота (см. app.js: categoryRatio()). Заливка растёт
   слева направо; при 100% и больше (перегруз слота) - цвет "over". */
td.cell-gauge {
  position: relative;
  padding-top: 18px;
  padding-bottom: 18px;
}

.gauge-track {
  position: absolute;
  left: 10px;
  right: 10px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
.gauge-track.top { top: 6px; }
.gauge-track.bottom { bottom: 6px; }

.gauge-fill {
  height: 100%;
  width: 0%;
  border-radius: 2px;
}

.cell-numbers { position: relative; z-index: 1; }

.empty-state {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

@media (max-width: 720px) {
  .filters { flex-direction: column; align-items: stretch; }
  .filter-block select, .filter-block input[type=date] { min-width: 0; width: 100%; }
}
