:root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --border: #d8dde3;
    --text: #1d2330;
    --muted: #6b7280;
    --primary: #2b6cb0;
    --primary-hover: #245a93;
    --error-bg: #fde2e1;
    --error-text: #9b1c1c;
    --ok: #2f855a;
}

* { box-sizing: border-box; }

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

.muted   { color: var(--muted); }
.hint    { color: var(--muted); font-size: 0.9em; margin-top: 4px; }
.ta-right{ text-align: right; }

/* --- Login --- */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-card {
    background: var(--card);
    width: 100%;
    max-width: 380px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 28px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.04);
}
.login-card h1 { margin: 0 0 4px; font-size: 1.4rem; }
.login-card .subtitle { margin: 0 0 20px; color: var(--muted); }
.login-card .login-logo {
    display: block;
    width: 100%;
    max-width: 280px;
    height: auto;
    margin: 0 auto 18px;
}
.login-card label { display: block; margin-bottom: 6px; font-weight: 600; }
.login-card input[type=password] {
    width: 100%;
    padding: 10px 12px;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 16px;
}
.login-card button {
    width: 100%;
}

/* --- Topbar --- */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.topbar .brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}
.topbar .topbar-logo {
    height: 44px;
    width: auto;
    flex-shrink: 0;
}
.topbar .brand-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.topbar .logout {
    color: var(--primary);
    text-decoration: none;
    flex-shrink: 0;
}
.topbar .logout:hover { text-decoration: underline; }

/* --- Card / Hauptlayout --- */
.card {
    max-width: min(1320px, calc(100vw - 32px));
    margin: 24px auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 24px;
}
.card h1 { margin-top: 0; }

fieldset {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 18px;
    margin: 0 0 16px;
}
fieldset legend {
    padding: 0 8px;
    font-weight: 600;
}

/* --- Farblich hervorgehobene Bereiche --- */
fieldset.fieldset-anlass,
fieldset.fieldset-persoenlich,
fieldset.fieldset-belege {
    border-left-width: 4px;
}
fieldset.fieldset-anlass legend,
fieldset.fieldset-persoenlich legend,
fieldset.fieldset-belege legend {
    border-radius: 4px;
    padding: 2px 10px;
}
fieldset.fieldset-anlass input,
fieldset.fieldset-persoenlich input,
fieldset.fieldset-belege input,
fieldset.fieldset-belege table {
    background: #fff;
}

/* Veranstaltung / Anlass - gelb */
fieldset.fieldset-anlass {
    background: #fff8e1;
    border: 1px solid #f1c40f;
    border-left: 4px solid #f1c40f;
}
fieldset.fieldset-anlass legend {
    background: #f1c40f;
    color: #1d2330;
}

/* Persoenliche Daten - blau */
fieldset.fieldset-persoenlich {
    background: #eaf2fb;
    border: 1px solid #2b6cb0;
    border-left: 4px solid #2b6cb0;
}
fieldset.fieldset-persoenlich legend {
    background: #2b6cb0;
    color: #fff;
}

/* Belege - gruen */
fieldset.fieldset-belege {
    background: #e8f4ec;
    border: 1px solid #38a169;
    border-left: 4px solid #38a169;
}
fieldset.fieldset-belege legend {
    background: #38a169;
    color: #fff;
}

/* Bemerkung - dezentes Grau */
fieldset.fieldset-bemerkung {
    background: #f3f4f6;
    border: 1px solid #9ca3af;
    border-left: 4px solid #9ca3af;
}
fieldset.fieldset-bemerkung legend {
    background: #9ca3af;
    color: #fff;
    border-radius: 4px;
    padding: 2px 10px;
}
fieldset.fieldset-bemerkung textarea {
    background: #fff;
}

label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    font-size: 0.95em;
}

