/* ========== CSS Variables ========== */
:root {
    --glass-bg: rgba(218, 214, 252, 0.80);
    --glass-bg-hover: rgba(228, 225, 255, 0.90);
    --glass-border: rgba(155, 140, 220, 0.35);
    --glass-border-bright: rgba(175, 162, 232, 0.60);
    --glass-blur: blur(28px);
    --glass-shadow: 0 8px 40px rgba(60, 50, 120, 0.25);

    --accent: #4f46e5;
    --accent-2: #ec4899;
    --accent-green: #10b981;
    --accent-red: #ef4444;

    --text-primary: #0e0c2e;
    --text-secondary: #2e2c5e;
    --text-hint: #6e6e9e;

    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;

    --transition: 0.2s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    min-height: 100vh;
    background: linear-gradient(135deg, #6a6ec8 0%, #8b70cc 50%, #a87fd4 100%);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px 16px 48px;
    color: var(--text-primary);
    overflow-x: hidden;
}

/* ========== Background Orbs ========== */
.bg-orbs {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.30;
    animation: orbFloat 14s ease-in-out infinite;
}

.orb-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #4f52a8, transparent 70%);
    top: -160px;
    left: -100px;
    animation-delay: 0s;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, #c084fc, transparent 70%);
    top: 20%;
    right: -100px;
    animation-delay: 5s;
}

.orb-3 {
    width: 360px;
    height: 360px;
    background: radial-gradient(circle, #818cf8, transparent 70%);
    bottom: -100px;
    left: 30%;
    animation-delay: 10s;
}

@keyframes orbFloat {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-28px) scale(1.04); }
}

/* ========== App Container ========== */
#app {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 860px;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid rgba(155, 140, 220, 0.30);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ========== Header ========== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--glass-border);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
}

.brand-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

/* ========== Glass Panels (shared) ========== */
.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
}

/* ========== Config Panel ========== */
#config-container {
    background: rgba(255, 255, 255, 0.50);
    border: 1px solid rgba(255, 255, 255, 0.80);
    border-radius: var(--radius-md);
    padding: 20px;
    display: none;
}

#config-container.active {
    display: block;
}

.config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(99, 102, 241, 0.12);
}

.config-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.config-wrapper {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.setting-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.setting-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.setting-hint {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-hint);
    text-transform: none;
    letter-spacing: 0;
}

/* ========== Form Inputs ========== */
input[type="text"],
input[type="password"],
input[type="number"],
textarea {
    background: rgba(255, 255, 255, 0.80);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    padding: 10px 14px;
    outline: none;
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
    width: 100%;
}

input[type="text"]::placeholder,
input[type="password"]::placeholder,
textarea::placeholder {
    color: var(--text-hint);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
textarea:focus {
    border-color: #6366f1;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

/* ========== Custom Select ========== */
.cs-wrapper {
    position: relative;
    width: 100%;
    user-select: none;
}

.cs-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: rgba(255, 255, 255, 0.80);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    padding: 10px 14px;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
    width: 100%;
    min-height: 41px;
}

.cs-trigger:hover {
    border-color: var(--glass-border-bright);
    background: rgba(255, 255, 255, 0.90);
}

.cs-wrapper.open .cs-trigger {
    border-color: #6366f1;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.cs-display {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cs-arrow {
    flex-shrink: 0;
    color: rgba(99, 102, 241, 0.50);
    transition: transform var(--transition);
}

.cs-wrapper.open .cs-arrow {
    transform: rotate(180deg);
}

.cs-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(28px) saturate(1.4);
    -webkit-backdrop-filter: blur(28px) saturate(1.4);
    border: 1px solid rgba(99, 102, 241, 0.12);
    border-radius: var(--radius-sm);
    box-shadow: 0 12px 40px rgba(60, 50, 120, 0.15);
    z-index: 200;
    max-height: 220px;
    overflow-y: auto;
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.cs-dropdown::-webkit-scrollbar {
    display: none;
}

.cs-wrapper.open .cs-dropdown {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.cs-option {
    padding: 10px 14px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.cs-option:hover {
    background: rgba(99, 102, 241, 0.06);
    color: var(--text-primary);
}

.cs-option.selected {
    color: #6366f1;
    background: rgba(99, 102, 241, 0.08);
    font-weight: 500;
}

.cs-option.selected::before {
    content: '✓';
    font-size: 12px;
    flex-shrink: 0;
    width: 14px;
}

.cs-option:not(.selected)::before {
    content: '';
    width: 14px;
    flex-shrink: 0;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* Remove native number input spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

input:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ========== Buttons ========== */
.btn-confirm {
    padding: 10px 24px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    align-self: flex-start;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.btn-confirm:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.btn-confirm:active {
    transform: translateY(0);
}

/* Connect button */
.connect-section {
    display: flex;
    justify-content: center;
}

.btn-connect {
    padding: 12px 48px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: none;
    border-radius: 50px;
    color: white;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

.btn-connect:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.45);
}

.btn-connect:active {
    transform: translateY(0);
}

.btn-connect.connected {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.35);
}

.btn-connect.connected:hover {
    box-shadow: 0 8px 24px rgba(239, 68, 68, 0.45);
}

/* Icon buttons */
.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(130, 115, 200, 0.30);
    background: rgba(255, 255, 255, 0.40);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition), border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.65);
    border-color: rgba(130, 115, 200, 0.55);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(80, 60, 160, 0.18);
}

