/* Grundlegende Sektion-Styles */
.keybinds-section {
    padding: 0;
    background-color: #071c33;
    text-align: center;
}
.keybinds-section h3 {
    font-size: 2rem;
    margin-bottom: 40px;
    color: #fff;
}

/* Filter-Bereich */
.keybind-filters {
    margin-bottom: 30px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    align-items: center;
    color: #f5f5f5;
    background-color: #0f3057;
    padding: 15px 20px;
    border-radius: 8px;
    max-width: 800px;
    margin: 0 auto 30px auto;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}
.keybind-filters label {
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 5px;
}
.keybind-filters select,
.keybind-filters input[type="checkbox"] {
    padding: 8px 12px;
    border-radius: 5px;
    background-color: #0d2a4a;
    color: #f5f5f5;
    border: 1px solid #00aaff;
    font-size: 1em;
    cursor: pointer;
}
.keybind-filters input[type="checkbox"] {
    appearance: none;
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    border: 2px solid #00aaff;
    background-color: #1a3c66;
    border-radius: 4px;
    position: relative;
    vertical-align: middle;
}
.keybind-filters input[type="checkbox"]:checked {
    background-color: #00aaff;
    border-color: #00aaff;
}
.keybind-filters input[type="checkbox"]:checked::after {
    content: '✔';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #0a192f;
    font-size: 14px;
    font-weight: bold;
}
.keybind-filters select:focus,
.keybind-filters input[type="checkbox"]:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 170, 255, 0.5);
}


/* Tastatur-Layout Container (der äußerste blaue Kasten) */
.keyboard-layout {
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Oben ausrichten */
    min-height: 300px;
    position: relative;
    padding: 15px;
    overflow: hidden; /* Für Lade-Nachricht-Überlagerung */
    background-color: #1a3c66;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.5);
    max-width: 1450px; /* ANGEPASST: Startwert für Gesamtbreite der Tastatur */
    margin: 0 auto;
}

