:root {
  --bg: #f6f6f4;
  --card: #ffffff;
  --line: #dedddb;
  --text: #1d1d1b;
  --muted: #6a6a68;
  --accent: #00457c;
  --gut: #1f7a3f;
  --schlecht: #a32b25;
  --focus: #a15c00;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  color-scheme: light;
  font: 16px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 1.1rem; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 1rem; flex: 1; min-width: 0; }
.topbar nav a { text-decoration: none; white-space: nowrap; padding-bottom: 0.15rem; border-bottom: 2px solid transparent; }
.topbar nav a:hover { text-decoration: underline; }
.topbar nav a.aktiv { font-weight: 600; border-bottom-color: var(--accent); }
.logout { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; min-width: 0; }
.logout .user { display: flex; align-items: center; gap: 0.45rem; color: var(--muted); font-size: 0.85rem; }
.user-role { padding-left: 0.45rem; border-left: 1px solid var(--line); white-space: nowrap; }

main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
footer { max-width: 1100px; margin: 0 auto; padding: 1.5rem; color: var(--muted); font-size: 0.85rem; }

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 2rem 0 0.75rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.kacheln { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem; }
.kachel {
  flex: 1 1 160px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.75rem 1rem;
}
.kachel .zahl { font-size: 1.6rem; font-weight: 600; }
.kachel .label { color: var(--muted); font-size: 0.85rem; }

table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
.table-scroll {
  width: 100%;
  margin-bottom: 1rem;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  -webkit-overflow-scrolling: touch;
}
.table-scroll table { min-width: 32rem; }
.table-scroll table.compakt { min-width: 24rem; }
table.rahmen { border: 0; border-radius: 0; overflow: visible; }
caption { text-align: left; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.ja { background: #e7f3ec; color: var(--gut); border-color: #bcdcc8; }
.badge.nein { background: #f1f1ef; color: var(--muted); }
.badge.warn { background: #fdecea; color: var(--schlecht); border-color: #f0c4c0; }
.badge.ok { background: #e7f3ec; color: var(--gut); border-color: #bcdcc8; }
.badge.warning { background: #fff4d6; color: #825800; border-color: #e7c875; }
.badge.error { background: #fdecea; color: var(--schlecht); border-color: #f0c4c0; }

.score { font-variant-numeric: tabular-nums; font-weight: 600; }
.score.plus { color: var(--gut); }
.score.minus { color: var(--schlecht); }

.regeln { color: var(--muted); font-size: 0.8rem; margin: 0.25rem 0 0; padding-left: 1rem; }
.meta { color: var(--muted); font-size: 0.85rem; }

form.suche { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, textarea {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.35;
  background: var(--card);
  color: var(--text);
}
textarea { min-height: 5rem; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; min-height: auto; accent-color: var(--accent); }
select { min-height: 2.5rem; }
button, .knopf {
  display: inline-block;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  line-height: 1.35;
  min-height: 2.5rem;
  cursor: pointer;
  text-decoration: none;
}
button.sekundaer, .knopf.sekundaer { background: transparent; color: var(--accent); }
/* Fuer Knoepfe, die da sein muessen, aber nichts an sich ziehen sollen. */
button.leise {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.25rem 0.4rem;
}
button.leise:hover { text-decoration: underline; }
.zeilenknopf {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.inline-form { display: inline; }
.table-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; }
.table-actions .inline-form { display: inline-flex; }
.table-actions a, .table-actions button { white-space: nowrap; }
.action-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.card-title { margin-top: 0; }

.system-status-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.system-status-item { padding: 0.75rem; border: 1px solid var(--line); border-radius: 4px; }
.system-status-item p { margin: 0 0 0.35rem; }
.system-status-item p:last-child { margin-bottom: 0; }
.system-status.error { border-color: #f0c4c0; }
.system-status.warning { border-color: #e7c875; }
.msg.info { border-color: var(--line); background: var(--card); }

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, .knopf:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.formular { max-width: 26rem; margin: 3rem auto; }
.formular-breit { max-width: 40rem; }
.formular-breit p { margin: 0 0 1rem; }
.formular-breit label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.2rem; }
.formular-breit input:not([type=checkbox]):not([type=radio]):not([type=hidden]),
.formular-breit textarea, .formular-breit select { width: 100%; }
.formular-breit ul { list-style: none; padding-left: 0; margin: 0; }
.formular-breit ul label { font-weight: 400; display: inline; }
.formular-breit ul li { margin-bottom: 0.35rem; }
.formular-breit .helptext { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; }
.formular .card p { margin: 0 0 1rem; }
.formular label { display: block; font-size: 0.9rem; margin-bottom: 0.25rem; }
.formular input:not([type=checkbox]):not([type=radio]):not([type=hidden]) { width: 100%; }
.formular .hilfe { color: var(--muted); font-size: 0.85rem; }
.errorlist { color: var(--schlecht); font-size: 0.85rem; padding-left: 1rem; }
.form-error-summary { margin-bottom: 1rem; padding: 0.75rem 1rem; border: 1px solid #f0c4c0; border-radius: 4px; background: #fdecea; color: var(--schlecht); }
.form-error-summary ul { margin: 0.35rem 0 0; padding-left: 1.25rem; }

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.msg { padding: 0.6rem 0.9rem; border-radius: 4px; border: 1px solid var(--line); background: var(--card); margin-bottom: 0.5rem; }
.msg.error { border-color: #f0c4c0; background: #fdecea; }
.msg.success { border-color: #bcdcc8; background: #e7f3ec; }

.blaettern { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; color: var(--muted); }
iframe.report { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 6px; background: #fff; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --card: #202225;
    --line: #35373b;
    --text: #e9e9e7;
    --muted: #9b9b98;
    --accent: #6fb0e8;
    --gut: #66c48a;
    --schlecht: #e58b84;
    --focus: #ffd166;
  }
  body { color-scheme: dark; }
  .badge.ja { background: #1d3527; border-color: #2f5a3f; }
  .badge.ok { background: #1d3527; border-color: #2f5a3f; }
  .badge.warn { background: #3a2320; border-color: #5e352f; }
  .badge.warning { background: #3a3020; color: #ffd166; border-color: #6c5726; }
  .badge.error { background: #3a2320; border-color: #5e352f; }
  .msg.error { background: #3a2320; border-color: #5e352f; }
  .msg.success { background: #1d3527; border-color: #2f5a3f; }
  button, .knopf { color: #10171d; }
  button.leise { color: var(--muted); }
  button.sekundaer, .knopf.sekundaer { color: var(--accent); }
  .zeilenknopf { color: var(--accent); }
  .form-error-summary { background: #3a2320; border-color: #5e352f; }
  .msg.info { background: var(--card); }
}

@media (max-width: 760px) {
  .topbar { padding: 0.75rem 1rem; }
  .topbar nav {
    order: 3;
    flex-basis: 100%;
    overflow-x: auto;
    padding-bottom: 0.25rem;
  }
  .logout { margin-left: auto; }
  .logout .user { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .logout .user { display: block; }
  .user-email, .user-role { display: block; overflow: hidden; text-overflow: ellipsis; }
  .user-role { padding-left: 0; border-left: 0; }
  main { padding: 1rem; }
  footer { padding: 1rem; }
}

@media (max-width: 420px) {
  .logout { flex-basis: 100%; margin-left: 0; justify-content: space-between; }
  .logout .user { max-width: calc(100% - 5rem); }
  .action-row { align-items: stretch; }
  .action-row > * { flex: 1 1 auto; text-align: center; }
  .system-status-grid { grid-template-columns: 1fr; }
}
