:root {
  --ink: #17202b;
  --muted: #4a5565;
  --ground: #f5f6f8;
  --card: #ffffff;
  --line: #d5dae1;
  --soft: #e3e7ec;
  --edge: #7c8797;
  --blue: #1d4ed8;
  --blue-soft: #eaf0ff;
  --orange: #c2410c;
  --orange-soft: #ffe1cc;
  --orange-ink: #6b2a00;
  --red: #b42318;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 34px; line-height: 1.1; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 21px; font-weight: 700; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.loading { padding: 48px 24px; text-align: center; color: var(--muted); }

.page { max-width: 1180px; margin: 0 auto; padding: 28px 20px 72px; display: flex; flex-direction: column; gap: 24px; }
.main { display: flex; flex-direction: column; gap: 22px; }
.start { max-width: 460px; margin: 0 auto; padding: 48px 20px; display: flex; flex-direction: column; gap: 20px; }

.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.top-title { display: flex; flex-direction: column; gap: 4px; }
.top-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.sub { color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
.card.narrow { gap: 14px; }
.card.feedback { background: var(--blue-soft); border-color: #b8c8f5; }
.block { display: flex; flex-direction: column; gap: 10px; }
.block > .btn { align-self: flex-start; }
.row-between { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; }
.two { display: flex; flex-wrap: wrap; gap: 16px 32px; }
.two > div { flex: 1 1 280px; display: flex; flex-direction: column; gap: 4px; }

.hint { font-size: 14px; color: var(--muted); }
.hint.pad { padding: 16px; }
.warn { background: var(--orange-soft); color: var(--orange-ink); border: 1px solid var(--orange); border-radius: 8px; padding: 10px 14px; }
.strong { font-weight: 600; }
.muted { color: var(--muted); }
.pre { white-space: pre-line; overflow-wrap: anywhere; }
.label { font-size: 14px; font-weight: 600; color: var(--muted); }
.subject { font-size: 14px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.04em; }
.mono.big { font-size: 20px; font-weight: 700; }
.num { font-variant-numeric: tabular-nums; }

/* Formulare */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-weight: 600; }
.input { min-height: 46px; padding: 8px 12px; border: 2px solid var(--edge); border-radius: 8px; background: #fff; width: 100%; }
textarea.input { line-height: 1.4; resize: vertical; }
.input.slim { width: auto; min-width: 120px; }
.input.short { flex: 0 0 130px; width: 130px; }
.code-input { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 20px; letter-spacing: 0.06em; text-transform: uppercase; }
.file { padding: 8px 0; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; }
.under { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; min-height: 20px; }
.save-state { font-size: 14px; color: var(--muted); }
.event-edit { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.event-edit .input:not(.short) { flex: 1 1 220px; width: auto; }

/* Knöpfe */
.btn { white-space: nowrap; min-height: 44px; padding: 0 16px; border-radius: 8px; border: 2px solid var(--ink); background: #fff; font-weight: 600; font-size: 15px; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.ghost { border-color: var(--edge); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.small { min-height: 44px; padding: 0 12px; font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab { min-height: 44px; padding: 0 16px; border-radius: 8px; border: 2px solid var(--ink); background: #fff; font-weight: 600; font-size: 15px; }
.tab.on { background: var(--ink); color: #fff; }

/* Aufträge */
.task { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.task-indiv { border: 2px solid var(--orange); }
.task-main { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.task-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.task-title { font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.task-meta { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.code { color: var(--ink); font-weight: 700; }
.code.big { font-size: 18px; min-width: 40px; }
.tag { padding: 2px 8px; border-radius: 6px; border: 2px solid var(--ink); font-size: 13px; font-weight: 600; white-space: nowrap; }
.tag-pflicht { background: var(--ink); color: #fff; }
.tag-wahl { background: #fff; color: var(--ink); }
.tag-indiv { background: var(--orange-soft); color: var(--orange-ink); border-color: var(--orange); }

.status-set { display: flex; flex-wrap: wrap; gap: 6px; }
.st { min-height: 44px; padding: 0 14px; border-radius: 8px; border: 2px solid var(--edge); background: #fff; font-size: 14px; font-weight: 600; }
.st-0.on { background: var(--soft); border-color: var(--ink); }
.st-1.on { background: var(--orange-soft); border-color: var(--orange); color: var(--orange-ink); }
.st-2.on { background: var(--blue); border-color: var(--blue); color: #fff; }

.bar { height: 12px; background: var(--soft); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 12px; width: 0; background: var(--blue); }

.events { display: flex; flex-direction: column; gap: 6px; }
.event { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.event-tag { min-width: 96px; font-weight: 600; }

/* Raster */
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; font-size: 14px; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; }
.glyph { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--edge); background: #fff; vertical-align: middle; }
.glyph.g1 { border-color: var(--orange); background: linear-gradient(90deg, var(--orange) 50%, #fff 50%); }
.glyph.g2 { border-color: var(--blue); background: var(--blue); position: relative; }
.glyph.g2::after { content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.badge-e { display: inline-block; margin-left: 4px; padding: 1px 5px; border-radius: 4px; background: var(--orange-soft); color: var(--orange-ink); font-size: 12px; font-weight: 700; vertical-align: middle; }

.grid-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.grid { border-collapse: collapse; width: 100%; }
.grid th, .grid td { padding: 6px 8px; text-align: center; border-bottom: 1px solid var(--soft); white-space: nowrap; }
.grid thead th { border-bottom: 2px solid var(--ink); font-size: 14px; vertical-align: bottom; padding: 10px 8px; }
.grid .left { text-align: left; }
.grid .right { text-align: right; }
.grid tr.sel { background: var(--blue-soft); }
.grid tr.foot { background: var(--ground); font-size: 14px; }
.grid tr.foot th, .grid tr.foot td { border-bottom: none; padding: 12px 8px; }
.grid tr.inactive { color: var(--muted); background: var(--ground); }
.grid.list td, .grid.list th { padding: 8px 12px; }
.th-code { display: block; font-size: 16px; font-weight: 700; }
.th-kind { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.name-btn { min-height: 44px; padding: 0 6px; border: none; background: none; font-weight: 600; text-align: left; text-decoration: underline; text-underline-offset: 3px; display: inline-flex; align-items: baseline; gap: 8px; }
.name-code { font-size: 12px; font-weight: 400; color: var(--muted); }

.grid.trials th, .grid.trials td { text-align: left; padding: 10px 10px; vertical-align: top; }
.grid.trials thead th { white-space: nowrap; }
.grid.trials td, .grid.trials tbody th { white-space: normal; overflow-wrap: break-word; hyphens: auto; }
.grid.trials td.wrap { white-space: pre-line; min-width: 140px; max-width: 300px; }
.grid.trials .nowrap { white-space: nowrap; }
.grid.trials tr.dream { background: #f8f9fb; }
.grid.trials tr.first th, .grid.trials tr.first td { border-top: 2px solid var(--line); }
.grid.trials tbody th.top-cell { font-weight: 600; white-space: nowrap; }
.tag-state { background: #fff; color: var(--ink); border-color: var(--edge); }
.tag-state.state-angefragt { background: var(--orange-soft); color: var(--orange-ink); border-color: var(--orange); }
.tag-state.state-zugesagt { background: var(--blue-soft); color: #1e3a8a; border-color: var(--blue); }
.tag-state.state-absolviert { background: var(--blue); color: #fff; border-color: var(--blue); }
.tag-state.state-abgesagt { background: var(--soft); color: var(--muted); border-color: var(--edge); }

.line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.grow { flex: 1 1 240px; overflow-wrap: anywhere; }

/* Zugangskarten */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.access-card { background: #fff; border: 1px solid var(--edge); border-radius: 8px; padding: 14px; display: flex; gap: 14px; align-items: center; break-inside: avoid; }
.qr { width: 116px; height: 116px; flex: 0 0 auto; }
.access-text { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.access-name { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }
.access-link { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }

/* Meldungen */
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 8px; background: var(--ink); color: #fff; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 0.15s; }
#toast.show { opacity: 1; }
#toast.error { background: var(--red); }

@media (max-width: 560px) {
  h1 { font-size: 28px; }
  .page { padding: 20px 14px 64px; }
  .status-set { width: 100%; }
  .st { flex: 1 1 0; padding: 0 8px; }
}

@media print {
  body { background: #fff; }
  .no-print, #toast { display: none !important; }
  .page { padding: 0; max-width: none; }
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
}
