/*
 * Partnerabrechnung – Gestaltung wie im GMB-Tracker (Alpha Digitalagentur).
 * Die Farben stecken in CSS-Variablen; der Wechsel zwischen hell und dunkel
 * tauscht nur diese Variablen aus, die Bausteine bleiben unverändert.
 */

/* ---------- Farbwerte ---------- */
:root {
    --radius: 14px;
    --radius-sm: 9px;
    --sidebar-w: 244px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;

    --blue: #2563eb;
    --blue-soft: rgba(37, 99, 235, .12);
    --green: #16a34a;
    --amber: #d97706;
    --red: #dc2626;
}

[data-theme="dark"] {
    --bg: #0b1120;
    --bg-side: #0f172a;
    --surface: #131c2e;
    --surface-2: #0b1220;
    --line: #1f2a3d;
    --line-soft: #172136;
    --text: #e6edf7;
    --text-dim: #94a3b8;
    --text-faint: #64748b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .28);
    color-scheme: dark;
}

[data-theme="light"] {
    --bg: #f1f5f9;
    --bg-side: #ffffff;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --line: #e2e8f0;
    --line-soft: #eef2f7;
    --text: #0f172a;
    --text-dim: #55637a;
    --text-faint: #8593a8;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .08);
    color-scheme: light;
}

/* ---------- Grundlagen ---------- */
* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

.skip { position: absolute; left: -9999px; }
.skip:focus {
    left: 12px;
    top: 12px;
    z-index: 100;
    background: var(--surface);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
}

/* ---------- Gerüst ---------- */
.shell { display: flex; min-height: 100%; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--bg-side);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ---------- Marke ---------- */
.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 18px 18px 16px;
    border-bottom: 1px solid var(--line-soft);
    text-decoration: none;
    color: var(--text);
}

.brand-mark {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    border-radius: 10px;
    background: var(--blue);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 12px;
    letter-spacing: .02em;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.brand-text strong { font-size: 14px; }
.brand-text small { color: var(--text-faint); font-size: 11.5px; }

/* Fassungszeile unter der Marke */
.fassung {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px 10px;
    font-size: 11.5px;
    color: var(--text-faint);
    text-decoration: none;
    border-bottom: 1px solid var(--line-soft);
}
a.fassung:hover { color: var(--text-dim); background: var(--line-soft); }
.fassung-punkt {
    width: 6px;
    height: 6px;
    flex: 0 0 6px;
    border-radius: 999px;
    background: var(--green);
}
.fassung-punkt.warn { background: var(--amber); }
.fassung-punkt.err { background: var(--red); }

/* ---------- Navigation ---------- */
.nav { padding: 14px 10px; flex: 1 1 auto; overflow-y: auto; }

.nav-group {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-faint);
    font-weight: 700;
    padding: 14px 10px 6px;
}
.nav-group:first-child { padding-top: 2px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
}
.nav-item:hover { background: var(--line-soft); color: var(--text); }
.nav-item.is-active { background: var(--blue-soft); color: var(--blue); }

.nav-icon { display: grid; place-items: center; }
.nav-icon svg { width: 18px; height: 18px; }

/* ---------- Fuß der Seitenleiste ---------- */
.sidebar-foot {
    border-top: 1px solid var(--line-soft);
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: space-between;
}

.who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.who-avatar {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border-radius: 50%;
    background: var(--blue-soft);
    color: var(--blue);
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 13px;
}
.who-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.who-text strong { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-text small { color: var(--text-faint); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.sidebar-actions form { margin: 0; display: contents; }

.icon-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text-dim);
    display: grid;
    place-items: center;
    cursor: pointer;
    text-decoration: none;
}
.icon-btn:hover { background: var(--line-soft); color: var(--text); filter: none; }
.icon-btn svg { width: 16px; height: 16px; }

[data-theme="dark"] .icon-sun { display: grid; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: grid; }