/* Lade-Meldungen müssen das ganze Layout überspannen */
.keyboard-layout .loading-message,
.keyboard-layout .error-message,
.keyboard-layout .no-results-message {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(26, 60, 102, 0.9);
    color: #ccc;
    padding: 0;
    text-align: center;
    border-radius: 10px;
    z-index: 1000;
}
.keyboard-layout .error-message { color: #ff6666; }

/* Basis für die gesamte Tastatur (der innere blaue Kasten, der Main, Right und Numpad enthält) */
.keyboard {
    display: flex;
    /*gap: 15px; */ /* Wir steuern Abstände zwischen Blöcken jetzt manuell mit Margin/Spacer */
    padding: 0;
    width: 100%;
    flex-wrap: nowrap; /* WICHTIG: Verhindert Umbruch des Numpads auf Desktop */
    justify-content: flex-start; /* Beginnt am linken Rand */
    align-items: flex-start; /* Blöcke oben ausrichten */
    transition: opacity 0.5s ease-in-out;
}

.main-block {
    display: flex;
    flex-direction: column;
    gap: 7px; /* Abstand zwischen Reihen */
    flex-shrink: 0;
    /* Breite des Main-Blocks, angepasst, um die Lücken wie im Bild zu ergeben */
    /* Dies ist eine Schätzung und muss feinjustiert werden */
    min-width: calc(14 * 48px + 12 * 7px + 15px); /* 14 Tasten + 12 Gaps + ca. 15px für die rechte Lücke der ASDF-Reihe */
    /* Der rechte Teil der A-Reihe im Bild hat eine sichtbare Lücke, die nicht von einer Taste gefüllt wird. */
    /* Wir müssen min-width des main-block so setzen, dass er diese Lücke beinhaltet. */
}

.right-blocks {
    display: flex;
    flex-direction: column;
    gap: 7px; /* Abstand zwischen oberen (Druck) und unteren (Nav/Arrow) Blöcken */
    flex-shrink: 0;
    /* Dies ist die Breite für die 3er-Tastenblöcke (Druck/Einfg/Pfeile) */
    width: calc(3 * 48px + 2 * 7px);
    margin-left: 20px; /* ANGEPASST: Abstand zum Main-Block */
}

.nav-and-arrow-block {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-top: calc(48px + 7px); /* ANGEPASST: Sitzt eine Reihe unter dem Druck/Rollen/Pause Block */
    /* Höhe einer Taste + Gap */
}

.numpad-block {
    display: flex;
    flex-direction: column;
    gap: 7px; /* Abstand zwischen Reihen */
    flex-shrink: 0;
    /* Numpad-Breite. 4 Tasten + 3 Gaps */
    width: calc(4 * 48px + 3 * 7px);
    margin-left: 80px; /* ANGEPASST: Abstand zum right-blocks Bereich */
}


.row {
    display: flex;
    gap: 7px; /* Abstand zwischen Tasten in einer Reihe */
    position: relative;
    align-items: flex-start;
    flex-wrap: nowrap; /* Tasten in der Reihe brechen nicht um (Desktop) */
}

/* Basis-Stil für jede Taste */
.key {
    background: #0f3057;
    color: #f5f5f5;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    font-weight: bold;
    height: 48px; /* Standardhöhe für Tasten */
    min-width: 48px; /* Standardbreite für Tasten (quadratisch) */
    border: 1px solid #00aaff;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    cursor: default;
    user-select: none;
    position: relative;
    text-transform: uppercase;
    overflow: hidden;
    padding: 0 2px;
    box-sizing: border-box;
    flex-shrink: 0;
    flex-grow: 0;
}

/* Spezial-Breiten für Tasten - ABGLEICH MIT BILD */
.key.wide { min-width: 76px; } /* ^ Taste */
.key.wide-backspace { min-width: calc(2.25 * 48px + 2 * 7px); } /* Backspace */
.key.wide-tab { min-width: 76px; } /* Tab */
.key.wide-caps { min-width: 90px; } /* Capslock */
.key.wide-shift-left { min-width: calc(2.25 * 48px + 2 * 7px); } /* Linker Shift */
.key.wide-shift-right { min-width: calc(3.25 * 48px + 3 * 7px); } /* Rechter Shift */
.key.space { min-width: calc(7.5 * 48px + 7 * 7px); } /* Leertaste - sehr breit */

/* STRG, WIN, ALT Tasten in der untersten Reihe haben die gleiche Breite */
.key.ctrl-alt-win {
    min-width: 60px; /* Einheitliche Breite, wie im Bild */
}

/* Haupt-Enter Taste (breit, nicht hoch, im Fluss) */
.key.main-enter-row-3 {
    min-width: calc(2.75 * 48px + 2 * 7px); /* ca. 2.75 Tasten + 2 Gaps, wie im Bild sehr breit */
    height: 48px; /* Standardhöhe */
    flex-grow: 1; /* Nimmt restlichen Platz ein */
}


/* Spacer für Abstände - angepasste Breiten */
.spacer-f1-block { min-width: 20px; } /* Spacer nach Esc */
.spacer-f-group { min-width: 15px; } /* Spacer in F-Reihe */

/* Pfeiltasten-Reihen in nav-and-arrow-block */
.nav-and-arrow-block .arrow-block-row {
    margin-top: 15px; /* Abstand zum oberen Nav-Block */
    justify-content: center; /* Pfeile zentrieren sich */
}
.nav-and-arrow-block .arrow-block-row .key {
    min-width: 48px; /* Standardbreite für Pfeile */
    height: 48px;
    font-size: 1.1rem;
}


/* Numpad Spezifische Breiten/Höhen */
.numpad-block .key { min-width: 48px; } /* Nummernblock-Tasten sind Standardbreite */

.key.num-tall-plus { /* Nummernblock '+' */
    height: calc(48px + 7px); /* 2 Reihen + 1 Gap */
    align-self: flex-start;
}
.key.num-tall-enter { /* Nummernblock 'Enter' */
    height: calc(48px + 7px); /* 2 Reihen + 1 Gap */
    align-self: flex-start;
}
.key.num-wide-zero { /* Nummernblock '0' */
    min-width: calc(2 * 48px + 7px); /* 2 Tastenbreiten + 1 Gap */
}


/* Sekundäre Beschriftungen */
.key span.sub-key-text {
    font-size: 0.7em;
    opacity: 0.7;
    text-transform: none;
    position: absolute;
    bottom: 3px;
    right: 3px;
    line-height: 1;
}
.key span.top-left-sub {
    position: absolute;
    top: 3px;
    left: 3px;
    font-size: 0.7em;
    opacity: 0.7;
    line-height: 1;
}

/* Hover und Filter Effekte (bleiben gleich) */
.key.has-bind {
    cursor: help;
    background-color: rgba(0, 170, 255, 0.2);
    border-color: #00aaff;
}
.key.has-bind:hover {
    background-color: #00aaff;
    color: #0a192f;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 170, 255, 0.4);
}
.key.active-filter-bind {
    background-color: #00e6e6;
    color: #0a192f;
    box-shadow: 0 0 15px rgba(0, 230, 230, 0.6);
}
.key.active-filter-bind:hover {
    background-color: #00ffff;
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.8);
}