.icon-btn:active {
    transform: translateY(0);
}

.icon-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.icon-btn.accent {
    background: rgba(99, 102, 241, 0.08);
    border-color: rgba(99, 102, 241, 0.2);
    color: var(--accent);
}

.icon-btn.accent:hover {
    background: rgba(99, 102, 241, 0.15);
}

/* ========== Logs Container ========== */
#logs-container {
    height: 280px;
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(99, 102, 241, 0.10);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    scroll-behavior: smooth;
}

#logs-container::-webkit-scrollbar {
    width: 4px;
}

#logs-container::-webkit-scrollbar-track {
    background: transparent;
}

#logs-container::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.25);
    border-radius: 2px;
}

.log-entry {
    font-size: 13px;
    line-height: 1.5;
    margin-bottom: 6px;
    display: flex;
    gap: 6px;
    align-items: baseline;
}

.log-entry.system { color: #059669; }
.log-entry.user   { color: #4f46e5; }
.log-entry.ai     { color: #7c3aed; }

.log-entry .timestamp {
    font-size: 11px;
    color: var(--text-hint);
    flex-shrink: 0;
}

.log-entry .emoji {
    flex-shrink: 0;
}

/* ========== Input Row ========== */
.input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-row input[type="text"] {
    flex: 1;
    border-radius: 50px;
    padding: 10px 18px;
}

/* Mic / Camera / Screen buttons */
#mic-button {
    background: rgba(99, 102, 241, 0.07);
    border-color: rgba(99, 102, 241, 0.18);
    color: var(--accent);
}

#mic-button[style*="background-color: rgb(234, 67, 53)"],
#mic-button.recording {
    background: rgba(239, 68, 68, 0.12) !important;
    border-color: rgba(239, 68, 68, 0.35) !important;
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.18) !important;
    color: var(--accent-red) !important;
}

#camera-button,
#screen-button {
    background: rgba(99, 102, 241, 0.07);
    border-color: rgba(99, 102, 241, 0.18);
    color: var(--accent);
}

#camera-button.active,
#screen-button.active {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.35);
    color: var(--accent-red);
}

/* ========== Audio Visualizers ========== */
.audio-visualizers {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.visualizer-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.visualizer-container label {
    font-size: 11px;
    color: var(--text-hint);
    width: 72px;
    flex-shrink: 0;
    text-align: right;
}

#input-audio-visualizer,
#audio-visualizer {
    flex: 1;
    height: 6px;
    background: rgba(99, 102, 241, 0.10);
    border-radius: 3px;
    overflow: hidden;
}

#input-audio-visualizer .audio-bar {
    height: 100%;
    background: linear-gradient(90deg, #10b981, #34d399);
    width: 0%;
    border-radius: 3px;
    transition: width 0.05s ease;
}

#audio-visualizer .audio-bar {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #ec4899);
    width: 0%;
    border-radius: 3px;
    transition: width 0.05s ease;
}