/* ---------- Kopfleiste ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px 28px;
    border-bottom: 1px solid var(--line);
    background: var(--bg-side);
    position: sticky;
    top: 0;
    z-index: 20;
    flex-wrap: wrap;
}
.topbar-title { flex: 1 1 auto; min-width: 0; }
.topbar-title h1 { margin: 0; font-size: 20px; line-height: 1.3; }
.topbar-title p { margin: 2px 0 0; color: var(--text-dim); font-size: 13.5px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.topbar-actions form { margin: 0; }

.only-mobile { display: none; }

/* ---------- Inhalt ---------- */
.content {
    padding: 24px 28px 8px;
    max-width: 1180px;
    width: 100%;
    flex: 1 1 auto;
}
.content.is-wide { max-width: none; }

.backlink { margin: 0 0 14px; }
.backlink a { color: var(--text-dim); text-decoration: none; font-size: 14px; }
.backlink a:hover { color: var(--text); }

/* ---------- Karten ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
}
.card > h2:first-child,
.card > h3:first-child { margin-top: 0; }
.card h2 { font-size: 16px; margin: 0 0 4px; }
.card h3 { font-size: 14px; margin: 22px 0 8px; }
.card-sub { color: var(--text-dim); font-size: 13.5px; margin: 0 0 16px; }

.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.card-head h2 { margin: 0; }
.card-head .card-sub { margin: 2px 0 0; }

.cards { display: grid; gap: 18px; }
.cards.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cards.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cards.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cards.stats { margin-bottom: 18px; }

/* ---------- Kennzahlen ---------- */
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-label { color: var(--text-dim); font-size: 12.5px; font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.stat-value.blue { color: var(--blue); }
.stat-value.small { font-size: 20px; }
.stat-hint { color: var(--text-faint); font-size: 12px; }

/* ---------- Formulare ---------- */
label {
    display: block;
    margin: 0 0 6px;
    font-weight: 600;
    font-size: 13.5px;
}

.field { margin-bottom: 16px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
input[type="url"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: 14.5px;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-soft);
}

input[readonly] { color: var(--text-dim); }
textarea { min-height: 110px; resize: vertical; }

.hint { color: var(--text-faint); font-size: 12.5px; margin: 6px 0 0; }

.laeuft-hinweis {
    margin: 10px 0 0;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--blue-soft);
    border: 1px solid var(--blue);
    color: var(--text);
    font-size: 13.5px;
    line-height: 1.5;
}

button:disabled { opacity: .65; cursor: progress; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.grid-port { display: grid; grid-template-columns: minmax(0, 1fr) 130px; gap: 0 16px; }
.grid .full, .grid3 .full { grid-column: 1 / -1; }

.check {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    font-weight: 600;
    font-size: 14px;
    margin: 0 0 6px;
    cursor: pointer;
}
.check input { width: auto; margin-top: 4px; }

/* Filterzeile über Tabellen */
.filter-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 16px;
}
.filter-row .field { margin: 0; min-width: 150px; }
.filter-row .field.grow { flex: 1 1 220px; }
.filter-row .check { margin: 0 0 10px; }

/* Umschalter (z.B. Jahre) */
.segmente { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }

/* Nummerierte Schritte (Einrichtung) */
.step { display: flex; gap: 12px; align-items: baseline; margin-bottom: 10px; }
.step-nr {
    flex: 0 0 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--blue-soft);
    color: var(--blue);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
}

.anleitung { font-size: 14px; line-height: 1.7; margin: 0; padding-left: 20px; }
.anleitung li { margin-bottom: 6px; }

.mono { font-family: ui-monospace, Consolas, monospace; }

/* Löschbereich – abgesetzt, damit man nicht versehentlich hineinklickt */
.gefahr { border-color: var(--red); }
.gefahr h2 { color: var(--red); }

/* ---------- Schaltflächen ---------- */
.btn, button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    background: var(--blue);
    color: #fff;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 9px 15px;
    font-weight: 600;
    font-size: 14px;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    line-height: 1.4;
}
.btn:hover, button:hover { filter: brightness(1.08); }
.btn:active, button:active { transform: translateY(1px); }
.btn svg, button svg { width: 16px; height: 16px; }

