:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #5f6b76;
  --line: #e2ddd5;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --gold: #c8962e;
  --red: #d64541;
  --orange: #f0932b;
  --green: #2e9e5b;
  --ok-bg: #e7f5ec;
  --warn-bg: #fff4e0;
  --err-bg: #fdeaea;
  --info-bg: #e8f1f8;
  --radius: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }

.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }

.top {
  background: linear-gradient(135deg, #17324d, #1f5f8b);
  color: #fff;
  padding: 22px 0 18px;
  margin-bottom: 18px;
}
.top h1 { margin: 0; font-size: 1.7rem; letter-spacing: .01em; }
.top p { margin: 4px 0 0; opacity: .85; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 0 0 16px;
}
h2 { font-size: 1.2rem; margin: 0 0 12px; }
h3 { font-size: 1.15rem; margin: 0; }
h4 { font-size: .95rem; margin: 0 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.section-title { margin: 26px 0 12px; }

label { display: block; font-size: .92rem; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 11px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #c9c3b9;
  border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input:disabled { background: #f1efeb; color: var(--muted); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }

.check { display: flex; align-items: flex-start; gap: 9px; color: var(--ink); font-size: 1rem; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.check.small { font-size: .9rem; align-items: center; }
.check.small input { width: 16px; height: 16px; margin: 0; }
section.card > .check { margin-top: 12px; }

.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.inline input { width: auto; flex: 1 1 220px; margin: 0; }
.grow { flex: 1 1 auto; }
.center { text-align: center; }
.hint { color: var(--muted); font-size: .85rem; }

button { font: inherit; cursor: pointer; }
.btn-primary {
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 8px; padding: 11px 22px; font-weight: 600;
}
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-secondary {
  background: #fff; color: var(--accent);
  border: 1px solid var(--accent); border-radius: 8px; padding: 8px 14px;
}
.btn-link { background: none; border: 0; color: var(--accent); text-decoration: underline; padding: 4px; }
.btn-mini {
  background: #fff; color: var(--accent); border: 1px solid var(--accent);
  border-radius: 6px; padding: 3px 9px; font-size: .85rem;
}
.danger { color: var(--red) !important; border-color: var(--red) !important; }

/* Hinweise */
.box { border-radius: var(--radius); padding: 12px 16px; margin: 0 0 16px; border: 1px solid transparent; }
.box p { margin: 0 0 6px; }
.box p:last-child { margin: 0; }
.box.info { background: var(--info-bg); border-color: #c6dbeb; }
.box.warn { background: var(--warn-bg); border-color: #f2d3a0; }
.box.ok   { background: var(--ok-bg);   border-color: #bfe3cc; }
.box .important { font-weight: 600; }
details summary { cursor: pointer; color: var(--accent); margin-top: 6px; }

.msg { border-radius: var(--radius); padding: 10px 14px; margin: 0 0 16px; font-weight: 500; }
.msg-ok { background: var(--ok-bg); }
.msg-warn { background: var(--warn-bg); }
.msg-err { background: var(--err-bg); color: #8c1d1a; }

/* Kinder */
.child { border: 1px dashed var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; background: #fcfbf9; }
.child-head { display: flex; gap: 10px; align-items: flex-end; }
fieldset.roles { border: 0; padding: 0; margin: 12px 0 0; }
fieldset.roles legend { font-size: .92rem; color: var(--muted); padding: 0; margin-bottom: 4px; }
.role-groups { display: flex; flex-wrap: wrap; gap: 8px; }
.radio {
  display: flex; align-items: center; gap: 7px;
  border: 1px solid #c9c3b9; border-radius: 20px; padding: 6px 14px;
  color: var(--ink); font-size: .95rem; cursor: pointer; background: #fff;
}
.radio:has(input:checked) { border-color: var(--accent); background: var(--info-bg); }
.radio input { accent-color: var(--accent); margin: 0; }
.role-select { margin-top: 10px; max-width: 360px; }

/* Termine */
.event header { border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 10px; }
.event .when { font-weight: 600; color: var(--accent); }
.event .where, .event .note { color: var(--muted); font-size: .92rem; }
.kids-count { margin-top: 6px; font-size: .9rem; color: var(--muted); }
.block { padding: 6px 0; }
.block + .block { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px; }
.kid-row { display: grid; grid-template-columns: minmax(170px, 1fr) 2fr; gap: 10px; align-items: center; padding: 5px 0; }
.kid-row .comment { margin: 0; }
@media (max-width: 600px) { .kid-row { grid-template-columns: 1fr; gap: 4px; padding: 8px 0; } }

.helper-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 6px 0; }
.helper-row + .helper-row { border-top: 1px dotted var(--line); }
.helper-meta { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.count { font-size: .82rem; color: var(--muted); min-width: 70px; }

/* Tacho */
.gauge { display: inline-block; width: 58px; line-height: 0; flex: none; }
.gauge svg { width: 100%; height: auto; }
.gauge path { fill: none; stroke-width: 11; }
.g-red { stroke: var(--red); }
.g-orange { stroke: var(--orange); }
.g-green { stroke: var(--green); }
.g-needle { stroke: var(--ink); stroke-width: 4; stroke-linecap: round; }
.g-hub { fill: var(--ink); }

.legend-row { display: flex; align-items: center; gap: 12px; padding: 4px 0; }

/* Admin direkt auf der Seite */
.admin-badge {
  background: #2b2f36; color: #fff; border-radius: var(--radius);
  padding: 8px 14px; margin-bottom: 16px; font-size: .9rem;
}
.admin-badge a { color: #ffd479; }
.admin-inline {
  flex-basis: 100%;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  background: #f3f0fa; border: 1px solid #ddd5f0; border-radius: 6px;
  padding: 6px 8px; font-size: .85rem; color: #4a3f6b;
}
.admin-inline .num { width: 64px; display: inline-block; margin: 0; padding: 4px 6px; }
.admin-inline input[type=text] { flex: 1 1 220px; width: auto; margin: 0; padding: 5px 8px; }
.add-field { margin-top: 10px; }

/* Speichern-Leiste */
.savebar {
  position: sticky; bottom: 0;
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0;
  padding: 10px 14px; margin-top: 10px;
  box-shadow: 0 -4px 14px rgba(0, 0, 0, .06);
}
.save-msg { flex: 1; font-size: .9rem; color: var(--muted); }
.save-msg.t-ok { color: var(--green); }
.save-msg.t-warn { color: #a3610a; }
.save-msg.t-err { color: var(--red); }

.foot { padding: 24px 16px 40px; color: var(--muted); font-size: .9rem; text-align: center; }

/* Verwaltung */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.tabs button {
  background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 6px 14px;
}
.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td input[type=text], td input[type=number], td input[type=datetime-local], td select { margin: 0; padding: 5px 7px; }
td input.num { width: 70px; }
.pill { display: inline-block; border-radius: 10px; padding: 1px 8px; font-size: .8rem; }
.pill.yes { background: var(--ok-bg); color: #1d6b3d; }
.pill.no { background: var(--warn-bg); color: #8a5208; }
.stats { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.stat { background: var(--info-bg); border-radius: 8px; padding: 8px 14px; }
.stat b { display: block; font-size: 1.4rem; }
.muted { color: var(--muted); }
ul.plain { margin: 4px 0; padding-left: 18px; }

/* Proben-Matrix */
table.matrix { border-collapse: separate; border-spacing: 0; }
table.matrix th, table.matrix td { border-bottom: 1px solid var(--line); padding: 8px; }
table.matrix thead th { background: #faf8f4; position: sticky; top: 0; }
table.matrix .kid-col { text-align: center; min-width: 150px; color: var(--ink); }
table.matrix .ev-cell {
  position: sticky; left: 0; background: #fff; z-index: 1;
  min-width: 150px; font-weight: normal; color: var(--ink); white-space: normal;
}
.ev-date { font-weight: 700; color: var(--accent); }
.ev-title { font-weight: 600; }
.ev-time, .ev-count { font-size: .82rem; color: var(--muted); }
.kid-cell { text-align: center; }
.kid-cell .check { justify-content: center; margin-bottom: 6px; }
.kid-cell .check input { width: 24px; height: 24px; }
.kid-cell .comment { font-size: .85rem; padding: 5px 7px; margin: 0; min-width: 120px; }
.only-mobile { display: none; }

/* Helferdienste */
.service { padding: 12px 0; border-top: 1px solid var(--line); }
.service-label { font-weight: 600; margin-bottom: 8px; }
.service-cells { display: flex; flex-wrap: wrap; gap: 8px; }
.service-cell {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid #c9c3b9; border-radius: 10px; padding: 8px 10px;
  background: #fff; cursor: pointer; color: var(--ink); min-width: 190px;
}
.service-cell.on { border-color: var(--accent); background: var(--info-bg); }
.service-cell .check { align-items: center; }
.service-cell small { color: var(--muted); }
.service-cell .helper-meta { margin-left: auto; }
.admin-details { margin-top: 8px; font-size: .85rem; }
.admin-details > div { margin: 6px 0; }
.admin-inline select { width: auto; display: inline-block; margin: 0; padding: 4px 6px; }

/* Admin-editierbare Texte */
.text-block { position: relative; }
.text-block p { margin: 0 0 10px; }
.text-block p:last-child { margin-bottom: 0; }
.text-block .md-h2 { font-size: 1.45rem; margin: 0 0 4px; color: var(--accent); }
.text-block .md-h3 { font-size: 1.15rem; margin: 0 0 12px; color: var(--gold); }
.text-block .md-img { display: block; max-width: 100%; height: auto; margin: 6px auto 14px; border-radius: 8px; }
.text-block.hinweis { background: #fffaf0; border-color: #efdcb4; }
.text-block.hinweis .md-h3 { color: #8a5d12; }
.text-block textarea { display: block; width: 100%; font: inherit; padding: 10px; border: 1px solid #c9c3b9; border-radius: 8px; }
.edit-pen {
  position: absolute; top: 8px; right: 8px;
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; color: var(--accent);
  font-size: 1rem; line-height: 1;
}
.edit-pen:hover { background: var(--info-bg); }

/* Gemeinsame Matrix: Helferspalte */
table.matrix .svc-col { min-width: 260px; }
.svc-cell { min-width: 260px; }
.svc + .svc { margin-top: 6px; }
.svc-check {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid #d8d2c8; border-radius: 8px; padding: 5px 8px;
  background: #fff; color: var(--ink); cursor: pointer; font-size: .92rem;
}
.svc-check.on { border-color: var(--accent); background: var(--info-bg); }
.svc-check input { width: 18px; height: 18px; flex: none; accent-color: var(--accent); margin: 0; }
.svc-label { flex: 1; }
.svc-check .gauge { width: 46px; }
.svc-check .count { min-width: 36px; text-align: right; }
tr.helper-only .ev-cell { background: #fbf9f5; }
tr.helper-only td { background: #fbf9f5; }

/* Schafherde statt Tacho */
.svc-check { flex-wrap: wrap; row-gap: 4px; }
.svc-check .helper-meta { flex-basis: 100%; margin-left: 26px; }
.herd { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
.flock { display: inline-flex; align-items: flex-end; gap: 1px; }
.sheep { width: 30px; height: 23px; display: block; }
.sheep .legs rect { fill: #3b3530; }
.sheep .wool-line circle { fill: #8f826d; stroke: #8f826d; stroke-width: 2.2; }
.sheep .wool circle { fill: #fffdf7; }
.sheep .face { fill: #3b3530; }
.sheep .ear { fill: #2e2925; }
.sheep .eye { fill: #fff; }
.sheep.off .legs rect, .sheep.off .face, .sheep.off .ear { fill: #d9d3c9; }
.sheep.off .wool-line circle { fill: #cfc8bc; stroke: #cfc8bc; stroke-width: 1.4; }
.sheep.off .wool circle { fill: #f4f1ec; }
.sheep.off .eye { fill: #f4f1ec; }
.sheep.on { animation: hop .35s ease-out; }
@keyframes hop { 0% { transform: translateY(0); } 40% { transform: translateY(-3px); } 100% { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .sheep.on { animation: none; } }
.herd-num { font-size: .8rem; color: var(--muted); }
.herd-pill { font-size: .78rem; font-weight: 600; border-radius: 10px; padding: 1px 8px; white-space: nowrap; }
.herd-red .herd-pill { background: #fdeaea; color: #a32d2d; }
.herd-orange .herd-pill { background: #fff1dc; color: #8a5208; }
.herd-green .herd-pill { background: #e7f5ec; color: #1d6b3d; }
.legend-row .herd { min-width: 210px; }

/* Matrix: eigener Scrollbereich, damit Kopfzeile (Kindernamen) und Terminspalte stehen bleiben */
.matrix-wrap {
  max-height: max(340px, calc(100vh - 150px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table.matrix thead th { position: sticky; top: 0; z-index: 3; background: #f3efe8; box-shadow: 0 1px 0 var(--line); }
table.matrix thead th:first-child { left: 0; z-index: 4; }
table.matrix .ev-cell { z-index: 2; }

/* Rollen-Auswahl mit Altershinweis */
.radio-text { display: flex; flex-direction: column; line-height: 1.2; }
.radio-text small { font-size: .75rem; color: var(--muted); }

/* Login oben rechts */
.top-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.account { position: relative; flex: none; }
.acct-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.acct-who { display: flex; flex-direction: column; align-items: flex-end; font-size: .85rem; line-height: 1.2; }
.acct-who small { opacity: .8; }
.acct-btn {
  background: rgba(255, 255, 255, .14); color: #fff; border: 1px solid rgba(255, 255, 255, .45);
  border-radius: 18px; padding: 5px 14px; font-size: .9rem; text-decoration: none; cursor: pointer;
}
.acct-btn:hover { background: rgba(255, 255, 255, .25); }
.acct-btn.primary { background: #fff; color: var(--accent); border-color: #fff; font-weight: 600; }
.acct-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50; width: min(340px, calc(100vw - 32px));
  background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
}
.acct-panel h3 { font-size: 1rem; margin: 0 0 4px; }
.acct-panel hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.acct-form { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.acct-form input { margin: 0; }
@media (max-width: 600px) { .top-row { flex-direction: column; } .account { align-self: flex-end; } }

/* eigenes Schaf (noch ungespeichert/inkl. eigener Meldung) */
.sheep.mine .wool circle { fill: #d6e8fb; }
.sheep.mine .wool-line circle { fill: var(--accent); stroke: var(--accent); }

/* 1. / 2. Wahl nebeneinander */
.role-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.role-pair fieldset.second legend { color: var(--muted); }
@media (max-width: 760px) { .role-pair { grid-template-columns: 1fr; } }

/* Rollenvergabe */
.cast-role { border-top: 1px solid var(--line); padding: 12px 0; }
.cast-role:first-of-type { border-top: 0; }
.cast-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cast-head h3 { margin: 0; }
.cast-count { font-size: .85rem; border-radius: 10px; padding: 2px 10px; background: #f1efeb; color: var(--muted); }
.cast-count.on { background: var(--ok-bg); color: #1d6b3d; font-weight: 600; }
.cast-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 6px; }
@media (max-width: 700px) { .cast-cols { grid-template-columns: 1fr; } }
.cast-list { list-style: none; margin: 0; padding: 0; }
.cast-kid { padding: 4px 6px; border-radius: 6px; }
.cast-kid.on { background: var(--ok-bg); }
.cast-kid .check { font-size: .95rem; }
.cast-mark { width: 20px; text-align: center; color: var(--green); font-weight: 700; }
.cast-add { margin-top: 8px; max-width: 360px; }
.cast-role h4 { margin: 6px 0 4px; }

/* Helferdienste-Tabelle (ein Häkchen = alle Termine des Dienstes) */
.svc-table { display: flex; flex-direction: column; gap: 10px; }
.svc-row {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  border: 1px solid #d8d2c8; border-radius: 10px; padding: 10px 14px;
  background: #fff; color: var(--ink); cursor: pointer;
}
.svc-row.on { border-color: var(--accent); background: var(--info-bg); box-shadow: inset 4px 0 0 var(--accent); }
.svc-box input { width: 24px; height: 24px; accent-color: var(--accent); margin: 0; }
.svc-main { display: flex; flex-direction: column; gap: 6px; }
.svc-name { font-weight: 600; font-size: 1.02rem; }
.svc-dates { display: flex; flex-wrap: wrap; gap: 6px; }
.date-chip {
  font-size: .82rem; border: 1px solid #d8d2c8; border-radius: 12px; padding: 1px 9px;
  background: #faf8f4; color: var(--ink); white-space: nowrap;
}
.svc-row.on .date-chip { border-color: #9cc0dd; background: #fff; }
.svc-herd { justify-self: end; }
@media (max-width: 640px) {
  .svc-row { grid-template-columns: auto 1fr; }
  .svc-herd { grid-column: 2; justify-self: start; }
}
