:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #667085;
    --border: #e3e6eb;
    --accent: #2f5bea;
    --accent-text: #ffffff;
    --incoming: #ffffff;
    --outgoing: #eef3ff;
    --error: #c0362c;
    --badge-offen: #fff4d6;
    --badge-offen-text: #7a5300;
    --badge-beantwortet: #e3efff;
    --badge-beantwortet-text: #1f4fb8;
    --badge-erledigt: #e6f4ea;
    --badge-erledigt-text: #1e6b34;
    --verdict-rot-bg: #fde7e5;
    --verdict-rot-text: #9b261c;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12151b;
        --surface: #1b1f27;
        --text: #e7e9ee;
        --muted: #98a1b3;
        --border: #2c323d;
        --accent: #6f8fff;
        --accent-text: #0d1020;
        --incoming: #1b1f27;
        --outgoing: #1d2740;
        --error: #ff7b6e;
        --badge-offen: #3d3216;
        --badge-offen-text: #ffd57a;
        --badge-beantwortet: #1d2c4d;
        --badge-beantwortet-text: #9dbbff;
        --badge-erledigt: #173322;
        --badge-erledigt-text: #8fd9a6;
        --verdict-rot-bg: #3f1a17;
        --verdict-rot-text: #ffb4ab;
    }
}

* { box-sizing: border-box; }

/* hidden gilt auch für Elemente, denen das CSS ein display gibt */
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topnav { display: flex; gap: 16px; margin-left: 24px; margin-right: auto; }
.topnav a { color: var(--muted); text-decoration: none; padding: 8px 0; }
.topnav a[aria-current="page"] { color: var(--text); font-weight: 600; }

.page { max-width: 860px; margin: 0 auto; padding: 24px 16px 64px; }

h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }

.page-head {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.muted { color: var(--muted); font-weight: 400; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 8px 0 0; }
/* Hinweis direkt über einem Formular oder Feld: Abstand zum folgenden Label */
.panel > .hint + form { margin-top: 16px; }
.note + .knowledge-facts { margin-top: 12px; }
.panel > .hint:only-child { margin: 0; }
.empty { color: var(--muted); padding: 32px 0; }
.error { color: var(--error); margin: 0; }
.back { margin: 0 0 12px; }

.button, .link-button {
    font: inherit;
    cursor: pointer;
}
.button {
    min-height: 40px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
a.button { display: inline-flex; align-items: center; text-decoration: none; }
.link-button { background: none; border: 0; color: var(--accent); padding: 8px 0; }

.tabs { display: flex; gap: 4px; }
.tabs a {
    padding: 6px 12px;
    border-radius: 999px;
    text-decoration: none;
    color: var(--muted);
}
.tabs a[aria-current="page"] { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

.ticket-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ticket-row {
    display: grid;
    gap: 4px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    text-decoration: none;
}
.ticket-row:hover { border-color: var(--accent); }
.ticket-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 0.9rem; }
.ticket-meta .app { font-weight: 600; }
.ticket-meta .lang, .ticket-meta .from { color: var(--muted); }
.preview { overflow-wrap: anywhere; }
.date { color: var(--muted); font-size: 0.85rem; }

.badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}
.status-offen { background: var(--badge-offen); color: var(--badge-offen-text); }
.status-beantwortet { background: var(--badge-beantwortet); color: var(--badge-beantwortet-text); }
.status-erledigt { background: var(--badge-erledigt); color: var(--badge-erledigt-text); }

.facts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    margin: 0 0 24px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.facts dt { font-size: 0.8rem; color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select, input[type="password"], input[type="text"] {
    font: inherit;
    min-height: 40px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.thread { list-style: none; margin: 0 0 24px; padding: 0; display: grid; gap: 12px; }
.message {
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--incoming);
}
.message.outgoing { background: var(--outgoing); margin-left: 32px; }
.message-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; margin-bottom: 6px; font-size: 0.9rem; }
.message-body { overflow-wrap: anywhere; }
.original { margin-top: 10px; font-size: 0.9rem; }
.original summary { cursor: pointer; color: var(--muted); }
.original .message-body { margin-top: 6px; padding-left: 10px; border-left: 3px solid var(--border); }

.reply { padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }

.login { max-width: 360px; margin: 10vh auto 0; }
.login h1 { margin-bottom: 16px; }
.stack { display: grid; gap: 8px; }

@media (max-width: 600px) {
    .message.outgoing { margin-left: 12px; }
    /* Navigation in eigener Zeile unter Marke und Abmelden – sonst zu breit für das Handy */
    .topbar { flex-wrap: wrap; row-gap: 2px; }
    .topnav { order: 3; width: 100%; margin: 0; }
}

/* --- Antworten */
.reply label { display: block; font-weight: 600; margin: 8px 0 4px; }
.reply textarea {
    width: 100%;
    font: inherit;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    resize: vertical;
}
.reply-actions { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-top: 12px; }
.button:disabled { opacity: 0.55; cursor: progress; }

.steps { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 6px; font-size: 0.95rem; }
.step { padding-left: 26px; position: relative; color: var(--muted); }
.step::before { position: absolute; left: 0; width: 18px; text-align: center; }
.step-pending::before { content: "○"; }
.step-running { color: var(--text); font-weight: 600; }
.step-running::before { content: "◌"; animation: spin 1s linear infinite; }
.step-done::before { content: "✓"; color: var(--badge-erledigt-text); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .step-running::before { animation: none; } }

.reply-result { margin-top: 16px; display: grid; gap: 12px; }
.note { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--badge-offen); color: var(--badge-offen-text); }

