/* ---------- Farben ---------- */
:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #2563eb;
    --accent-text: #ffffff;
    --accent-soft: #dbeafe;

    --p1: #dc2626; --p1-soft: #fee2e2;   /* Kritisch */
    --p2: #ea580c; --p2-soft: #ffedd5;   /* Hoch */
    --p3: #2563eb; --p3-soft: #dbeafe;   /* Normal */
    --p4: #6b7280; --p4-soft: #f3f4f6;   /* Niedrig */

    --s-neu: #7c3aed;        --s-neu-soft: #ede9fe;
    --s-in_arbeit: #0284c7;  --s-in_arbeit-soft: #e0f2fe;
    --s-wartet: #b45309;     --s-wartet-soft: #fef3c7;
    --s-erledigt: #15803d;   --s-erledigt-soft: #dcfce7;

    --ok-bg: #dcfce7; --ok-text: #166534;
    --err-bg: #fee2e2; --err-text: #991b1b;

    --radius: 10px;
    --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 3px rgba(0,0,0,.06);
    color-scheme: light;
}

/* Dunkel: automatisch nach Geräteeinstellung (außer "Hell" ist gewählt) ... */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f1115;
        --surface: #181b21;
        --surface-2: #1f232b;
        --text: #e5e7eb;
        --muted: #9ca3af;
        --border: #2d323c;
        --accent: #3b82f6;
        --accent-soft: #1e3a5f;

        --p1: #f87171; --p1-soft: #3f1d1d;
        --p2: #fb923c; --p2-soft: #3d2614;
        --p3: #60a5fa; --p3-soft: #1e3050;
        --p4: #9ca3af; --p4-soft: #2a2e36;

        --s-neu: #a78bfa;        --s-neu-soft: #2e2550;
        --s-in_arbeit: #38bdf8;  --s-in_arbeit-soft: #123447;
        --s-wartet: #fbbf24;     --s-wartet-soft: #3a2e10;
        --s-erledigt: #4ade80;   --s-erledigt-soft: #14321f;

        --ok-bg: #14321f; --ok-text: #86efac;
        --err-bg: #3f1d1d; --err-text: #fca5a5;
        --shadow: none;
        color-scheme: dark;
    }
    :root:not([data-theme="light"]) .to-dark { display: none; }
    :root:not([data-theme="light"]) .to-light { display: inline; }
}

/* ... oder fest gewählt */
:root[data-theme="dark"] {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #1f232b;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #2d323c;
    --accent: #3b82f6;
    --accent-soft: #1e3a5f;

    --p1: #f87171; --p1-soft: #3f1d1d;
    --p2: #fb923c; --p2-soft: #3d2614;
    --p3: #60a5fa; --p3-soft: #1e3050;
    --p4: #9ca3af; --p4-soft: #2a2e36;

    --s-neu: #a78bfa;        --s-neu-soft: #2e2550;
    --s-in_arbeit: #38bdf8;  --s-in_arbeit-soft: #123447;
    --s-wartet: #fbbf24;     --s-wartet-soft: #3a2e10;
    --s-erledigt: #4ade80;   --s-erledigt-soft: #14321f;

    --ok-bg: #14321f; --ok-text: #86efac;
    --err-bg: #3f1d1d; --err-text: #fca5a5;
    --shadow: none;
    color-scheme: dark;
}

/* Umschalter: zeigt jeweils das andere Schema an */
.to-light { display: none; }
:root[data-theme="dark"] .to-dark { display: none; }
:root[data-theme="dark"] .to-light { display: inline; }

