:root {
    --red: #e20917;
    --ink: #1d1d1f;
    --muted: #5f6673;
    --line: #e5e7eb;
    --bg: #f5f6f7;
    --card: #ffffff;
}

* { box-sizing: border-box; }
/* hidden-Attribut muss auch display:inline-flex-Elemente (z. B. .btn-link) verbergen */
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    border-bottom: 1px solid var(--line);
    padding: 14px 24px;
}
.brand { font-weight: 700; color: var(--red); letter-spacing: .2px; }
.brand span { color: var(--ink); font-weight: 600; }
.topbar nav a { margin-left: 18px; text-decoration: none; color: var(--ink); font-size: 14px; }
.topbar nav a:hover { color: var(--red); }
.topbar nav a.muted { color: var(--muted); }

.container { max-width: 860px; margin: 28px auto; padding: 0 20px; }

h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px 22px;
    margin: 18px 0;
}
.card.narrow { max-width: 380px; margin: 48px auto; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

.muted { color: var(--muted); }
.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; }
.small { font-size: 13px; }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }

.form { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.form input {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 15px;
    font-weight: 400;
}
.form input:focus { outline: 2px solid rgba(226,9,23,.25); border-color: var(--red); }
.pw-field { position: relative; display: block; }
.pw-field input { width: 100%; box-sizing: border-box; padding-right: 44px; }
.pw-toggle {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    background: none; color: var(--muted); border: 0; padding: 6px; border-radius: 6px; cursor: pointer;
}
.pw-toggle:hover { background: none; color: var(--ink); }
.pw-toggle:focus-visible { outline: 2px solid var(--red); outline-offset: 1px; }

button {
    background: var(--red);
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: 11px 16px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
button:hover { background: #c40510; }

.alert { padding: 10px 12px; border-radius: 8px; font-size: 14px; margin: 0 0 6px; }
.alert.error { background: #fde8ea; color: #b3121f; }

table.list { width: 100%; border-collapse: collapse; margin-top: 6px; }
table.list th, table.list td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
table.list th { color: var(--muted); font-weight: 600; }

dl.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 6px 0 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }

/* Formular-Reihen */
.row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.row > label { flex: 1 1 180px; }

.page-head { display: flex; align-items: center; justify-content: space-between; }

.btn-link {
    display: inline-block; text-decoration: none; background: var(--red); color: #fff;
    padding: 9px 14px; border-radius: 8px; font-size: 14px; font-weight: 600;
}
.btn-link:hover { background: #c40510; }
.card-head a:not(.btn-link) { font-size: 14px; text-decoration: none; color: var(--red); }

.check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 400 !important; }
.form input[type=checkbox] { width: auto; padding: 0; border: 0; }
.form input[type=file] { font-size: 13px; padding: 7px 0; border: 0; }

table.list td.actions { white-space: nowrap; }
table.list td.actions a { margin-right: 0; }
table.list td.actions form { display: inline; margin: 0; }
.link-danger { display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; color: var(--red); cursor: pointer; font-size: 14px; padding: 5px 9px; font-weight: 600; border-radius: 6px; }
.link-danger:hover { background: #fdeaec; color: #c40510; }
.link-danger .icon { vertical-align: 0; }

.alert.success { background: #e6f4ea; color: #127a2b; }

/* ===== UI-Überarbeitung ===== */
html { height: 100%; }
body { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { flex: 0 0 auto; flex-wrap: wrap; gap: 10px; }
.foot { flex: 0 0 auto; }
.container { flex: 1 0 auto; width: 100%; max-width: 860px; align-self: center; margin: 28px 0; padding: 0 20px; box-sizing: border-box; }

/* Marke mit Logo statt "SWV" */
.topbar .brand { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); font-weight: 600; }
.topbar .brand .brand-logo { height: 26px; width: auto; display: block; }
.topbar .brand span { color: var(--ink); font-weight: 600; }

/* Hauptmenü mit Icons */
.mainnav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.topbar .mainnav a {
    display: inline-flex; align-items: center; gap: 7px; margin: 0;
    text-decoration: none; color: var(--muted);
    padding: 7px 12px; border-radius: 8px; font-size: 14px; font-weight: 500;
}
.topbar .mainnav a:hover { background: #f3f4f6; color: var(--ink); }
.topbar .mainnav a.active { background: #fdeaec; color: var(--red); font-weight: 600; }
.topbar .mainnav a.muted:hover { color: var(--red); background: #fdeaec; }

.icon { vertical-align: -3px; flex: 0 0 auto; }

/* Buttons mit Icon */
button { display: inline-flex; align-items: center; gap: 7px; }
.btn-link { display: inline-flex; align-items: center; gap: 7px; }
.btn-ghost {
    display: inline-flex; align-items: center; gap: 6px;
    text-decoration: none; color: var(--muted);
    padding: 11px 14px; border-radius: 8px; font-size: 15px; font-weight: 600;
}
.btn-ghost:hover { color: var(--ink); }

/* Sekundär-Button mit Umriss (klar klickbar, aber nicht rot) */
.btn-outline {
    display: inline-flex; align-items: center; gap: 7px;
    background: #fff; color: var(--ink); border: 1px solid var(--line);
    padding: 10px 15px; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-outline:hover { border-color: #cbd0d6; background: #f9fafb; }

/* Icon-Buttons (Tabellen-Aktionen) */
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; padding: 0; border-radius: 8px;
    border: 1px solid var(--line); background: #fff; color: var(--muted); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { color: var(--ink); border-color: #cbd0d6; background: #f9fafb; }
.icon-btn.danger:hover { color: var(--red); border-color: #f1c7c9; background: #fff5f5; }
table.list td.actions { white-space: nowrap; text-align: right; }
table.list td.actions .icon-btn { vertical-align: middle; }
table.list td.actions form { display: inline-block; margin: 0 0 0 6px; vertical-align: middle; }

.icon-link { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; text-decoration: none; color: var(--red); }
.icon-link:hover { text-decoration: underline; }

/* Bild-Vorschau */
.thumb { display: inline-block; margin: 6px 0; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.thumb img { display: block; max-height: 60px; max-width: 220px; width: auto; }
.thumb.thumb-sm { padding: 3px; }
.thumb.thumb-sm img { max-height: 28px; max-width: 120px; }

/* Dashboard-Raster */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 .card { margin: 0; }
@media (max-width: 680px) { .grid-2 { grid-template-columns: 1fr; } }

ul.plain { list-style: none; padding: 0; margin: 6px 0 0; }
ul.plain li { padding: 4px 0; font-size: 14px; }

/* Aussendung / Editor */
.form select {
    padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
    font-size: 15px; background: #fff; font-weight: 400;
}
.form select:focus { outline: 2px solid rgba(226,9,23,.25); border-color: var(--red); }
.field-label { display: block; font-weight: 600; font-size: 14px; margin: 16px 0 6px; }

/* Gleichmäßiger Abstand zwischen Formularfeldern — Label gehört optisch zum Feld DARUNTER */
.form .card > label,
.form .card > .row { margin-top: 16px; }
.form .card > .card-head + label,
.form .card > .card-head + .row { margin-top: 0; }
.wysiwyg { background: #fff; min-height: 150px; }
.ql-toolbar.ql-snow { border-color: var(--line); border-top-left-radius: 8px; border-top-right-radius: 8px; }
.ql-container.ql-snow { border-color: var(--line); border-bottom-left-radius: 8px; border-bottom-right-radius: 8px; font-family: inherit; font-size: 14px; }
.ql-editor { min-height: 150px; }
.ql-editor p { margin: 0 0 10px !important; }
.src-toggle { display: inline-block; margin: 6px 0 0; padding: 4px 10px; font-size: 12px; border: 1px solid var(--line); background: #fff; color: var(--muted); border-radius: 6px; cursor: pointer; }
.src-toggle:hover { color: var(--ink); background: #f9fafb; }
.src-toggle.active { background: #fdeaec; color: var(--red); border-color: #f1c7c9; }
.html-source { width: 100%; min-height: 170px; margin-top: 4px; font-family: Consolas, "Courier New", monospace; font-size: 12px; line-height: 1.5; padding: 10px; border: 1px solid var(--line); border-radius: 8px; box-sizing: border-box; }
.placeholders dl.kv { grid-template-columns: 200px 1fr; }
.placeholders code { background: #f3f4f6; padding: 1px 6px; border-radius: 5px; font-size: 13px; }
table.list td a { color: var(--ink); text-decoration: none; }
table.list td a:hover { color: var(--red); text-decoration: underline; }

/* Import-Vorschau */
.stats { display: flex; flex-wrap: wrap; gap: 18px; font-size: 14px; margin-bottom: 10px; }
.stats .ok strong { color: #127a2b; }
.stats .bad strong { color: #c0202f; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge.ok { background: #e6f4ea; color: #127a2b; }
.badge.warn { background: #fff3e0; color: #9a5b00; }
.badge.bad { background: #fde8ea; color: #b3121f; }
tr.row-error td { background: #fdf3f4; }
tr.row-warn td { background: #fff9f0; }
td.msg { color: var(--muted); font-size: 13px; }
/* Einzelfall-Freigabe „trotzdem importieren“ (nur bei fehlender Adresse) */
.allow-check { display: inline-flex; align-items: center; gap: 4px; margin-top: 5px; font-size: 12px; font-weight: 600; color: var(--red); white-space: nowrap; cursor: pointer; }
.allow-check input { width: auto; margin: 0; }

/* Fortschritt (PDF-Erzeugung / Versand / Download) */
.head-actions { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.progress { background: #eef0f2; border-radius: 8px; height: 14px; overflow: hidden; margin: 12px 0; }
.progress-bar { background: #127a2b; height: 100%; width: 0; transition: width .25s ease; }
/* Bewegter Balken während ein Lauf aktiv ist (auch bei 0 % sichtbar) */
.progress.active {
    background-image: linear-gradient(45deg, rgba(0,0,0,.08) 25%, transparent 25%, transparent 50%, rgba(0,0,0,.08) 50%, rgba(0,0,0,.08) 75%, transparent 75%, transparent);
    background-size: 18px 18px;
    animation: progress-stripes .7s linear infinite;
}
@keyframes progress-stripes { from { background-position: 0 0; } to { background-position: 18px 0; } }
/* Deaktivierter Aktions-Button (z. B. „Download“, solange keine PDFs da sind) */
.btn-link.is-disabled { background: #e5e7eb; color: #9ca3af; cursor: default; pointer-events: none; }
.btn-link.is-disabled:hover { background: #e5e7eb; }

/* angemeldete:r Benutzer:in im Menü */
.topbar .who { font-size: 13px; color: var(--muted); padding: 7px 6px; }
/* einfache Textlinks (ohne Klasse) im Inhalt – nicht lila */
main.container a:not([class]) { color: var(--red); }
main.container a:not([class]):visited { color: var(--red); }
main.container a:not([class]):hover { text-decoration: underline; }

/* Lade-Spinner */
.spinner-overlay { position: fixed; inset: 0; background: rgba(255,255,255,.65); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.spinner-overlay[hidden] { display: none; }
.spinner-box { display: flex; flex-direction: column; align-items: center; gap: 14px; background: #fff; padding: 28px 34px; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.12); }
.spinner { width: 46px; height: 46px; border: 4px solid #e5e7eb; border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Topbar-Aktionen (Icons) + Hamburger ============ */
.nav-actions { display: inline-flex; align-items: center; gap: 2px; margin-left: auto; }
.nav-icon {
    background: none; border: 0; padding: 7px 9px; border-radius: 8px; cursor: pointer;
    color: var(--muted); display: inline-flex; align-items: center; text-decoration: none;
}
.nav-icon:hover { background: rgba(127, 127, 127, .15); color: var(--ink); }
#theme-toggle .i-moon, #theme-toggle .i-sun { display: inline-flex; }
#theme-toggle .i-sun { display: none; }
[data-theme="dark"] #theme-toggle .i-moon { display: none; }
[data-theme="dark"] #theme-toggle .i-sun { display: inline-flex; }
.nav-toggle { display: none; } /* Hamburger nur mobil */

/* Tabellen: eigener Scroll-Container mit gut greifbarer Leiste */
.table-scroll { overflow-x: auto; }
.table-scroll::-webkit-scrollbar { height: 10px; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb { background: #c4c8cf; border-radius: 5px; }
.table-scroll::-webkit-scrollbar-thumb:hover { background: #adb2bb; }

/* ============ Dark Mode ============ */
[data-theme="dark"] {
    --ink: #e7e8ea;
    --muted: #969aa3;
    --line: #313640;
    --bg: #15171b;
    --card: #1e2127;
}
[data-theme="dark"] .topbar { background: #1a1d22; }
[data-theme="dark"] .form input,
[data-theme="dark"] .form select,
[data-theme="dark"] .html-source { background: #14161a; color: var(--ink); border-color: var(--line); }
[data-theme="dark"] .btn-outline,
[data-theme="dark"] .icon-btn,
[data-theme="dark"] .thumb,
[data-theme="dark"] .spinner-box,
[data-theme="dark"] .src-toggle { background: var(--card); color: var(--ink); border-color: var(--line); }
[data-theme="dark"] .topbar .mainnav a:hover,
[data-theme="dark"] .icon-btn:hover,
[data-theme="dark"] .btn-outline:hover,
[data-theme="dark"] .src-toggle:hover { background: #2a2f38; color: var(--ink); }
[data-theme="dark"] .progress { background: #2a2f38; }
[data-theme="dark"] code,
[data-theme="dark"] .placeholders code { background: #2a2f38; color: var(--ink); }
[data-theme="dark"] .spinner { border-color: #313640; border-top-color: var(--red); }
[data-theme="dark"] .spinner-overlay { background: rgba(0, 0, 0, .55); }
[data-theme="dark"] .mainnav a.active,
[data-theme="dark"] .src-toggle.active,
[data-theme="dark"] .topbar .mainnav a.muted:hover { background: #3a1c20; color: #ff8089; }
[data-theme="dark"] .alert.error,
[data-theme="dark"] .badge.bad { background: #3a1c20; color: #f4a6ad; }
[data-theme="dark"] .alert.success,
[data-theme="dark"] .badge.ok { background: #15301f; color: #8ed7a4; }
[data-theme="dark"] .badge.warn { background: #312712; color: #e7c07a; }
[data-theme="dark"] tr.row-error td { background: #2a1b1d; }
[data-theme="dark"] tr.row-warn td { background: #2a2415; }
[data-theme="dark"] .stats .ok strong { color: #8ed7a4; }
[data-theme="dark"] .stats .bad strong { color: #f4a6ad; }
/* Editor (Quill) bleibt hell & lesbar: weißer Hintergrund + dunkler Text, nur Rahmen dunkel */
[data-theme="dark"] .ql-toolbar.ql-snow { border-color: var(--line); }
[data-theme="dark"] .wysiwyg,
[data-theme="dark"] .ql-container.ql-snow,
[data-theme="dark"] .ql-editor { background: #fff; color: #1d1d1f; border-color: var(--line); }
[data-theme="dark"] .table-scroll::-webkit-scrollbar-thumb { background: #4a4f59; }

/* ============ Responsive (Mobil) ============ */
@media (max-width: 640px) {
    .topbar { padding: 12px 16px; gap: 8px; }
    .container { padding: 0 14px; margin: 18px 0; max-width: 100%; }
    .card { padding: 16px 15px; }
    h1 { font-size: 19px; }
    h2 { font-size: 16px; }
    .page-head { flex-direction: column; align-items: flex-start; gap: 8px; }
    .card-head { flex-wrap: wrap; gap: 8px; }
    .row { flex-direction: column; align-items: stretch; gap: 10px; }
    .row > label { flex: 1 1 auto; }
    .head-actions { justify-content: flex-start; }
    dl.kv, .placeholders dl.kv { grid-template-columns: 1fr; gap: 2px 0; }
    dl.kv dt { margin-top: 8px; }
    /* Hauptmenü als Hamburger-Aufklappmenü */
    .nav-toggle { display: inline-flex; }
    .mainnav { display: none; flex-basis: 100%; order: 10; flex-direction: column; align-items: stretch; gap: 2px; padding-top: 6px; }
    .mainnav.open { display: flex; }
    .mainnav a { padding: 10px 12px; }
    .who { display: none; } /* Username mobil ausblenden — nur Icons sichtbar */
    /* breite Tabellen: Zellen nicht umbrechen → der Scroll-Container scrollt sauber */
    .table-scroll table.list { white-space: nowrap; }
}
