/* Spa Room Page — Device Controller Layout */

/* Hide mode toggle from hamburger menu (it's inline on the spa page) */
.spa-room-page .mode-toggle-item {
    display: none;
}

/* ═══════════════════════════════════════════════════════════
   Status Bar
   ═══════════════════════════════════════════════════════════ */

.spa-status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 48px;
    z-index: 10;
}

.status-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.status-scene-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.btn-activate-current {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: none;
    border-radius: 20px;
    background: var(--success);
    color: var(--bg-dark);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.2s, transform 0.1s;
}

.btn-activate-current:active { transform: scale(0.95); }
.btn-activate-current.loading { opacity: 0.6; pointer-events: none; }
.btn-activate-current.activated { animation: pulse-success 0.5s; }

@keyframes pulse-success {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.btn-scene-picker {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-light);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, color 0.2s;
}

.btn-scene-picker:hover {
    background: var(--accent);
    color: var(--text-primary);
}

/* ═══════════════════════════════════════════════════════════
   Device Controls Grid
   ═══════════════════════════════════════════════════════════ */

.device-controls {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 12px;
    height: calc(100vh - 48px - 50px - 24px); /* viewport - nav - status - padding */
    height: calc(100dvh - 48px - 50px - 24px);
    min-height: 300px;
    overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════
   Screen 1 Panel (main, left side)
   ═══════════════════════════════════════════════════════════ */

.panel-screen-1 {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    min-height: 0;
}

.screen-1-display {
    flex: 1;
    min-height: 0;
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-dark);
    border: 1px solid var(--border);
}

/* Scene view (thumbnail) */
.screen-1-scene-view,
.screen-1-tv-view {
    width: 100%;
    height: 100%;
    position: relative;
}

.screen-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.screen-thumb-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-dark);
    color: var(--text-muted);
}

/* Power overlay (shown when screen is off) */
.screen-power-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    background: rgba(0, 0, 0, 0.75);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    z-index: 2;
}

.screen-power-overlay.visible {
    display: flex;
}

.screen-power-overlay.small svg {
    width: 20px;
    height: 20px;
}

/* Overlay bar on scene thumbnail (mode toggle + power, top-right) */
.screen-overlay-bar {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    z-index: 3;
}

.overlay-power {
    background: rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
}

.overlay-power.on {
    color: var(--success);
    border-color: rgba(76, 175, 80, 0.6);
}

.screen-overlay-bar .mode-toggle-inline {
    background: rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.15);
}

/* TV mode: inline remote */
.inline-remote {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 6px;
}

/* Top row: power, back, home, spacer, mode toggle */
.remote-top-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* Power buttons in remote top row inherit .overlay-power styles */

.remote-top-spacer {
    flex: 1;
}

/* Body: app column left + d-pad right */
.remote-body {
    flex: 1;
    display: flex;
    gap: 8px;
    min-height: 0;
    align-items: center;
}

.remote-app-column {
    display: flex;
    flex-direction: column;
    gap: 6px;
    justify-content: center;
    flex-shrink: 0;
}

.remote-app-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-light);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s;
}

.remote-app-btn:hover {
    background: var(--bg-hover);
}

.remote-app-btn svg {
    width: 20px;
    height: 20px;
}

.remote-dpad-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    min-width: 0;
}

/* Make d-pad fill available space */
.remote-dpad-area .remote-dpad-circular {
    width: min(200px, 90%);
    height: min(200px, 90%);
    aspect-ratio: 1;
}

/* Screen 1 controls bar (volume slider only) */
.screen-1-controls {
    flex-shrink: 0;
}

.screen-power-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-light);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}

.screen-power-btn:hover {
    background: var(--bg-hover);
}

.screen-power-btn.on {
    color: var(--success);
    border-color: var(--success);
}

/* Mode toggle (Scene / TV) */
.mode-toggle-inline {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    flex-shrink: 0;
}

.mode-toggle-btn {
    padding: 6px 14px;
    border: none;
    background: var(--bg-light);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.mode-toggle-btn.active {
    background: var(--accent);
    color: var(--text-primary);
}

.mode-toggle-btn:first-child {
    border-right: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════
   Sidebar (Screen 2, Lights, Music)
   ═══════════════════════════════════════════════════════════ */

.controls-sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 200px;
    min-height: 0;
    overflow-y: auto;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

/* Screen 2 thumbnail */
.screen-2-thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: border-color 0.2s;
}

.screen-2-thumb:hover {
    border-color: var(--text-muted);
}

.screen-2-thumb .screen-thumb-img {
    border-radius: 0;
}

/* Screen 2 power button (top-right, matching screen 1 style) */
.screen-2-power-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    z-index: 3;
    width: 26px;
    height: 26px;
    background: rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.2);
}