.btn.alt, button.alt {
    background: transparent;
    color: var(--text);
    border-color: var(--line);
}
.btn.alt:hover, button.alt:hover { background: var(--line-soft); filter: none; }

.btn.ghost, button.ghost {
    background: transparent;
    color: var(--text-dim);
    border-color: transparent;
    padding: 6px 9px;
}
.btn.ghost:hover, button.ghost:hover { background: var(--line-soft); color: var(--text); filter: none; }

.btn.danger, button.danger { background: var(--red); }
.btn.alt.danger, button.alt.danger { background: transparent; color: var(--red); border-color: rgba(220, 38, 38, .35); }
.btn.small, button.small { padding: 6px 11px; font-size: 13px; }
.btn.is-current { background: var(--blue); color: #fff; border-color: var(--blue); }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row.end { justify-content: flex-end; }
.btn-row form { margin: 0; }
.inline-form { display: inline; margin: 0; }

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, .45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: drehen .8s linear infinite;
}
@keyframes drehen { to { transform: rotate(360deg); } }

.sync-status { color: var(--text-dim); font-size: 13px; }
.sync-status.err { color: var(--red); font-weight: 600; }
.sync-status.ok { color: var(--green); font-weight: 600; }
.sync-status.warn { color: var(--amber); font-weight: 600; }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; }
.card > .table-wrap { margin: 0 -22px -20px; padding: 0 22px 20px; }

table { width: 100%; border-collapse: collapse; }

th, td {
    text-align: left;
    padding: 11px 12px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
    font-size: 14px;
}

th {
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom-color: var(--line);
    white-space: nowrap;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--line-soft); }

tfoot th, tfoot td {
    border-top: 1px solid var(--line);
    border-bottom: 0;
    color: var(--text);
    font-size: 14px;
    text-transform: none;
    letter-spacing: 0;
}

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }
td .sub, .sub-line { display: block; font-size: 12px; color: var(--text-faint); }
tr.is-muted td { color: var(--text-faint); }
tr.is-muted td strong { color: var(--text-dim); }
.neg { color: var(--red); }

table.compact th, table.compact td { padding: 8px 10px; font-size: 13.5px; }

/* ---------- Meldungen und Marken ---------- */
.flash {
    padding: 12px 15px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    font-weight: 600;
    font-size: 14px;
    border: 1px solid transparent;
    line-height: 1.6;
}
.flash span { display: block; font-weight: 400; margin-top: 2px; }
.flash.ok { background: rgba(22, 163, 74, .13); border-color: rgba(22, 163, 74, .35); color: var(--green); }
.flash.err { background: rgba(220, 38, 38, .13); border-color: rgba(220, 38, 38, .35); color: var(--red); }
.flash.warn { background: rgba(217, 119, 6, .13); border-color: rgba(217, 119, 6, .35); color: var(--amber); }
.flash.info { background: var(--blue-soft); border-color: rgba(37, 99, 235, .3); color: var(--blue); }
.flash a { color: inherit; }

