/* GRUNDLAGEN: Farben, Schrift und allgemeine Regeln ========================================= */
/* Farben und Rundungen koennen hier zentral angepasst werden. */

:root {
    --header: #494b8f;
    --toolbar: #c8c9e7;
    --panel: #e7e7f0;
    --surface: #f8f8ff;
    --accent: #625bd6;
    --text: #17171d;
    --danger: #b63f4a;
    --success: #2f9e61;
    --radius: 22px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    overflow-x: hidden;
    background-color: #ffffff;
    color: var(--text);
    font-family: Arial, sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(98, 91, 214, 0.45);
    outline-offset: 2px;
}


/* HEADER: Obere violette Leiste mit Logo und Titel ========================================= */

header {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 116px;
    padding: 16px 88px;
    background-color: var(--header);
    color: white;
}

#header-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
}

#header-brand img {
    width: 70px;
    height: 70px;
    object-fit: contain;
}

header h1 {
    margin: 0;
    font-family: "BriceSemiExpanded", "Arial Black", sans-serif;
    font-size: 48px;
    font-weight: 400;
    line-height: 1;
}

.icon-button {
    display: grid;
    place-items: center;
    border: none;
    background: transparent;
}

/* TOOLBAR: Leiste fuer Profile, Tastaturtyp, Verbindung und Senden ========================================= */

#toolbar {
    position: relative;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 18px;
    width: min(1220px, 88%);
    margin: 36px auto 0;
    padding: 16px 28px;
    border-radius: var(--radius);
    background-color: var(--toolbar);
}

.toolbar-menu {
    position: relative;
}

.toolbar-menu-title,
#toolbar button {
    border: none;
    border-radius: 18px;
    padding: 12px 24px;
    background-color: var(--surface);
}

.toolbar-menu-title {
    white-space: nowrap;
}

.toolbar-menu:hover,
.toolbar-menu:focus-within {
    z-index: 30;
}

.toolbar-options {
    position: absolute;
    top: 100%;
    left: 0;
    display: none;
    gap: 10px;
    min-width: 250px;
    padding: 14px;
    border: 1px solid #4a4a54;
    border-radius: 18px;
    background-color: var(--panel);
    box-shadow: 0 6px 16px rgba(26, 26, 42, 0.12);
}

.toolbar-options::before {
    content: "";
    position: absolute;
    top: -12px;
    left: 0;
    width: 100%;
    height: 12px;
}

.toolbar-menu:hover .toolbar-options,
.toolbar-menu:focus-within .toolbar-options {
    display: grid;
}

.toolbar-options label {
    font-size: 13px;
    font-weight: bold;
}

.toolbar-options input,
.toolbar-options select {
    width: 100%;
    border: none;
    border-radius: 13px;
    padding: 10px 12px;
    background-color: white;
}

.toolbar-options button {
    width: 100%;
}

.profile-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
}

.profile-actions button {
    min-width: 0;
    padding: 10px 7px !important;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    font-size: 14px;
}

.status-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background-color: #8a8b99;
}

.connection-status.connected .status-dot {
    background-color: var(--success);
}

.send-device-button {
    border: none !important;
    background-color: var(--accent) !important;
    color: white;
    white-space: nowrap;
}

.send-device-button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

/* TOOLBAR-AKTIONEN: Drei-Punkte-Menue und allgemeine Button-Farben ========================================= */

#toolbar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

#toolbar-actions > .icon-button,
#more-menu-button {
    width: 42px;
    height: 42px;
    padding: 0;
    background-color: transparent;
    font-size: 25px;
}

#more-menu-wrapper {
    position: relative;
}

#more-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 50;
    display: grid;
    min-width: 240px;
    overflow: hidden;
    border: 1px solid #d4d5df;
    border-radius: 14px;
    background-color: white;
    box-shadow: 0 6px 16px rgba(26, 26, 42, 0.14);
}

#more-menu[hidden] {
    display: none;
}

#more-menu button {
    width: 100%;
    border-radius: 0;
    padding: 12px 16px;
    background-color: white;
    text-align: left;
}

#more-menu button:hover {
    background-color: var(--surface);
}

#more-menu .danger-menu-item {
    color: var(--danger);
}

.primary-button {
    background-color: var(--accent) !important;
    color: white;
}

.danger-button {
    background-color: #fff0f1 !important;
    color: var(--danger);
}

/* CREATOR-LAYOUT: Ordnet Tastenfeld und Aktionsbereich nebeneinander an ========================================= */

#creator-layout {
    display: grid;
    grid-template-columns: minmax(390px, 1fr) minmax(390px, 1fr);
    align-items: start;
    gap: 42px;
    width: min(1060px, 88%);
    margin: 36px auto 48px;
}

#creator-layout > * {
    min-width: 0;
}


/* TASTENFELD: Aussehen der 3x3 Shortcut-Tasten ========================================= */