/* ═══════════════════════════════════════════════════════════
   Horizontal Sliders
   ═══════════════════════════════════════════════════════════ */

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

.h-slider-row.compact {
    gap: 6px;
}

.h-slider-icon {
    color: var(--text-muted);
    flex-shrink: 0;
    display: flex;
}

.h-slider {
    flex: 1;
    height: 28px;
    background: var(--bg-input, var(--bg-dark));
    border: 1px solid var(--border);
    border-radius: 14px;
    position: relative;
    cursor: pointer;
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.h-slider-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 14px;
    pointer-events: none;
    transition: width 20ms linear;
}

/* Volume sliders - blue/cyan */
.tv-vol-slider .h-slider-fill,
.window-vol-slider .h-slider-fill,
.music-vol-slider .h-slider-fill {
    background: var(--accent);
    opacity: 0.6;
}

/* Brightness slider - gold/orange */
.brightness-h-slider .h-slider-fill {
    background: linear-gradient(to right, #e65100, #ffb300, #ffeb3b);
    opacity: 0.7;
}

/* Dragging feedback for release-only sliders */
.h-slider.dragging {
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
}

.h-slider.dragging .h-slider-fill {
    opacity: 0.5;
}

.h-slider-val {
    color: var(--text-secondary);
    font-size: 0.75rem;
    min-width: 2.5rem;
    text-align: right;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════════════
   Responsive: Portrait Phone
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 600px) and (orientation: portrait) {
    .device-controls {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 48px - 50px - 24px);
        min-height: calc(100dvh - 48px - 50px - 24px);
        overflow-y: auto;
    }

    .panel-screen-1 {
        min-height: 0;
    }

    .screen-1-display {
        aspect-ratio: 16 / 9;
        flex: none;
    }

    /* TV mode: let the remote fill remaining vertical space */
    .screen-1-display:has(.screen-1-tv-view:not([hidden])) {
        aspect-ratio: auto;
        flex: 1;
        min-height: 280px;
    }

    .device-controls:has(.screen-1-tv-view:not([hidden])) .panel-screen-1 {
        flex: 1;
    }

    .controls-sidebar {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        align-content: start;
    }

    .sidebar-section {
        gap: 4px;
    }

    /* Screen 2 spans left column */
    .screen-2-section {
        grid-column: 1;
        grid-row: 1 / 4;
    }

    /* Right column: lights, music, diffuser stacked */
    .diffuser-section {
        gap: 4px;
    }
}

/* ═══════════════════════════════════════════════════════════
   Responsive: Landscape Phone
   ═══════════════════════════════════════════════════════════ */

@media (max-height: 500px) and (orientation: landscape) {
    .device-controls {
        height: calc(100vh - 48px - 50px - 16px);
        height: calc(100dvh - 48px - 50px - 16px);
        padding: 8px;
        gap: 8px;
    }

    .controls-sidebar {
        width: 160px;
        gap: 8px;
    }

    .sidebar-label {
        font-size: 0.65rem;
    }

    .h-slider {
        height: 24px;
    }

    .h-slider-val {
        font-size: 0.7rem;
        min-width: 2rem;
    }

    .screen-2-thumb {
        aspect-ratio: 16 / 10;
    }

    /* Smaller d-pad in landscape */
    .remote-dpad-area .remote-dpad-circular {
        width: min(140px, 80%);
        height: min(140px, 80%);
    }

    .remote-app-btn {
        width: 34px;
        height: 34px;
    }

    .remote-app-btn svg {
        width: 16px;
        height: 16px;
    }

    .remote-top-row {
        gap: 4px;
    }
}

/* ═══════════════════════════════════════════════════════════
   Responsive: Tablet / Desktop
   ═══════════════════════════════════════════════════════════ */

/* Diffuser toggle — inline label + button */
.diffuser-section {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.diffuser-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-light);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
    flex-shrink: 0;
}

.diffuser-toggle-btn:hover {
    background: var(--bg-hover);
}

.diffuser-toggle-btn.on {
    color: var(--success);
    border-color: var(--success);
}

@media (min-width: 768px) {
    .controls-sidebar {
        width: 240px;
    }

    .device-controls {
        padding: 16px;
        gap: 16px;
    }
}