@keyframes audio-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.65; }
}

.audio-bar.active {
    animation: audio-pulse 0.5s infinite;
}

/* ========== Floating Video ========== */
#video-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 280px;
    z-index: 100;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: rgba(255, 255, 255, 0.70);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.85);
    box-shadow: 0 8px 32px rgba(99, 102, 241, 0.15);
    cursor: grab;
    touch-action: none;
    user-select: none;
}

#video-container:active {
    cursor: grabbing;
}

#video-container video {
    width: 100%;
    display: block;
    pointer-events: none;
}

/* Hide the internal frame-preview canvas — it's for processing only */
#video-container canvas {
    display: none;
}

.video-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity var(--transition);
}

#video-container:hover .video-controls {
    opacity: 1;
}

#stop-video {
    background: rgba(239, 68, 68, 0.85);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
}

#flip-camera {
    background: rgba(255, 255, 255, 0.70);
    border: none;
    padding: 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
}

/* ========== Floating Screen Share ========== */
#screen-container {
    position: fixed;
    top: 24px;
    right: 24px;
    width: 400px;
    height: 300px;
    z-index: 1000;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #000;
    border: 1px solid rgba(99, 102, 241, 0.2);
    box-shadow: 0 8px 32px rgba(99, 102, 241, 0.2);
    transition: transform var(--transition), box-shadow var(--transition);
}

#screen-container:hover {
    transform: scale(1.02);
    box-shadow: 0 12px 40px rgba(99, 102, 241, 0.25);
}

#screen-preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
    display: block;
}

#screen-container .close-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    opacity: 0;
    transition: opacity var(--transition);
}

#screen-container:hover .close-button {
    opacity: 1;
}

/* ========== Responsive ========== */
@media (max-width: 600px) {
    body {
        padding: 12px 8px 32px;
    }

    #app {
        padding: 16px;
        border-radius: var(--radius-md);
        gap: 12px;
    }

    .brand-title {
        font-size: 15px;
    }

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

    .btn-connect {
        padding: 10px 32px;
        font-size: 14px;
    }

    #logs-container {
        height: 200px;
    }

    #video-container {
        width: 50%;
        bottom: 0;
        right: 0;
        border-radius: var(--radius-sm) 0 0 0;
    }

    #screen-container {
        width: 100%;
        height: 45vw;
        top: auto;
        bottom: 0;
        right: 0;
        border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    }

    #config-container.active {
        position: fixed;
        inset: 0;
        z-index: 999;
        border-radius: 0;
        overflow-y: auto;
        background: rgba(80, 84, 180, 0.98);
        backdrop-filter: blur(24px);
        -webkit-backdrop-filter: blur(24px);
        padding: 24px 20px;
    }

    #config-container.active .config-title,
    #config-container.active .setting-label {
        color: rgba(255, 255, 255, 0.95);
    }

    #config-container.active .setting-hint {
        color: rgba(255, 255, 255, 0.60);
    }

    #config-container.active .config-header {
        border-bottom-color: rgba(255, 255, 255, 0.20);
    }

    #config-container.active input[type="text"],
    #config-container.active input[type="password"],
    #config-container.active input[type="number"],
    #config-container.active textarea {
        background: rgba(255, 255, 255, 0.18);
        border-color: rgba(255, 255, 255, 0.30);
        color: #fff;
    }

    #config-container.active input::placeholder,
    #config-container.active textarea::placeholder {
        color: rgba(255, 255, 255, 0.45);
    }

    #config-container.active input:focus,
    #config-container.active textarea:focus {
        background: rgba(255, 255, 255, 0.25);
        border-color: rgba(255, 255, 255, 0.70);
        box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.15);
    }

    #config-container.active .cs-trigger {
        background: rgba(255, 255, 255, 0.18);
        border-color: rgba(255, 255, 255, 0.30);
        color: #fff;
    }

    #config-container.active .cs-arrow {
        color: rgba(255, 255, 255, 0.60);
    }

    #config-container.active .icon-btn {
        background: rgba(255, 255, 255, 0.18);
        border-color: rgba(255, 255, 255, 0.30);
        color: #fff;
    }
}
