:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1e2430;
  --ink-soft: #5b6473;
  --line: #e2e6ec;
  --line-strong: #cdd3dc;
  --accent: #2b6cb0;
  --accent-ink: #ffffff;
  --current: #fff4d6;
  --current-line: #f0c14b;
  --shadow: 0 6px 24px rgba(20, 30, 50, 0.14);
  --col-emp: 190px;
  --col-wk: 66px;
  --row-h: 46px;
  --head-h: 40px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------------- topbar -- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar__title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.topbar__sub { color: var(--ink-soft); font-size: 13px; }

.topbar__actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.masternav { display: flex; align-items: center; gap: 8px; }
.yearnav { display: flex; align-items: center; gap: 8px; }

.btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 12px;
  line-height: 1;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
}
.btn:hover { background: #f0f3f7; }
.btn:active { transform: translateY(1px); }
.btn--icon { width: 36px; height: 36px; font-size: 20px; padding: 0; }
.btn--accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn--accent:hover { background: #245a95; }

.year-select {
  font: inherit;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  min-width: 92px;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- legend --- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.legend__item { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.legend__swatch {
  width: 14px; height: 14px; border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12);
  flex: none;
}
.legend__name { color: var(--ink); }
.legend__empty { color: var(--ink-soft); font-size: 13px; }

/* --------------------------------------------------------------- status --- */
.status {
  display: none;
  padding: 6px 18px;
  font-size: 13px;
  color: var(--ink-soft);
  background: #eef2f7;
  border-bottom: 1px solid var(--line);
}
.status--visible { display: block; }
.status--error { color: #a12626; background: #fdecec; }

/* --------------------------------------------------------------- matrix --- */
.matrix-wrap {
  flex: 1;
  min-height: 0;
  padding: 14px;
}

.matrix-scroll {
  overflow: auto;
  -webkit-overflow-scrolling: touch;   /* momentum scroll on touch/tablet */
  overscroll-behavior-x: contain;
  max-height: calc(100vh - 190px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(20,30,50,0.05);
}

.matrix {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  width: max-content;
}

.matrix th, .matrix td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

/* header cells (KW numbers) — sticky top */
.matrix thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--head-h);
  background: #eef2f7;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  width: var(--col-wk);
  min-width: var(--col-wk);
  text-align: center;
  white-space: nowrap;
}

/* first column (employee names) — sticky left */
.sticky-col {
  position: sticky;
  left: 0;
  z-index: 15;
  width: var(--col-emp);
  min-width: var(--col-emp);
  max-width: var(--col-emp);
  background: #f7f9fc;
  text-align: left;
  padding: 0 12px;
  font-weight: 600;
  box-shadow: 2px 0 0 0 var(--line-strong);
}

/* corner cell — sticky in both directions, must sit above everything */
.corner {
  z-index: 30;
  background: #eaeef4;
  color: var(--ink);
  font-size: 13px;
}

.empname {
  height: var(--row-h);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.cell {
  width: var(--col-wk);
  min-width: var(--col-wk);
  max-width: var(--col-wk);
  height: var(--row-h);
  padding: 3px;
  vertical-align: top;
  cursor: pointer;
  background: #fff;
  transition: background 0.1s;
}
.cell:hover { background: #eef5ff; }
.cell--active { background: #dcebff; box-shadow: inset 0 0 0 2px var(--accent); }

/* current-week highlighting */
.wk--current {
  background: var(--current) !important;
  color: #8a6d16 !important;
  box-shadow: inset 0 -3px 0 0 var(--current-line);
}
.cell--current { background: #fffbef; }
.cell--current:hover { background: #fff4d6; }

.empty-row {
  padding: 24px;
  text-align: center;
  color: var(--ink-soft);
  background: #fff;
}

/* -------------------------------------------------------------- chips ----- */
.chip {
  display: block;
  font-size: 11px;
  line-height: 1.2;
  padding: 2px 6px;
  border-radius: 5px;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.10);
}
.chip:last-child { margin-bottom: 0; }

/* pulse animation for "heute" jump */
.pulse { animation: pulseBg 1.6s ease-out; }
@keyframes pulseBg {
  0%   { box-shadow: inset 0 0 0 3px var(--accent); }
  60%  { box-shadow: inset 0 0 0 3px rgba(43,108,176,0.35); }
  100% { box-shadow: inset 0 0 0 0 rgba(43,108,176,0); }
}

/* ------------------------------------------------------------- popover ---- */
.popover {
  position: fixed;
  z-index: 100;
  width: 260px;
  max-width: calc(100vw - 16px);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px;
  animation: pop 0.1s ease-out;
}
@keyframes pop {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}
.popover[hidden] { display: none; }

.popover__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.popover__title {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.popover__close {
  border: none;
  background: #eef2f7;
  color: var(--ink-soft);
  width: 26px; height: 26px;
  border-radius: 7px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.popover__close:hover { background: #e0e6ee; color: var(--ink); }

.popover__section { margin-bottom: 12px; }
.popover__section:last-child { margin-bottom: 0; }
.popover__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.popover__none { color: var(--ink-soft); font-size: 13px; }
.popover__assigned { display: flex; flex-direction: column; gap: 5px; }

.chip--removable {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  padding: 4px 4px 4px 8px;
}
.chip__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip__x {
  border: none;
  background: rgba(0,0,0,0.18);
  color: inherit;
  width: 20px; height: 20px;
  border-radius: 5px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.chip__x:hover { background: rgba(0,0,0,0.34); }

.popover__projects {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}
.pick {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
.pick:hover { background: #f0f5ff; border-color: var(--accent); }
.pick__swatch {
  width: 14px; height: 14px; border-radius: 4px; flex: none;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12);
}
.pick__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pick--completed { opacity: 0.55; }
.pick--completed .pick__name::after {
  content: " (abgeschlossen)";
  color: var(--ink-soft);
  font-size: 11px;
}

.popover__toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-soft);
  cursor: pointer;
}
.popover__toggle input { cursor: pointer; }

/* ---------------------------------------------------------------- modal --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}
.modal[hidden] { display: none; }
.modal__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 50, 0.42);
  animation: fade 0.12s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal__dialog {
  position: relative;
  z-index: 1;
  width: 560px;
  max-width: 100%;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
  animation: pop 0.12s ease-out;
}
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.modal__title { font-size: 18px; margin: 0; }
.modal__close {
  border: none;
  background: #eef2f7;
  color: var(--ink-soft);
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.modal__close:hover { background: #e0e6ee; color: var(--ink); }
.modal__body { padding: 16px 18px; }

.md-create {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.md-create--proj { flex-wrap: wrap; }
.md-input {
  font: inherit;
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.md-input:focus { outline: none; border-color: var(--accent); }

.md-list { list-style: none; margin: 0; padding: 0; }
.md-list__empty {
  color: var(--ink-soft);
  font-size: 13px;
  padding: 12px 0;
}

.md-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.md-row:last-child { border-bottom: none; }
.md-row--completed { opacity: 0.55; }

.md-row__name { flex: 2 1 140px; min-width: 0; }
.md-row__customer { flex: 1 1 110px; min-width: 0; }
.md-row__color {
  width: 38px; height: 34px;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  flex: none;
}
.md-row__toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
  cursor: pointer;
  flex: none;
}
.md-row__toggle input { cursor: pointer; }

.md-del {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #a12626;
  width: 32px; height: 32px;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.md-del:hover { background: #fdecec; border-color: #e0a0a0; }

/* --------------------------------------------------------------- mobile --- */
@media (max-width: 640px) {
  :root { --col-emp: 130px; --col-wk: 60px; }
  .topbar h1 { font-size: 17px; }
  .topbar__sub { display: none; }
  .matrix-scroll { max-height: calc(100vh - 210px); }
  .modal { padding: 16px 8px; }
  .md-create { flex-wrap: wrap; }
  .md-row { flex-wrap: wrap; }
  .md-row__name, .md-row__customer { flex: 1 1 100%; }
}
