* {
    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;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.hex-address-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    align-items: center;
}

input.hex-addr-box {
    width: 1.35rem;
    padding: 0.25rem 0.1rem;
    text-align: center;
    font-family: ui-monospace, monospace;
    font-size: 0.85rem;
}

.device-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
    gap: 0.75rem;
    align-items: end;
}

.device-field-label {
    display: block;
    font-size: 0.8rem;
    color: #aaa;
    margin-bottom: 0.25rem;
}

.device-row-mac {
    font-size: 0.82em;
    color: #b0b0b0;
    letter-spacing: 0.02em;
}

.device-form-actions {
    display: flex;
    align-items: flex-end;
}

#devices-modal select {
    width: 100%;
    max-width: 16rem;
    padding: 0.35rem;
    background-color: #2e2e2e;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    color: white;
}

#edit-device-modal select {
    width: 100%;
    max-width: 20rem;
    padding: 0.35rem;
    background-color: #2e2e2e;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    color: white;
}

.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;
}

/* BPM + desktop actions + mobile menu share one row; BPM stays visible on mobile. */
.header-end {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    justify-content: flex-end;
    margin-left: auto;
    min-width: 0;
}

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

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

.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;
}

.menu-brightness-control {
    padding: 0.45rem 0.75rem 0.55rem;
    border-bottom: 1px solid #333;
}

.menu-brightness-control label {
    display: block;
    font-size: 0.78rem;
    color: #bdbdbd;
    margin-bottom: 0.3rem;
}

.menu-brightness-control input[type="range"] {
    width: 100%;
}

.header-brightness-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 13rem;
    padding: 0.2rem 0.1rem;
}

.header-brightness-control label {
    font-size: 0.8rem;
    color: #bdbdbd;
    white-space: nowrap;
}

.header-brightness-control input[type="range"] {
    width: 8.5rem;
}

.audio-top-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.55rem;
    border: 1px solid #4a4a4a;
    border-radius: 6px;
    background-color: #1a1a1a;
    min-width: 6.5rem;
}

.audio-top-indicator-label {
    font-size: 0.72rem;
    color: #bdbdbd;
    letter-spacing: 0.05em;
}

.audio-top-indicator-value {
    font-size: 1rem;
    font-weight: 700;
    color: #ffd54f;
    min-width: 2.4rem;
    text-align: right;
}

.audio-top-indicator-subvalue {
    font-size: 0.75rem;
    color: #9e9e9e;
    min-width: 2.2rem;
    text-align: right;
}

.audio-top-indicator.flash {
    background-color: #ff5252;
    border-color: #ff8a80;
}

.audio-top-indicator.flash .audio-top-indicator-value,
.audio-top-indicator.flash .audio-top-indicator-label,
.audio-top-indicator.flash .audio-top-indicator-subvalue {
    color: #fff;
}

/* Header/menu actions that should only appear in Edit mode */
body.preset-ui-run .edit-mode-only {
    display: none !important;
}

.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;
}

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

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

.zone-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;
}

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

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

.zone-content {
    flex: 1;
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px) + 3.5rem);
    -webkit-overflow-scrolling: touch;
}

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

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

.zone-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.75rem;
    justify-content: space-between;
}

.n-param-group label {
    flex: 1;
    min-width: 0;
    font-weight: 500;
}

.n-input {
    flex: 0 0 var(--n-input-width, 5ch);
    width: var(--n-input-width, 5ch);
    max-width: 100%;
    box-sizing: border-box;
    padding: 0.5rem;
    background-color: #3a3a3a;
    color: white;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    font-size: 1rem;
    text-align: right;
}

.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;
}

/* Zone preset selecting area: 8 columns on desktop, vertical scroll only */
#presets-list-zone {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-auto-rows: 5rem;
    column-gap: 0.3rem;
    row-gap: 0.3rem;
    align-content: start;
    width: 100%;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 5.5rem);
    scroll-padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 5.5rem);
}

#presets-list-zone > :last-child {
    margin-bottom: calc(env(safe-area-inset-bottom, 0px) + 2.5rem);
}

/* 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;
}

/* Devices modal: live TCP presence (Wi-Fi only) */
.device-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    align-self: center;
}

.device-status-dot--online {
    background: #4caf50;
    box-shadow: 0 0 6px rgba(76, 175, 80, 0.45);
}

.device-status-dot--offline {
    background: #616161;
}

.device-status-dot--unknown {
    background: #424242;
    border: 1px solid #757575;
}

.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;
}

.audio-bpm-readout {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #ffd54f;
    text-align: center;
    padding: 0.4rem;
    background-color: #1a1a1a;
    border: 1px solid #4a4a4a;
    border-radius: 6px;
}

.audio-hit-type-readout {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: #81d4fa;
    text-transform: lowercase;
    text-align: center;
    padding: 0.35rem;
    background-color: #1a1a1a;
    border: 1px solid #4a4a4a;
    border-radius: 6px;
}

.audio-beat-flash {
    width: 100%;
    height: 56px;
    border-radius: 6px;
    border: 1px solid #4a4a4a;
    background: #202020;
    box-shadow: inset 0 0 0 0 rgba(255, 82, 82, 0.5);
    transition: background-color 80ms linear, box-shadow 120ms linear;
}