#keyboard-preview {
    display: grid;
    grid-template-columns: repeat(3, 90px);
    justify-content: center;
    gap: 50px;
    width: 100%;
    padding: 45px;
    border-radius: var(--radius);
    background-color: var(--panel);
}

.shortcut-key {
    position: relative;
    display: grid;
    place-items: center;
    width: 90px;
    height: 90px;
    overflow: hidden;
    border: none;
    border-radius: 24px;
    background-color: var(--surface);
    font-size: 38px;
}

.key-number {
    position: absolute;
    top: 6px;
    left: 8px;
    color: #777887;
    font-size: 10px;
    font-weight: bold;
}

.key-content {
    display: grid;
    place-items: center;
    gap: 3px;
    max-width: 100%;
}

.key-icon {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    overflow: hidden;
    border-radius: 8px;
    color: white;
    font-size: 18px;
    font-weight: bold;
}

.key-label {
    width: 72px;
    overflow: hidden;
    font-size: 11px;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.remove-key {
    position: absolute;
    top: 5px;
    right: 5px;
    display: none;
    place-items: center;
    width: 21px;
    height: 21px;
    border-radius: 50%;
    background-color: rgba(182, 63, 74, 0.95);
    color: white;
    font-size: 14px;
}

.shortcut-key.assigned:hover .remove-key,
.shortcut-key.assigned:focus-visible .remove-key {
    display: grid;
}

.shortcut-key.locked {
    background-color: #c9cad2 !important;
    color: #71727c;
    cursor: not-allowed;
    opacity: 0.72;
}

.shortcut-key.drag-over {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}


/* AKTIONEN: Rechter Bereich mit Suche, Kategorien und Aktionsliste ========================================= */

#actions-panel {
    width: 100%;
    min-height: 500px;
    padding: 24px;
    border-radius: var(--radius);
    background-color: var(--panel);
}

#actions-panel h2 {
    margin: 0 0 14px;
    font-size: 28px;
    font-weight: normal;
}

.actions-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.actions-heading h2 {
    margin-bottom: 0;
}

.add-action-button {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 50%;
    background-color: var(--accent);
    color: white;
    font-size: 25px;
}

#usage-hint {
    margin: 6px 0 16px;
    color: #666775;
    font-size: 13px;
}

#search-box {
    display: block;
}

#search-box input {
    min-width: 0;
    border: none;
    border-radius: 18px;
    padding: 14px 18px;
    background-color: var(--surface);
}

#shortcut-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    margin: 18px 0;
}

#shortcut-categories button {
    border: none;
    border-radius: 20px;
    padding: 9px 14px;
    background-color: white;
}

#shortcut-categories button.active {
    background-color: var(--toolbar);
}

#shortcut-list {
    display: grid;
    gap: 12px;
}

.action-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 52px;
    padding: 8px 12px 8px 18px;
    border: none;
    border-radius: 20px;
    background-color: white;
    text-align: left;
}

.execution-mode-badge {
    border-radius: 10px;
    padding: 4px 7px;
    background-color: #e9e9f5;
    color: #4b4c5b;
    font-size: 10px;
    font-weight: bold;
    white-space: nowrap;
}

.execution-mode-badge.fallback {
    background-color: #fff0d8;
    color: #7a4b00;
}

.action-item.selected-action {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.action-item.dragging {
    opacity: 0.5;
}

.action-icon {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    overflow: hidden;
    border-radius: 9px;
    color: white;
    font-weight: bold;
}

.edit-action-button {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background-color: var(--surface);
}

.empty-list {
    margin: 24px 0;
    color: #666775;
    text-align: center;
}


/* DIALOG: Popup zum Bearbeiten oder Erstellen einer Aktion ========================================= */

#action-dialog {
    width: min(620px, calc(100% - 32px));
    max-height: calc(100vh - 32px);
    overflow: auto;
    border: none;
    border-radius: 18px;
    padding: 0;
    box-shadow: 0 10px 28px rgba(19, 19, 32, 0.22);
}

#action-dialog::backdrop,
#help-dialog::backdrop {
    background-color: rgba(26, 26, 42, 0.48);
}

#action-form {
    padding: 24px;
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.dialog-header h2 {
    margin: 0;
}

.required-note {
    margin: -8px 0 16px;
    color: #666775;
    font-size: 12px;
}

.required-mark {
    color: var(--danger);
    font-weight: bold;
}

.optional-label {
    color: #777887;
    font-size: 11px;
    font-weight: normal;
}

.dialog-header .icon-button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--surface);
}

.form-grid {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    align-items: center;
    gap: 12px 16px;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
    width: 100%;
    border: 1px solid #d1d2dc;
    border-radius: 10px;
    padding: 10px 12px;
}

.form-grid textarea {
    resize: vertical;
}

.value-field-group {
    display: grid;
    gap: 6px;
}

.execution-mode-group {
    display: grid;
    gap: 8px;
}

.execution-mode-group[hidden] {
    display: none;
}

