:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #66727f;
  --line: #d9dee4;
  --accent: #b3121f;
  --accent-dark: #8c0e18;
  --ok: #1e7b45;
  --ok-bg: #e5f4ea;
  --err: #a1261b;
  --err-bg: #fbe9e7;
  --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 "Segoe UI", system-ui, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.2rem; margin: 2rem 0 .8rem; }
h3 { margin: 0 0 .4rem; font-size: 1rem; }
code { background: #eef1f4; padding: 0 .3em; border-radius: 4px; }
.muted { color: var(--muted); }
small { font-size: .82em; }

/* Kopfzeile */
.topbar { display: flex; align-items: center; gap: 2rem; padding: 0 1.5rem; background: #1f2933; color: #fff; height: 56px; position: sticky; top: 0; z-index: 10; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand span { font-weight: 400; font-size: .75rem; background: var(--accent); padding: .1rem .45rem; border-radius: 4px; margin-left: .3rem; vertical-align: middle; }
.topbar nav { display: flex; gap: .3rem; overflow-x: auto; }
.topbar nav a { color: #cfd6dd; text-decoration: none; padding: .45rem .8rem; border-radius: 6px; white-space: nowrap; }
.topbar nav a:hover { background: #33404c; color: #fff; }
.topbar nav a.active { background: var(--accent); color: #fff; }

.usermenu { margin-left: auto; display: flex; align-items: center; gap: .8rem; white-space: nowrap; }
.usermenu a { color: #fff; text-decoration: none; padding: .35rem .6rem; border-radius: 6px; }
.usermenu a:hover, .usermenu a.active { background: #33404c; }
.usermenu small { color: #aeb8c2; margin-left: .2rem; }
.linkbtn { background: none; border: 1px solid #56636f; color: #cfd6dd; font: inherit; font-size: .85rem; padding: .25rem .6rem; border-radius: 6px; cursor: pointer; }
.linkbtn:hover { color: #fff; border-color: #cfd6dd; }

.auth-box { max-width: 420px; margin: 3rem auto; padding: 1.6rem 1.8rem; }
.auth-box h1 { margin-top: 0; }
.btn.wide { width: 100%; padding: .6rem; margin-top: .3rem; }
.small-note { font-size: .85rem; margin: 1rem 0 0; }
.narrow { max-width: 680px; }
.role-choice { padding: .35rem 0; margin: 0; cursor: pointer; }
.role-admin { background: #fde7e9; color: #8c0e18; }
.role-bearbeiter { background: #e7eef8; color: #24508f; }
.role-pruefer { background: #fff1dc; color: #8a5300; }
.role-leser { background: #eef1f4; color: #3e4a55; }
tr.inactive td { color: #9aa4ad; }

.container { max-width: 1150px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.headline { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }

/* Meldungen */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: .8rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--err-bg); color: var(--err); }

/* Buttons */
.btn { display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--text); padding: .45rem .9rem; border-radius: 6px; cursor: pointer; font: inherit; text-decoration: none; line-height: 1.3; }
.btn:hover { border-color: #aab4be; background: #f8f9fa; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--err); }
.btn.danger:hover { background: var(--err-bg); border-color: var(--err); }
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
.btn:disabled { opacity: .35; cursor: default; }
form.inline { display: inline; }
.actions { display: flex; gap: .6rem; margin: 1rem 0; flex-wrap: wrap; }

/* Karten & Formulare */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1rem; }
fieldset.card { min-width: 0; }
legend { font-weight: 600; padding: 0 .4rem; }
label { display: block; margin-bottom: .7rem; }
.label { display: block; margin-bottom: .3rem; }
input, select, textarea { font: inherit; width: 100%; padding: .45rem .55rem; border: 1px solid #c4ccd4; border-radius: 6px; background: #fff; color: var(--text); margin-top: .2rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f0b8bd; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; margin: 0 .3rem 0 0; vertical-align: middle; }
input[type=file] { border: 1px dashed #aab4be; background: #fafbfc; }
input.tiny { width: 5rem; text-align: right; margin: 0; padding: .2rem .4rem; }
label.short input { width: 8rem; }
.inline-check { display: inline-block; margin-right: 1.2rem; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .8rem; }
.inline-form label { margin: 0; }
.inline-form .grow { flex: 1 1 260px; }
.grid-2, .grid-3 { display: grid; gap: 0 1.2rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }

/* Tabellen */
table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list th, .list td { padding: .55rem .8rem; border-bottom: 1px solid #edf0f3; text-align: left; vertical-align: top; }
.list th { background: #f8f9fb; font-weight: 600; font-size: .88rem; color: #4a5560; }
.list.compact td { padding: .3rem .8rem; }
.list tr:last-child td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.tree .top { font-weight: 600; }
.branch { color: #aab4be; margin-right: .35rem; }

/* Thema bearbeiten (Popover) */
.inline-edit { display: inline-block; position: relative; }
.inline-edit summary { list-style: none; }
.inline-edit summary::-webkit-details-marker { display: none; }
.popover { position: absolute; right: 0; top: 2.1rem; z-index: 5; width: 320px; background: #fff; border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,.12); border-radius: var(--radius); padding: 1rem; text-align: left; white-space: normal; }

/* Kacheln */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; text-decoration: none; color: var(--text); display: flex; flex-direction: column; }
.tile:hover { border-color: var(--accent); }
.tile strong { font-size: 2rem; color: var(--accent); line-height: 1.1; }
.tile small { color: var(--muted); margin-top: .3rem; }

/* Fragen */
.question header { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-bottom: .5rem; }
.question .spacer, .rte-toolbar .spacer { flex: 1; }
.qtext { white-space: pre-wrap; }
.qtext.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.badge { font-size: .75rem; font-weight: 600; padding: .15rem .5rem; border-radius: 99px; white-space: nowrap; }
.badge-text { background: #e7eef8; color: #24508f; }
.badge-bild { background: #f3e8f8; color: #6d2b8a; }
.badge-mc { background: #fff1dc; color: #8a5300; }
.points { font-size: .8rem; color: var(--muted); }
.tag { font-size: .78rem; background: #eef1f4; color: #3e4a55; padding: .1rem .45rem; border-radius: 4px; text-decoration: none; }
.images { display: flex; flex-wrap: wrap; gap: .6rem; margin: .6rem 0; }
.images img { max-height: 180px; max-width: 280px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.options { list-style: none; padding: 0; margin: .5rem 0; }
.options li { padding: .1rem 0; }
.options li.correct { color: var(--ok); font-weight: 600; }
.answer summary { cursor: pointer; color: var(--accent); font-size: .9rem; }
.answer .qtext { background: #f7f9fa; border-left: 3px solid var(--ok); padding: .5rem .8rem; margin-top: .4rem; }
.thumb { max-height: 60px; margin-top: .3rem; border: 1px solid var(--line); border-radius: 4px; }

/* Fragenformular */
.question-form { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 0 1rem; align-items: start; }
.form-main { min-width: 0; }
.form-side { position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow: auto; }
.question-form .form-actions { grid-column: 1 / -1; }
.topic-checks label { margin: 0; padding: .15rem 0; cursor: pointer; }
.topic-checks .top { font-weight: 600; margin-top: .3rem; }
.segmented { display: flex; flex-wrap: wrap; gap: .5rem; }
.segmented label { margin: 0; border: 1px solid var(--line); border-radius: 6px; padding: .45rem .9rem; cursor: pointer; }
.segmented label:has(input:checked) { border-color: var(--accent); background: #fdf0f1; font-weight: 600; }
.option-row { display: flex; align-items: center; gap: .6rem; margin-bottom: .45rem; }
.option-row label { margin: 0; white-space: nowrap; font-size: .85rem; }
.option-row input[name=opt_text] { margin: 0; }
.img-thumb { display: inline-flex; flex-direction: column; align-items: center; gap: .2rem; margin: 0; font-size: .85rem; }
.img-thumb img { max-height: 120px; }
.images-edit { margin-top: .4rem; }

/* Deckblatt-Editor */
.logo-preview { display: block; max-height: 70px; margin: .3rem 0; }
.logo-edit { margin-bottom: .8rem; }
.logo-pos { margin-bottom: .8rem; }
.cover-kind { margin-bottom: .8rem; }
.cover-datei { margin-bottom: .8rem; }
.cover-thumbs { display: flex; flex-wrap: wrap; gap: .6rem; margin: .4rem 0 .6rem; }
.cover-thumbs img { height: 160px; border: 1px solid var(--line); box-shadow: 0 1px 4px rgba(0,0,0,.12); background: #fff; }
.logo-mini { max-height: 28px; }
.rte { border: 1px solid #c4ccd4; border-radius: 6px; background: #fff; margin: .4rem 0; }
.rte-toolbar { display: flex; flex-wrap: wrap; gap: .25rem; padding: .4rem; border-bottom: 1px solid var(--line); background: #f8f9fb; border-radius: 6px 6px 0 0; position: sticky; top: 56px; z-index: 2; }
.rte-toolbar button { font: inherit; font-size: .85rem; border: 1px solid transparent; background: none; padding: .2rem .5rem; border-radius: 4px; cursor: pointer; }
.rte-toolbar button:hover, .rte-toolbar button.active { background: #fff; border-color: var(--line); }
.rte-toolbar select { width: auto; margin: 0; padding: .15rem .3rem; font-size: .85rem; }
.rte-toolbar .sep { width: 1px; background: var(--line); margin: 0 .2rem; }
.rte-area { min-height: 320px; padding: 1rem 1.4rem; outline: none; }
.rte-source { width: 100%; min-height: 320px; border: 0; font-family: Consolas, monospace; font-size: .85rem; margin: 0; border-radius: 0 0 6px 6px; }

/* Gemeinsame Formatierung des Deckblatt-Inhalts (Editor + Druck) */
.deckblatt-inhalt h2 { font-size: 1.15rem; margin: 1.2rem 0 .5rem; }
.deckblatt-inhalt table.deck-tabelle { width: 100%; border-collapse: collapse; margin: .6rem 0 1rem; }
.deckblatt-inhalt table.deck-tabelle td { border: 1px solid #8a949e; padding: .55rem .7rem; height: 2.4rem; }
.deckblatt-inhalt table.deck-tabelle td:first-child { width: 35%; background: #f4f6f8; font-weight: 600; }
.deckblatt-inhalt .schreiblinie { border-bottom: 1px solid #333; height: 2rem; margin: .4rem 0; }

details.card > summary { cursor: pointer; }
details.card[open] > summary { margin-bottom: 1rem; }
.danger-zone { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }

@media (max-width: 800px) {
  .question-form { grid-template-columns: 1fr; }
  .form-side { position: static; max-height: none; }
  .topbar { gap: 1rem; padding: 0 1rem; }
  .brand span, .usermenu small { display: none; }
  .topbar { height: auto; min-height: 56px; flex-wrap: wrap; padding-top: .4rem; padding-bottom: .4rem; }
  .list th, .list td { padding: .45rem .5rem; }
}