/* Keybind-Info-Bubble (bleibt gleich) */
.keybind-info-bubble {
    display: none;
    position: fixed;
    background-color: rgba(0, 0, 0, 0.9);
    color: #f5f5f5;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.6);
    z-index: 2000;
    white-space: normal;
    /* max-width und transform werden jetzt durch JS gesetzt für zentrale Positionierung */
    max-width: 90vw; /* Standard max width, kann durch JS überschrieben werden */
    max-height: 90vh; /* Standard max height, kann durch JS überschrieben werden */
    text-align: left;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    backdrop-filter: blur(3px);
}
.keybind-info-bubble.show {
    display: block;
    opacity: 1;
}
.keybind-info-bubble h4 {
    margin: 0 0 8px 0;
    color: #00aaff;
    font-size: 1.2em;
    text-transform: uppercase;
    text-align: center; /* Titel zentrieren */
    margin-bottom: 20px;
}
.keybind-info-bubble .keybind-detail-entry {
    /* Diese Regeln werden jetzt weitestgehend vom .keybind-forms-wrapper und .keybind-detail-entry im Admin-Modus überschrieben */
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px dashed rgba(255,255,255,0.2);
}
.keybind-info-bubble .keybind-detail-entry:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}
.keybind-info-bubble .keybind-context {
    font-weight: bold;
    color: #00ffff;
    font-size: 0.9em;
    margin-bottom: 3px;
    display: block;
}
.keybind-info-bubble p {
    margin: 0;
    font-size: 0.95em;
    color: #ccc;
    line-height: 1.4;
}
.keybind-info-bubble .category-tag {
    display: inline-block;
    background-color: #00aaff;
    color: #0a192f;
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 0.75em;
    font-weight: bold;
    margin-top: 5px;
    margin-right: 5px;
    white-space: nowrap;
}