input[type=text],
input[type=email],
input[type=password],
input[type=date],
input[type=number],
input[type=file],
textarea,
select {
    width: 100%;
    padding: 8px 10px;
    font-size: 1rem;
    font: inherit;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

textarea { resize: vertical; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 16px;
}
@media (max-width: 700px) {
    .grid-2 { grid-template-columns: 1fr; }
}

/* --- Tabelle --- */
.table-wrap {
    overflow-x: auto;
    margin-bottom: 12px;
}
table {
    width: 100%;
    border-collapse: collapse;
}
#belege-tabelle {
    table-layout: fixed;
}
th, td {
    border-bottom: 1px solid var(--border);
    padding: 8px 6px;
    text-align: left;
    vertical-align: top;
}
#belege-tabelle tfoot td { vertical-align: middle; }
th { background: #f8f9fb; font-size: 0.9em; }
tfoot td { border-bottom: 0; padding-top: 12px; }
table input { padding: 6px 8px; }

/* (row-del und link-del sind weiter unten unifiziert) */

/* --- Buttons --- */
button, .btn {
    appearance: none;
    background: var(--primary);
    color: #fff;
    border: 0;
    padding: 10px 16px;
    font-size: 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}
button:hover, .btn:hover { background: var(--primary-hover); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

button.secondary {
    background: #fff;
    color: var(--primary);
    border: 1px solid var(--primary);
}
button.secondary:hover { background: #eef4fb; }

.actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* --- Datei-Anzeige in der Geschaeft-Spalte --- */
.file-info-slot {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78em;
}
.file-info-slot .badge {
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    border-radius: 4px;
    background: #eef4fb;
    color: var(--muted);
    word-break: break-word;
    overflow-wrap: anywhere;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.file-info-slot .badge.ok  { background: #f3f4f6; color: var(--muted); }
.file-info-slot .badge.bad { background: var(--error-bg); color: var(--error-text); }
.file-info-slot .badge .file-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--muted);
}

/* Einheitlicher "Loeschen"-Button (Zeile, Datei, Eigenbeleg, Foto) */
button.row-del,
button.link-del {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--error-text);
    font-size: 1.1em;
    line-height: 1;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    flex-shrink: 0;
}
button.row-del:hover,
button.link-del:hover { background: var(--error-bg); }

/* --- Beleg-Zelle: Buttons + State --- */
.beleg-cell { vertical-align: top; }
.beleg-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.beleg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 100%;
    padding: 6px 8px;
    font-size: 0.78em;
    font-weight: 600;
    color: #1e3a8a;
    background: #eef4fb;
    border: 1px solid transparent;
    border-radius: 6px;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.beleg-btn:hover {
    background: #2b6cb0;
    color: #fff;
}
.beleg-btn:active {
    transform: translateY(1px);
}
.beleg-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}
.beleg-state {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85em;
}
.beleg-state .badge {
    flex: 1;
    min-width: 0;
    padding: 4px 6px;
    border-radius: 4px;
    background: #eef4fb;
    color: var(--text);
    word-break: break-word;
    overflow-wrap: anywhere;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85em;
}
.beleg-state .badge.self {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.78em;
    font-weight: 600;
}
.beleg-state .badge.ok         { background: #e6f4ea; color: var(--ok); }
.beleg-state .badge.bad        { background: var(--error-bg); color: var(--error-text); }
.beleg-state .badge.self       { background: #fff8e1; color: #5a4a10; border: 1px solid #f1c40f; }
.beleg-state .badge.converting { background: #eef4fb; color: #1e3a8a; }
.beleg-state .row-thumb {
    width: 24px;
    height: 24px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border);
    flex-shrink: 0;
}
/* .beleg-state .link-del wird durch die unifizierte Regel oben gestylt */

/* --- Modal --- */
.modal[hidden] { display: none; }
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(20, 26, 36, 0.55);
    backdrop-filter: blur(2px);
}
.modal-card {
    position: relative;
    background: #fff;
    border-radius: 12px;
    padding: 22px 24px;
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    overflow: auto;
    box-shadow: 0 12px 48px rgba(0,0,0,0.18);
}
.modal-card h2 { margin: 0 0 6px; font-size: 1.2rem; }
.modal-close {
    position: absolute;
    top: 8px; right: 10px;
    background: transparent;
    border: 0;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
}
.modal-close:hover { color: var(--text); background: transparent; }

.modal-grid {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 24px;
    margin-top: 12px;
}
@media (max-width: 640px) {
    .modal-grid { grid-template-columns: 1fr; }
}

.qr-wrap { text-align: center; }
.qr-wrap #qr-canvas {
    display: inline-block;
    padding: 8px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.qr-wrap .qr-url {
    margin-top: 8px;
    font-size: 0.78em;
    word-break: break-all;
}

.thumbs-wrap h3 { margin: 0 0 6px; font-size: 1rem; }
.thumbs {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
}
.thumb-item {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: #f8f9fb;
}
.thumb-assign {
    background: transparent;
    border: 0;
    padding: 0;
    width: 100%;
    cursor: pointer;
    display: block;
    color: inherit;
}
.thumb-assign img {
    display: block;
    width: 100%;
    height: 90px;
    object-fit: cover;
}
.thumb-assign .thumb-meta {
    display: block;
    padding: 4px 6px;
    font-size: 0.8em;
    color: var(--muted);
    text-align: center;
    background: #fff;
}
.thumb-assign:hover { background: #eef4fb; }
.thumb-del {
    position: absolute;
    top: 4px; right: 4px;
    background: rgba(255,255,255,0.92);
    color: var(--error-text);
    border: 1px solid var(--border);
    border-radius: 4px;
    width: 22px; height: 22px;
    font-size: 1em;
    line-height: 1;
    padding: 0;
    cursor: pointer;
}
.thumb-del:hover { background: var(--error-bg); }

/* --- Meldungen --- */
.error {
    background: var(--error-bg);
    color: var(--error-text);
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
}
.success {
    background: #e6f4ea;
    color: var(--ok);
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
}
