/* === Reset & Base === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    background: #0d1117;
    color: #c9d1d9;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overflow: hidden;
}

/* === Connect Panel === */
#connect-panel {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, #161b22 0%, #0d1117 100%);
}

#connect-panel .card {
    width: 380px;
    padding: 40px 32px;
    background: rgba(22, 27, 34, 0.95);
    border: 1px solid #30363d;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    text-align: center;
    animation: fadeInUp 0.5s ease;
}

#connect-panel h1 {
    font-size: 24px;
    font-weight: 600;
    color: #f0f6fc;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

#connect-panel p {
    font-size: 13px;
    color: #8b949e;
    margin-bottom: 28px;
}

#connect-panel input {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 8px;
    color: #c9d1d9;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#connect-panel select {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 8px;
    color: #c9d1d9;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

#connect-panel select:focus {
    border-color: #58a6ff;
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

#connect-panel input:focus {
    border-color: #58a6ff;
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

/* === Mode Selector === */
.mode-selector {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 8px;
    overflow: hidden;
}

.mode-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #8b949e;
    transition: all 0.2s ease;
    position: relative;
    user-select: none;
}

.mode-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.mode-option:first-child {
    border-right: 1px solid #30363d;
}

.mode-option:has(input:checked) {
    background: rgba(88, 166, 255, 0.1);
    color: #58a6ff;
}

.mode-option:hover {
    background: rgba(88, 166, 255, 0.05);
    color: #c9d1d9;
}

#connect-panel button {
    width: 100%;
    padding: 12px;
    background: #238636;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

#connect-panel button:hover {
    background: #2ea043;
}

#connect-panel button:active {
    transform: scale(0.98);
}

#connect-panel button:disabled {
    background: #484f58;
    cursor: not-allowed;
    opacity: 0.7;
}

#status {
    margin-top: 16px;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    display: inline-block;
    transition: all 0.3s ease;
}

#status.status-disconnected {
    color: #f85149;
    background: rgba(248, 81, 73, 0.1);
}

#status.status-connecting {
    color: #f0883e;
    background: rgba(240, 136, 62, 0.1);
}

#status.status-connected {
    color: #3fb950;
    background: rgba(63, 185, 80, 0.1);
}

#status.status-error {
    color: #f85149;
    background: rgba(248, 81, 73, 0.1);
}

/* === Desktop Container === */
#desktop-container {
    width: 100%;
    height: 100%;
    background: #000;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#remote-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    cursor: none;
}

/* === Cache Overlay === */
.cache-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* === Watermark Overlay === */
.watermark-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 6;
}

/* === Metrics Panel === */
#metrics-panel {
    position: absolute;
    top: 16px;
    right: 16px;
    padding: 10px 16px;
    background: rgba(13, 17, 23, 0.8);
    border: 1px solid #30363d;
    border-radius: 8px;
    backdrop-filter: blur(8px);
    display: flex;
    gap: 16px;
    font-size: 12px;
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    color: #8b949e;
    user-select: none;
    transition: opacity 0.3s ease;
    z-index: 10;
}

#metrics-panel span {
    white-space: nowrap;
}

/* === Toolbar === */
#toolbar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 16px;
    background: rgba(13, 17, 23, 0.7);
    border-top: 1px solid #30363d;
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    gap: 12px;
    transform: translateY(100%);
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    z-index: 10;
}

#desktop-container:hover #toolbar {
    transform: translateY(0);
    opacity: 1;
}

#toolbar button {
    padding: 8px 16px;
    background: rgba(48, 54, 61, 0.8);
    border: 1px solid #30363d;
    border-radius: 6px;
    color: #c9d1d9;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

#toolbar button:hover {
    background: #30363d;
    border-color: #8b949e;
}

#toolbar button:active {
    transform: scale(0.96);
}

#fullscreen-btn {
    background: rgba(35, 134, 54, 0.2) !important;
    border-color: #238636 !important;
}

#fullscreen-btn:hover {
    background: rgba(35, 134, 54, 0.35) !important;
}

#disconnect-btn {
    background: rgba(248, 81, 73, 0.15) !important;
    border-color: #f85149 !important;
    color: #f85149 !important;
}

#disconnect-btn:hover {
    background: rgba(248, 81, 73, 0.3) !important;
}

/* === Fullscreen Adjustments === */
#desktop-container:fullscreen {
    background: #000;
}

#desktop-container:fullscreen #remote-video {
    object-fit: contain;
}

/* === Channel Status Bar === */
.channel-status-bar {
    position: fixed;
    bottom: 10px;
    left: 10px;
    display: flex;
    gap: 6px;
    z-index: 100;
}

.channel-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    color: white;
    font-family: monospace;
}

