:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success-bg: #ecfdf5;
    --success: #065f46;
    --error-bg: #fef2f2;
    --own: #f59e0b;
    --radius: 10px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111827;
        --surface: #1f2937;
        --text: #f3f4f6;
        --muted: #9ca3af;
        --border: #374151;
        --primary: #3b82f6;
        --primary-dark: #2563eb;
        --success-bg: #064e3b;
        --success: #d1fae5;
        --error-bg: #450a0a;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.2rem; margin: 0 0 .75rem; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* Kopf- und Fußzeile */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .6rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; }

.footer {
    display: flex;
    gap: 1rem;
    justify-content: center;
    padding: .75rem 1rem;
    font-size: .85rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.footer a { color: var(--muted); }

/* Inhalt */
.page { width: 100%; max-width: 960px; margin: 0 auto; padding: 1.5rem 1rem; flex: 1; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
}
.card.narrow { max-width: 460px; margin: 2rem auto; }
.danger-zone { border-color: var(--danger); }
.prose { max-width: 760px; margin: 0 auto; }
.prose h2 { margin-top: 1.5rem; }

.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error { background: var(--error-bg); color: var(--danger); }

/* Formulare */
.field { margin-bottom: 1rem; position: relative; }
.field > label, .field legend { display: block; font-weight: 600; margin-bottom: .3rem; }
.field input[type=text], .field input[type=email], .field input[type=password], .field input[type=search] {
    width: 100%;
    padding: .55rem .7rem;
    font: inherit;
    color: inherit;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.field input:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.field.checkbox { display: flex; gap: .5rem; align-items: flex-start; flex-wrap: wrap; }
.field.checkbox > label { font-weight: normal; flex: 1; margin: 0; }
.field.checkbox input { margin-top: .3rem; }
.field.checkbox .errors { flex-basis: 100%; }
.field fieldset, .field > div[id] { border: 0; padding: 0; margin: 0; }
.field div:has(> input[type=radio]) { display: grid; grid-template-columns: auto 1fr; gap: .35rem .5rem; align-items: center; }
.field input[type=radio] + label { font-weight: normal; margin: 0; }
.field input[type=radio] { margin: 0; }
.help { display: block; color: var(--muted); font-size: .85rem; margin-top: .25rem; }
.errors { color: var(--danger); margin: .3rem 0 0; padding-left: 1.1rem; font-size: .9rem; }
.has-error input { border-color: var(--danger) !important; }

.btn {
    display: inline-block;
    padding: .55rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.small { padding: .3rem .6rem; font-size: .85rem; }
button.link { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: 0; }
form.inline { display: inline; }

.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table .actions { display: flex; gap: .4rem; justify-content: flex-end; }
.badge { font-size: .75rem; background: var(--primary); color: #fff; border-radius: 999px; padding: .05rem .5rem; }
.card:has(.table) { overflow-x: auto; }

/* Karte */
.map-layout {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 360px;
    min-height: 0;
}
.map-layout > .flash { grid-column: 1 / -1; margin: .75rem 1rem 0; }
#map { min-height: 400px; height: 100%; z-index: 0; }
.panel {
    background: var(--surface);
    border-left: 1px solid var(--border);
    padding: 1.25rem;
    overflow-y: auto;
}
.panel .current { background: var(--bg); padding: .6rem .8rem; border-radius: 8px; }
.delete-pin { margin-top: .75rem; }

body.map-page { height: 100vh; }
body.map-page .map-layout { height: 100%; }

@media (max-width: 800px) {
    .map-layout { grid-template-columns: 1fr; grid-template-rows: auto 60vh auto; }
    #map { height: 60vh; }
    .panel { border-left: 0; border-top: 1px solid var(--border); }
    body.map-page { height: auto; }
}

.suggestions {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 10;
    list-style: none;
    margin: .25rem 0 0;
    padding: .25rem 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgb(0 0 0 / .15);
    max-height: 18rem;
    overflow-y: auto;
}
.suggestions li { padding: .45rem .75rem; cursor: pointer; }
.suggestions li[aria-selected=true], .suggestions li:hover { background: var(--primary); color: #fff; }
.suggestions li.empty { color: var(--muted); cursor: default; background: none; }

.leaflet-marker-icon.pin-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: .85rem;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgb(0 0 0 / .35);
}
.pin-icon.own { background: var(--own); }
.preview-marker { stroke: var(--own); fill: var(--own); fill-opacity: .4; }
.leaflet-popup-content ul { margin: .4rem 0 0; padding-left: 1.1rem; max-height: 12rem; overflow-y: auto; }
.leaflet-container { font: inherit; }

/* Zwei-Faktor-Anmeldung */
.steps { padding-left: 1.2rem; }
.steps > li { margin-bottom: 1.25rem; }
.qr { display: block; margin: .75rem 0; background: #fff; border-radius: 8px; }
.secret { display: inline-block; margin-top: .4rem; font-size: 1.05rem; letter-spacing: .05em; word-break: break-all; }
.backup-codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; margin: 1rem 0 1.5rem; }
.backup-codes code { display: block; padding: .4rem .6rem; background: var(--bg); border-radius: 6px; text-align: center; font-size: 1.05rem; }
.cancel-2fa { margin-top: 1rem; }
