/* Call View & Mesh Grid UI */
/* Premium Corporate Theme Update */
:root {
    --bg-color: #0b0f19;
    --card-bg: #1e293b;
    --primary: #3b82f6; 
    --primary-hover: #2563eb;
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --border: #334155;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#app-container {
    width: 100%;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

.view {
    display: none;
    width: 100%;
    height: 100%;
}

.view.active {
    display: flex;
}

/* Auth View */
#auth-view {
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at top right, #1a202c, var(--bg-color));
}

.auth-card {
    background-color: var(--card-bg);
    padding: 2.5rem;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
    justify-content: center;
}

.logo svg {
    color: var(--primary);
}

.tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.tabs button {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0.75rem;
    cursor: pointer;
    font-weight: 500;
    font-size: 1rem;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.tabs button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.auth-form {
    display: none;
    flex-direction: column;
    gap: 1rem;
}

.auth-form.active {
    display: flex;
}

input {
    background-color: rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    padding: 0.875rem;
    border-radius: 8px;
    color: var(--text-color);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

input:focus {
    border-color: var(--primary);
}

.btn-primary, .btn-secondary, .btn-success, .btn-danger {
    padding: 0.875rem;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.btn-primary {
    background-color: var(--primary);
    color: #000;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text-color);
}

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

.btn-success { background-color: var(--primary); color: #000; }
.btn-success:hover { background-color: var(--primary-hover); }
.btn-danger { background-color: var(--danger); color: #fff; }
.btn-danger:hover { background-color: var(--danger-hover); }

.error-msg {
    color: var(--danger);
    font-size: 0.85rem;
    min-height: 1.2rem;
    text-align: center;
}

/* Dashboard View */
#dashboard-view {
    flex-direction: column;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border);
    background-color: var(--card-bg);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.dashboard-main {
    flex: 1;
    padding: 3rem 2rem;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    overflow-y: auto;
}

.search-panel {
    background-color: var(--card-bg);
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid var(--border);
}

.search-panel h3 {
    margin-bottom: 1.5rem;
    font-weight: 500;
}

.search-box {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.search-box input {
    flex: 1;
}

.search-box button {
    padding: 0 1.5rem;
}

#search-result {
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    display: none;
}

.result-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(0,0,0,0.2);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

/* Call Overlay */
.call-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0,0,0,0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.incoming-card {
    background-color: var(--card-bg);
    padding: 2.5rem;
    border-radius: 16px;
    text-align: center;
    border: 1px solid var(--primary);
    box-shadow: 0 0 30px rgba(74, 222, 128, 0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.4); }
    70% { box-shadow: 0 0 0 20px rgba(74, 222, 128, 0); }
    100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

.incoming-card h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.incoming-card p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.incoming-card .actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Call View & Mesh Grid UI */
#call-view {
    background-color: #000;
}

#video-grid {
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    gap: 15px;
    padding: 1rem;
    padding-bottom: 120px; /* Space for controls */
    width: 100%;
    height: 100%;
    overflow-y: auto;
}

.video-wrapper {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    background-color: #111;
    border: 1px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    flex: 1 1 40%;
    min-width: 250px;
    max-height: 45vh;
    transition: all 0.3s ease;
    cursor: pointer;
}

.video-wrapper.maximized {
    flex: 1 1 100%;
    max-height: 70vh;
    order: -1;
    z-index: 5;
    border-color: var(--primary);
    box-shadow: 0 15px 35px rgba(74, 222, 128, 0.2);
}

/* For mobile portraits */
@media (max-width: 768px) {
    #video-grid {
        flex-direction: column;
        flex-wrap: nowrap;
        justify-content: flex-start;
    }
    .video-wrapper {
        flex: none;
        width: 100%;
        max-height: 33vh;
    }
    .video-wrapper.maximized {
        flex: none;
        height: 65vh;
        max-height: none;
        order: -1;
    }
    #video-grid:has(.video-wrapper.maximized) .video-wrapper:not(.maximized) {
        flex: none;
        height: 120px;
        max-height: 120px;
        opacity: 0.8;
    }
}

.video-wrapper video {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Prevents cutting off and overlapping */
}

.local-video-wrapper {
    border: 2px solid var(--primary);
}

video.mirror {
    transform: scaleX(-1);
}

@media (min-width: 769px) {
    #video-grid.has-maximized {
        display: grid;
        grid-template-columns: 1fr 250px;
        grid-auto-rows: min-content;
        gap: 15px;
        align-content: start;
        padding-right: 15px;
        overflow-x: hidden;
    }
    #video-grid.has-maximized .video-wrapper.maximized {
        flex: none;
        grid-column: 1 / 2;
        grid-row: 1 / 100;
        width: 100%;
        height: calc(100vh - 200px);
        max-height: none;
        margin: 0;
    }
    #video-grid.has-maximized .video-wrapper:not(.maximized) {
        flex: none;
        grid-column: 2 / 3;
        width: 100%;
        height: 150px;
        max-height: 150px;
        margin-bottom: 10px;
        opacity: 1;
    }
}

@media (max-width: 768px) {
    #video-grid.has-maximized {
        align-content: flex-start;
    }
    #video-grid.has-maximized .video-wrapper:not(.maximized) {
        flex: 0 1 200px;
        min-width: 150px;
        max-height: 20vh;
        opacity: 0.8;
    }
}

.peer-name {
    position: absolute;
    bottom: 15px;
    left: 15px;
    background: rgba(0,0,0,0.7);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    backdrop-filter: blur(4px);
}

