* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #2e2e2e;
    color: white;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    background-color: #1a1a1a;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #4a4a4a;
    gap: 0.75rem;
}

header h1 {
    font-size: 1.35rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.header-menu-mobile {
    display: none;
    position: relative;
}

.main-menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background-color: #1a1a1a;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    padding: 0.25rem 0;
    display: none;
    min-width: 160px;
    z-index: 1100;
}

.main-menu-dropdown.open {
    display: block;
}

.main-menu-dropdown button {
    width: 100%;
    background: none;
    border: none;
    color: white;
    text-align: left;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
}

.main-menu-dropdown button:hover {
    background-color: #333;
}

.btn {
    padding: 0.45rem 0.9rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background-color 0.2s;
}

.btn-primary {
    background-color: #4a4a4a;
    color: white;
}

.btn-primary:hover {
    background-color: #5a5a5a;
}

.btn-secondary {
    background-color: #3a3a3a;
    color: white;
}

.btn-secondary:hover {
    background-color: #4a4a4a;
}

.btn-danger {
    background-color: #d32f2f;
    color: white;
}

.btn-danger:hover {
    background-color: #c62828;
}

.btn-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tabs-container {
    background-color: transparent;
    padding: 0.5rem 0;
    flex: 1;
    min-width: 0;
    align-self: stretch;
    display: flex;
    align-items: center;
}

.tabs-list {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    flex: 1;
    min-width: 0;
}

.tab-button {
    padding: 0.5rem 1rem;
    background-color: #3a3a3a;
    color: white;
    border: none;
    border-radius: 4px 4px 0 0;
    cursor: pointer;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: background-color 0.2s;
}

.tab-button:hover {
    background-color: #4a4a4a;
}

.tab-button.active {
    background-color: #6a5acd;
    color: white;
}

.tab-content {
    flex: 1;
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 1rem 1rem;
}

.presets-toolbar {
    align-items: center;
}

.tab-brightness-group {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    margin-left: auto;
}

.tab-brightness-group label {
    white-space: nowrap;
    font-size: 0.85rem;
}

.left-panel {
    flex: 0 0 50%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
    border-right: 2px solid #4a4a4a;
    padding-right: 1rem;
}

.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
    padding-left: 1rem;
}

.ids-display {
    padding: 0.5rem;
    background-color: #3a3a3a;
    border-radius: 4px;
    font-size: 0.9rem;
}

.left-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.left-panel-toggle {
    padding: 0.25rem 0.5rem;
    min-width: 32px;
}

.left-panel-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.left-panel.collapsed {
    flex: 0 0 48px;
    padding-right: 0.5rem;
}

.left-panel.collapsed .left-panel-body {
    display: none;
}

.left-panel.collapsed .left-panel-toggle {
    transform: rotate(180deg);
}

.controls-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-group label {
    min-width: 100px;
    font-weight: 500;
}

.slider {
    flex: 1;
    height: 8px;
    background-color: #3a3a3a;
    border-radius: 4px;
    outline: none;
    -webkit-appearance: none;
    margin: 0 0.5rem;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background-color: #6a5acd;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.2s;
}

.slider::-webkit-slider-thumb:hover {
    background-color: #7a6add;
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background-color: #6a5acd;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: background-color 0.2s;
}

.slider::-moz-range-thumb:hover {
    background-color: #7a6add;
}

/* Red slider */
#red-slider {
    accent-color: #ff0000;
}

#red-slider::-webkit-slider-thumb {
    background-color: #ff0000;
}

#red-slider::-moz-range-thumb {
    background-color: #ff0000;
}

/* Green slider */
#green-slider {
    accent-color: #00ff00;
}

#green-slider::-webkit-slider-thumb {
    background-color: #00ff00;
}

#green-slider::-moz-range-thumb {
    background-color: #00ff00;
}

/* Blue slider */
#blue-slider {
    accent-color: #0000ff;
}

#blue-slider::-webkit-slider-thumb {
    background-color: #0000ff;
}

#blue-slider::-moz-range-thumb {
    background-color: #0000ff;
}

/* Brightness slider */
#brightness-slider {
    accent-color: #ffff00;
}

#brightness-slider::-webkit-slider-thumb {
    background-color: #ffff00;
}

#brightness-slider::-moz-range-thumb {
    background-color: #ffff00;
}

.slider-value {
    min-width: 50px;
    text-align: right;
    font-weight: 500;
    font-size: 0.9rem;
}

.n-params-section {
    margin-top: 1rem;
}

