/* ═══════════════════════════════════════════════════════════════════════════
   MORPHIOUS CONNECT — WEB VIEWER STYLE SHEET
   Glassmorphism, dark purple/cyan neon theme, responsive layout
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --bg-primary: #080510;
    --bg-secondary: #0f0a1e;
    --bg-card: rgba(255, 255, 255, 0.03);
    --bg-card-hover: rgba(255, 255, 255, 0.06);
    --bg-input: rgba(0, 0, 0, 0.2);
    
    --accent: #a855f7;
    --accent-dim: #7c3aed;
    --accent-cyan: #00e5ff;
    --accent-gradient: linear-gradient(135deg, #a855f7, #00e5ff);
    
    --text-primary: #f1f5f9;
    --text-secondary: #a5b4c8;
    --text-muted: #4a5578;
    
    --border: rgba(255, 255, 255, 0.06);
    --border-accent: rgba(168, 85, 247, 0.3);
    
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    position: relative;
}

/* ─── Background Effects ─────────────────────────────────────────────────── */
.bg-effects {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.15;
    animation: float 20s infinite alternate;
}

.orb-1 {
    width: 40vw;
    height: 40vw;
    background: var(--accent);
    top: -10vw;
    left: -10vw;
}

.orb-2 {
    width: 50vw;
    height: 50vw;
    background: var(--accent-cyan);
    bottom: -15vw;
    right: -15vw;
    animation-delay: -5s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(5vw, 5vh) scale(1.1); }
}

.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(255,255,255,0.005) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.005) 1px, transparent 1px);
    background-size: 40px 40px;
    z-index: 0;
    pointer-events: none;
}

/* ─── Glassmorphism Base ─────────────────────────────────────────────────── */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Overlays ───────────────────────────────────────────────────────────── */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(8, 5, 16, 0.85);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: opacity 0.3s ease;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ─── Auth Card ──────────────────────────────────────────────────────────── */
.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 40px 32px;
    border-color: var(--border-accent);
}

.brand {
    text-align: center;
    margin-bottom: 30px;
}

.brand-logo {
    width: 64px;
    height: 64px;
    margin-bottom: 12px;
    filter: drop-shadow(0 0 12px rgba(168, 85, 247, 0.5));
}

.brand h2 {
    font-size: 24px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tab-buttons {
    display: flex;
    background: var(--bg-input);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.25s ease;
}

.tab-btn.active {
    background: rgba(255,255,255,0.06);
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: opacity 0.3s ease;
}

.auth-form.hidden {
    display: none;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 15px;
    transition: all 0.25s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.2);
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    box-shadow: 0 4px 15px rgba(168, 85, 247, 0.3);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(168, 85, 247, 0.5);
    filter: brightness(1.1);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

/* ─── App Container ──────────────────────────────────────────────────────── */
#app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    position: relative;
    z-index: 1;
}

#app-container.hidden {
    display: none !important;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
    width: 320px;
    height: 100%;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-left: none;
    padding: 30px 24px;
    display: flex;
    flex-direction: column;
    gap: 30px;
    z-index: 10;
}

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

.sidebar-logo {
    width: 32px;
    height: 32px;
    filter: drop-shadow(0 0 6px var(--accent));
}

.sidebar-title {
    font-size: 18px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.info-section {
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.info-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.my-id-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#my-device-id {
    font-size: 20px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    color: var(--accent-cyan);
    letter-spacing: 0.05em;
}

.control-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.status-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: auto;
}

.status-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.connected {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-badge.disconnected {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.status-badge.connecting {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

/* ─── Viewer Main ────────────────────────────────────────────────────────── */
.viewer-main {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

.viewer-header {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    height: 60px;
    border-radius: 12px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 5;
}

.viewer-header.hidden {
    display: none;
}

#connected-peer-name {
    font-weight: 600;
    font-size: 15px;
}

.header-controls {
    display: flex;
    gap: 8px;
}

.remote-desktop-container {
    flex: 1;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: #000;
    cursor: default;
}

#remote-video {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    pointer-events: none; /* Pointer events captured on the container instead */
}

.remote-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.remote-overlay.hidden {
    display: none !important;
}

.overlay-content {
    text-align: center;
}

#overlay-text {
    font-size: 16px;
    color: var(--text-secondary);
    margin-top: 20px;
}

.pulse-ring {
    width: 80px;
    height: 80px;
    border: 3px solid var(--accent);
    border-radius: 50%;
    margin: 0 auto;
    animation: pulse 2s infinite ease-out;
}

@keyframes pulse {
    0% { transform: scale(0.6); opacity: 0; }
    50% { opacity: 0.5; }
    100% { transform: scale(1.2); opacity: 0; }
}

.hidden-input {
    position: absolute;
    top: -100px;
    left: -100px;
    opacity: 0;
    width: 1px;
    height: 1px;
    z-index: -100;
}

/* ─── Slide-out Chat Drawer ──────────────────────────────────────────────── */
.chat-drawer {
    width: 350px;
    height: 100%;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-right: none;
    display: flex;
    flex-direction: column;
    z-index: 8;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-drawer.hidden {
    transform: translateX(100%);
    display: none;
}

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

.chat-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-muted);
    gap: 12px;
}

.empty-state p {
    font-size: 14px;
    font-weight: 500;
}

.chat-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
}

.chat-msg.outgoing {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.incoming {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg-time {
    font-size: 9px;
    color: rgba(255,255,255,0.6);
    margin-top: 4px;
    text-align: right;
}

.chat-msg.incoming .msg-time {
    color: var(--text-muted);
}

.chat-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    align-items: center;
}

#chat-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 8px;
    resize: none;
    font-size: 14px;
    line-height: 1.3;
}

#chat-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* ─── Toast System ───────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2000;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: toast-in 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    transition: all 0.3s ease;
}

.toast.info { background: #3b82f6; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.toast.removing {
    opacity: 0;
    transform: translateY(20px);
}

@keyframes toast-in {
    from { transform: translateY(50px) scale(0.9); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

/* ─── Mobile Responsiveness ──────────────────────────────────────────────── */
@media (max-width: 1024px) {
    #app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        border-bottom: 1px solid var(--border);
        border-right: none;
        padding: 16px 20px;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
    }
    
    .sidebar-header, .status-section, #btn-logout {
        display: none !important;
    }
    
    .info-section, .control-section {
        flex: 1;
        margin: 0;
    }
    
    .control-section {
        display: flex;
        gap: 10px;
        align-items: center;
    }
    
    .control-section h3, .info-label {
        display: none;
    }
    
    .control-section .form-group {
        flex: 1;
        margin: 0;
    }
    
    .btn-block {
        width: auto;
        white-space: nowrap;
    }

    #btn-connect, #btn-disconnect {
        padding: 12px 16px;
    }
    
    .chat-drawer {
        position: fixed;
        right: 0;
        bottom: 0;
        top: auto;
        height: 60vh;
        width: 100vw;
        border-left: none;
        border-top: 1px solid var(--border);
        transform: translateY(100%);
    }
    
    .chat-drawer.hidden {
        transform: translateY(100%);
    }
    
    .viewer-header {
        top: 10px;
        left: 10px;
        right: 10px;
        height: 50px;
        padding: 0 12px;
    }
}

@media (max-width: 600px) {
    .sidebar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .info-section {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 16px;
    }
    
    .my-id-container {
        width: 100%;
    }
    
    .control-section {
        flex-direction: row;
    }
    
    .auth-card {
        padding: 24px 20px;
    }
}
