:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --line: #dde3eb;
  --text: #0b1220;
  --muted: #637286;
  --brand: #113b8f;
  --brand-soft: #e6eefc;
  --warn: #fff2f2;
  --warn-line: #f2a6a6;
  --good: #e8f7ef;
  --good-text: #1a7f4b;
  --danger: #fef0f0;
  --danger-text: #b91c1c;
  --caution: #fffbeb;
  --caution-text: #b45309;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top right, #e6eefb 0%, var(--bg) 42%);
  color: var(--text);
  font-family: "SF Pro Text", "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
}

.topbar {
  padding: 18px 26px 12px;
}

.topbar__row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar__logo {
  height: 40px;
  width: auto;
  object-fit: contain;
  border-radius: 8px;
}

.topbar__title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.logout-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #b91c1c;
  text-decoration: none;
  padding: 6px 14px;
  border: 1px solid #fca5a5;
  border-radius: 20px;
  background: #fef2f2;
  transition: background .15s, border-color .15s, color .15s;
}

.logout-btn::before {
  content: "⎋";
  font-size: 14px;
  line-height: 1;
}

.logout-btn:hover {
  background: #fee2e2;
  border-color: #f87171;
  color: #991b1b;
}

.topbar__subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 15px;
}

.shift-active-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  background: #ecfdf5;
  border: 1px solid #6ee7b7;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  color: #065f46;
}

.shift-active-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  animation: pulse-dot 1.6s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.75); }
}

.layout {
  padding: 0 20px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 6px 16px rgba(8, 15, 32, 0.06);
  min-width: 0;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.card__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.filters__grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
}

.filters__grid.compact {
  grid-template-columns: minmax(150px, 220px) minmax(150px, 220px) auto;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field span {
  font-size: 12px;
  color: var(--muted);
}

input,
select,
button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  padding: 8px 10px;
}

button {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.filters__actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.link-btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  background: #fff;
  font-size: 14px;
}

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
}

.kpi-grid.compact {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  transition: border-color 0.15s;
}

.kpi-card__label {
  color: var(--muted);
  font-size: 12px;
}

.kpi-card__value {
  margin-top: 6px;
  font-size: 24px;
  font-weight: 800;
}

.kpi-card.kpi--good {
  background: var(--good);
  border-color: #6fcf97;
}
.kpi-card.kpi--good .kpi-card__value {
  color: var(--good-text);
}

.kpi-card.kpi--warn {
  background: var(--caution);
  border-color: #fcd34d;
}
.kpi-card.kpi--warn .kpi-card__value {
  color: var(--caution-text);
}

.kpi-card.kpi--danger {
  background: var(--danger);
  border-color: #fca5a5;
}
.kpi-card.kpi--danger .kpi-card__value {
  color: var(--danger-text);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.6;
}

.badge--ok {
  background: var(--good);
  color: var(--good-text);
}

.badge--warn {
  background: var(--caution);
  color: var(--caution-text);
}

.badge--neutral {
  background: var(--brand-soft);
  color: var(--brand);
}

/* Grid */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 300px;
  min-height: 240px;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

.table-wrap--scrollable {
  max-height: 540px;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  font-size: 14px;
  text-align: left;
  white-space: nowrap;
  padding: 8px 8px;
  border-bottom: 1px solid #edf1f6;
}

td[colspan] {
  color: var(--muted);
  white-space: normal;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.table-wrap--scrollable thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--card);
  box-shadow: 0 1px 0 var(--line);
}

tr.warn {
  background: #fff5f5;
}

tr.warn td:first-child {
  border-left: 3px solid #f87171;
}

/* Активная (незакрытая) смена */
tr.row-shift-open {
  background: #f0fdf4;
}

tr.row-shift-open td:first-child {
  border-left: 3px solid #34d399;
}

.shift-close-form {
  margin: 4px 0 0;
}

.btn-close-shift {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.75rem;
  line-height: 1.4;
  color: #b91c1c;
  background: #fff;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-close-shift:hover {
  color: #fff;
  background: #ef4444;
  border-color: #ef4444;
}

/* Аномалия: статус CLOSED но нет времени закрытия */
tr.row-shift-anomaly {
  background: #fff7ed;
}

tr.row-shift-anomaly td:first-child {
  border-left: 3px solid #fb923c;
}

.anomaly-cell {
  color: #b91c1c;
  font-weight: 700;
}

.checklist-status {
  max-width: 430px;
  white-space: normal;
}

.status-main {
  display: inline-block;
}

