:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #1d2330;
  --muted: #667085;
  --line: #e3e6eb;
  --accent: #c8102e;
  --accent-dark: #a00d25;
  /* Gruen = Plaetze frei, Rot = ausgebucht */
  --empty: #e3f5e8;
  --empty-text: #1e7a3c;
  --partial: #fff4d6;
  --partial-text: #8a5a00;
  --full: #fde7e9;
  --full-text: #a3132b;
  --ok: #e3f5e8;
  --ok-text: #1e7a3c;
  --error: #fde7e9;
  --error-text: #a3132b;
  --mine: #e5efff;
  --mine-line: #3b6fd8;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
.wrap { max-width: 1400px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-bottom: 48px; }
h1 { font-size: 1.6rem; margin: 24px 0 8px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.guides { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin: 16px 0 0; font-size: .9rem; display: flex; flex-direction: column; gap: 4px; }
.guides a::before { content: "📄"; display: inline-block; margin-right: 6px; text-decoration: none; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 24px 0 4px; }
.lead { color: var(--muted); margin-top: 0; max-width: 70ch; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Kopfzeile */
.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--text); }
.top nav a:hover { background: var(--bg); }
.top nav a.muted { color: var(--muted); }

/* Karten und Formulare */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 16px 0; }
.card.narrow { max-width: 460px; margin: 48px auto; }
label { display: block; margin: 0 0 14px; font-weight: 500; }
input, select { font: inherit; }
label input:not([type=checkbox]), label select { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
input:not([type=checkbox]), select {
  padding: 8px 10px; border: 1px solid #cfd4dc; border-radius: 6px; background: #fff; color: var(--text);
}
input[readonly], input[disabled] { background: var(--bg); color: var(--muted); }
input.need { width: 70px; display: inline-block; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
button {
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 9px 18px;
}
button:hover { background: var(--accent-dark); }
button.secondary { background: #fff; color: var(--text); border: 1px solid #cfd4dc; }
button.secondary:hover { background: var(--bg); }
button.danger { background: #fff; color: var(--accent); border: 1px solid #f1b8c1; }
button.small, select.small { padding: 4px 10px; font-size: .85rem; }
button.link { background: none; color: var(--muted); padding: 0 2px; font-size: 1rem; }
form.inline { display: inline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.flash { padding: 10px 14px; border-radius: 8px; margin: 16px 0; background: var(--ok); color: var(--ok-text); }
.flash.error { background: var(--error); color: var(--error-text); }
.chip { display: inline-flex; align-items: center; gap: 2px; background: var(--bg); border-radius: 99px; padding: 2px 4px 2px 10px; margin: 2px 4px 2px 0; font-size: .9rem; }
.subnav { display: flex; gap: 12px; margin-bottom: 8px; }
.small-link { font-size: .85rem; margin-left: 6px; }

/* Tabs mit Tagesuebersicht */
.tabs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 16px 0; }
.tab { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; text-decoration: none; color: var(--text); display: flex; flex-direction: column; }
.tab span { color: var(--muted); font-size: .9rem; }
.missing { color: var(--empty-text); }
.done { color: var(--full-text); }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 400; color: var(--muted); }
.toggle input { width: 18px; height: 18px; margin: 0; }
.only-open tr.closed { display: none; }

/* Raster Zeitslots x Ressorts */
.day { margin: 8px 0 32px; scroll-margin-top: 70px; }
.day h2 { margin-top: 16px; }
.grid-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
.grid { background: var(--card); border: 1px solid var(--line); font-size: .85rem; }
.grid th, .grid td { border: 1px solid var(--line); padding: 6px; vertical-align: top; }
.grid thead th { background: #fafbfc; font-weight: 600; text-align: left; min-width: 110px; position: sticky; top: 0; }
.grid thead th a { color: var(--text); text-decoration: none; }
.grid thead th a:hover { text-decoration: underline; }
.grid th.time { position: sticky; left: 0; background: #fafbfc; white-space: nowrap; min-width: 0; z-index: 1; }
.cell.none { color: #c3c8d0; text-align: center; background: #fcfcfd; }
.cell.empty { background: var(--empty); }
.cell.partial { background: var(--partial); }
.cell.full { background: var(--full); }
.cell.mine { box-shadow: inset 0 0 0 2px var(--mine-line); }
.cell.picked { box-shadow: inset 0 0 0 2px var(--accent); }
.count { font-weight: 700; }
.cell.empty .count { color: var(--empty-text); }
.cell.partial .count { color: var(--partial-text); }
.cell.full .count { color: var(--full-text); }
.names { list-style: none; margin: 2px 0 0; padding: 0; color: var(--text); }
.names li.me { font-weight: 700; }
.pick { display: flex; align-items: center; gap: 4px; margin: 4px 0 0; font-weight: 400; color: var(--muted); cursor: pointer; white-space: nowrap; }
.pick input { width: 18px; height: 18px; margin: 0; }
.you { display: block; margin-top: 4px; color: var(--mine-line); font-weight: 600; }

.submit-bar {
  position: sticky; bottom: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-top: 12px;
}
.day:not(.has-selection) .submit-bar button { opacity: .5; }

.legend-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin: 12px 0; font-size: .9rem; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; list-style: none; margin: 8px 0 0; padding: 0; }
.dot.none { background: #fcfcfd; border: 1px solid #d0d5dd; }
h3.first { margin-top: 0; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }
.dot.empty { background: var(--empty); border: 1px solid #a9dbb7; }
.dot.partial { background: var(--partial); border: 1px solid #f0d58c; }
.dot.full { background: var(--full); border: 1px solid #f1b8c1; }
.dot.mine { background: #fff; border: 2px solid var(--mine-line); }

/* Listen */
.list th, .list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list th { font-weight: 600; color: var(--muted); font-size: .85rem; }
.list th.right, .list td.right { text-align: right; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .8rem; font-weight: 700; margin-left: 6px; }
.badge.empty { background: var(--empty); color: var(--empty-text); }
.badge.partial { background: var(--partial); color: var(--partial-text); }
.badge.full { background: var(--full); color: var(--full-text); }
.badge.none { background: var(--bg); color: var(--muted); }
.person { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 2px 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 16px 0; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.stats strong { display: block; font-size: 1.5rem; }
.stats span { color: var(--muted); font-size: .9rem; }

@media (max-width: 700px) {
  h1 { font-size: 1.35rem; }
  .cols, .tabs { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .card { padding: 16px; }
  .top nav a { padding: 4px 6px; font-size: .9rem; }
}

.mail { white-space: pre-wrap; font: .85rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }

a.button { display: inline-block; font-weight: 600; text-decoration: none; border-radius: 6px; padding: 9px 18px; }
a.button.secondary { background: #fff; color: var(--text); border: 1px solid #cfd4dc; }
@media print {
  .top, .no-print, .flash { display: none !important; }
  body { background: #fff; }
  .card, .stats div { border-color: #ccc; }
}

/* Ressortverantwortliche im Tabellenkopf der Uebersicht */
.lead-name { display: block; position: relative; margin-top: 2px; font-weight: 400; color: var(--muted); cursor: default; border-bottom: 1px dotted transparent; }
.lead-name:hover, .lead-name:focus { color: var(--text); outline: none; }
.lead-card {
  display: none; position: absolute; left: 0; top: 100%; z-index: 20; min-width: 220px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  box-shadow: 0 6px 20px rgba(16, 24, 40, .12); white-space: nowrap; color: var(--text);
}
.lead-card a { display: block; margin-top: 2px; }
.lead-name:hover .lead-card, .lead-name:focus-within .lead-card { display: block; }
.grid thead th:hover, .grid thead th:focus-within { z-index: 15; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.check input { width: 18px; height: 18px; margin: 0; flex: none; }
.center { text-align: center; }
.mail-pick { width: 18px; height: 18px; }
.howto { margin: 6px 0 0; padding-left: 20px; }
.howto li { margin: 2px 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px 24px; }
.hide-names .grid .names { display: none; }
.import-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: 0 0 16px; }
.import-form .muted { flex: 1 1 320px; font-size: .85rem; }
label.button { display: inline-block; margin: 0; font-weight: 600; cursor: pointer; border-radius: 6px; padding: 9px 18px; background: #fff; color: var(--text); border: 1px solid #cfd4dc; }
label.button:hover { background: var(--bg); }
.import-form input[type=file] { display: none; }
textarea { width: 100%; padding: 8px 10px; border: 1px solid #cfd4dc; border-radius: 6px; font: inherit; color: var(--text); background: #fff; box-sizing: border-box; }
textarea.mail-text { line-height: 1.5; resize: vertical; }
.dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 24px; width: min(520px, calc(100vw - 32px)); box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.dialog::backdrop { background: rgba(20, 24, 33, .45); }
.dialog select, .dialog input { width: 100%; box-sizing: border-box; }
.person + button[data-add], td > button[data-add] { margin-top: 4px; }
input.time-input { width: 110px; display: inline-block; margin: 0 4px; }
