/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: var(--z-modal);
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
    backdrop-filter: blur(2px);
}

/* Confirm dialog must stack above all other modals */
#confirm-modal {
    z-index: var(--z-confirm);
}

/* Audio test spectrum canvas */
.audio-test-canvas {
    display: block;
    width: 100%;
    height: 200px;
    background: #111;
    border-radius: 6px;
}

.audio-test-stats {
    display: flex;
    gap: 20px;
    align-items: center;
    padding: 10px 0 0;
    font-family: monospace;
}

.audio-test-stat {
    display: flex;
    align-items: center;
    gap: 6px;
}

.audio-test-stat-label {
    color: var(--text-muted, #888);
    font-size: 0.85em;
}

.audio-test-stat-value {
    font-weight: 600;
    min-width: 50px;
}

.audio-test-beat-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #444;
    transition: background 0.1s;
}

.audio-test-beat-dot.active {
    background: #ff4444;
    box-shadow: 0 0 8px #ff4444;
}

.audio-test-status {
    text-align: center;
    padding: 8px 0;
    color: var(--text-muted, #888);
    font-size: 0.9em;
}

/* Value source test chart canvas */
.vs-test-canvas {
    display: block;
    width: 100%;
    height: 200px;
    background: #111;
    border-radius: 6px;
}

.vs-test-color-swatch {
    margin-top: 8px;
}

.vs-test-color-canvas {
    display: block;
    width: 100%;
    height: 32px;
    border-radius: 6px;
}

.vs-test-stats {
    display: flex;
    gap: 20px;
    align-items: center;
    padding: 10px 0 0;
    font-family: monospace;
    flex-wrap: wrap;
}

.vs-test-stat {
    display: flex;
    align-items: center;
    gap: 6px;
}

.vs-test-stat-label {
    color: var(--text-muted, #888);
    font-size: 0.85em;
}

.vs-test-stat-value {
    font-weight: 600;
    min-width: 50px;
}

.vs-test-value-large {
    font-size: 1.3em;
    color: var(--primary-text-color);
}

.vs-test-status {
    text-align: center;
    padding: 8px 0;
    color: var(--text-muted, #888);
    font-size: 0.9em;
}

/* Color strip test preview */
.css-test-strip-wrap {
    position: relative;
}

.css-test-strip-canvas {
    display: block;
    width: 100%;
    height: 48px;
    background: #111;
    border-radius: 6px;
    image-rendering: pixelated;
}

.css-test-strip-axis {
    display: block;
    width: 100%;
    height: 20px;
}

.css-test-fire-btn {
    position: absolute;
    right: 6px;
    top: 24px;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    line-height: 1;
}

.css-test-fire-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.css-test-rect-outer {
    position: relative;
    padding: 22px 30px;
}

.css-test-rect-ticks {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.css-test-rect {
    display: grid;
    grid-template-columns: 14px 1fr 14px;
    grid-template-rows: 14px 1fr 14px;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 70vh;
    overflow: hidden;
    border-radius: 4px;
}

.css-test-rect-corner {
    background: transparent;
}

.css-test-rect-screen {
    position: relative;
    background-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-size: cover;
    background-position: center;
    border-radius: 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    overflow: hidden;
}

.css-test-rect-screen::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 2px solid var(--primary-color);
    border-radius: 2px;
    pointer-events: none;
    z-index: 10;
}

.css-test-border-label {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: var(--primary-color);
    font-size: 0.65rem;
    font-family: monospace;
    padding: 1px 5px;
    border-radius: 3px;
    z-index: 5;
}

.css-test-rect-label {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90%;
}

.css-test-rect-leds {
    font-size: 0.7rem;
    font-weight: 400;
    opacity: 0.75;
}

.css-test-edge-wrap {
    position: relative;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}

.css-test-edge {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    display: block;
}

.css-test-status {
    text-align: center;
    padding: 8px 0;
    color: var(--text-muted, #888);
    font-size: 0.9em;
}

/* FPS chart for api_input test preview — reuses .target-fps-row from cards.css */

/* Composite layers preview */
.css-test-layers {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.css-test-layer {
    position: relative;
}

.css-test-layer-canvas {
    display: block;
    width: 100%;
    height: 48px;
    border-radius: 4px;
    image-rendering: pixelated;
    background: #111;
}

.css-test-layer-label {
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.6rem;
    font-family: var(--font-mono, monospace);
    color: #fff;
    text-shadow: 0 0 3px rgba(0,0,0,0.9), 0 0 6px rgba(0,0,0,0.6);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    white-space: nowrap;
}

.css-test-layers:hover .css-test-layer-label {
    opacity: 1;
}

.css-test-layer-brightness {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.6rem;
    font-family: var(--font-mono, monospace);
    color: #fff;
    text-shadow: 0 0 3px rgba(0,0,0,0.9), 0 0 6px rgba(0,0,0,0.6);
    pointer-events: none;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 2px;
}
.css-test-layer-brightness svg { width: 12px; height: 12px; }

.css-test-layer-cal {
    position: absolute;
    right: 6px;
    bottom: 4px;
    font-size: 0.6rem;
    font-family: var(--font-mono, monospace);
    color: #fff;
    text-shadow: 0 0 3px rgba(0,0,0,0.9), 0 0 6px rgba(0,0,0,0.6);
    pointer-events: none;
    white-space: nowrap;
    opacity: 0.7;
    display: flex;
    align-items: center;
    gap: 2px;
}
.css-test-layer-cal svg { width: 12px; height: 12px; }
.css-test-layer-cal-warn {
    color: var(--warning-color, #ff9800);
    opacity: 1;
}

/* ── Settings modal tabs ───────────────────────────────────── */

.settings-tab-bar {
    display: flex;
    justify-content: center;
    gap: 0;
    border-bottom: 2px solid var(--border-color);
    padding: 0 0.75rem;
}

.settings-tab-btn {
    background: none;
    border: none;
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: color 0.2s ease, border-color 0.25s ease;
}

.settings-tab-btn:hover {
    color: var(--text-color);
}

.settings-tab-btn.active {
    color: var(--primary-text-color);
    border-bottom-color: var(--primary-color);
}

.settings-panel {
    display: none;
}

.settings-panel.active {
    display: block;
    animation: tabFadeIn 0.25s ease-out;
}

/* ── About panel ──────────────────────────────────────────── */
.about-section {
    text-align: center;
    padding: 8px 0 4px;
}

.about-logo {
    margin-bottom: 8px;
}

.about-logo .icon {
    width: 36px;
    height: 36px;
    color: var(--primary-color);
}

.about-title {
    margin: 0 0 2px;
    font-size: 1.1rem;
    color: var(--text-color);
}

.about-version {
    display: inline-block;
    margin-bottom: 8px;
    padding: 2px 10px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: var(--font-mono, monospace);
}

.about-text {
    margin: 0 0 12px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.4;
}

.about-license {
    margin: 10px 0 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
    opacity: 0.7;
}

.about-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 280px;
    margin: 0 auto;
}

.about-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.9rem;
    transition: border-color 0.15s, background 0.15s;
}

.about-link:hover {
    border-color: var(--primary-color);
    background: var(--bg-tertiary);
}

.about-link .icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.about-link .icon:last-child {
    width: 14px;
    height: 14px;
    margin-left: auto;
    color: var(--text-secondary);
}

.about-link span {
    flex: 1;
    text-align: left;
}

.about-link-donate .icon:first-child {
    color: #e25555;
}

/* ── Log viewer overlay (full-screen) ──────────────────────── */

.log-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-log-overlay);
    display: flex;
    flex-direction: column;
    background: var(--bg-color, #111);
    padding: 12px 16px;
    animation: fadeIn 0.2s ease-out;
}

.log-overlay-close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.3rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    z-index: 1;
    transition: color 0.15s, background 0.15s;
}

.log-overlay-close:hover {
    color: var(--text-color);
    background: var(--border-color);
}

.log-overlay-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 10px;
    padding-right: 36px;           /* space for corner close btn */
    flex-shrink: 0;
}

.log-overlay-toolbar h3 {
    margin: 0;
    font-size: 1rem;
    white-space: nowrap;
    margin-right: 4px;
}

.log-overlay .log-viewer-output {
    flex: 1;
    max-height: none;
    border-radius: 8px;
    min-height: 0;
}

/* ── Release notes content ─────────────────────────────────── */

.release-notes-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.5rem;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-color);
    background: var(--bg-secondary);
    border-radius: 8px;
}