.status-details {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.shifts-table th,
.shifts-table td {
  padding: 7px 6px;
  font-size: 13px;
}

.shifts-table .cell-employee,
.shifts-table .checklist-status {
  white-space: normal;
  min-width: 160px;
}

/* Two-row grouped header */
.shifts-table .th-group {
  text-align: center;
  font-weight: 700;
  border-bottom: none;
}

.shifts-table .th-group--open  { background: var(--good);    color: var(--good-text); }
.shifts-table .th-group--mid   { background: var(--caution); color: var(--caution-text); }
.shifts-table .th-group--close { background: var(--warn);    color: var(--danger-text); }

.shifts-table .th-sub {
  text-align: center;
  font-size: 11px;
}

.shifts-table .th-sub--open  { background: #f0fdf4; }
.shifts-table .th-sub--mid   { background: #fffbeb; }
.shifts-table .th-sub--close { background: #fff5f5; }

.shifts-table .th-vspan {
  vertical-align: middle;
}

.shifts-table .cell-time,
.shifts-table .cell-duration {
  text-align: center;
}

.shifts-table .cell-status {
  text-align: center;
  white-space: nowrap;
}

/* Sticky overrides for two-row header */
.table-wrap--scrollable .shifts-table thead tr:first-child th {
  top: 0;
  z-index: 2;
  box-shadow: none;
}

.table-wrap--scrollable .shifts-table thead tr:first-child th.th-vspan {
  box-shadow: 0 1px 0 var(--line);
}

.table-wrap--scrollable .shifts-table thead tr:nth-child(2) th {
  top: 32px;
  z-index: 1;
  box-shadow: 0 1px 0 var(--line);
}

.media-cell {
  min-width: 168px;
}

.media-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.media-thumb {
  display: inline-flex;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  overflow: hidden;
  background: #f0f4fb;
  cursor: zoom-in;
  transition: transform 0.12s, box-shadow 0.12s;
}

.media-thumb:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.lightbox.is-open {
  display: flex;
}

.lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 10, 24, 0.82);
  backdrop-filter: blur(4px);
}

.lightbox__content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: min(90vw, 800px);
  max-height: 90vh;
}

.lightbox__close {
  align-self: flex-end;
  min-height: unset;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}

.lightbox__close:hover {
  background: rgba(255, 255, 255, 0.28);
}

.lightbox__label {
  margin: 0;
  color: rgba(255, 255, 255, 0.75);
  font-size: 13px;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox__img {
  max-width: 100%;
  max-height: calc(90vh - 70px);
  border-radius: 10px;
  object-fit: contain;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

/* Tab navigation */
.tab-nav {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  border-bottom: 2px solid var(--line);
  background: var(--card);
}

.tab-nav__link {
  padding: 10px 18px;
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.12s;
}

.tab-nav__link.is-active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

/* Schedule matrix (dashboard) */
.schedule-matrix-card {
  overflow: hidden;
}

.schedule-table .col-date {
  width: 56px;
  text-align: center;
  font-size: 11px;
  white-space: pre-line;
}

.schedule-table .col-employee-name {
  min-width: 120px;
}

.schedule-table .cell-employee-name {
  font-weight: 600;
}

.schedule-table .cell-worked {
  text-align: center;
  color: var(--muted);
}

.schedule-table .cell-worked.worked {
  color: var(--good-text);
  font-weight: 700;
}

/* Schedule table (employees page) */
.schedule-table--month .col-day {
  width: 38px;
  text-align: center;
  font-size: 11px;
  white-space: pre-line;
  padding: 4px 2px;
}

.schedule-table--month .cell-schedule {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 5px 2px;
}

.schedule-table--month .cell-schedule.has-entry {
  color: var(--good-text);
  font-weight: 700;
}

.schedule-table--month .cell-schedule.half-shift {
  color: var(--caution-text);
}

.row-inactive td {
  opacity: 0.45;
}

/* Tall chart for Gantt */
.chart-wrap--tall {
  height: 420px;
  min-height: 360px;
}

/* Full-width Gantt chart */
.chart-wrap--gantt {
  height: 480px;
  min-height: 360px;
}

/* Employee management page */
.emp-table .input-inline {
  width: 160px;
  min-height: 32px;
  padding: 4px 8px;
  font-size: 13px;
}

.emp-table .select-inline {
  min-height: 32px;
  padding: 4px 8px;
  font-size: 13px;
}

.btn-small {
  min-height: 32px;
  padding: 4px 12px;
  font-size: 13px;
}

.schedule-form {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  align-items: end;
}

.month-nav {
  display: flex;
  gap: 6px;
}

@media (max-width: 1280px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }
}

@media (max-width: 880px) {
  .layout {
    padding: 0 8px 16px;
    gap: 9px;
  }
  .topbar {
    padding: 14px 10px 8px;
  }
  .topbar__title {
    font-size: 22px;
  }
  .filters__grid {
    grid-template-columns: 1fr 1fr;
  }
  .filters__grid.compact {
    grid-template-columns: 1fr 1fr;
  }
  .filters__actions {
    grid-column: 1 / -1;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .chart-wrap {
    height: 240px;
    min-height: 220px;
  }
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }
  .shifts-table th,
  .shifts-table td {
    padding: 6px 5px;
    font-size: 12px;
  }
  .shifts-table th.col-id,
  .shifts-table td.cell-id {
    display: none;
  }
  .shifts-table .cell-employee {
    min-width: 120px;
  }
  .status-details {
    display: none;
  }
  .media-cell {
    min-width: 120px;
  }
  .media-thumb {
    width: 36px;
    height: 36px;
  }
  .table-wrap--scrollable {
    max-height: 420px;
  }
}

/* ── Login page ───────────────────────────────────────────── */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top right, #e6eefb 0%, var(--bg) 50%);
}

.login-wrap {
  width: 100%;
  max-width: 380px;
  padding: 20px;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 36px 32px 32px;
  box-shadow: 0 12px 40px rgba(8, 15, 32, 0.10);
  text-align: center;
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.login-logo__img {
  height: 72px;
  width: auto;
  object-fit: contain;
  border-radius: 14px;
}

.login-logo__text {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}

.login-subtitle {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 22px;
}

.login-error {
  background: var(--danger);
  color: var(--danger-text);
  border: 1px solid #fca5a5;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.login-btn {
  width: 100%;
  min-height: 44px;
  font-size: 15px;
  margin-top: 4px;
  border-radius: 12px;
  cursor: pointer;
}

/* ── Группировка смен по датам ──────────────────────────────────── */
tr.date-divider {
  cursor: pointer;
  user-select: none;
}

tr.date-divider > td {
  padding: 8px 12px;
  background: #eef2f7;
  border-bottom: 1px solid #dfe5ec;
  white-space: normal;
  display: table-cell;
}

tr.date-divider:hover > td {
  background: #e2e8f0;
}

.table-wrap--scrollable tr.date-divider > td {
  position: sticky;
  top: 60px; /* под двумя строками заголовка таблицы */
  z-index: 1;
  box-shadow: 0 1px 0 var(--line);
}

.date-divider__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  padding: 0;
  font-size: 11px;
  line-height: 1;
  color: var(--brand);
  background: rgba(99, 102, 241, 0.12);
  border: none;
  border-radius: 4px;
  vertical-align: middle;
  cursor: pointer;
}

.date-divider__label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #475569;
  vertical-align: middle;
}