[data-theme="dark"] .flash.ok { color: #4ade80; }
[data-theme="dark"] .flash.err { color: #f87171; }
[data-theme="dark"] .flash.warn { color: #fbbf24; }
[data-theme="dark"] .flash.info { color: #93c5fd; }

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 11.5px;
    font-weight: 700;
    border: 1px solid transparent;
    white-space: nowrap;
    line-height: 1.4;
}
.badge.ok { background: rgba(22, 163, 74, .14); color: var(--green); border-color: rgba(22, 163, 74, .3); }
.badge.off { background: var(--line-soft); color: var(--text-faint); border-color: var(--line); }
.badge.err { background: rgba(220, 38, 38, .14); color: var(--red); border-color: rgba(220, 38, 38, .3); }
.badge.info { background: var(--blue-soft); color: var(--blue); border-color: rgba(37, 99, 235, .3); }
.badge.warn { background: rgba(217, 119, 6, .14); color: var(--amber); border-color: rgba(217, 119, 6, .3); }

[data-theme="dark"] .badge.ok { color: #4ade80; }
[data-theme="dark"] .badge.err { color: #f87171; }
[data-theme="dark"] .badge.warn { color: #fbbf24; }
[data-theme="dark"] .badge.info { color: #93c5fd; }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); font-size: 13px; }
.nowrap { white-space: nowrap; }

.empty { text-align: center; padding: 34px 20px; color: var(--text-dim); }

pre {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 13px 15px;
    overflow-x: auto;
    font-size: 12.5px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0 0 12px;
}

code {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 1px 6px;
    font-size: 12.5px;
    font-family: ui-monospace, Consolas, monospace;
    white-space: nowrap;
}
code.gross { font-size: 15px; padding: 3px 9px; font-weight: 700; color: var(--blue); }

details { margin-top: 10px; }
details summary { cursor: pointer; color: var(--blue); font-size: 13.5px; font-weight: 600; }
details[open] summary { margin-bottom: 12px; }

dl {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    gap: 9px 20px;
    margin: 0;
}
dt { font-weight: 600; color: var(--text-dim); font-size: 14px; }
dd { margin: 0; font-size: 14px; }

.card ul { padding-left: 20px; }
.card ul li { margin-bottom: 7px; }

/* Fortschrittsbalken (Abrechnungsstand, Verteilung) */
.balken {
    height: 10px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    overflow: hidden;
}
.balken-fuell { height: 100%; background: var(--green); }
.balken.klein { height: 8px; min-width: 110px; }
.balken.klein .balken-fuell { background: var(--blue); }

/* ---------- Öffentliche Seiten ohne Seitenleiste ---------- */
.public { max-width: 900px; margin: 0 auto; padding: 0 20px; }
.public.is-narrow { max-width: 460px; }
.public.is-medium { max-width: 720px; }
.public.is-narrow .public-title { text-align: center; }

.public-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 22px 0 20px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 28px;
}
.public-head .brand { padding: 0; border: 0; }
.public .content { padding: 0; max-width: none; }
.public-title { margin-bottom: 22px; }
.public-title h1 { margin: 0; font-size: 26px; line-height: 1.25; }
.public-title p { margin: 6px 0 0; color: var(--text-dim); font-size: 14px; }

/* ---------- Fußzeile ---------- */
.footer {
    color: var(--text-faint);
    font-size: 12px;
    line-height: 1.7;
    padding: 18px 28px 28px;
    border-top: 1px solid var(--line);
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
}
.footer strong { color: var(--text); }
.public .footer { padding-left: 0; padding-right: 0; }

/* ---------- Schmale Bildschirme ---------- */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, .55);
    z-index: 40;
}

@media (max-width: 1100px) {
    .cards.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
    .cards.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 780px) {
    .only-mobile { display: grid; }

    .sidebar {
        position: fixed;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform .18s ease;
        box-shadow: var(--shadow);
    }
    .sidebar.is-open { transform: none; }

    .topbar { padding: 14px 16px; }
    .content { padding: 18px 16px 8px; }
    .footer { padding-left: 16px; padding-right: 16px; }

    .cards.two, .cards.three, .grid, .grid3, .grid-port { grid-template-columns: 1fr; }
    .card > .table-wrap { margin: 0 -16px -20px; padding: 0 16px 20px; }
    .card { padding: 18px 16px; }
    .stat-value { font-size: 22px; }
}

@media (max-width: 640px) {
    dl { grid-template-columns: 1fr; gap: 2px; }
    dd { margin-bottom: 10px; }
}

@media (max-width: 480px) {
    .cards.four { grid-template-columns: 1fr; }
}

@media print {
    .sidebar, .topbar-actions, .filter-row, .btn, button, .footer { display: none !important; }
    .topbar { position: static; }
    .card { box-shadow: none; }
}