.release-notes-content h2,
.release-notes-content h3,
.release-notes-content h4 {
    margin: 1.2em 0 0.4em;
    color: var(--text-color);
}

.release-notes-content h2 { font-size: 1.2rem; }
.release-notes-content h3 { font-size: 1.05rem; }
.release-notes-content h4 { font-size: 0.95rem; }

.release-notes-content pre {
    background: #0d0d0d;
    color: #d4d4d4;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.82rem;
}

.release-notes-content code {
    background: var(--bg-tertiary, #2a2a2a);
    padding: 0.15em 0.4em;
    border-radius: 3px;
    font-size: 0.88em;
}

.release-notes-content pre code {
    background: none;
    padding: 0;
}

.release-notes-content a {
    color: var(--primary-color);
}

.release-notes-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1rem 0;
}

.release-notes-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0;
}

.release-notes-content th,
.release-notes-content td {
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.6rem;
    text-align: left;
    font-size: 0.85rem;
}

.release-notes-content th {
    background: var(--bg-tertiary, #2a2a2a);
}

/* ── Log viewer base ───────────────────────────────────────── */

.log-viewer-output {
    background: #0d0d0d;
    color: #d4d4d4;
    font-family: var(--font-mono, 'Consolas', 'Courier New', monospace);
    font-size: 0.75rem;
    line-height: 1.45;
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    max-height: 400px;
    overflow-y: auto;
    overflow-x: auto;
    white-space: pre;
    margin: 0;
    /* Scroll performance */
    contain: strict;
}

.log-viewer-output .log-line-error {
    color: #f48771;
}

.log-viewer-output .log-line-warning {
    color: #ce9178;
}

.log-viewer-output .log-line-debug {
    color: #6a9955;
}

/* LED count control */
.css-test-led-control {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0 0;
    font-size: 0.85em;
}

.css-test-led-control label {
    display: inline;
    margin-bottom: 0;
}

.css-test-led-input {
    width: 70px;
    flex: 0 0 70px;
    padding: 3px 6px;
    border: 1px solid var(--border-color, #333);
    border-radius: 4px;
    background: var(--input-bg, #1a1a2e);
    color: var(--text-color, #e0e0e0);
    font-size: 0.85em;
    text-align: center;
}

.css-test-led-apply {
    padding: 2px 6px;
    font-size: 0.85em;
    line-height: 1;
}

#css-test-led-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.css-test-separator {
    width: 1px;
    height: 18px;
    background: var(--border-color, #333);
    margin: 0 4px;
}

#test-css-source-modal .modal-content,
#test-stream-modal .modal-content {
    max-width: 700px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    max-width: 500px;
    width: 90%;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px var(--shadow-color);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#template-modal .modal-content {
    max-width: 500px !important;
    width: 100% !important;
}

#test-template-modal .modal-content {
    max-width: 420px;
}

@keyframes slideUp {
    from {
        transform: translateY(20px) scale(0.98);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.modal-header {
    padding: 24px 24px 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text-color);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    min-width: 0;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.modal-header-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
    flex-shrink: 0;
}
.modal-header-btn:hover {
    background: rgba(128, 128, 128, 0.15);
}
.modal-header-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}

.modal-close-btn:hover {
    color: var(--text-color);
    background: rgba(128, 128, 128, 0.15);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    scrollbar-gutter: stable;
    flex: 1 1 auto;
    min-height: 0;
}

.modal-description {
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.6;
}

.password-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-wrapper input {
    flex: 1;
    padding-right: 45px;
}

.password-toggle {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 8px;
    color: var(--text-color);
    opacity: 0.6;
    transition: opacity 0.2s;
}

.password-toggle:hover {
    opacity: 1;
}

.label-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 5px;
}

.label-row label {
    margin-bottom: 0;
}

.hint-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 0.7rem;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.hint-toggle:hover {
    opacity: 1;
}

.hint-toggle.active {
    opacity: 1;
    color: var(--primary-text-color);
    border-color: var(--primary-color);
}

.input-hint {
    display: block;
    margin: 0 0 6px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.field-desc {
    display: block;
    margin: 4px 0 0 0;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-style: italic;
}

.inline-fields {
    display: flex;
    gap: 12px;
}

.inline-field {
    flex: 1;
}

.inline-field label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.inline-field input[type="number"] {
    width: 100%;
}

/* Segment rows in target editor */
.segment-row {
    border: 1px solid var(--border-color, #333);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 6px;
    background: var(--card-bg, #1e1e1e);
}

.device-led-info {
    display: block;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 0.85em;
}

.segment-row-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.segment-index-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.btn-icon-inline {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.btn-icon-inline .icon {
    width: 16px;
    height: 16px;
}

.btn-danger-text {
    color: var(--danger-color, #f44336);
}

.btn-danger-text:hover {
    color: #ff6659;
}

.segment-row-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.segment-row-fields select {
    flex: 1 1 100%;
}

.segment-range-fields {
    display: flex;
    gap: 6px;
    align-items: center;
    flex: 1;
}

.segment-range-fields label {
    font-size: 0.82rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.segment-range-fields input[type="number"] {
    width: 70px;
}

.segment-reverse-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

.segment-reverse-label input[type="checkbox"] {
    margin: 0;
}

.btn-sm {
    font-size: 0.8rem;
    padding: 4px 10px;
    min-width: auto;
}

.select-with-action {
    display: flex;
    gap: 6px;
    align-items: center;
}

.select-with-action select {
    flex: 1;
    min-width: 0;
}

.fps-hint {
    display: block;
    margin-top: 4px;
    font-size: 0.82rem;
    color: var(--info-color, #2196F3);
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.slider-row input[type="range"] {
    flex: 1;
}

.slider-value {
    min-width: 28px;
    text-align: center;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.form-collapse {
    margin-bottom: 12px;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
}

.form-collapse > summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    padding: 4px 0;
    user-select: none;
}

.form-collapse > summary::-webkit-details-marker { display: none; }

.form-collapse > summary::before {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 0.35em solid currentColor;
    border-top: 0.25em solid transparent;
    border-bottom: 0.25em solid transparent;
    opacity: 0.6;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.form-collapse[open] > summary::before {
    transform: rotate(90deg);
}

.form-collapse > summary:hover {
    color: var(--text-color);
}

.form-collapse-body {
    padding-top: 8px;
}

.error-message {
    background: color-mix(in srgb, var(--danger-color) 10%, transparent); /* --danger-color tint */
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
    padding: 12px;
    border-radius: 4px;
    margin-top: 15px;
    font-size: 0.9rem;
}

.modal-footer {
    padding: 16px 24px 24px 24px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-footer .btn-icon {
    min-width: 60px;
    padding: 10px 20px;
    font-size: 1.4rem;
}

.btn-display-picker {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 1rem;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-weight: 400;
}

.btn-display-picker:hover {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 15%, transparent); /* --primary-color tint */
}

.modal-content-wide {
    width: fit-content;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
}

@media (min-width: 769px) {
    .modal-content-wide {
        min-width: 500px;
    }
}

.modal-content-wide .modal-body {
    overflow-y: auto;
    scrollbar-gutter: stable;
    flex: 1 1 auto;
    min-height: 0;
}

@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 20px;
    }

    .modal-footer .btn {
        min-width: 80px;
    }
}

/* Image Lightbox */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    z-index: var(--z-lightbox);
    justify-content: center;
    align-items: center;
    cursor: zoom-out;
}

.lightbox.active {
    display: flex;
}

.lightbox-content {
    position: relative;
    max-width: 95%;
    max-height: 95%;
    cursor: default;
}

.lightbox-content img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 4px;
    display: block;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 1;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-refresh-btn {
    position: absolute;
    top: 16px;
    right: 64px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 1;
}

.lightbox-refresh-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-refresh-btn.active {
    background: var(--primary-color);
}

.lightbox-fps-select {
    position: absolute;
    top: 16px;
    right: 116px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 0.8rem;
    cursor: pointer;
    z-index: 1;
    appearance: none;
    -webkit-appearance: none;
    text-align: center;
}

.lightbox-fps-select:hover {
    background: rgba(255, 255, 255, 0.15);
}

.lightbox-fps-select:focus {
    outline: 1px solid var(--primary-color);
}

.lightbox-stats {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    color: white;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.8rem;
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.lightbox-stats .stat-item {
    display: flex;
    gap: 4px;
    align-items: center;
}

.lightbox-stats .stat-item span {
    opacity: 0.7;
}

.lightbox-stats .stat-item strong {
    font-weight: 600;
}

/* Display Picker Lightbox */
.display-picker-content {
    max-width: 900px;
    width: 90%;
    text-align: center;
}

.display-picker-title {
    color: white;
    font-size: 1.3rem;
    margin-bottom: 20px;
    font-weight: 500;
}

.display-picker-canvas {
    background: rgba(255, 255, 255, 0.05);
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 24px;
    width: 100%;
    box-sizing: border-box;
}

.layout-display-pickable {
    cursor: pointer !important;
    border: 2px solid var(--border-color) !important;
    background: linear-gradient(135deg, rgba(128, 128, 128, 0.08), rgba(128, 128, 128, 0.03)) !important;
}

.layout-display-pickable:hover {
    box-shadow: 0 0 20px color-mix(in srgb, var(--primary-color) 40%, transparent); /* --primary-color glow */
    border-color: var(--primary-color) !important;
}

.layout-display-pickable.selected {
    border-color: var(--primary-color) !important;
    box-shadow: 0 0 16px color-mix(in srgb, var(--primary-color) 50%, transparent); /* --primary-color glow */
    background: color-mix(in srgb, var(--primary-color) 12%, transparent) !important; /* --primary-color tint */
}

/* ── Device picker list (cameras, scrcpy) ─────────────────────── */

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

.device-picker-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(128, 128, 128, 0.08), rgba(128, 128, 128, 0.03));
    cursor: pointer;
}

.device-picker-item .layout-index-label {
    position: static;
    flex-shrink: 0;
}

.device-picker-item .layout-display-label {
    text-align: left;
    padding: 0;
}

/* ── Gradient editor ────────────────────────────────────────────── */

.gradient-editor {
    position: relative;
    width: 100%;
    user-select: none;
}

#gradient-canvas,
#ge-gradient-canvas {
    width: 100%;
    height: 44px;
    display: block;
    border-radius: 6px 6px 0 0;
    cursor: crosshair;
    border: 1px solid var(--border-color);
    border-bottom: none;
}

.gradient-markers-track {
    position: relative;
    height: 28px;
    border: 1px solid var(--border-color);
    border-radius: 0 0 6px 6px;
    background: var(--card-bg);
    cursor: crosshair;
    margin-bottom: 12px;
}

.gradient-marker {
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    cursor: grab;
    transform: translateX(-50%);
    top: 6px;
    transition: box-shadow 0.1s;
}

.gradient-marker.selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-color), 0 1px 4px rgba(0, 0, 0, 0.5);
}

.gradient-marker:active {
    cursor: grabbing;
}

.gradient-stop-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    margin-bottom: 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--card-bg);
}

.gradient-stop-row.selected {
    border-color: var(--primary-color);
}

.gradient-stop-pos {
    width: 76px;
    max-width: 76px;
    flex-shrink: 0;
}

.gradient-stop-color {
    width: 38px;
    height: 28px;
    flex-shrink: 0;
    border: 1px solid var(--border-color);
    padding: 1px;
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
}

.gradient-stop-bidir-btn {
    font-size: 0.75rem;
    padding: 0;
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    opacity: 0.6;
}

.gradient-stop-remove-btn {
    padding: 0;
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
}

.gradient-stop-remove-btn .icon {
    width: 14px;
    height: 14px;
}

.gradient-stop-bidir-btn.active {
    background: var(--primary-color);
    color: var(--primary-contrast);
    border-color: var(--primary-color);
    opacity: 1;
}

.gradient-stop-spacer {
    flex: 1;
}

/* ── HA Light Mapping rows ────────────────────────────────── */

#ha-light-mappings-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 4px;
}