/* ---------- Grundlayout ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
.wrap { max-width: 1000px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 64px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.inline { display: inline; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------- Kopfzeile ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.mainnav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.mainnav a, .mainnav .linklike { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: .95rem; }
.mainnav a:hover, .mainnav .linklike:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.theme-toggle .linklike { font-size: 1.1rem; line-height: 1; padding: 6px 8px; }
.mainnav a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 600; }

/* ---------- Karten, Buttons, Formulare ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.narrow { max-width: 440px; margin: 40px auto; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
    text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: 1; cursor: default; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.linklike:hover { text-decoration: underline; }
.danger { color: var(--p1) !important; }

input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], select, textarea {
    width: 100%; padding: 9px 11px; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: block; font-weight: 600; font-size: .95rem; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2.top { align-items: start; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: .95rem; margin-bottom: 4px; padding: 0; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--ok-bg); color: var(--ok-text); }
.flash-error { background: var(--err-bg); color: var(--err-text); }

/* ---------- Prioritäts-Auswahl ---------- */
.prio-picker { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.prio-picker legend { width: 100%; }
.prio-option { font-weight: 500; cursor: pointer; }
.prio-option input { position: absolute; opacity: 0; pointer-events: none; }
.prio-option span { display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }
.prio-option input:focus-visible + span { outline: 2px solid var(--accent); }
.prio-option.prio-1 input:checked + span { background: var(--p1); border-color: var(--p1); color: #fff; }
.prio-option.prio-2 input:checked + span { background: var(--p2); border-color: var(--p2); color: #fff; }
.prio-option.prio-3 input:checked + span { background: var(--p3); border-color: var(--p3); color: #fff; }
.prio-option.prio-4 input:checked + span { background: var(--p4); border-color: var(--p4); color: #fff; }
.theme-option input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.prio-option input:disabled + span { cursor: default; opacity: .6; }
.prio-option input:disabled:checked + span { opacity: 1; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge.prio-1 { background: var(--p1-soft); color: var(--p1); }
.badge.prio-2 { background: var(--p2-soft); color: var(--p2); }
.badge.prio-3 { background: var(--p3-soft); color: var(--p3); }
.badge.prio-4 { background: var(--p4-soft); color: var(--p4); }
.status-neu       { --s: var(--s-neu);       --s-soft: var(--s-neu-soft); }
.status-in_arbeit { --s: var(--s-in_arbeit); --s-soft: var(--s-in_arbeit-soft); }
.status-wartet    { --s: var(--s-wartet);    --s-soft: var(--s-wartet-soft); }
.status-erledigt  { --s: var(--s-erledigt);  --s-soft: var(--s-erledigt-soft); }
.badge.status { background: var(--s-soft); color: var(--s); }

.due-overdue { color: var(--p1); font-weight: 700; }
.due-soon { color: var(--p2); font-weight: 600; }
.due-week { color: var(--text); }
.due-later, .due-none { color: var(--muted); }
.text-critical { color: var(--p1); font-weight: 600; }

/* ---------- Übersicht ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 20px; }
.filters input[type=search] { flex: 1 1 120px; width: auto; min-width: 0; }
.filters select { width: auto; flex: 0 1 auto; }

.focus { margin-bottom: 24px; }
.focus h2, .section-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }
.focus .task { border-width: 1px 1px 1px 5px; padding-top: 16px; padding-bottom: 16px; }
.focus .task-title { font-size: 1.08rem; }

.tasklist { display: flex; flex-direction: column; gap: 8px; }
.task {
    display: flex; align-items: flex-start; gap: 12px;
    background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--border);
    border-radius: var(--radius); padding: 12px 14px; color: var(--text); text-decoration: none; box-shadow: var(--shadow);
}
.task:hover { background: var(--surface-2); }
.task.prio-1 { border-left-color: var(--p1); }
.task.prio-2 { border-left-color: var(--p2); }
.task.prio-3 { border-left-color: var(--p3); }
.task.prio-4 { border-left-color: var(--p4); }
.task.status-erledigt .task-title { text-decoration: line-through; color: var(--muted); }
.task .badge.prio { min-width: 70px; text-align: center; margin-top: 2px; }
.task-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.task-title { font-weight: 600; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .85rem; color: var(--muted); align-items: center; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

/* ---------- Detailseite ---------- */
.task-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.task-detail { border-top: 4px solid var(--border); }
.task-detail.prio-border-1 { border-top-color: var(--p1); }
.task-detail.prio-border-2 { border-top-color: var(--p2); }
.task-detail.prio-border-3 { border-top-color: var(--p3); }
.task-detail.prio-border-4 { border-top-color: var(--p4); }
.task-detail h1 { overflow-wrap: anywhere; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; font-size: .9rem; }
.description { background: var(--surface-2); border-radius: 8px; padding: 14px 16px; margin: 12px 0; overflow-wrap: anywhere; }
.quick-status { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 16px 0 4px; }
.status-btn:disabled { background: var(--s-soft); color: var(--s); border-color: transparent; }
.edit-box { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.edit-box summary { cursor: pointer; font-weight: 600; color: var(--accent); margin-bottom: 12px; }
.sidebar h2 { font-size: 1rem; }
.sidebar .subs { margin-top: 12px; margin-bottom: 0; }
.danger-zone { margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--border); }

.timeline-section { margin-top: 24px; }
.timeline { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 10px; }
.tl-comment { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); }
.tl-comment.mine { border-left: 3px solid var(--accent); }
.tl-comment .tl-meta { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.tl-comment .tl-meta strong { color: var(--text); }
.tl-comment .tl-body { overflow-wrap: anywhere; }
.tl-system { font-size: .85rem; color: var(--muted); padding: 2px 16px; border-left: 2px dashed var(--border); margin-left: 8px; }
.tl-system .tl-meta { display: block; }
.tl-system .tl-body { color: var(--text); }
.comment-form { margin-top: 8px; }

/* ---------- Admin / Profil ---------- */
.inline-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 8px; }
.inline-form label { flex: 1 1 180px; }
.table-wrap { overflow-x: auto; margin-bottom: 12px; }
table.users { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.users th, table.users td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.users th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
table.users tr.inactive td { color: var(--muted); }
table.users .actions { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.linkbox .copy-field { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 8px 0; border-bottom: 1px solid var(--border); }
ul.plain li:last-child { border-bottom: 0; }
ul.plain a { text-decoration: none; color: var(--text); }

/* ---------- Handy ---------- */
@media (max-width: 760px) {
    .task-layout, .grid-2 { grid-template-columns: 1fr; }
    h1 { font-size: 1.35rem; }
    .card { padding: 16px; }
    .filters select, .filters .btn { flex: 1 1 calc(50% - 8px); }
    .task { flex-direction: column; gap: 6px; }
    .task .badge.prio { min-width: 0; }
    .topbar-inner { padding-top: 8px; padding-bottom: 8px; }
}