.n-params-section h3 {
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.n-params-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.n-param-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.n-param-group label {
    min-width: 40px;
    font-weight: 500;
}

.n-input {
    flex: 1;
    padding: 0.5rem;
    background-color: #3a3a3a;
    color: white;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    font-size: 1rem;
}

.n-input:focus {
    outline: none;
    border-color: #6a5acd;
}

.patterns-section,
.presets-section,
.color-palette-section {
    background-color: #1a1a1a;
    border: 2px solid #4a4a4a;
    border-radius: 4px;
    padding: 1rem;
}

.patterns-section h3,
.presets-section h3,
.color-palette-section h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

/* Make the presets area fill available vertical space; no border around presets */
.presets-section {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    overflow-x: hidden;
    border: none;
    background-color: transparent;
    padding: 0;
}

/* Tab preset selecting area: 3 columns, vertical scroll only */
#presets-list-tab {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-rows: 5rem;
    column-gap: 0.3rem;
    row-gap: 0.3rem;
    align-content: start;
    width: 100%;
}

/* Settings modal layout */
.settings-section {
    background-color: #1a1a1a;
    border-radius: 8px;
    padding: 1rem;
    margin-top: 1rem;
    border: 1px solid #4a4a4a;
}

.settings-section h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    color: #fff;
    border-bottom: 1px solid #4a4a4a;
    padding-bottom: 0.25rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #ccc;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 0.5rem;
    background-color: #2e2e2e;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    color: white;
    font-size: 0.95rem;
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    color: #888;
    font-size: 0.8rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.status-info {
    background-color: #2e2e2e;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
}

.status-info h3,
.status-info h4 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: #fff;
}

.status-info p {
    color: #aaa;
    margin: 0.25rem 0;
    font-size: 0.9rem;
}

.status-connected {
    color: #4caf50;
}

.status-disconnected {
    color: #f44336;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.btn-full {
    flex: 1;
}

.message {
    padding: 0.75rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    display: none;
}

.message.success {
    background-color: #1b5e20;
    color: #4caf50;
    border: 1px solid #4caf50;
}

.message.error {
    background-color: #5e1b1b;
    color: #f44336;
    border: 1px solid #f44336;
}

.message.show {
    display: block;
}

.patterns-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.presets-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    width: 100%;
}

.pattern-button {
    height: 5rem;
    padding: 0 0.5rem;
    background-color: #3a3a3a;
    color: white;
    border: 3px solid #000;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    text-align: left;
    transition: background-color 0.2s;
    line-height: 1;
    display: flex;
    align-items: center;
    overflow: hidden;
    box-shadow: none;
    outline: none;
    position: relative;
}

/* Preset select buttons inside the tab grid */
#presets-list-tab .pattern-button {
    display: flex;
}
.pattern-button .pattern-button-label {
    text-shadow: 0 0 2px rgba(0,0,0,0.8), 0 1px 2px rgba(0,0,0,0.6);
}

.pattern-button:hover {
    background-color: #4a4a4a;
}

.pattern-button.active {
    background-color: #6a5acd;
    color: white;
    border-color: #ffffff;
}
.pattern-button.active[style*="background-image"] {
    background-color: transparent;
}

.pattern-button.active::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 7px;
    padding: 3px;
    pointer-events: none;
    background: #ffffff;
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask-composite: exclude;
}

.pattern-button.default-preset {
    /* No border; active state shows selection */
}

.color-palette {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
    max-height: 300px;
    overflow-y: auto;
}

.color-swatch {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    background-color: #3a3a3a;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: border-color 0.2s;
    gap: 0.5rem;
}

.color-swatch:hover {
    border-color: #6a5acd;
}

.color-swatch.selected {
    border-color: #FFD700;
    border-width: 3px;
}

.color-swatch-preview {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    border: 1px solid #4a4a4a;
    flex-shrink: 0;
}

.color-swatch-label {
    flex: 1;
    font-size: 0.9rem;
    min-width: 80px;
}

.color-picker-input {
    width: 60px;
    height: 40px;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    cursor: pointer;
    background: none;
    padding: 0;
    flex-shrink: 0;
}

.color-picker-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker-input::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.color-picker-input::-moz-color-swatch {
    border: none;
    border-radius: 4px;
}

.palette-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: #2e2e2e;
    padding: 2rem;
    border-radius: 8px;
    min-width: 320px;
    max-width: 500px;
}

