:root {
  --red: #b3121b;
  --red-dark: #8a0d14;
  --ink: #1c1f24;
  --muted: #667085;
  --line: #e4e2de;
  --bg: #f5f3f0;
  --card: #fff;
  --ok: #1f7a3d;     --ok-bg: #e5f4ea;
  --warn: #9a6200;   --warn-bg: #fff3d6;
  --bad: #b3121b;    --bad-bg: #fde5e6;
  --open: #475467;   --open-bg: #eceef2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.05);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; padding-top: 24px; padding-bottom: 40px; }
a { color: var(--red); }
h1 { font-size: 1.7rem; line-height: 1.2; margin: 0 0 .3em; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin: 1.6em 0 .6em; }
.card > h2:first-child, .card > h1:first-child { margin-top: 0; }
code { background: #f1efec; padding: 1px 6px; border-radius: 6px; font-size: .9em; }
.wrap { max-width: 1180px; margin: 0 auto; padding-left: 18px; padding-right: 18px; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.center { text-align: center; }

/* Topbar */
.topbar { background: var(--red); color: #fff; position: sticky; top: 0; z-index: 10; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.topbar-inner { display: flex; align-items: center; gap: 20px; min-height: 68px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; flex-shrink: 0; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; background: #fff; color: var(--red); font-weight: 900; font-size: .9rem; letter-spacing: -.02em; flex-shrink: 0; }
.brand-mark.big { width: 72px; height: 72px; font-size: 1.5rem; border-radius: 18px; background: var(--red); color: #fff; }
img.brand-mark.has-logo { width: auto; height: 48px; max-width: 200px; padding: 5px 10px; object-fit: contain; }
img.brand-mark.big.has-logo { height: 120px; max-width: 340px; background: #fff; padding: 12px 18px; border-radius: 18px; box-shadow: var(--shadow); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; }
.brand-text small { opacity: .85; font-size: .78rem; }
.mainnav { display: flex; gap: 2px; margin-left: auto; align-items: center; }
.mainnav a, .dd summary { color: #fff; text-decoration: none; padding: 8px 12px; border-radius: 8px; font-size: .93rem; white-space: nowrap; cursor: pointer; }
.mainnav > a:hover, .mainnav a.active, .dd summary:hover, .dd summary.active, .dd[open] summary { background: rgba(255,255,255,.16); }
.mainnav .nav-san { background: #fff; color: var(--red); font-weight: 600; margin-left: 6px; }
.mainnav .nav-san:hover { background: #ffe9ea; }
.dd { position: relative; }
.dd summary { list-style: none; display: flex; align-items: center; gap: 6px; }
.dd summary::-webkit-details-marker { display: none; }
.dd summary::after { content: "▾"; font-size: .75em; opacity: .8; }
.dd-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: #fff; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 6px; z-index: 20; }
.dd-menu a { display: block; color: var(--ink); padding: 10px 12px; }
.dd-menu a:hover, .dd-menu a.active { background: #f6f1f1; color: var(--red); }
.avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: #fff; color: var(--red); font-weight: 800; font-size: .78rem; }
.dd-user summary { padding: 4px 10px 4px 4px; margin-left: 4px; }
.nav-toggle { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 1.6rem; cursor: pointer; }

/* Cards & layout */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 18px; overflow-x: auto; }
.card.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.scroll { overflow-x: auto; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }

/* Buttons */
.btn { display: inline-block; background: var(--red); color: #fff; border: 0; border-radius: 10px; padding: 11px 18px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; transition: background .15s; }
.btn:hover { background: var(--red-dark); }
.btn-ghost { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn-ghost:hover { background: #f6f4f1; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; color: var(--red); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
form.inline { display: inline; margin-left: 8px; }

/* Forms */
.form label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 14px; }
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea {
  display: block; width: 100%; margin-top: 5px; font: inherit; font-weight: 400; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 10px; background: #fff; }
.form input:focus, .form select:focus, .form textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(179,18,27,.12); }
.form textarea.code { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }
label.check { display: flex !important; gap: 10px; align-items: flex-start; font-weight: 500 !important; }
label.check input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--red); flex-shrink: 0; }
fieldset.pick { border: 1.5px solid var(--line); border-radius: 10px; margin: 0 0 14px; padding: 10px 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 2px 14px; }
fieldset.pick legend { font-weight: 600; font-size: .92rem; padding: 0 6px; }
fieldset.pick label.check { margin-bottom: 4px; }
.ans-row { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.ans-row label.check { margin: 0; white-space: nowrap; font-size: .85rem; }
.ans-row input[name^="a["] { margin: 0 !important; }

/* Flash */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; }
.f-ok { background: var(--ok-bg); color: var(--ok); }
.f-warn { background: var(--warn-bg); color: var(--warn); }
.f-err { background: var(--bad-bg); color: var(--bad); }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-expired { background: var(--bad-bg); color: var(--bad); }
.b-open { background: var(--open-bg); color: var(--open); }
.b-na { background: #f4f4f4; color: #98a2b3; }
.tag { display: inline-block; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--muted); }
.mini { font-size: .68rem; background: #f1efec; color: var(--muted); border-radius: 5px; padding: 1px 5px; margin-left: 6px; font-weight: 700; }
.role { font-size: .8rem; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: #f1efec; }
.r-admin { background: #1c1f24; color: #fff; }
.r-kommandant { background: var(--red); color: #fff; }
.r-agw { background: #fff3d6; color: #7a4d00; }

/* Dashboard */
.hello { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 6px; }
.todo { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.todo strong { font-size: 2rem; line-height: 1; }
.todo-open strong { color: var(--red); }
.todo-ok strong { color: var(--ok); }
.courses { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.course { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; display: flex; flex-direction: column; border-top: 5px solid var(--open); }
.course h3 { margin: 10px 0 4px; font-size: 1.12rem; }
.course p { margin: 0 0 8px; }
.course .meta { font-size: .84rem; color: var(--muted); margin-top: auto; padding-top: 8px; }
.course-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.course-actions { display: flex; gap: 8px; margin-top: 10px; }
.cat-atemschutz { border-top-color: #1d4ed8; }
.cat-uvv { border-top-color: #e8a400; }
.cat-fahrer { border-top-color: #0f766e; }
.cat-allgemein { border-top-color: var(--red); }

.san-banner { display: flex; align-items: center; gap: 16px; margin: 28px 0 0; padding: 18px 22px; border-radius: var(--radius); background: linear-gradient(120deg, #fff, #fff5f5); box-shadow: var(--shadow), inset 0 0 0 2px #f6c9cc; color: var(--ink); text-decoration: none; transition: transform .15s, box-shadow .15s; }
.san-banner:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(179,18,27,.15), inset 0 0 0 2px var(--red); }
.san-banner strong { display: block; font-size: 1.08rem; color: var(--red); }
.san-banner small { color: var(--muted); }
.san-cross { flex-shrink: 0; width: 46px; height: 46px; border-radius: 12px; background: var(--red); color: #fff; display: grid; place-items: center; font-size: 1.6rem; font-weight: 700; }
.san-arrow { margin-left: auto; font-size: 1.5rem; color: var(--red); }

/* Kurs */
.course-head { border-top: 6px solid var(--open); }
.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 14px 0 0; counter-reset: s; flex-wrap: wrap; }
.steps li { counter-increment: s; font-size: .86rem; color: var(--muted); padding: 6px 12px 6px 8px; border-radius: 999px; background: #f4f2ef; }
.steps li::before { content: counter(s); display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #d5d2cd; color: #fff; font-size: .75rem; margin-right: 6px; font-weight: 700; }
.steps li.on { background: #fde5e6; color: var(--red); font-weight: 600; }
.steps li.on::before { background: var(--red); }
.steps li.done::before { background: var(--ok); content: "✓"; }
.content { font-size: 1.02rem; max-width: 860px; }
.content h2 { color: var(--red); border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.content li { margin-bottom: 4px; }
.content img, .content iframe { max-width: 100%; border-radius: 10px; }
.callout, .content blockquote { background: #fff5f5; border-left: 4px solid var(--red); padding: 12px 16px; border-radius: 6px; margin: 1em 0; }
.content iframe.video, .content iframe.ql-video { display: block; width: 100%; max-width: 800px; aspect-ratio: 16 / 9; height: auto; border: 0; border-radius: 10px; margin: 1em 0; }
.content img { display: block; height: auto; margin: 1em 0; }
.content .align-center { text-align: center; } .content .align-right { text-align: right; } .content .align-justify { text-align: justify; }
.content .align-center img { margin-left: auto; margin-right: auto; }
/* Editor */
.editor-label { font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
.editor-help { margin: 0 0 8px; }
.editor-wrap { margin-bottom: 14px; }
.editor-wrap .ql-toolbar.ql-snow { position: sticky; top: 68px; z-index: 5; background: #faf9f7; border: 1.5px solid var(--line); border-radius: 10px 10px 0 0; padding: 8px; }
.editor-wrap .ql-container.ql-snow { border: 1.5px solid var(--line); border-top: 0; border-radius: 0 0 10px 10px; font: inherit; font-size: 1.02rem; background: #fff; }
.editor-wrap .ql-editor { min-height: 420px; max-width: none; line-height: 1.6; }
.editor-wrap .ql-editor h2 { color: var(--red); border-bottom: 1px solid var(--line); padding-bottom: 6px; margin: 1.2em 0 .5em; }
.editor-wrap .ql-editor blockquote { border-left: 4px solid var(--red); background: #fff5f5; padding: 12px 16px; border-radius: 6px; margin: 1em 0; }
.editor-wrap .ql-editor iframe.ql-video { width: 100%; max-width: 640px; aspect-ratio: 16 / 9; height: auto; }
.card-editor { overflow: visible; }
.editor-wrap .ql-container .ql-editor img { max-width: min(100%, 560px); height: auto; border-radius: 8px; }
.content img { max-width: min(100%, 800px); }
.editor-wrap .ql-snow .ql-tooltip { z-index: 6; }
.editor-wrap .ql-snow .ql-tooltip[data-mode=link]::before { content: "Link:"; }
.editor-wrap .ql-snow .ql-tooltip::before { content: "Link öffnen:"; }
.editor-wrap .ql-snow .ql-tooltip a.ql-action::after { content: "Bearbeiten"; }
.editor-wrap .ql-snow .ql-tooltip a.ql-remove::before { content: "Entfernen"; }
.editor-wrap .ql-snow .ql-tooltip.ql-editing a.ql-action::after { content: "Speichern"; }
.editor-status { margin-top: 6px; padding: 8px 12px; border-radius: 8px; background: var(--open-bg); font-size: .9rem; }
.editor-status.err { background: var(--bad-bg); color: var(--bad); }
.question { border: 0; min-width: 0; }
.question legend { float: left; width: 100%; font-weight: 600; font-size: 1.05rem; padding: 0; margin-bottom: 12px; display: flex; gap: 10px; }
.question legend + * { clear: both; }
.qn { flex-shrink: 0; width: 28px; height: 28px; border-radius: 8px; background: var(--red); color: #fff; display: grid; place-items: center; font-size: .85rem; }
.answer { display: flex; gap: 12px; align-items: flex-start; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: 10px; margin-bottom: 8px; cursor: pointer; transition: border-color .12s, background .12s; }
.answer:hover { border-color: #d7a7aa; }
.answer:has(input:checked) { border-color: var(--red); background: #fff7f7; }
.answer input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--red); flex-shrink: 0; }

/* Ergebnis */
.result { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.result-score { font-size: 2.6rem; font-weight: 800; width: 130px; height: 130px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; }
.result-ok .result-score { background: var(--ok-bg); color: var(--ok); }
.result-fail .result-score { background: var(--bad-bg); color: var(--bad); }
.result .btn { margin: 4px 6px 4px 0; }
.review { border-left: 5px solid var(--line); padding: 14px 18px; }
.review p { margin: 0 0 6px; }
.review ul { margin: 0; padding-left: 20px; }
.rv-ok { border-left-color: var(--ok); }
.rv-bad { border-left-color: var(--bad); }
.review li.given { font-weight: 600; }
.review li.correct, .qlist li.correct { color: var(--ok); font-weight: 600; }
.review li.correct::after, .qlist li.correct::after { content: " ✔"; }
.qlist > li { margin-bottom: 14px; }

/* Tabellen */
.tbl { width: 100%; border-collapse: collapse; font-size: .93rem; }
.tbl th, .tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.tbl tr.inactive td { opacity: .5; }
.matrix th.rot { height: 150px; vertical-align: bottom; padding: 6px 4px; min-width: 46px; }
.matrix th.rot span { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; text-transform: none; letter-spacing: 0; font-size: .82rem; color: var(--ink); }
.matrix td.nm { white-space: nowrap; font-weight: 500; }
.matrix td.cell { text-align: center; font-size: .78rem; font-weight: 600; white-space: nowrap; border: 2px solid #fff; border-radius: 6px; }
.c-ok { background: var(--ok-bg); color: var(--ok); }
.c-warn { background: var(--warn-bg); color: var(--warn); }
.c-expired { background: var(--bad-bg); color: var(--bad); }
.c-open { background: var(--open-bg); color: var(--open); }
.c-na { color: #c0c4cc; }
.legend { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; border-left: 5px solid var(--open); }
.stat strong { display: block; font-size: 1.8rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .88rem; }
.s-ok { border-left-color: var(--ok); } .s-warn { border-left-color: #e8a400; } .s-expired { border-left-color: var(--bad); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.filters a { text-decoration: none; color: var(--ink); background: #fff; padding: 7px 14px; border-radius: 999px; box-shadow: inset 0 0 0 1.5px var(--line); font-size: .9rem; }
.filters a.on { background: var(--ink); color: #fff; box-shadow: none; }
.roles-info { background: #f8f7f5; padding: 10px 14px; border-radius: 10px; margin: 6px 0 14px; }

/* Login */
.login { max-width: 560px; margin: 20px auto; }
.login-hero { text-align: center; margin-bottom: 20px; }
.login-hero .brand-mark { margin: 0 auto 14px; }

/* Footer */
.foot { background: #1c1f24; color: #c7cbd1; font-size: .88rem; }
.foot-inner { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 18px; padding-bottom: 18px; }
.foot a { color: #fff; font-weight: 600; text-decoration: none; }

@media (max-width: 1100px) {
  .nav-toggle { display: block; }
  .mainnav { display: none; position: absolute; top: 100%; left: 0; right: 0; background: var(--red-dark); flex-direction: column; align-items: stretch; padding: 8px 14px 16px; box-shadow: 0 10px 20px rgba(0,0,0,.2); }
  .nav-open .mainnav { display: flex; }
  .mainnav a, .dd summary { padding: 12px; }
  .mainnav .nav-san { margin: 8px 0; text-align: center; }
  .dd summary { display: none; }
  .dd-menu { position: static; display: block; background: none; box-shadow: none; padding: 0; min-width: 0; border-top: 1px solid rgba(255,255,255,.18); }
  .dd-menu a { color: #fff; }
  .dd-menu a:hover, .dd-menu a.active { background: rgba(255,255,255,.16); color: #fff; }
}
@media (max-width: 860px) {
  .tbl { font-size: .85rem; }
  .tbl th, .tbl td { padding: 7px 6px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  h1 { font-size: 1.4rem; }
  .card { padding: 16px; }
}
@media (max-width: 480px) {
  .brand-text small { display: none; }
  img.brand-mark.has-logo { max-width: 150px; height: 42px; }
}
@media print {
  .topbar, .foot, .btn, .pagehead .btn, .filters { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
.r-ausbilder { background: #e0ecff; color: #1d4ed8; }