.verdict { padding: 12px 14px; border-radius: 10px; border: 1px solid transparent; }
.verdict-gruen { background: var(--badge-erledigt); color: var(--badge-erledigt-text); }
.verdict-gelb { background: var(--badge-offen); color: var(--badge-offen-text); }
.verdict-rot { background: var(--verdict-rot-bg); color: var(--verdict-rot-text); }
.verdict-stale { opacity: 0.6; }
.verdict-summary { margin: 6px 0 0; font-size: 0.9rem; }

.findings { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.finding { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.finding-line { margin: 4px 0 0; overflow-wrap: anywhere; }
.severity-rot { background: var(--verdict-rot-bg); color: var(--verdict-rot-text); }
.severity-gelb { background: var(--badge-offen); color: var(--badge-offen-text); }

.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.text-block h3 { font-size: 0.85rem; color: var(--muted); margin: 0 0 4px; font-weight: 600; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.translation summary { cursor: pointer; color: var(--muted); }
.translation .text { margin-top: 6px; }

@media (max-width: 600px) {
    .compare-grid { grid-template-columns: 1fr; }
}

/* --- Einstellungen */
.panel { padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 16px; }
.panel textarea {
    width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text); resize: vertical;
}
.panel label { font-weight: 600; }
.success { color: var(--badge-erledigt-text); margin: 0; }
.signature-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.signature-item .text { margin: 6px 0; }
.severity-gruen { background: var(--badge-erledigt); color: var(--badge-erledigt-text); }

/* --- Wissen und Versand */
.knowledge-facts { margin: 0; display: grid; gap: 8px; }
.knowledge-facts dt { font-size: 0.8rem; color: var(--muted); }
.knowledge-facts dd { margin: 0; overflow-wrap: anywhere; }
.mail-preview summary { cursor: pointer; font-weight: 600; }
.mail-preview .mail-head { margin: 8px 0 4px; font-size: 0.9rem; color: var(--muted); overflow-wrap: anywhere; }
.send-box { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.send-box label { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; margin: 0; }
.send-box input[type="checkbox"] { margin-top: 4px; width: 18px; height: 18px; flex: none; }

/* --- Wissen */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0 16px; }
.filter-bar input[type="search"] {
    font: inherit; min-height: 40px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); color: var(--text); flex: 1 1 180px;
}
.knowledge-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.knowledge-entry { margin: 0; }
.knowledge-entry.is-old { opacity: 0.7; }
.knowledge-entry.is-saved { border-color: var(--accent); }
.knowledge-entry .knowledge-facts { margin: 8px 0 4px; }
.knowledge-form input[type="text"], .knowledge-form textarea { width: 100%; }
.radio-group { border: 0; padding: 0; margin: 4px 0; display: grid; gap: 6px; }
.radio-group legend { font-weight: 600; padding: 0; margin-bottom: 4px; }
.radio-group label { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.radio-group input { width: 18px; height: 18px; }
.link-button.danger { color: var(--error); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.error p { margin: 0; }

/* --- Vorschlag */
.suggestion { display: grid; gap: 8px; padding: 12px; margin-bottom: 12px; border: 1px dashed var(--border); border-radius: 10px; }
.suggestion-head { font-size: 0.95rem; }
.suggestion-text summary { cursor: pointer; color: var(--muted); }
.suggestion-text .text { margin-top: 6px; }
.suggestion-label { margin: 0; font-size: 0.9rem; font-weight: 600; }
.suggestion-list { margin: 0; padding-left: 20px; display: grid; gap: 4px; font-size: 0.9rem; }
.suggestion-list .badge { margin-left: 6px; }