/* Responsivität */
@media (max-width: 1080px) { /* Passt sich an, wenn der Platz für alle Blöcke nebeneinander zu gering wird */
    .keyboard {
        flex-direction: column; /* Stapelt Hauptblock und rechte Blöcke */
        gap: 10px;
        align-items: center; /* Zentriert die gestapelten Blöcke */
    }
    .main-block, .right-blocks, .numpad-block { /* Alle Top-Level-Blöcke werden vertikal gestapelt */
        width: 100%;
        min-width: unset;
        flex-basis: auto;
    }
    .right-blocks { /* Wenn sie gestapelt sind, müssen sie nebeneinander gehen */
        flex-direction: row; /* Nav- und Numpad-Block nebeneinander auf Mobile */
        justify-content: center; /* Zentriert die beiden Blöcke */
        flex-wrap: wrap; /* Erlaubt Umbruch, falls der Bildschirm zu schmal wird */
    }
    .nav-and-arrow-block { /* Navigations- und Pfeil-Block auf Mobil */
        margin-top: 0; /* Kein spezieller Margin-Top mehr, da gestapelt */
        width: calc(3 * 35px + 2 * 4px); /* Angepasst an mobile Tasten */
    }
    .nav-and-arrow-block .arrow-block-row { /* Pfeiltasten-Reihen auf Mobil */
        margin-top: 4px; /* Kleiner Abstand auf Mobil */
    }


    .row {
        flex-wrap: wrap; /* Tasten können umbrechen */
        justify-content: center;
        align-items: flex-start;
        gap: 4px; /* Kleinerer Gap auf Mobil */
    }
    .key {
        min-width: 35px;
        height: 35px;
        font-size: 0.8rem;
        flex-grow: 1; /* Tasten können wachsen, um Platz zu füllen */
        flex-shrink: 1; /* Und schrumpfen, wenn nötig */
    }
    /* Spezial-Breiten auf Mobil zurücksetzen/anpassen */
    .key.wide, .key.wide-backspace, .key.wide-tab, .key.wide-caps,
    .key.wide-shift-left, .key.wide-shift-right, .key.space,
    .key.ctrl-alt-win, .key.main-enter-row-3 { /* main-enter-row-3 auch flexibel machen */
        min-width: unset;
        width: auto;
        flex-grow: 1;
    }
    /* Vertikale Tasten auf Mobile */
    .key.num-tall-plus, .key.num-tall-enter {
        height: calc(2 * 35px + 4px); /* Angepasst an mobile Höhe und Gap */
    }
    .key.num-wide-zero {
        min-width: calc(2 * 35px + 4px); /* 2 Mobile-Tasten + Gap */
    }

    /* Spacer auf Mobil ausblenden */
    .spacer-f1-block, .spacer-f-group {
        display: none;
    }

    /* Info-Bubble auf Mobil-Geräten bleibt unten, wenn nicht zentriert */
    /* Die JS-Logik für zentrales Öffnen sollte diese @media überschreiben */
    /* Wenn du NUR ZENTRIERT willst, auch auf Mobil, kann dieser Block weg */
    .keybind-info-bubble {
        /* max-width: 90%; */ /* Entfernt, da flex-item widths now manage overall width */
        /* left: 50% !important; */
        /* top: auto !important; */
        /* bottom: 10px; */
        /* transform: translate(-50%, 0) !important; */
        /* background-color: rgba(0, 0, 0, 0.95); */
        /* box-shadow: 0 0 15px rgba(0,0,0,0.7); */
    }
}

@media (max-width: 600px) {
    .keybinds-section h3 {
        font-size: 1.8rem;
    }
    .keybind-filters {
        flex-direction: column;
        align-items: flex-start;
        padding: 10px;
    }
    .keybind-info-bubble h4 {
        font-size: 1.1em;
    }
    .keybind-info-bubble p {
        font-size: 0.9em;
    }
}

/* Neue CSS-Regeln für Admin-Modus */
.admin-mode-active .key.active-filter-bind {
    cursor: pointer !important; /* Zeigt an, dass man draufklicken kann zum Bearbeiten */
    border-color: #ffcc00; /* Admin-Farbe */
    box-shadow: 0 0 8px rgba(255, 204, 0, 0.5);
}

.admin-mode-active .key.active-filter-bind:hover {
    background-color: #ffcc00;
    color: #0a192f;
    box-shadow: 0 0 15px rgba(255, 204, 0, 0.8);
}

/* Neuer Container für die Edit-Formulare, um sie nebeneinander anzuordnen */
.keybind-forms-wrapper {
    display: flex;
    flex-wrap: wrap; /* Erlaubt den Umbruch auf kleinere Bildschirme */
    gap: 15px; /* Abstand zwischen den einzelnen Formularen */
    justify-content: center; /* Zentriert die Formulare im Wrapper */
    align-items: flex-start; /* Formulare oben ausrichten, falls sie unterschiedliche Höhen haben */
    padding: 10px 0; /* Etwas Innenabstand */
    max-height: 70vh; /* Optional: Maximale Höhe setzen, damit Inhalt scrollbar wird */
    overflow-y: auto; /* Optional: Scrollbar, wenn Inhalt zu lang wird */
    -webkit-overflow-scrolling: touch; /* Für flüssiges Scrolling auf iOS */
}

