* { box-sizing: border-box; }

/* hidden-Attribut gewinnt immer – auch gegen display:flex/inline-block usw. */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
    margin: 0;
    font-family: "Segoe UI", system-ui, sans-serif;
    background: #1e2430;
    color: #e8ecf2;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    position: relative;
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 10px 18px;
    background: #141923;
    border-bottom: 1px solid #2e3748;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }

/* Aktionen (Modus-Umschalter + An-/Abmelden). Auf dem Desktop eine Reihe,
   auf Mobilgeräten ein Dropdown hinter dem Burger-Button. */
.topbar-actions { display: flex; align-items: center; gap: 20px; }
.burger-btn { display: none; font-size: 20px; line-height: 1; padding: 6px 12px; }

.mode-switch { display: flex; gap: 8px; }
.mode-btn {
    padding: 8px 16px;
    border: 1px solid #3a4558;
    border-radius: 8px;
    background: #232b3a;
    color: #aab4c4;
    cursor: pointer;
    font-size: 14px;
}
.mode-btn.active { background: #2f6fed; color: #fff; border-color: #2f6fed; }

.tool-btn, button {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid #3a4558;
    background: #232b3a;
    color: #e8ecf2;
    cursor: pointer;
    font-size: 14px;
}
button:hover { filter: brightness(1.15); }
button.primary { background: #2f6fed; border-color: #2f6fed; color: #fff; }
button.danger { background: #b3342e; border-color: #b3342e; color: #fff; }
.tool-btn.active { background: #2f6fed; border-color: #2f6fed; color: #fff; }
.topbar h1 + .mode-switch { margin-left: 0; }

.layout {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    gap: 14px;
    padding: 14px;
    align-items: stretch;
}

.plan-wrap {
    /* Steuert Größe/Abstand der Kartenbuttons (Zoom + Suche), damit
       beide Gruppen exakt denselben lückenlosen Rhythmus haben. */
    --map-btn-size: 40px;
    --map-btn-gap: 6px;
    --map-btn-top: 16px;
    flex: 1;
    min-width: 0;
    min-height: 0;
    background: #10141c;
    border: 1px solid #2e3748;
    border-radius: 10px;
    padding: 8px;
    position: relative;
    display: flex;
}
#plan {
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    display: block;
    border-radius: 6px;
    touch-action: none;   /* Pan & Pinch selbst behandeln (Desktop) */
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

.zoom-controls {
    position: absolute;
    top: var(--map-btn-top);
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: var(--map-btn-gap);
    z-index: 7;
}
.zoom-controls button {
    width: var(--map-btn-size);
    height: var(--map-btn-size);
    padding: 0;
    font-size: 18px;
    border-radius: 10px;
    background: rgba(23, 29, 41, 0.9);
}
.plan-hint {
    position: absolute;
    left: 16px;
    bottom: 14px;
    font-size: 12px;
    color: #9fb0c8;
    background: rgba(16,20,28,.8);
    padding: 4px 10px;
    border-radius: 6px;
    pointer-events: none;
}
.plan-hint:empty { display: none; }

/* Overlay-Hinweis „Mit 2 Fingern zoomen/verschieben" (nur auf Touch-Geräten). */
.plan-pinch-hint {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(16, 20, 28, 0.86);
    color: #eef2f8;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    pointer-events: none;
    z-index: 8;
    opacity: 0;
    transition: opacity .2s ease;
    text-align: center;
    white-space: nowrap;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
}
.plan-pinch-hint.visible { opacity: 1; }

.sidebar {
    width: 320px;
    flex-shrink: 0;
    overflow-y: auto;
    max-height: 100%;
}
.sidebar.collapsed { display: none; }

/* ---- Filter (Parken) & Suche (Ansicht) ---- */
.filter-input {
    width: 100%;
    margin: 4px 0 6px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #3a4558;
    background: #101520;
    color: #e8ecf2;
    font-size: 14px;
}
.filter-input::placeholder { color: #7a879c; }

.view-search {
    position: absolute;
    /* Gleicher Rhythmus wie die 3 Zoom-Buttons darüber: gleiche Größe + Lücke */
    top: calc(var(--map-btn-top) + 3 * (var(--map-btn-size) + var(--map-btn-gap)));
    right: 16px;
    width: min(300px, calc(100% - 90px));
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}
.view-search[hidden] { display: none; }
.view-search.collapsed { width: auto; }
.view-search.collapsed input { display: none; }
.view-search.collapsed .view-search-results { display: none; }
.view-search-btn {
    width: var(--map-btn-size);
    height: var(--map-btn-size);
    padding: 0;
    font-size: 18px;
    border-radius: 10px;
    background: rgba(23, 29, 41, 0.9);
    border: 1px solid #3a4558;
    color: #e8ecf2;
    cursor: pointer;
    flex-shrink: 0;
}
.view-search-btn:hover { filter: brightness(1.15); }
.view-search:not(.collapsed) .view-search-btn { display: none; }
.view-search input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #3a4558;
    background: rgba(16, 20, 28, 0.94);
    color: #e8ecf2;
    font-size: 15px;
    box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
.view-search input::placeholder { color: #8ea0bd; }
.view-search-results {
    margin-top: 8px;
    max-height: 320px;
    overflow-y: auto;
    background: rgba(20, 26, 38, 0.97);
    border: 1px solid #2e3748;
    border-radius: 10px;
    padding: 8px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 12px 30px rgba(0,0,0,.45);
}
.panel {
    background: #171d29;
    border: 1px solid #2e3748;
    border-radius: 10px;
    padding: 14px;
}
.panel h2 { margin: 0 0 10px; font-size: 16px; }
.panel h3 { margin: 16px 0 6px; font-size: 13px; color: #9fb0c8; text-transform: uppercase; letter-spacing: .5px; }
.hint { font-size: 12px; color: #8593a8; margin: 8px 0; }
.unit { color: #8593a8; font-weight: normal; font-size: 11px; }

label { display: block; font-size: 13px; margin: 8px 0; font-weight: 600; }
label input {
    display: block;
    width: 100%;
    margin-top: 3px;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid #3a4558;
    background: #101520;
    color: #e8ecf2;
    font-size: 14px;
}
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-stack { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.btn-stack > button { width: 100%; }

/* ---- Fahrzeug-Liste ---- */
.car-list { display: flex; flex-direction: column; gap: 8px; min-height: 30px; }
.car-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: #202839;
    border: 1px solid #34405a;
    border-radius: 8px;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;   /* Ziehen per Finger ermöglichen */
}
.car-card.not-accepted { border-color: #6b2320; }
.car-card.not-accepted .cc-title::after {
    content: " 🚫";
    font-size: 11px;
}
.car-card.pending { border-color: #7a5c00; }
.car-card.pending .cc-title::after {
    content: " ⏳";
    font-size: 11px;
}
.car-card:active { cursor: grabbing; }
.car-card img {
    width: 42px; height: 42px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}
.car-card .cc-info { flex: 1; min-width: 0; }
.car-card .cc-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.car-card .cc-sub { font-size: 11px; color: #8ea0bd; }
.car-card .cc-badge {
    font-size: 11px;
    font-weight: 700;
    background: #2f6fed;
    color: #fff;
    border-radius: 6px;
    padding: 3px 7px;
    flex-shrink: 0;
}
.car-card.dragging { opacity: .45; }
.car-card.selectable { cursor: pointer; }
.car-card.selectable:hover { border-color: #2f6fed; background: #263352; }

/* ---- SVG Parkplätze ---- */
.spot {
    fill: rgba(255,255,255,0.10);
    stroke: #ffffff;
    stroke-width: 0.8;
    cursor: pointer;
}
.spot.occupied { fill: rgba(47,111,237,0.18); stroke: #7fb0ff; }
.spot.selected { stroke: #ffd23f; stroke-width: 1.4; fill: rgba(255,210,63,0.15); }
.spot.droptarget { stroke: #3ddc84; stroke-width: 1.6; fill: rgba(61,220,132,0.25); }
.spot.multi-selected { stroke: #ff6b6b; stroke-width: 1.8; fill: rgba(255,107,107,0.28); }

.spot-number {
    /* Optik kommt über SVG-Attribute (Firefox-Mindestschriftgröße!) */
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

.corner-handle {
    fill: #ffd23f;
    stroke: #7a5c00;
    cursor: move;
}
.corner-handle.dragging { opacity: 0.35; }

/* ---- Kurven-Werkzeug ---- */
.curve-line {
    fill: none;
    stroke: #ffd23f;
    stroke-width: 3;
    stroke-dasharray: 10 6;
    pointer-events: none;
}
.curve-anchor {
    fill: #3ddc84;
    stroke: #0c5c30;
    stroke-width: 1.5;
    cursor: move;
}
.curve-preview-spot {
    fill: rgba(61,220,132,0.22);
    stroke: #3ddc84;
    stroke-width: 1;
    stroke-dasharray: 4 3;
    pointer-events: none;
}
.curve-preview-label {
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}
#btnCurve.active, #btnMultiSelect.active { background: #2f6fed; border-color: #2f6fed; color: #fff; }

/* ---- Modal ---- */
.modal-backdrop[hidden], .toast[hidden], .panel[hidden], #spotProps[hidden], #curvePanel[hidden], #multiSelectPanel[hidden] { display: none; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.modal {
    position: relative;
    width: min(440px, 92vw);
    max-height: 86vh;
    overflow-y: auto;
    background: #1b2230;
    border: 1px solid #3a4558;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 18px 60px rgba(0,0,0,.5);
}
.modal-close {
    position: absolute;
    top: 10px; right: 10px;
    width: 32px; height: 32px;
    padding: 0;
    border-radius: 50%;
}
.modal h2 { margin: 0 0 2px; font-size: 20px; }
.modal .nickname { color: #8ea0bd; font-size: 13px; margin-bottom: 12px; }
.modal img.car-pic {
    width: 110px; height: 110px;
    border-radius: 10px;
    float: right;
    margin: 0 0 10px 12px;
}
.spec-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 10px 0; }
.spec-table td { padding: 4px 6px; border-bottom: 1px solid #2b3446; }
.spec-table td:first-child { color: #8ea0bd; width: 45%; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge.ok { background: #1d5c33; color: #7bf2a8; }
.badge.no { background: #6b2320; color: #ff9d97; }
.badge.wait { background: #5c4a1d; color: #f2d67b; }
.rejection-reason { font-size: 13px; color: #ff9d97; margin: 8px 0 0; }
.notes {
    white-space: pre-line;
    font-size: 13px;
    color: #c0cbdc;
    background: #141a26;
    border-radius: 8px;
    padding: 10px;
    margin: 10px 0;
    clear: both;
}
.modal .btn-row { justify-content: flex-end; }

/* ---- Login-Dialog ---- */
.login-modal { width: min(360px, 92vw); }
.login-modal h2 { margin-bottom: 4px; }
.login-modal form { margin-top: 12px; }
.login-error { color: #ff9d97; font-size: 13px; margin: 6px 0 0; }

/* ---- Ghost beim Ziehen ---- */
.ghost-card {
    position: fixed;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 6px;
    background: #2f6fed;
    color: #fff;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    pointer-events: none;
    transform: translate(-50%, -110%);
    box-shadow: 0 10px 28px rgba(0,0,0,.5);
}
.ghost-card img {
    width: 34px; height: 34px;
    border-radius: 6px;
    object-fit: cover;
}

/* ---- Sync-Status ---- */
.sync-status {
    font-size: 12px;
    color: #8ea0bd;
    margin: 0 0 8px;
}
.sync-changes {
    display: inline-block;
    margin-left: 8px;
    color: #ffd23f;
    font-weight: 700;
}
.sync-current {
    display: inline-block;
    margin-left: 8px;
    color: #7bf2a8;
    font-weight: 700;
}
.sync-btn { width: 100%; margin: 0 0 10px; }
.sync-btn:disabled { opacity: .5; cursor: default; filter: none; }

/* ---- Wartung (einklappbar) ---- */
.collapsible.maintenance-box {
    border-color: #34405a;
    background: #171d29;
}
.collapsible.maintenance-box summary { color: #9fb0c8; }
.collapsible.maintenance-box[open] summary { border-bottom-color: #34405a; }
.maintenance-body { padding: 10px; margin-top: 0; }

/* ---- Einklappbare Liste ---- */
.collapsible {
    margin-top: 16px;
    border: 1px solid #4a2a28;
    border-radius: 8px;
    background: #1d1418;
}
.collapsible.pending-box {
    border-color: #4a3f1d;
    background: #1c1810;
}
.collapsible.pending-box summary { color: #d9c79b; }
.collapsible.pending-box[open] summary { border-bottom-color: #4a3f1d; }
/* Nicht geparkt: Lime */
.collapsible.free-box {
    border-color: #3f4a1d;
    background: #171b0f;
}
.collapsible.free-box summary { color: #c4e070; }
.collapsible.free-box[open] summary { border-bottom-color: #3f4a1d; }
/* Geparkt: Grün */
.collapsible.parked-box {
    border-color: #1d4a30;
    background: #101a14;
}
.collapsible.parked-box summary { color: #7fe0a2; }
.collapsible.parked-box[open] summary { border-bottom-color: #1d4a30; }
.collapsible summary {
    cursor: pointer;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #d9a09b;
    user-select: none;
    list-style-position: inside;
}
.collapsible[open] summary { border-bottom: 1px solid #4a2a28; }
.collapsible .car-list { padding: 10px; }

/* ---- Mobil ---- */
@media (max-width: 900px) {
    .topbar {
        flex-wrap: wrap;
        gap: 10px;
        padding: 10px 12px;
    }
    .topbar { flex-wrap: nowrap; }
    .topbar h1 { font-size: 15px; flex: 1; flex-basis: auto; }
    /* Burger rechts; Aktionen klappen als Dropdown darunter auf. */
    .burger-btn { display: block; }
    .topbar-actions {
        position: absolute;
        top: 100%;
        right: 8px;
        z-index: 30;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 10px;
        background: #141923;
        border: 1px solid #2e3748;
        border-radius: 10px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
        min-width: 200px;
    }
    .topbar-actions:not(.open) { display: none; }
    .topbar-actions .mode-switch { flex-direction: column; }
    .topbar-actions .mode-btn,
    .topbar-actions .tool-btn { width: 100%; text-align: left; }
    .layout {
        flex: 0 0 auto;
        flex-direction: column;
        padding: 10px;
        gap: 10px;
        align-items: stretch;
        min-height: 0;
    }
    body { overflow-y: auto; }
    .sidebar {
        width: 100%;
        max-height: none;
        overflow-y: visible;
        flex-shrink: 0;
    }
    /* In den Bearbeitungsmodi (Parken/Parkplätze) steht das Menü über der Karte,
       damit die Bedienelemente ohne Scrollen erreichbar sind. */
    body[data-mode="park"] .sidebar,
    body[data-mode="edit"] .sidebar { order: -1; }
    .mode-btn, .tool-btn, button { padding: 10px 14px; }  /* größere Touch-Ziele */
    .plan-wrap {
        --map-btn-size: 46px;
        /* Karte füllt fast den ganzen Bildschirm — Sidebar wird per Page-Scroll erreicht. */
        flex: 0 0 auto;
        height: calc(100dvh - 84px);
        min-height: 320px;
    }
    .plan-hint { display: none; }
    /* 1 Finger = Seite scrollen, 2 Finger = Karte pan/zoom (JS). Spots/Ecken
       bleiben mit 1 Finger direkt bewegbar (siehe .spot / .corner-handle). */
    #plan { touch-action: pan-y; height: 100%; }
    .spot, .corner-handle, .curve-anchor { touch-action: none; }
    .plan-pinch-hint { display: block; }
    label input { padding: 10px; font-size: 16px; }  /* verhindert iOS-Autozoom */
}

/* ---- Toast ---- */
.toast {
    position: fixed;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%);
    background: #2f6fed;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 99;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast.error { background: #b3342e; }
