:root {
    --color-bg:           #f5f5f5;
    --color-surface:      #ffffff;
    --color-border:       #dde1e7;
    --color-filter-bar:    #eeeeee;
    --color-text:         #1a1a2e;
    --color-text-muted:   #5a6270;
    --color-primary:      #2563eb;
    --color-primary-hover:#1d4ed8;
    --color-text-danger: #4B1818;
    --footer-height:      28px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
}

h1, h2, h3, h4 {
    margin: 0 0 1rem;
    line-height: 1.2;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    padding: 0 1.25rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
    color: var(--color-text);
    text-decoration: none;
}

.topbar-brand-icon {
    width: 22px;
    height: 22px;
    display: block;
}

.topbar-brand:hover {
    text-decoration: none;
    color: var(--color-text);
}

.topbar-user {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-profile,
.topbar-logout {
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.topbar-admin {
    color: var(--color-text-danger);
    font-size: 0.875rem;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
    margin-left: 1.25rem;
}

.topbar-nav-link {
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    text-decoration: none;
}

.topbar-nav-link:hover {
    background: var(--color-bg);
    color: var(--color-text);
    text-decoration: none;
}

.topbar-nav-link.active {
    background: #e8effc;
    color: var(--color-primary);
    font-weight: 500;
}

/* ── Hilfe: «?»-Button, Panel rechts, Artikel-Typografie (auch ?page=help) ── */

.topbar-help {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
}

.topbar-help:hover,
.topbar-help.active {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: #e8effc;
}

.help-panel {
    position: fixed;
    top: 48px;
    right: 0;
    bottom: 0;
    width: 420px;
    max-width: 100vw;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
    z-index: 90;
}

.help-panel[hidden] {
    display: none;
}

.help-panel-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
}

.help-panel-title {
    font-weight: 600;
    flex: 1;
}

.help-panel-open {
    font-size: 0.8rem;
}

.help-panel-close {
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--color-text-muted);
    cursor: pointer;
}

.help-panel-toc {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
}

.help-panel-toc a {
    font-size: 0.78rem;
    padding: 0.2rem 0.55rem;
    border-radius: 12px;
    color: var(--color-text-muted);
    text-decoration: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
}

.help-panel-toc a.active {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.help-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem 2rem;
}

.help-article {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--color-text);
}

.help-article h1 {
    font-size: 1.35rem;
    margin: 0 0 0.75rem;
}

.help-article h2 {
    font-size: 1.05rem;
    margin: 1.6rem 0 0.5rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--color-border);
}

.help-article h3 {
    font-size: 0.95rem;
    margin: 1.1rem 0 0.35rem;
}

.help-article p,
.help-article ul,
.help-article ol {
    margin: 0 0 0.75rem;
}

.help-article ul,
.help-article ol {
    padding-left: 1.3rem;
}

.help-article li {
    margin-bottom: 0.3rem;
}

.help-article .help-lead {
    font-size: 0.95rem;
    color: var(--color-text-muted);
}

.help-article .help-tip {
    padding: 0.6rem 0.85rem;
    margin: 0 0 0.75rem;
    border-left: 3px solid var(--color-primary);
    background: #e8effc;
    border-radius: 0 4px 4px 0;
}

.help-article kbd {
    font-family: inherit;
    font-size: 0.8em;
    padding: 0.05rem 0.35rem;
    border: 1px solid var(--color-border);
    border-bottom-width: 2px;
    border-radius: 3px;
    background: var(--color-surface);
}

.help-article .ui {
    font-weight: 600;
    white-space: nowrap;
}

/* ── Richtext editor (shared) ────────────────────────────────────────────── */

.richtext-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: initial;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.partial-points-warning {
    color: #c0392b;
    font-weight: 600;
}

.richtext-wrap {
    border: 1px solid var(--color-border);
    border-radius: 4px;
    overflow: hidden;
}

.richtext-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 4px 6px;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}

.rtb-btn {
    background: none;
    border: 1px solid transparent;
    border-radius: 3px;
    padding: 2px 7px;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--color-text);
    line-height: 1.5;
}

