:root {
  --ink: #1b1820;
  --muted: #6c6475;
  --paper: #fbfafc;
  --panel: #ffffff;
  --rule: #e5e0ea;
  --accent: #8e2472;
  --accent-soft: #f6ecf4;
  --present: #2f8b52;
  --absent: #c34049;
  --unknown: #dcd7e1;
  --w-first: 108px;
  --w-last: 104px;
  --w-year: 48px;
  --w-tools: 64px;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Login ---------- */

.gate {
  max-width: 22rem;
  margin: 18vh auto 0;
  padding: 0 1.25rem;
}
.gate h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.01em; }
.gate p { margin: 0.15rem 0 1.75rem; color: var(--muted); }
.gate-form { display: grid; gap: 0.4rem; }
.gate-form label { font-size: 0.85rem; color: var(--muted); }
.gate-form input {
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--panel);
}
.gate-form button {
  margin-top: 0.6rem;
  padding: 0.6rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.gate-error { color: var(--absent); font-size: 0.9rem; margin: 0.2rem 0 0; }

/* ---------- Kopfzeile ---------- */

.top {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.85rem 1rem 0.7rem;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
}
.top h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.top h1 span {
  font-weight: 400;
  color: var(--muted);
  margin-left: 0.45rem;
}
.top-actions { margin-left: auto; display: flex; gap: 0.4rem; flex-shrink: 0; }

.btn {
  padding: 0.42rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  white-space: nowrap;
}
.btn:hover { border-color: #cdc6d4; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #7a1e62; border-color: #7a1e62; }
.btn-quiet { border-color: transparent; color: var(--muted); }
.btn-danger { border-color: transparent; color: var(--absent); }

/* ---------- Filterleiste ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.55rem 1rem;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.bar input[type="search"] {
  flex: 1 1 11rem;
  min-width: 8rem;
  max-width: 18rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--panel);
}
.seg { display: flex; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.seg button {
  padding: 0.4rem 0.65rem;
  border: 0;
  border-right: 1px solid var(--rule);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.count { color: var(--muted); font-size: 0.86rem; margin-left: auto; }

/* ---------- Raster ---------- */

.scroller { overflow: auto; max-width: 100%; }
table.grid {
  border-collapse: separate;
  border-spacing: 0;
  background: var(--panel);
}
.grid th, .grid td {
  border-bottom: 1px solid var(--rule);
  padding: 0;
  text-align: left;
  font-weight: inherit;
}
.grid thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel);
  border-bottom: 1px solid #cdc6d4;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  vertical-align: bottom;
  white-space: nowrap;
}
.c-first, .c-last, .c-year, .c-tools {
  position: sticky;
  z-index: 5;
  background: var(--panel);
}
.grid thead .c-first, .grid thead .c-last,
.grid thead .c-year, .grid thead .c-tools { z-index: 20; }
.c-first { left: 0; width: var(--w-first); min-width: var(--w-first); max-width: var(--w-first); }
.c-last  { left: var(--w-first); width: var(--w-last); min-width: var(--w-last); max-width: var(--w-last); }
.c-year  { left: calc(var(--w-first) + var(--w-last)); width: var(--w-year); min-width: var(--w-year); }
.c-tools {
  left: calc(var(--w-first) + var(--w-last) + var(--w-year));
  width: var(--w-tools);
  min-width: var(--w-tools);
  border-right: 1px solid var(--rule);
}
.grid tbody td.c-first, .grid tbody td.c-last, .grid tbody td.c-year { padding: 0 0.5rem; }
.c-first .t, .c-last .t {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.grid thead .c-first, .grid thead .c-last, .grid thead .c-year { padding: 0 0.5rem 0.35rem; }
.grid tbody tr:hover td { background: #fdfcfe; }
tr.is-inactive td.c-first, tr.is-inactive td.c-last, tr.is-inactive td.c-year { color: #a49cad; }

.sortable { cursor: pointer; }
.sortable.on { color: var(--accent); }

/* Trainingsspalte */
.c-train { width: 46px; min-width: 46px; }
.th-train {
  display: block;
  width: 100%;
  padding: 0.3rem 0 0.35rem;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: center;
  color: inherit;
}
.th-train:hover { background: var(--accent-soft); }
.th-train .d { display: block; font-size: 0.74rem; color: var(--muted); }
.th-train .m { display: block; font-size: 0.74rem; color: #a49cad; }
.th-train .n { display: block; font-size: 0.95rem; font-weight: 650; color: var(--accent); }
.th-train .lbl {
  display: block;
  font-size: 0.66rem;
  color: var(--muted);
  max-width: 44px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.c-add { width: 44px; min-width: 44px; text-align: center; }
.c-add button {
  width: 30px; height: 30px;
  border: 1px dashed #cdc6d4;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}

/* Punkt */
.dot-cell { text-align: center; padding: 0; }
/* Training liegt vor der Trainingsanfrage – kein Status möglich */
.dot-cell.pre, .grid tbody tr:hover td.pre { background: #f3f0f5; }
.dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 34px;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.dot::before {
  content: "";
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--unknown);
  transition: background 0.12s ease, transform 0.12s ease;
}
.dot[data-s="present"]::before { background: var(--present); }
.dot[data-s="absent"]::before { background: var(--absent); }
.dot:active::before { transform: scale(0.82); }
.dot.busy::before { opacity: 0.45; }

.icon {
  width: 28px; height: 28px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  border-radius: 6px;
  line-height: 1;
  font-size: 0.95rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon:hover { background: var(--accent-soft); color: var(--accent); }
.wa { color: var(--present); }

/* ---------- Erfassungsansicht ---------- */

.session { max-width: 34rem; margin: 0 auto; padding: 0.75rem 1rem 4rem; }
.session-head {
  position: sticky;
  top: 3rem;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.1rem;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.session-head h2 { margin: 0; font-size: 1.05rem; font-weight: 650; }
.session-head .btn { flex: 0 0 auto; }
.session-head .tally { margin-left: auto; color: var(--accent); font-weight: 650; }
.session-list { list-style: none; margin: 0; padding: 0; }
.session-list li { border-bottom: 1px solid var(--rule); }
.session-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.6rem 0.2rem;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.session-row:hover { background: var(--panel); }
.session-row .mark {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--unknown);
  flex: 0 0 auto;
}
.session-row[data-s="present"] .mark { background: var(--present); }
.session-row[data-s="absent"] .mark { background: var(--absent); }
.session-row .who { font-weight: 500; }
.session-row .jg { margin-left: auto; color: var(--muted); font-size: 0.86rem; }

.empty { padding: 2.5rem 1rem; color: var(--muted); text-align: center; }
.empty strong { display: block; color: var(--ink); margin-bottom: 0.25rem; }

/* ---------- Dialoge ---------- */

dialog {
  border: 0;
  border-radius: 12px;
  padding: 1.1rem 1.2rem 0.9rem;
  width: min(30rem, calc(100vw - 1.5rem));
  box-shadow: 0 18px 44px rgba(27, 24, 32, 0.22);
  color: var(--ink);
}
dialog::backdrop { background: rgba(27, 24, 32, 0.38); }
dialog h2 { margin: 0 0 0.9rem; font-size: 1.05rem; font-weight: 650; }
.fields { display: flex; flex-wrap: wrap; gap: 0.6rem 0.7rem; }
.f { margin: 0; flex: 1 1 100%; display: grid; gap: 0.2rem; }
.f-third { flex: 1 1 7rem; }
.f-check { flex: 0 0 auto; align-self: center; }
.f label { font-size: 0.82rem; color: var(--muted); }
.f .hint { color: #a49cad; }
.f-check label { font-size: 0.95rem; color: var(--ink); display: flex; align-items: center; gap: 0.4rem; }
.f input, .f select, .f textarea {
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--panel);
  width: 100%;
}
.f textarea { resize: vertical; }
.dlg-foot { display: flex; align-items: center; gap: 0.4rem; margin-top: 1rem; }
.dlg-foot .spacer { flex: 1; }

/* ---------- Hinweis ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translate(-50%, 1.5rem);
  max-width: min(26rem, calc(100vw - 2rem));
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 90;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--absent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 4px;
}

@media (max-width: 560px) {
  :root { --w-first: 88px; --w-last: 72px; --w-year: 42px; --w-tools: 58px; }
  body { font-size: 14px; }
  .top { flex-wrap: wrap; }
  .top h1 span { display: none; }
  .session-head { top: 5.5rem; flex-wrap: wrap; }
  .session-head h2 { font-size: 0.98rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