.modal-content h2 {
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.modal-content label {
    display: block;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.modal-content input {
    width: 100%;
    padding: 0.5rem;
    background-color: #3a3a3a;
    color: white;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    font-size: 1rem;
}

.modal-content input:focus {
    outline: none;
    border-color: #6a5acd;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
    justify-content: flex-end;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #1a1a1a;
}

::-webkit-scrollbar-thumb {
    background: #4a4a4a;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #5a5a5a;
}

/* Mobile-friendly layout */
@media (max-width: 800px) {
    header {
        flex-direction: row;
        align-items: center;
        gap: 0.25rem;
    }    header h1 {
        font-size: 1.1rem;
    }    /* On mobile, hide header buttons; all actions (including Tabs) are in the Menu dropdown */
    .header-actions {
        display: none;
    }

    .header-menu-mobile {
        display: block;
        margin-top: 0;
        margin-left: auto;
    }

    .btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.7rem;
    }

    .tabs-container {
        padding: 0.5rem 0;
        border-bottom: none;
    }

    .tab-content {
        padding: 0.5rem;
    }

    .left-panel {
        flex: 1;
        border-right: none;
        padding-right: 0;
    }

    .right-panel {
        padding-left: 0;
        margin-top: 1rem;
    }

    /* Hide the "Presets for ..." heading to save space on mobile */
    .presets-section h3 {
        display: none;
    }

    .modal-content {
        min-width: 280px;
        max-width: 95vw;
        padding: 1.25rem;
    }

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

/* Styles moved from inline <style> in templates/index.html */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
}
.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background-color: #2e2e2e;
    padding: 2rem;
    border-radius: 8px;
    min-width: 400px;
    max-width: 600px;
}
.modal-content label {
    display: block;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}
.modal-content input[type="text"] {
    width: 100%;
    padding: 0.5rem;
    background-color: #3a3a3a;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    color: white;
}
.profiles-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}
.profiles-actions input[type="text"] {
    flex: 1;
}
.profiles-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
    max-height: 50vh;
    overflow-y: auto;
}
.profiles-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem;
    background-color: #3a3a3a;
    border-radius: 4px;
}
/* Hide any text content in palette rows - only show color swatches */
#palette-container .profiles-row {
    font-size: 0; /* Hide any text nodes */
}
#palette-container .profiles-row > * {
    font-size: 1rem; /* Restore font size for buttons */
}
#palette-container .profiles-row > span:not(.btn),
#palette-container .profiles-row > label,
#palette-container .profiles-row::before,
#palette-container .profiles-row::after {
    display: none !important;
    content: none !important;
}
/* Preset colors container */
#preset-colors-container {
    min-height: 80px;
    padding: 0.5rem;
    background-color: #2a2a2a;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}
#preset-colors-container .muted-text {
    color: #888;
    font-size: 0.9rem;
    padding: 1rem;
    text-align: center;
}
.muted-text {
    text-align: center;
    color: #888;
}
.modal-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
    justify-content: flex-end;
}
.error {
    color: #d32f2f;
    padding: 0.5rem;
    background-color: #3a1a1a;
    border-radius: 4px;
    margin-top: 0.5rem;
}
/* Drag and drop styles for presets */
.draggable-preset {
    cursor: move;
    transition: opacity 0.2s, transform 0.2s;
}
.draggable-preset.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}
.draggable-preset:hover {
    opacity: 0.8;
}
/* Drag and drop styles for color swatches */
.draggable-color-swatch {
    transition: opacity 0.2s, transform 0.2s;
}
.draggable-color-swatch.dragging-color {
    opacity: 0.5;
    transform: scale(0.9);
}
.draggable-color-swatch.drag-over-color {
    transform: scale(1.1);
}
.color-swatches-container {
    min-height: 80px;
}
/* Presets list: 3 columns and vertical scroll (defined above); mobile same */
@media (max-width: 800px) {
    #presets-list-tab {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
/* Help modal readability */
#help-modal .modal-content {
    max-width: 720px;
    line-height: 1.6;
    font-size: 0.95rem;
}
#help-modal .modal-content h2 {
    margin-bottom: 0.75rem;
}
#help-modal .modal-content h3 {
    margin-top: 1.25rem;
    margin-bottom: 0.4rem;
    font-size: 1.05rem;
    font-weight: 600;
}
#help-modal .modal-content p {
    text-align: left;
    margin-bottom: 0.5rem;
}
#help-modal .modal-content ul {
    margin-top: 0.25rem;
    margin-left: 1.25rem;
    padding-left: 0;
    text-align: left;
}
#help-modal .modal-content li {
    margin: 0.2rem 0;
    line-height: 1.5;
}
#help-modal .muted-text {
    text-align: left;
    color: #bbb;
    font-size: 0.9rem;
}

/* Tab content placeholder (no tab selected) */
.tab-content-placeholder {
    padding: 2rem;
    text-align: center;
    color: #aaa;
}

/* Preset editor: color actions row */
#preset-editor-modal .preset-colors-container + .profiles-actions {
    margin-top: 0.5rem;
}

/* Preset editor: brightness/delay field wrappers */
.preset-editor-field {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Settings modal */
#settings-modal .modal-content {
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
}#settings-modal .modal-content > p.muted-text {
    margin-bottom: 1rem;
}#settings-modal .settings-section.ap-settings-section {
    margin-top: 1.5rem;
}