.ha-light-mapping-row {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px;
    background: var(--bg-secondary, var(--bg-color));
}

.ha-mapping-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.ha-mapping-header .ha-mapping-label {
    font-weight: 600;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.ha-mapping-header .ha-mapping-label .icon {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.btn-remove-mapping {
    background: none;
    border: none;
    color: var(--danger-color, #dc3545);
    cursor: pointer;
    padding: 2px 6px;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.btn-remove-mapping .icon {
    width: 16px;
    height: 16px;
}

/* HA Light color swatches */
.ha-light-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.ha-light-swatch {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 4px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    font-size: 0.75rem;
}
.ha-light-swatch .swatch-color {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid rgba(255,255,255,0.2);
    transition: background 0.3s;
}
.ha-light-swatch .swatch-label {
    opacity: 0.8;
}

.btn-remove-mapping:hover {
    opacity: 1;
}

.ha-mapping-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ha-mapping-field label {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 3px;
    color: var(--text-muted);
}

.ha-mapping-range-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

.ha-mapping-range-row label {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 3px;
    color: var(--text-muted);
}

/* ── Custom gradient presets list ───────────────────────────── */

.custom-presets-list {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.custom-preset-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 6px;
    background: var(--surface-2, rgba(255,255,255,0.04));
    border: 1px solid var(--border-color, rgba(255,255,255,0.1));
}

.custom-preset-name {
    flex: 1;
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Color Cycle editor ──────────────────────────────────────── */

#color-cycle-colors-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.color-cycle-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.color-cycle-item input[type="color"] {
    width: 36px;
    height: 28px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 1px;
    cursor: pointer;
    background: transparent;
    flex-shrink: 0;
}

.color-cycle-remove-btn {
    padding: 0;
    width: 36px;
    height: 14px;
    min-width: unset;
    line-height: 1;
}

.color-cycle-remove-btn .icon {
    width: 12px;
    height: 12px;
}

.color-cycle-add-btn {
    width: 36px;
    height: 28px;
    min-width: unset;
    padding: 0;
    font-size: 1.1rem;
    line-height: 1;
}

/* ── Notification per-app overrides (unified color + sound) ──── */

#notification-app-overrides-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 4px;
}

.notif-override-row {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px;
    background: var(--bg-secondary, var(--bg-color));
}

.notif-override-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.notif-override-label {
    font-weight: 600;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.notif-override-label .icon {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.btn-remove-override {
    background: none;
    border: none;
    color: var(--danger-color, #dc3545);
    cursor: pointer;
    padding: 2px 6px;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.btn-remove-override:hover {
    opacity: 1;
}

.btn-remove-override .icon {
    width: 16px;
    height: 16px;
}

.notif-override-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notif-override-app-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.notif-override-app-row .notif-override-name {
    flex: 1;
    min-width: 0;
}

.notif-override-app-row .notif-override-color {
    width: 26px;
    height: 26px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 1px;
    cursor: pointer;
    background: transparent;
    flex-shrink: 0;
}

.notif-override-sound-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    align-items: center;
}

.notif-override-sound-row .notif-override-sound,
.notif-override-sound-row .entity-select-trigger {
    min-width: 0;
    width: 100%;
}

.notif-override-sound-row .notif-override-volume {
    width: 100%;
}


/* ── Notification history list ─────────────────────────────────── */

.notif-history-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.82rem;
}

.notif-history-row:last-child {
    border-bottom: none;
}

.notif-history-app {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.notif-history-time {
    color: var(--text-muted);
    white-space: nowrap;
    font-size: 0.78rem;
    flex-shrink: 0;
}

.notif-history-badges {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
}

.notif-history-badge {
    display: inline-block;
    min-width: 18px;
    padding: 0 4px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
    text-align: center;
    line-height: 18px;
}

.notif-history-badge--fired {
    background: var(--primary-color);
    color: #fff;
}

.notif-history-badge--filtered {
    background: var(--border-color);
    color: var(--text-muted);
}

.notif-history-empty {
    padding: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ── Composite layer editor ────────────────────────────────────── */

#composite-layers-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
}

.composite-layer-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-secondary, var(--bg-color));
}

.composite-layer-header {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

.composite-layer-expand-btn {
    font-size: 0.6rem;
    color: var(--text-secondary);
    transition: transform 0.15s ease;
    flex-shrink: 0;
    width: 12px;
    text-align: center;
}

.composite-layer-expanded .composite-layer-expand-btn {
    transform: rotate(90deg);
}

.composite-layer-summary {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
}

.composite-layer-summary-name {
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.composite-layer-summary-blend {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 1px 6px;
    border-radius: 3px;
    white-space: nowrap;
    flex-shrink: 0;
}

.composite-layer-body-wrapper {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.2s ease;
}

.composite-layer-expanded .composite-layer-body-wrapper {
    grid-template-rows: 1fr;
}

.composite-layer-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-top: 0;
    overflow: hidden;
    min-height: 0;
    transition: padding-top 0.2s ease;
    font-size: 0.85rem;
}

.composite-layer-expanded .composite-layer-body {
    padding-top: 4px;
}

.composite-layer-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.composite-layer-source {
    flex: 1;
    min-width: 0;
}

.composite-layer-brightness-label {
    flex-shrink: 0;
    width: 90px;
    color: var(--text-secondary);
}

.composite-layer-brightness,
.composite-layer-cspt {
    flex: 1;
    min-width: 0;
}

.composite-layer-blend {
    width: 100px;
    flex-shrink: 0;
}

.composite-layer-opacity-label {
    white-space: nowrap;
    flex-shrink: 0;
}

.composite-layer-opacity-container,
.composite-layer-brightness-container {
    flex: 1;
    min-width: 60px;
}

.composite-layer-toggle {
    flex-shrink: 0;
}

.composite-layer-remove-btn {
    background: none;
    border: none;
    color: var(--danger-color, #dc3545);
    cursor: pointer;
    padding: 2px 6px;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.composite-layer-remove-btn .icon {
    width: 16px;
    height: 16px;
}

.composite-layer-remove-btn:hover {
    opacity: 1;
}

.composite-layer-range-toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

.composite-layer-range-fields {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.composite-layer-range-fields label {
    color: var(--text-secondary);
    flex-shrink: 0;
}

.composite-layer-range-fields input[type="number"] {
    width: 60px;
    flex-shrink: 0;
}

.composite-layer-range-disabled {
    opacity: 0.35;
    pointer-events: none;
}

.composite-layer-reverse-label {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    white-space: nowrap;
    color: var(--text-secondary);
}

/* ── Composite layer drag-to-reorder ── */

.composite-layer-drag-handle {
    cursor: grab;
    opacity: 0;
    color: var(--text-secondary);
    font-size: 0.75rem;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 3px;
    transition: opacity 0.2s ease;
    user-select: none;
    touch-action: none;
    flex-shrink: 0;
}

.composite-layer-item:hover .composite-layer-drag-handle {
    opacity: 0.5;
}

.composite-layer-drag-handle:hover {
    opacity: 1 !important;
    background: var(--border-color);
}

/* ── Weather source location row ── */

.weather-location-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.weather-location-field {
    display: flex;
    align-items: center;
    gap: 4px;
}

.weather-location-field label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.weather-location-field input[type="number"] {
    width: 80px;
}

.composite-layer-drag-handle:active {
    cursor: grabbing;
}

.composite-layer-drag-clone {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    opacity: 0.92;
    transform: scale(1.02);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25);
    will-change: top;
}

.composite-layer-drag-placeholder {
    border: 2px dashed var(--primary-color);
    border-radius: 4px;
    background: rgba(33, 150, 243, 0.04);
    min-height: 42px;
    transition: height 0.15s ease;
}

body.composite-layer-dragging .composite-layer-item {
    transition: none !important;
}

body.composite-layer-dragging .composite-layer-drag-handle {
    opacity: 0 !important;
}

/* ── File drop zone ── */
.file-dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 28px 20px;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-color);
    cursor: pointer;
    transition: border-color var(--duration-normal) ease,
                background var(--duration-normal) ease,
                box-shadow var(--duration-normal) ease;
    user-select: none;
    outline: none;
}

.file-dropzone:hover {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 5%, var(--bg-color));
}

.file-dropzone:focus-visible {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.15);
}

.file-dropzone.dragover {
    border-color: var(--primary-color);
    border-style: solid;
    background: color-mix(in srgb, var(--primary-color) 10%, var(--bg-color));
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.15),
                inset 0 0 20px rgba(76, 175, 80, 0.06);
}

.file-dropzone.has-file {
    border-style: solid;
    border-color: var(--primary-color);
    padding: 16px 20px;
}

.file-dropzone-icon {
    color: var(--text-muted);
    transition: color var(--duration-normal) ease, transform var(--duration-normal) var(--ease-spring);
}

.file-dropzone:hover .file-dropzone-icon,
.file-dropzone.dragover .file-dropzone-icon {
    color: var(--primary-color);
    transform: translateY(-2px);
}

.file-dropzone.has-file .file-dropzone-icon {
    color: var(--primary-color);
}

.file-dropzone-text {
    text-align: center;
}

.file-dropzone-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: color var(--duration-normal) ease;
}

.file-dropzone:hover .file-dropzone-label {
    color: var(--text-secondary);
}

.file-dropzone-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.file-dropzone-filename {
    flex: 1;
    font-size: 0.88rem;
    font-weight: var(--weight-medium);
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-dropzone-filesize {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    font-family: var(--font-mono);
}

.file-dropzone-remove {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    transition: background var(--duration-fast) ease, color var(--duration-fast) ease;
    line-height: 1;
    padding: 0;
}

.file-dropzone-remove:hover {
    background: var(--danger-color);
    color: white;
}