.mode-info {
    border-left: 3px solid #9293a0;
    border-radius: 0;
    padding: 6px 10px;
    background-color: transparent;
    color: #555665;
    font-size: 12px;
    line-height: 1.45;
}

.mode-info.fallback {
    border-left-color: #9293a0;
    background-color: transparent;
    color: #555665;
}

.form-grid .field-error {
    border-color: var(--danger);
    background-color: #fff5f6;
    box-shadow: 0 0 0 2px rgba(182, 63, 74, 0.14);
}

.editor-key-preview {
    display: grid;
    place-items: center;
    gap: 5px;
    width: 94px;
    height: 94px;
    overflow: hidden;
    border-radius: 22px;
    background-color: #625bd6;
    color: white;
}

#key-preview-icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    overflow: hidden;
    border-radius: 9px;
    background-color: rgba(255, 255, 255, 0.2);
    font-size: 20px;
    font-weight: bold;
}

#key-preview-name {
    width: 80px;
    overflow: hidden;
    font-size: 11px;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#action-color {
    width: 72px;
    height: 42px;
    padding: 3px;
}

.error-message {
    min-height: 20px;
    margin: 12px 0 0;
    color: var(--danger);
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.dialog-actions button {
    border: none;
    border-radius: 12px;
    padding: 10px 16px;
}

/* HILFE: Popup mit kurzer Bedienungsanleitung ========================================= */

#help-dialog {
    width: min(680px, calc(100% - 32px));
    max-height: calc(100vh - 32px);
    overflow: auto;
    border: none;
    border-radius: 18px;
    padding: 0;
    box-shadow: 0 10px 28px rgba(19, 19, 32, 0.22);
}

.help-panel {
    padding: 24px;
}

.help-step {
    padding: 13px 0;
    border-top: 1px solid #e1e2ea;
}

.help-step h3,
.help-step p {
    margin: 0;
}

.help-step h3 {
    margin-bottom: 5px;
    font-size: 16px;
}

.help-step p {
    color: #555665;
    line-height: 1.45;
}


/* TOAST: Kleine Meldung unten rechts ========================================= */

#toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 100;
    max-width: min(360px, calc(100% - 40px));
    padding: 12px 16px;
    border-radius: 12px;
    background-color: #232338;
    color: white;
    opacity: 0;
    pointer-events: none;
}

#toast.visible {
    opacity: 1;
}

#toast.error {
    background-color: var(--danger);
}


/* RESPONSIVE: Anpassungen fuer kleinere Bildschirme ========================================= */

@media (max-width: 980px) {
    #toolbar {
        flex-wrap: wrap;
    }

    .connection-status {
        width: calc(100% - 72px);
        margin-left: 0;
    }

    #creator-layout {
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        width: 92%;
    }

    #keyboard-preview {
        grid-template-columns: repeat(3, 68px);
        gap: 22px;
        padding: 30px;
    }

    .shortcut-key {
        width: 68px;
        height: 68px;
    }
}

@media (max-width: 720px) {
    header {
        min-height: 96px;
        padding: 14px 16px;
    }

    #header-brand {
        min-width: 0;
        max-width: 100%;
    }

    #header-brand img {
        width: 44px;
        height: 44px;
        flex: 0 0 44px;
    }

    header h1 {
        min-width: 0;
        overflow: hidden;
        font-size: 26px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #toolbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 12px 8px;
        width: calc(100% - 40px);
        padding: 16px;
    }

    .toolbar-menu,
    .toolbar-menu-title {
        width: 100%;
    }

    .toolbar-menu {
        grid-column: 1 / -1;
    }

    .toolbar-command {
        grid-column: 1 / -1;
        width: 100%;
    }

    .toolbar-options {
        position: static;
        margin-top: 8px;
    }

    .connection-status {
        grid-column: 1 / -1;
        width: auto;
        min-width: 0;
        margin-left: 0;
        font-size: 12px;
    }

    .send-device-button {
        grid-column: 1 / -1;
        min-width: 0;
        padding-inline: 12px !important;
    }

    #toolbar-actions {
        grid-column: 1 / -1;
        justify-self: end;
        justify-content: flex-end;
    }

    #toolbar-actions {
        margin-left: 0;
    }

    #toolbar-actions > .icon-button,
    #more-menu-button {
        width: 34px;
        height: 34px;
        font-size: 22px;
    }

    #creator-layout {
        grid-template-columns: 1fr;
        width: calc(100% - 32px);
    }

    #keyboard-preview {
        grid-template-columns: repeat(3, 76px);
        gap: 24px;
    }

    .shortcut-key {
        width: 76px;
        height: 76px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .dialog-actions {
        flex-wrap: wrap;
    }

    .dialog-actions button {
        flex: 1;
    }
}

@media (max-width: 390px) {
    header h1 {
        font-size: 23px;
    }

    #keyboard-preview {
        grid-template-columns: repeat(3, 64px);
        gap: 15px;
        padding: 22px;
    }

    .shortcut-key {
        width: 64px;
        height: 64px;
    }
}