/* Anpassungen für die einzelnen Formular-Einträge */
.keybind-info-bubble .keybind-detail-entry {
    /* Setze eine Basisbreite für jeden Formular-Eintrag, um sie nebeneinander zu ermöglichen */
    flex: 1 1 calc(50% - 15px); /* Zwei Spalten: 50% Breite minus die Hälfte des Gaps */
    min-width: 300px; /* Mindestbreite, damit Formular nicht zu schmal wird */
    max-width: 450px; /* Maximale Breite, um nicht zu breit zu werden */
    background-color: rgba(0, 0, 0, 0.7); /* Hintergrund für jeden Eintrag */
    border: 1px solid rgba(0, 170, 255, 0.2); /* Kleiner Rahmen */
    border-radius: 8px;
    padding: 15px;
    box-sizing: border-box; /* Wichtig für die Breitenberechnung */
    margin-bottom: 0; /* Entferne standardmäßigen margin-bottom */
    /* Remove the dashed border, it's now per form if desired */
    border-bottom: none;
    padding-bottom: 0;
}
/* Wenn nur ein Eintrag, volle Breite */
.keybind-forms-wrapper .keybind-detail-entry:only-child {
    flex: 1 1 100%; /* Nimmt die volle Breite ein */
    max-width: 600px; /* Oder eine andere maximale Breite für Einzeleinträge */
}

/* Anpassungen für Formulare selbst innerhalb der Detail-Einträge */
.keybind-info-bubble .keybind-edit-form {
    padding: 0; /* Kein Padding, da der .keybind-detail-entry Container es hat */
    border-bottom: none; /* Keine Linie mehr zwischen Forms im Flex-Layout */
    margin-bottom: 0;
}

/* Style für die "Löschen" und "Neue Belegung hinzufügen" Buttons */
.keybind-info-bubble .admin-controls {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.3);
    text-align: right;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Spezifische Controls für Löschen in jedem Formular-Eintrag */
.keybind-detail-entry .admin-controls.keybind-specific-controls {
    margin-top: 15px; /* Abstand zum Formularinhalt */
    padding-top: 10px;
    border-top: 1px dashed rgba(255,255,255,0.2); /* Trennlinie zum Löschen-Button */
}
/* Die "Neue Belegung hinzufügen"-Schaltfläche */
.keybind-info-bubble .admin-controls.general-controls {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid rgba(255,255,255,0.3);
    justify-content: center; /* Zentriert den "Neue Belegung hinzufügen" Button */
}

/* Anpassung der Breite der Formularfelder */
.keybind-edit-form input[type="text"],
.keybind-edit-form textarea,
.keybind-edit-form select {
    width: 100%; /* Volle Breite im Container */
    padding: 8px 10px;
    margin-bottom: 10px;
    border-radius: 5px;
    border: 1px solid #00aaff;
    background-color: #0d2a4a;
    color: #f5f5f5;
    font-size: 0.9em;
    box-sizing: border-box;
}

/* Medien-Query für kleinere Bildschirme: stapelt die Formulare */
@media (max-width: 768px) {
    .keybind-forms-wrapper {
        flex-direction: column; /* Spaltenlayout, Formulare untereinander */
        align-items: center; /* Zentriert die einzelnen Formulare */
    }
    .keybind-info-bubble .keybind-detail-entry {
        flex: 1 1 95%; /* Fast volle Breite, mit etwas Rand */
        max-width: 95%; /* Max Breite auch für Mobilgeräte */
    }
    .keybind-forms-wrapper .keybind-detail-entry:only-child {
        flex: 1 1 95%;
    }
}