/* === Animations === */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

#connect-panel button:disabled {
    animation: pulse 1.5s ease-in-out infinite;
}

/* === Recording Controls === */
.recording-controls {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    margin-right: 8px;
}

.recording-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: none;
}

.recording-indicator.recording-active {
    display: inline-block;
    background: #e53e3e;
    animation: recording-blink 1s infinite;
}

.recording-indicator.recording-paused {
    display: inline-block;
    background: #ed8936;
    animation: recording-blink 2s infinite;
}

@keyframes recording-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.recording-duration {
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    font-size: 12px;
    color: #e53e3e;
    min-width: 60px;
}

.control-btn {
    background: none;
    border: 1px solid #4a5568;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 14px;
    color: #e2e8f0;
    transition: all 0.2s;
}

.control-btn:hover {
    background: #4a5568;
}

.control-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.control-btn.active {
    background: #2b6cb0;
    border-color: #2b6cb0;
    color: #fff;
}

/* === Audio Controls === */
.audio-controls {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
}

.volume-slider {
    width: 60px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: #4a5568;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #63b3ed;
    cursor: pointer;
}

.audio-status {
    font-size: 11px;
    color: #a0aec0;
    margin-left: 4px;
}

/* === Display Selector === */
.display-selector {
    display: flex;
    gap: 4px;
    padding: 4px 8px;
    background: #1a202c;
    border-bottom: 1px solid #2d3748;
    align-items: center;
    z-index: 10;
}

.display-tab {
    padding: 4px 12px;
    border: 1px solid #4a5568;
    border-radius: 4px;
    background: transparent;
    color: #a0aec0;
    cursor: pointer;
    font-size: 12px;
}

.display-tab.active {
    background: #2b6cb0;
    color: #fff;
    border-color: #2b6cb0;
}

.display-tab:hover {
    background: #2d3748;
}

.display-mode-btn {
    margin-left: auto;
    padding: 4px 8px;
    border: 1px solid #4a5568;
    border-radius: 4px;
    background: transparent;
    color: #a0aec0;
    cursor: pointer;
    font-size: 16px;
}

.display-mode-btn:hover {
    background: #2d3748;
}

/* === Video Container === */
.video-container {
    width: 100%;
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* === Side-by-Side Mode === */
.video-container.side-by-side {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
}

.usb-panel {
    position: fixed;
    right: -280px;
    top: 60px;
    width: 270px;
    background: #1a202c;
    border: 1px solid #2d3748;
    border-radius: 8px;
    padding: 12px;
    transition: right 0.3s ease;
    z-index: 100;
    box-shadow: -2px 0 10px rgba(0,0,0,0.3);
}

.usb-panel.visible { right: 10px; }

.usb-panel-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid #2d3748;
    color: #e2e8f0; font-size: 14px; font-weight: 600;
}

.usb-close-btn { background: none; border: none; color: #a0aec0; cursor: pointer; font-size: 16px; }

.usb-device { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 4px; margin-bottom: 4px; background: #2d3748; }
.usb-device.connected { border-left: 3px solid #48bb78; }
.usb-device-name { flex: 1; color: #e2e8f0; font-size: 12px; }
.usb-device-id { color: #718096; font-size: 10px; font-family: monospace; }
.usb-btn { padding: 2px 8px; border: 1px solid #4a5568; border-radius: 3px; background: transparent; color: #a0aec0; cursor: pointer; font-size: 11px; }
.usb-btn:hover { background: #4a5568; }
.usb-empty { color: #718096; font-size: 12px; text-align: center; padding: 20px; }
.usb-refresh-btn { width: 100%; margin-top: 8px; padding: 6px; border: 1px solid #4a5568; border-radius: 4px; background: transparent; color: #a0aec0; cursor: pointer; }
.usb-refresh-btn:hover { background: #2d3748; }

/* === Mobile Adaptations === */
@media (max-width: 600px) {
    #connect-panel .card {
        width: 100%;
        max-width: 100%;
        padding: 32px 20px;
        border-radius: 0;
        border: none;
        box-shadow: none;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    #connect-panel input,
    #connect-panel select,
    #connect-panel button {
        min-height: 44px;
        font-size: 16px; /* prevent iOS zoom on focus */
    }

    #remote-video {
        width: 100%;
        height: 100vh;
        object-fit: contain;
    }

    #toolbar {
        padding: 16px;
        transform: translateY(0);
        opacity: 1;
    }

    #toolbar button {
        min-height: 44px;
        padding: 10px 20px;
        font-size: 14px;
    }

    #metrics-panel {
        top: 8px;
        right: 8px;
        padding: 6px 10px;
        gap: 8px;
        font-size: 10px;
    }
}