.rtb-btn:hover { background: var(--color-border); }
.rtb-btn:active { background: var(--color-primary); color: #fff; }

.rtb-fontsize-select {
    height: 26px;
    border: 1px solid var(--color-border);
    border-radius: 3px;
    background: #fff;
    font-size: 0.75rem;
    padding: 0 2px;
    cursor: pointer;
    color: inherit;
}

.rtb-reset-btn {
    margin-left: auto;
    background: var(--color-text-muted, #666);
    color: #fff;
    border-color: transparent;
    padding: 2px 9px;
}
.rtb-reset-btn:hover { background: var(--color-text, #333); }

.rtb-sep {
    display: inline-block;
    width: 1px;
    background: var(--color-border);
    margin: 3px 3px;
}

.richtext-editor {
    min-height: 80px;
    padding: 0.6rem 0.75rem;
    line-height: 1.6;
    outline: none;
    background: #fff;
}

.richtext-editor:focus {
    box-shadow: inset 0 0 0 2px var(--color-primary);
}

.richtext-editor h2 { font-size: 1.1rem; font-weight: 600; margin: 0.25rem 0 0.5rem; }
.richtext-editor p  { margin: 0 0 0.5rem; }
.richtext-editor ul { margin: 0 0 0.5rem 1.25rem; padding: 0; }
.richtext-editor code { background: #f3f4f6; border-radius: 3px; padding: 1px 4px; font-family: monospace; font-size: 0.85em; }
.richtext-editor pre  { background: #f3f4f6; border-radius: 4px; padding: 0.6rem 0.75rem; font-family: monospace; font-size: 0.85em; white-space: pre-wrap; margin: 0 0 0.5rem; }
.richtext-editor pre code { background: none; padding: 0; border-radius: 0; font-size: inherit; }
.question-text pre { white-space: pre; }
.richtext-editor img { max-width: 100%; height: auto; cursor: pointer; outline: 2px solid transparent; transition: outline 0.1s; }
.richtext-editor img:hover { outline: 2px solid #aac; }
.richtext-editor img.img-selected { outline: 2px solid var(--color-primary); }
.richtext-editor .tc-box {
    border: 1px solid currentColor;
    padding: 0.5rem 0.75rem;
    margin: 0.5rem 0;
    border-radius: 3px;
}

.img-size-popup {
    position: fixed;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 10px 14px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.18);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
    min-width: 190px;
}
.img-size-popup label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.img-size-popup label span { white-space: nowrap; }
.img-size-popup .img-size-fields { display: flex; align-items: center; gap: 4px; }
.img-size-popup input[type=number] { width: 64px; padding: 2px 4px; border: 1px solid #ccc; border-radius: 3px; }
.img-size-popup .img-size-unit { color: #666; }
.img-size-popup .img-size-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 2px; }
.img-size-popup .img-file-actions { display: flex; align-items: center; gap: 10px; padding-top: 6px; border-top: 1px solid #eee; }
.img-size-popup .img-file-feedback { color: #2e7d32; }
.img-size-popup .img-file-feedback--error { color: #c0392b; }

/* Textknopf (z.B. «Alle»/«Keine», «Bild speichern») */
.btn-link {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.8rem;
    color: var(--color-primary);
    cursor: pointer;
}

.btn-link:hover {
    text-decoration: underline;
}

@media print {
    .richtext-editor img { max-width: none; }
}

.app-footer {
    height: var(--footer-height);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 1.5rem;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* ── Dialog «Block hinzufügen» (partials/blocktypedialog.php) ─────────────── */

.blocktype-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
}

.blocktype-overlay[hidden] {
    display: none;
}

.blocktype-modal {
    width: 600px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    box-sizing: border-box;
    padding: 1.5rem;
    border-radius: 8px;
    background: var(--color-surface);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.blocktype-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.blocktype-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.blocktype-close {
    border: none;
    background: none;
    padding: 0.25rem;
    font-size: 1rem;
    color: var(--color-text-muted);
    cursor: pointer;
}

.blocktype-close:hover {
    color: var(--color-text);
}

.blocktype-hint {
    margin: 0.25rem 0 0;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.blocktype-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.6rem;
    margin-top: 1rem;
}

.blocktype-card {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.blocktype-card:hover,
.blocktype-card:focus-visible {
    border-color: var(--color-primary);
    background: var(--color-bg);
    outline: none;
}

.blocktype-glyph {
    flex: 0 0 2.25rem;
    height: 2.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: #e8effd;
    color: var(--color-primary);
    font-size: 0.95rem;
    font-weight: 600;
}

.blocktype-text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.blocktype-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
}

.blocktype-desc {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    line-height: 1.35;
}

/* ── «+» zwischen den Blöcken (core/blocktypedialog.js) ──────────────────── */
/* Füllt mit negativem Rand genau den Abstand zwischen zwei Blöcken (Flex-Gap 1rem der Liste) */
.block-insert {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 1.5rem;
    margin: -1rem 0;
}

.block-insert::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    border-top: 2px solid var(--color-primary);
    opacity: 0;
    transition: opacity 0.15s;
}

.block-insert-btn {
    position: relative;
    width: 1.4rem;
    height: 1.4rem;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: 50%;
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.45;
    transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}

.block-insert:hover::before {
    opacity: 0.35;
}

.block-insert:hover .block-insert-btn,
.block-insert-btn:focus-visible {
    opacity: 1;
    color: var(--color-primary);
    border-color: var(--color-primary);
    outline: none;
}

/* Ohne Maus (iPad): etwas deutlicher, damit der Knopf auffindbar bleibt */
@media (hover: none) {
    .block-insert-btn {
        opacity: 0.7;
    }
}

/* ── Dialog «HTML bearbeiten» (core/wysiwyg.js) ──────────────────────────── */

.rtb-html {
    font-family: monospace;
    font-size: 0.8rem;
}

.wysiwyg-html-overlay {
    position: fixed;
    inset: 0;
    z-index: 110;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
}

.wysiwyg-html-overlay[hidden] {
    display: none;
}

.wysiwyg-html-modal {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 720px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 32px);
    box-sizing: border-box;
    padding: 1.5rem;
    border-radius: 8px;
    background: var(--color-surface);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.wysiwyg-html-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.wysiwyg-html-text {
    width: 100%;
    min-height: 280px;
    flex: 1;
    box-sizing: border-box;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.85rem;
    line-height: 1.45;
    resize: vertical;
}

.wysiwyg-html-text:focus {
    outline: none;
    border-color: var(--color-primary);
}

.wysiwyg-html-hint {
    margin: 0;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.wysiwyg-html-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}