.audio-beat-flash.active {
    background: #ff5252;
    box-shadow: inset 0 0 24px 6px rgba(255, 255, 255, 0.35);
}

.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 tile: main button + optional edit/remove (Edit mode) */
.preset-tile-row {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    min-width: 0;
    min-height: 0;
}

.preset-tile-row--run .preset-tile-actions {
    display: none;
}

.preset-tile-main {
    flex: 1;
    min-width: 0;
    height: 5rem;
}

/* Edit only beside the preset tile in edit mode. */
.preset-tile-actions {
    display: flex;
    flex-direction: column;
    justify-content: stretch;
    gap: 0.2rem;
    flex-shrink: 0;
    padding: 0.15rem 0 0.15rem 0.25rem;
    width: auto;
    min-width: 0;
}

.preset-editor-modal-actions {
    flex-wrap: wrap;
    gap: 0.35rem;
}

.preset-tile-actions .btn {
    width: 100%;
    min-height: 2.35rem;
    padding: 0.15rem 0.35rem;
    font-size: 0.68rem;
    line-height: 1.15;
    white-space: normal;
}

.ui-mode-toggle--edit {
    background-color: #4a3f8f;
    border: 1px solid #7b6fd6;
}

.ui-mode-toggle--edit:hover {
    background-color: #5a4f9f;
}

/* Preset select buttons inside the zone grid */
#presets-list-zone .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: 1000px) {
    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: flex;
        flex-direction: row;
        align-items: center;
        gap: 0.35rem;
        margin-top: 0;
        margin-left: 0;
    }

    .header-end {
        gap: 0.35rem;
        flex-shrink: 0;
    }

    .header-end .audio-top-indicator {
        min-width: 5rem;
        padding: 0.2rem 0.45rem;
        flex-shrink: 0;
    }

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

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

    .zone-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;
        max-height: calc(100dvh - 1rem);
        overflow-y: auto;
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    }

    .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);
    overflow-y: auto;
    padding: 1rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.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;
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
    -webkit-overflow-scrolling: touch;
}

/* Real-phone viewport fallback for browsers with unstable 100dvh behavior. */
@supports (-webkit-touch-callout: none) {
    .modal {
        min-height: -webkit-fill-available;
    }
    .modal-content {
        max-height: calc(-webkit-fill-available - 2rem);
    }
}
.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;
}

.zone-modal-create-row {
    flex-wrap: wrap;
    align-items: center;
}

.zone-modal-create-row input[type="text"] {
    flex: 1;
    min-width: 8rem;
}

.zone-devices-label {
    display: block;
    margin-top: 0.75rem;
    margin-bottom: 0.35rem;
    font-weight: 600;
}

.zone-devices-editor {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    max-height: 14rem;
    overflow-y: auto;
}

.zone-device-row-label {
    flex: 1;
    min-width: 0;
}

.zone-device-add-select {
    flex: 1;
    min-width: 10rem;
    padding: 0.5rem;
    background-color: #3a3a3a;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    color: white;
}

.zone-devices-add {
    margin-top: 0;
    flex-wrap: wrap;
}

.zone-presets-section-label {
    display: block;
    margin-top: 1rem;
    margin-bottom: 0.35rem;
    font-weight: 600;
}

.edit-zone-presets-scroll {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 1rem;
}
/* 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 on phone-sized screens */
@media (max-width: 600px) {
    #presets-list-zone {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 7rem);
        scroll-padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 7rem);
    }
}
/* 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;
}

/* Zone content placeholder (no zone selected) */
.zone-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-modal .preset-editor-field {
    flex: 1;
    min-width: 10rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

#preset-editor-modal .preset-editor-field label {
    align-self: stretch;
}

#preset-editor-modal .preset-editor-field input[type="number"] {
    width: 100%;
    min-width: 5.5rem;
    max-width: 7rem;
    box-sizing: border-box;
    text-align: right;
}

/* Preset editor n-parameter inputs need extra room for values + spinner controls. */
#preset-editor-modal .n-input {
    width: 6.5ch;
    min-width: 5.5rem;
}

/* Pattern editor: numeric metadata row */
#pattern-editor-modal input[type="number"] {
    width: var(--n-input-width, 5ch);
    max-width: 100%;
    box-sizing: border-box;
    text-align: right;
}

/* Pattern editor: human-readable n labels (text), full width */
#pattern-editor-modal .n-params-grid {
    grid-template-columns: 1fr;
}

#pattern-editor-modal .n-param-group:has(.pattern-n-readable-input) {
    justify-content: stretch;
}

#pattern-editor-modal .n-param-group:has(.pattern-n-readable-input) label {
    flex: 0 0 auto;
    min-width: 2.25rem;
    font-weight: 500;
}

#pattern-editor-modal .pattern-n-readable-input {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    text-align: left;
}

@supports not selector(:has(*)) {
    #pattern-editor-modal #pattern-create-n-section .n-param-group {
        justify-content: stretch;
    }
}

/* 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;
}