.date-divider__counter {
  display: inline-block;
  margin-left: 10px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 600;
  color: #475569;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  vertical-align: middle;
}

tr.shift-row.is-hidden,
tr.shift-details-row.is-hidden {
  display: none;
}

/* Снять ограничение по высоте, когда раскрыта любая деталь смены */
.table-wrap--scrollable.is-expanded {
  max-height: none;
  overflow-y: visible;
}

/* ── Раскрывающиеся детали смены ─────────────────────────────────── */
.row-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-right: 6px;
  padding: 0;
  font-size: 12px;
  line-height: 1;
  color: var(--brand);
  background: var(--brand-soft);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease;
}

.row-toggle:hover {
  background: var(--brand);
  color: #fff;
}

.row-toggle.is-open {
  background: var(--brand);
  color: #fff;
}

.cell-date__label {
  vertical-align: middle;
}

.shift-details-row.is-hidden {
  display: none;
}

.shift-details-row > td {
  padding: 0;
  background: #fafbfd;
  border-bottom: 1px solid #edf1f6;
  white-space: normal;
}

.shift-details {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 14px 16px;
}

.checklist-block {
  background: #fff;
  border: 1px solid #e4e9f0;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.checklist-block--open {
  background: #f1faf4;
  border-color: #d4ecdd;
}
.checklist-block--mid {
  background: #fdf8ec;
  border-color: #ecdfc1;
}
.checklist-block--close {
  background: #fbf1f1;
  border-color: #ecd1d1;
}

.checklist-block__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.checklist-block__header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.checklist-block__counter {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.checklist-empty {
  margin: 4px 0 0;
  font-size: 12px;
}

.checklist-sections {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.checklist-section {
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.checklist-section--ok {
  border-color: rgba(34, 197, 94, 0.25);
}

.checklist-section--warn {
  border-color: rgba(248, 113, 113, 0.25);
}

.checklist-section > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  white-space: normal;
}

.checklist-section > summary::-webkit-details-marker {
  display: none;
}

.checklist-section > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 4px;
  color: var(--muted);
  transition: transform 0.12s ease;
}

.checklist-section[open] > summary::before {
  transform: rotate(90deg);
}

.checklist-section__title {
  flex: 1;
  min-width: 0;
}

.checklist-section__counter {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.checklist-items {
  list-style: none;
  margin: 0;
  padding: 4px 10px 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 12.5px;
  line-height: 1.35;
  white-space: normal;
}

.checklist-item__mark {
  flex-shrink: 0;
  width: 16px;
  text-align: center;
  font-weight: 700;
}

.checklist-item--done .checklist-item__mark { color: #16a34a; }
.checklist-item--miss .checklist-item__mark { color: #dc2626; }

.checklist-item--miss .checklist-item__text {
  color: #7f1d1d;
}

.checklist-item__text {
  flex: 1;
  min-width: 0;
}

.checklist-item__badge {
  flex-shrink: 0;
  font-size: 11px;
}

@media (max-width: 900px) {
  .shift-details {
    grid-template-columns: 1fr;
  }
}
