:root {
  --bg: #f3f5f7;
  --panel: #fff;
  --line: #dde3e8;
  --ink: #1d2329;
  --muted: #66727d;
  --primary: #0b5cad;
  --primary-dark: #094c90;
  --danger: #c62828;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 4px 16px rgba(16, 24, 32, .05);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; display: flex; flex-direction: column; background: var(--bg); color: var(--ink); font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; }
[hidden] { display: none !important; }

/* ---------- Kopfzeile ---------- */
.topbar { flex: none; display: flex; align-items: center; gap: 24px; height: 52px; padding: 0 20px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 24px; height: 24px; border-radius: 6px; background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9 9h14M9 16h14M9 23h9' stroke='white' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E") center / 100%; }
.topnav { display: flex; gap: 4px; }
.topnav a { padding: 6px 12px; border-radius: 6px; color: var(--muted); font-weight: 500; text-decoration: none; }
.topnav a.on, .topnav a:hover { background: #eef2f6; color: var(--ink); }
#app { flex: 1; min-height: 0; overflow: auto; }
body.is-editor #app { overflow: hidden; }

/* ---------- Grundelemente ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 28px 20px 60px; }
.page-narrow { max-width: 760px; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; font: inherit; font-weight: 600; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 7px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #f7f9fa; border-color: #c3ccd4; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #a32020; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost-danger { color: var(--danger); }
.btn-small { padding: 4px 10px; font-size: 13px; }
.icon-btn { display: inline-grid; place-items: center; width: 30px; height: 30px; padding: 0; font-size: 14px; color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: 6px; cursor: pointer; }
.icon-btn:hover:not(:disabled) { background: #eef2f6; color: var(--ink); }
.icon-btn:disabled { opacity: .3; cursor: default; }

.input { width: 100%; padding: 8px 10px; font: inherit; color: inherit; background: #fff; border: 1px solid var(--line); border-radius: 7px; }
.input:focus { outline: 2px solid color-mix(in srgb, var(--primary) 30%, transparent); border-color: var(--primary); }
textarea.input { resize: vertical; field-sizing: content; min-height: 2.7em; }
select.input { padding-right: 4px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field-label { font-size: 12px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); }
.card { margin-bottom: 16px; padding: 18px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-title { margin: 0 0 4px; font-size: 16px; }
.card-hint { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.span-2 { grid-column: span 2; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.color { width: 44px; height: 36px; padding: 2px; background: #fff; border: 1px solid var(--line); border-radius: 7px; }
.logo-box { display: flex; align-items: center; gap: 10px; }
.logo-box img { max-width: 200px; max-height: 48px; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }

/* ---------- Übersicht ---------- */
.search { max-width: 360px; margin-bottom: 16px; }
.m-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.m-card { display: flex; flex-direction: column; overflow: hidden; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.m-thumb { display: grid; place-items: center; aspect-ratio: 16 / 10; overflow: hidden; background: #e9edf1; color: var(--muted); text-decoration: none; }
.m-thumb img { width: 100%; height: 100%; object-fit: cover; }
.m-info { flex: 1; padding: 12px 14px 6px; }
.m-title { font-size: 15px; font-weight: 700; color: var(--ink); text-decoration: none; }
.m-title:hover { color: var(--primary); }
.m-sub { font-size: 13px; color: var(--muted); }
.m-meta { margin-top: 6px; font-size: 12px; color: var(--muted); }
.m-actions { display: flex; gap: 6px; padding: 8px 14px 14px; }
.m-actions .btn-ghost-danger { margin-left: auto; }
.empty { grid-column: 1 / -1; padding: 24px 0; text-align: center; }
.empty h2 { font-size: 18px; }
.start-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-top: 16px; text-align: left; }
.start-tile { display: flex; flex-direction: column; gap: 6px; padding: 20px; font: inherit; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); cursor: pointer; }
.start-tile strong { font-size: 16px; }
.start-tile span { color: var(--muted); }
.start-tile:hover { border-color: var(--primary); }

/* ---------- Editor ---------- */
.editor { display: flex; flex-direction: column; height: 100%; }
.ed-bar { flex: none; display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.ed-title { min-width: 0; overflow: hidden; font-weight: 700; white-space: nowrap; text-overflow: ellipsis; }
.save-status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-status[data-state="saved"]::before { content: "✓ "; color: #2e7d32; }
.save-status[data-state="error"] { color: var(--danger); }
.ed-bar-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.ed-main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(440px, 1fr) minmax(0, 1fr); }
.ed-form { overflow: auto; padding: 18px 20px 80px; }
.ed-preview { overflow: auto; padding: 20px; background: #e3e8ed; border-left: 1px solid var(--line); }
.paper { width: fit-content; margin: 0 auto; }
.btn-preview-toggle { display: none; }
@media (max-width: 1100px) {
  .ed-main { grid-template-columns: minmax(0, 1fr); }
  .ed-preview { display: none; border-left: 0; }
  .editor.show-preview .ed-form { display: none; }
  .editor.show-preview .ed-preview { display: block; }
  .btn-preview-toggle { display: inline-flex; }
}
@media (max-width: 700px) {
  .ed-bar { flex-wrap: wrap; }
  .grid-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .ed-form { padding: 12px 10px 60px; }
}

.step-card { margin-bottom: 14px; padding: 12px; background: #fbfcfd; border: 1px solid var(--line); border-radius: 9px; }
.step-card-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.step-badge { flex: none; display: grid; place-items: center; width: 30px; height: 30px; font-weight: 700; color: #fff; background: var(--primary); border-radius: 50%; }
.step-title { font-weight: 600; }
.sub-row { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 8px; padding: 8px 4px 8px 0; border: 1px dashed transparent; border-radius: 8px; }
.sub-row:hover, .sub-row:focus-within { background: #fff; border-color: var(--line); }
.sub-row.drop { background: #eef5fd; border-color: var(--primary); }
.sub-letter { padding-top: 8px; font-weight: 700; color: var(--primary); text-align: right; }
.row-actions { display: flex; flex-direction: column; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumb { position: relative; width: 132px; }
.thumb-img { display: block; width: 100%; padding: 0; overflow: hidden; background: #eee; border: 1px solid var(--line); border-radius: 6px; cursor: crosshair; }
.thumb-img:hover { border-color: var(--primary); }
.thumb-badge { position: absolute; top: 4px; left: 4px; padding: 1px 6px; font-size: 11px; color: #fff; background: rgba(0, 0, 0, .65); border-radius: 10px; pointer-events: none; }
.thumb-actions { position: absolute; top: 4px; right: 4px; display: none; background: rgba(255, 255, 255, .96); border-radius: 6px; box-shadow: 0 1px 4px rgba(0, 0, 0, .2); }
.thumb:hover .thumb-actions, .thumb:focus-within .thumb-actions { display: flex; }
.thumb-actions .icon-btn { width: 24px; height: 24px; font-size: 12px; }
.thumb-add { width: 132px; min-height: 88px; font: inherit; font-weight: 600; color: var(--muted); background: transparent; border: 1.5px dashed #b9c3cc; border-radius: 6px; cursor: pointer; }
.thumb-add:hover { color: var(--primary); border-color: var(--primary); }
.thumb-add-sm { width: auto; min-height: 0; padding: 3px 12px; font-size: 13px; }
.add-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.notes-edit .add-row { margin: 0 0 6px; }
.add-step { justify-content: center; width: 100%; padding: 12px; border-style: dashed; }

.chip { padding: 2px 10px; font: inherit; font-size: 12px; font-weight: 600; color: var(--nc); background: #fff; border: 1px solid color-mix(in srgb, var(--nc) 35%, #fff); border-radius: 999px; cursor: pointer; }
.chip:hover { background: var(--nb); }
.chip-warning, .note-row-warning { --nc: #c62828; --nb: #fdecea; }
.chip-caution, .note-row-caution { --nc: #c77700; --nb: #fff5db; }
.chip-info, .note-row-info { --nc: #1565c0; --nb: #e8f1fb; }
.chip-tip, .note-row-tip { --nc: #2e7d32; --nb: #eaf5eb; }
.note-row { display: grid; grid-template-columns: 112px minmax(0, 1fr) auto; gap: 8px; align-items: start; margin-bottom: 8px; padding: 8px; background: var(--nb); border-left: 4px solid var(--nc); border-radius: 6px; }

/* ---------- Dialoge, Meldungen, Ladeanzeige ---------- */
dialog.modal { width: min(580px, calc(100vw - 32px)); padding: 22px 24px; border: 0; border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
dialog.modal::backdrop { background: rgba(15, 22, 30, .45); }
.modal h2 { margin: 0 0 10px; font-size: 18px; }
.modal-body p { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.notes-input { min-height: 240px; }

#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; max-width: min(460px, calc(100vw - 40px)); }
.toast { display: flex; align-items: center; gap: 12px; padding: 10px 14px; color: #fff; background: #1d2329; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); animation: toast-in .2s ease-out; }
.toast-error { background: #b3261e; }
.toast-success { background: #1e6b34; }
.toast .btn { color: #fff; background: rgba(255, 255, 255, .16); border-color: transparent; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.busy { position: fixed; inset: 0; z-index: 900; display: grid; place-items: center; background: rgba(15, 22, 30, .35); }
.busy-box { display: flex; flex-direction: column; align-items: center; gap: 12px; max-width: 360px; padding: 24px 28px; text-align: center; background: #fff; border-radius: 12px; }
.busy-box p { margin: 0; }
.spinner { width: 34px; height: 34px; border: 3px solid #dbe4ec; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Bildeditor ---------- */
.anno-modal { position: fixed; inset: 0; z-index: 800; display: flex; flex-direction: column; color: #fff; background: #14191e; }
.anno-bar, .anno-foot { flex: none; display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; padding: 10px 14px; background: #1e252c; }
.anno-bar { border-bottom: 1px solid #2c353e; }
.anno-foot { border-top: 1px solid #2c353e; }
.anno-foot .input { flex: 1; min-width: 200px; color: #fff; background: #263039; border-color: #39444f; }
.anno-group { display: flex; gap: 4px; align-items: center; }
.tool { padding: 6px 11px; font: inherit; font-size: 13px; font-weight: 600; color: #dde5ec; background: #263039; border: 1px solid #39444f; border-radius: 6px; cursor: pointer; }
.tool:hover { background: #2e3943; }
.tool.on { color: #fff; background: var(--primary); border-color: #3d8be0; }
.tool-sm { width: 32px; padding: 6px 0; }
.swatch { width: 26px; height: 26px; padding: 0; background: var(--c); border: 2px solid #39444f; border-radius: 50%; cursor: pointer; }
.swatch.on { outline: 2px solid #fff; outline-offset: 2px; }
.anno-canvas { flex: 1; min-height: 0; display: grid; place-items: center; padding: 16px; overflow: hidden; }
.anno-stage { position: relative; }
.anno-stage img { display: block; width: 100%; height: 100%; user-select: none; pointer-events: none; }
svg.anno-edit { cursor: crosshair; touch-action: none; }
svg.anno-edit[data-tool="erase"] { cursor: pointer; }
svg.anno-edit[data-tool="erase"] g:hover { opacity: .45; }
.anno-text-input { position: absolute; z-index: 2; min-width: 180px; padding: 4px 8px; font: 600 16px/1.2 "Segoe UI", Arial, sans-serif; border: 2px solid var(--primary); border-radius: 4px; transform: translateY(-50%); }

/* ---------- Vorlagen ---------- */
.page-sub { margin: 4px 0 0; }
.badge { display: inline-block; margin-left: 8px; padding: 1px 8px; font-size: 11px; font-weight: 600; vertical-align: 2px; color: var(--primary); background: #e8f1fb; border-radius: 999px; }
.t-thumb { display: grid; place-items: center; aspect-ratio: 16 / 7; padding: 18px; color: #fff; font-weight: 700; text-decoration: none; background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 70%, #000)); }
.t-thumb img { max-width: 70%; max-height: 100%; object-fit: contain; padding: 8px 12px; background: #fff; border-radius: 6px; }
.tpl-row .input { flex: 1; }
.choice-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.choice { display: flex; flex-direction: column; gap: 2px; padding: 10px; font: inherit; text-align: left; background: #fff; border: 1.5px solid var(--line); border-radius: 8px; cursor: pointer; }
.choice:hover { border-color: #b9c3cc; }
.choice.on { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 25%, transparent); }
.choice small { color: var(--muted); font-size: 12px; }
/* Mini-Skizzen der Titelseiten-Stile */
.choice-mini { position: relative; display: block; height: 64px; margin-bottom: 6px; background: #f4f6f8; border: 1px solid var(--line); border-radius: 4px; }
.choice-mini i, .choice-mini b, .choice-mini em { position: absolute; display: block; }
.mini-classic i { left: 10%; top: 40%; width: 55%; height: 8px; background: #8a96a1; }
.mini-classic b { left: 10%; top: 56%; width: 70%; height: 3px; background: var(--c); }
.mini-band i { left: 0; right: 0; top: 32%; height: 34%; background: var(--c); }
.mini-band b { left: 10%; top: 42%; width: 50%; height: 7px; background: #fff; }
.mini-minimal i { left: 35%; top: 14%; width: 30%; height: 14px; background: #b9c3cc; border-radius: 2px; }
.mini-minimal b { left: 22%; top: 48%; width: 56%; height: 7px; background: #8a96a1; }
.mini-minimal em { left: 42%; top: 64%; width: 16%; height: 3px; background: var(--c); }
.mini-full { background: var(--c); border-color: var(--c); }
.mini-full i { left: 10%; top: 14%; width: 30%; height: 5px; background: rgba(255, 255, 255, .8); }
.mini-full b { left: 10%; top: 46%; width: 62%; height: 9px; background: #fff; }
.mini-full em { left: 10%; top: 64%; width: 40%; height: 4px; background: rgba(255, 255, 255, .55); }
@media (max-width: 1300px) { .choice-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.switch { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-weight: 600; cursor: pointer; }
.switch input { width: 18px; height: 18px; }
@media (max-width: 700px) { .choice-row { grid-template-columns: 1fr; } }
.view { height: 100%; }

/* ---------- Tool-Portal ---------- */
.portal-link { flex: none; width: 30px; height: 30px; margin-right: -12px; border-radius: 7px; background: center / 18px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='%2366727d'%3E%3Crect x='3' y='3' width='8' height='8' rx='2'/%3E%3Crect x='13' y='3' width='8' height='8' rx='2'/%3E%3Crect x='3' y='13' width='8' height='8' rx='2'/%3E%3Crect x='13' y='13' width='8' height='8' rx='2'/%3E%3C/g%3E%3C/svg%3E"); }
.portal-link:hover { background-color: #eef2f6; }
.brand-mark-portal { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cg fill='white'%3E%3Crect x='8' y='8' width='7' height='7' rx='1.5'/%3E%3Crect x='17' y='8' width='7' height='7' rx='1.5'/%3E%3Crect x='8' y='17' width='7' height='7' rx='1.5'/%3E%3Crect x='17' y='17' width='7' height='7' rx='1.5' opacity='.6'/%3E%3C/g%3E%3C/svg%3E"); }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.tool-card { position: relative; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; padding: 20px; color: var(--ink); text-decoration: none; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
a.tool-card:hover { border-color: var(--c); box-shadow: 0 0 0 1px var(--c), var(--shadow); }
.tool-icon { display: grid; place-items: center; width: 48px; height: 48px; color: #fff; background: var(--c); border-radius: 12px; }
.tool-icon svg { width: 28px; height: 28px; }
.tool-icon img { max-width: 32px; max-height: 32px; }
.tool-icon-letter { font-size: 22px; font-weight: 700; }
.tool-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tool-name { font-size: 16px; font-weight: 700; }
.tool-desc { color: var(--muted); }
.tool-open { grid-column: 2; margin-top: 6px; font-weight: 600; color: var(--c); }
.tool-card.is-planned { opacity: .6; }
.tool-card.is-planned .tool-icon { background: #9aa6b1; }

/* ---------- Anmeldung & Benutzer ---------- */
.topbar-user { display: flex; align-items: center; gap: 10px; margin-left: auto; font-size: 13px; }
.auth-wrap { display: grid; place-items: center; min-height: 100%; padding: 32px 16px; }
.auth-card { width: min(440px, 100%); margin: 0; padding: 26px 28px; }
.auth-title { margin: 0 0 6px; font-size: 20px; }
.auth-submit { justify-content: center; width: 100%; padding: 10px; }
.auth-foot { margin: 14px 0 0; font-size: 13px; text-align: center; }
.success-note { margin: 0; font-weight: 600; color: #1e6b34; }
.twofa-steps { margin: 0; padding-left: 20px; color: var(--muted); }
.twofa-qr { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.qr { flex: none; width: 168px; height: 168px; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.qr svg { display: block; width: 100%; height: 100%; }
.twofa-secret { display: block; padding: 6px 8px; font-size: 13px; letter-spacing: .04em; word-break: break-all; background: #f3f5f7; border-radius: 6px; }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; margin: 0; padding: 12px 16px; font: 600 14px/1.4 ui-monospace, Consolas, monospace; list-style: none; background: #f3f5f7; border-radius: 8px; }
.otp-box { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #f3f5f7; border-radius: 8px; }
.otp-box code { flex: 1; font: 700 18px/1.3 ui-monospace, Consolas, monospace; letter-spacing: .06em; }
.badge-ok { color: #1e6b34; background: #eaf5eb; }
.badge-warn { color: #8a5300; background: #fff5db; }
.badge-off { color: var(--muted); background: #eceff1; }
.admin-table-wrap { padding: 0; overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.admin-table th { font-size: 11px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table .badge { margin-left: 0; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