/* Chat Panel */
.chat-panel {
    position: absolute;
    right: -350px;
    top: 0;
    width: 320px;
    height: 100vh;
    background-color: var(--card-bg);
    border-left: 1px solid var(--border);
    transition: right 0.3s ease-out;
    display: flex;
    flex-direction: column;
    z-index: 50;
    box-shadow: -5px 0 25px rgba(0,0,0,0.5);
}
.chat-panel.open { right: 0; }
@media (max-width: 768px) {
    .chat-panel { width: 100%; right: -100%; }
    .chat-panel.open { right: 0; }
}
.chat-header {
    display: flex;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.chat-message {
    background: #2a2e38;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
    align-self: flex-start;
    max-width: 85%;
    word-break: break-word;
}
.chat-message.self {
    background: var(--primary);
    color: #000;
    align-self: flex-end;
}
.chat-message .sender {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-bottom: 4px;
}
.chat-input-area {
    padding: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
}

/* Host Panel */
.host-panel {
    position: fixed;
    top: 0;
    left: -300px;
    height: 100vh;
    width: 280px;
    background: rgba(11, 15, 25, 0.95);
    backdrop-filter: blur(10px);
    padding: 1.5rem;
    border-right: 1px solid var(--primary);
    z-index: 60;
    box-shadow: 5px 0 25px rgba(0,0,0,0.5);
    overflow-y: auto;
    transition: left 0.3s ease;
}
.host-panel.open {
    left: 0;
}
.host-panel h4 {
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    color: var(--primary);
}

/* Dashboard Professional Upgrades */
.dash-card {
    cursor:pointer; 
    background: var(--card-bg); 
    padding: 2.5rem; 
    border-radius: 20px; 
    border: 2px solid var(--border); 
    text-align: center; 
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.dash-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    border-color: var(--primary);
}
.dash-icon {
    font-size: 3.5rem; 
    margin-bottom: 15px;
}

/* Audio Call Dimension UI */
#call-view.audio-call-mode {
    justify-content: center;
    align-items: center;
}
#call-view.audio-call-mode #video-grid {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 30px;
    height: 100%;
}
@media(max-width: 768px) {
    #call-view.audio-call-mode #video-grid { flex-direction: column; }
}
#call-view.audio-call-mode .video-wrapper {
    flex: none !important;
    width: 350px;
    height: 600px;
    max-height: 85vh;
    border-radius: 40px;
    border: 8px solid var(--border);
    background: var(--card-bg);
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    margin: 0;
}
#call-view.audio-call-mode .video-wrapper video {
    display: none !important; /* Force hide camera tracks during audio dial loops cleanly */
}
#call-view.audio-call-mode .audio-profile {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}
.audio-avatar-huge {
    font-size: 5rem;
    background: rgba(59, 130, 246, 0.1);
    padding: 35px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    box-shadow: 0 0 30px rgba(59, 130, 246, 0.2);
}
.audio-caller-name {
    font-size: 1.6rem;
    font-weight: 700;
}
.audio-caller-id {
    font-size: 0.95rem;
    color: var(--text-muted);
}
#call-view.audio-call-mode .peer-name {
    display: none !important;
}
.participant-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}
.participant-actions {
    display: flex;
    gap: 5px;
}
.participant-actions button {
    background: rgba(239, 68, 68, 0.2);
    border: none;
    color: var(--danger);
    cursor: pointer;
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 0.70rem;
    transition: background 0.2s;
}
.participant-actions button:hover {
    background: var(--danger);
    color: #fff;
}
.audio-only video {
    opacity: 0 !important;
}
.audio-only::before {
    content: "📞 Audio Context";
    position: absolute;
    color: #fff;
    font-size: 1.1rem;
    font-weight: bold;
    z-index: 10;
}
.chat-input-area input { flex: 1; padding: 0.5rem; font-size: 0.9rem; margin:0; }

/* Call Controls */
.call-controls {
    position: fixed;
    bottom: max(2rem, env(safe-area-inset-bottom, 20px));
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(26, 29, 36, 0.8);
    backdrop-filter: blur(10px);
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    width: 90%;
    max-width: 450px;
    gap: 1rem;
    border: 1px solid var(--border);
    z-index: 999;
}

.control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background-color: rgba(255,255,255,0.1);
    color: white;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
}
.extra-controls {
    display: none;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}
.extra-controls.active {
    display: flex;
}

.control-btn:hover {
    background-color: rgba(255,255,255,0.2);
}

.control-btn.muted {
    background-color: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.control-btn.end-btn {
    background-color: var(--danger);
}

.control-btn.end-btn:hover {
    background-color: var(--danger-hover);
    transform: scale(1.05);
}

/* Mobile Responsive Overrides */
@media (max-width: 768px) {
    header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }
    .dashboard-main {
        padding: 1.5rem 1rem calc(5rem + env(safe-area-inset-bottom, 20px));
    }
    .dash-card {
        padding: 1.5rem;
    }
    .search-panel {
        padding: 1.5rem;
    }
    .search-box {
        flex-direction: column;
    }
    .search-box button {
        padding: 1rem;
        width: 100%;
    }
    .auth-card {
        padding: 1.5rem;
        margin: 1rem;
    }
    .chat-panel {
        width: 280px;
        height: 100vh;
        top: 0;
        bottom: auto;
        right: auto;
        left: -300px;
        border-right: 1px solid var(--border);
        border-left: none;
        border-radius: 0;
        transition: left 0.3s ease;
    }
    .chat-panel.open {
        left: 0;
        right: auto;
    }
    .sidebar-grid {
        width: 100px;
        gap: 5px;
    }
    #video-grid.has-maximized .video-wrapper.maximized {
        width: calc(100vw - 110px);
    }
}
