/* ============================================
   NexusChat - 通話介面樣式
   ============================================ */

/* ============================================
   通話模態框
   ============================================ */

#call-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

#call-modal.open {
    opacity: 1;
    visibility: visible;
}

#call-modal .modal-content {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 50%, #0f0f1a 100%);
    transform: none;
    border-radius: 0;
    max-height: 100%;
}

/* 背景動畫效果 */
.call-background {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.call-background::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 30%, rgba(6, 199, 85, 0.15) 0%, transparent 50%),
                radial-gradient(circle at 70% 70%, rgba(99, 102, 241, 0.1) 0%, transparent 50%);
    animation: call-bg-rotate 20s linear infinite;
}

@keyframes call-bg-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* 呼吸燈效果 */
.call-background::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 300px;
    height: 300px;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgba(6, 199, 85, 0.2) 0%, transparent 70%);
    animation: call-pulse 3s ease-in-out infinite;
}

@keyframes call-pulse {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.5;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 0.8;
    }
}

/* ============================================
   語音通話介面
   ============================================ */

.call-content {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
    color: white;
    text-align: center;
    z-index: 1;
}

.call-avatar {
    position: relative;
    width: 140px;
    height: 140px;
    margin-bottom: 28px;
}

.call-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid rgba(255, 255, 255, 0.2);
}

/* 通話中的頭像動畫 */
.call-avatar::before {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: var(--primary);
    animation: avatar-ring 2s linear infinite;
    opacity: 0;
}

#call-modal.connected .call-avatar::before {
    opacity: 1;
}

@keyframes avatar-ring {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* 來電時的波紋效果 */
#call-modal.incoming .call-avatar::after,
#call-modal:not(.connected) .call-avatar::after {
    content: '';
    position: absolute;
    inset: -20px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    animation: avatar-ripple 1.5s ease-out infinite;
}

@keyframes avatar-ripple {
    0% {
        transform: scale(0.8);
        opacity: 1;
    }
    100% {
        transform: scale(1.3);
        opacity: 0;
    }
}

.call-name {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.call-status {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 8px;
}

.call-timer {
    font-size: 24px;
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--primary);
    display: none;
}

#call-modal.connected .call-timer {
    display: block;
}

/* 通話類型標籤 */
.call-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
    font-size: 13px;
    margin-top: 16px;
}

.call-type-badge svg {
    width: 16px;
    height: 16px;
}

/* ============================================
   通話操作按鈕
   ============================================ */

.call-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 24px;
    padding: 40px;
    padding-bottom: calc(40px + var(--safe-area-bottom));
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.5));
    z-index: 2;
}

.call-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: white;
    background: none;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.call-action:active {
    transform: scale(0.95);
}

.call-action-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    transition: all var(--transition-fast);
}

.call-action:hover .call-action-icon {
    background: rgba(255, 255, 255, 0.25);
}

.call-action.active .call-action-icon {
    background: white;
    color: var(--text-primary);
}

.call-action-icon svg {
    width: 26px;
    height: 26px;
}

.call-action-label {
    font-size: 12px;
    font-weight: 500;
    opacity: 0.9;
}

/* 結束通話按鈕 */
.call-action.end .call-action-icon {
    width: 72px;
    height: 72px;
    background: #F44336;
}

.call-action.end:hover .call-action-icon {
    background: #D32F2F;
}

.call-action.end .call-action-icon svg {
    width: 32px;
    height: 32px;
    transform: rotate(135deg);
}

/* 接聽按鈕 */
.call-action.answer .call-action-icon {
    width: 72px;
    height: 72px;
    background: var(--primary);
}

.call-action.answer:hover .call-action-icon {
    background: var(--primary-dark);
}

/* 來電時的按鈕容器 */
#call-modal.incoming .call-actions {
    justify-content: space-around;
    padding-left: 60px;
    padding-right: 60px;
}

/* 來電時顯示接聽/拒絕按鈕 */
.incoming-actions {
    display: none;
}

#call-modal.incoming .call-actions > *:not(.incoming-actions) {
    display: none;
}

#call-modal.incoming .incoming-actions {
    display: contents;
}

/* ============================================
   視訊通話介面
   ============================================ */

#call-modal.video-call .call-content {
    padding: 0;
}

#call-modal.video-call .call-avatar {
    display: none;
}

#call-modal.video-call .call-info {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 20px;
    padding-top: calc(20px + var(--safe-area-top));
    background: linear-gradient(rgba(0, 0, 0, 0.6), transparent);
    z-index: 10;
}

.video-container {
    position: absolute;
    inset: 0;
}

/* 遠端視訊（全螢幕） */
.remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

/* 本地視訊（小視窗） */
.local-video-wrapper {
    position: absolute;
    top: calc(80px + var(--safe-area-top));
    right: 16px;
    width: 120px;
    height: 160px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 20;
    cursor: move;
    transition: all var(--transition-fast);
}

.local-video-wrapper:active {
    transform: scale(1.05);
}

.local-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* 鏡像 */
    background: #1a1a2e;
}

/* 視訊關閉時的佔位符 */
.video-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #1a1a2e;
    color: white;
}

.video-placeholder svg {
    width: 48px;
    height: 48px;
    opacity: 0.5;
    margin-bottom: 8px;
}

.video-placeholder span {
    font-size: 14px;
    opacity: 0.7;
}

/* 視訊通話的操作按鈕 */
#call-modal.video-call .call-actions {
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
}

/* 額外的視訊控制按鈕 */
.video-controls {
    display: none;
}

#call-modal.video-call .video-controls {
    display: contents;
}

/* 切換攝影機按鈕 */
.switch-camera-btn {
    position: absolute;
    top: calc(80px + var(--safe-area-top));
    left: 16px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    z-index: 20;
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition-fast);
}

#call-modal.video-call .switch-camera-btn {
    opacity: 1;
    pointer-events: auto;
}

.switch-camera-btn:hover {
    background: rgba(0, 0, 0, 0.7);
}

.switch-camera-btn svg {
    width: 22px;
    height: 22px;
}

/* ============================================
   通話品質指示
   ============================================ */

.call-quality {
    position: absolute;
    top: calc(20px + var(--safe-area-top));
    right: 16px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: var(--radius-full);
    z-index: 20;
}

.quality-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 12px;
}

.quality-bar {
    width: 3px;
    background: white;
    border-radius: 1px;
    opacity: 0.3;
}

.quality-bar.active {
    opacity: 1;
}

.quality-bar:nth-child(1) { height: 4px; }
.quality-bar:nth-child(2) { height: 7px; }
.quality-bar:nth-child(3) { height: 10px; }
.quality-bar:nth-child(4) { height: 12px; }

.call-quality.good .quality-bar { background: var(--success); }
.call-quality.fair .quality-bar { background: var(--warning); }
.call-quality.poor .quality-bar { background: var(--error); }

/* ============================================
   螢幕分享
   ============================================ */

.screen-share-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px 32px;
    background: rgba(0, 0, 0, 0.8);
    border-radius: var(--radius-xl);
    color: white;
    z-index: 15;
    display: none;
}

.screen-share-indicator.active {
    display: flex;
}

.screen-share-indicator svg {
    width: 40px;
    height: 40px;
    color: var(--primary);
}

/* ============================================
   來電通知橫幅
   ============================================ */

.incoming-call-banner {
    position: fixed;
    top: var(--safe-area-top);
    left: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: rgba(30, 30, 40, 0.95);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 9998;
    transform: translateY(-120%);
    transition: transform var(--transition-spring);
}

.incoming-call-banner.show {
    transform: translateY(8px);
}

.incoming-call-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
}

.incoming-call-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.incoming-call-info {
    flex: 1;
}

.incoming-call-name {
    font-size: 16px;
    font-weight: 600;
    color: white;
    margin-bottom: 2px;
}

.incoming-call-type {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
}

.incoming-call-actions {
    display: flex;
    gap: 12px;
}

.incoming-call-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.incoming-call-btn.decline {
    background: #F44336;
    color: white;
}

.incoming-call-btn.accept {
    background: var(--primary);
    color: white;
}

.incoming-call-btn:hover {
    transform: scale(1.1);
}

.incoming-call-btn svg {
    width: 22px;
    height: 22px;
}

.incoming-call-btn.decline svg {
    transform: rotate(135deg);
}

/* ============================================
   群組通話
   ============================================ */

.group-call-grid {
    position: absolute;
    inset: 0;
    display: grid;
    gap: 4px;
    padding: 4px;
    background: #000;
}

.group-call-grid.participants-2 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
}

.group-call-grid.participants-3 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.group-call-grid.participants-3 > *:first-child {
    grid-column: span 2;
}

.group-call-grid.participants-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.participant-video {
    position: relative;
    background: #1a1a2e;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.participant-video video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.participant-info {
    position: absolute;
    bottom: 8px;
    left: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.participant-name {
    font-size: 13px;
    font-weight: 500;
    color: white;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.participant-muted {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.participant-muted svg {
    width: 12px;
    height: 12px;
    color: #F44336;
}

/* ============================================
   動畫效果
   ============================================ */

/* 撥打中的動畫 */
@keyframes calling {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#call-modal:not(.connected) .call-status {
    animation: calling 1.5s ease-in-out infinite;
}

/* 接聽按鈕的脈衝動畫 */
@keyframes answer-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(6, 199, 85, 0.5);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(6, 199, 85, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(6, 199, 85, 0);
    }
}

#call-modal.incoming .call-action.answer .call-action-icon {
    animation: answer-pulse 1.5s ease-out infinite;
}

/* 拒絕按鈕的搖晃動畫 */
@keyframes decline-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-3px); }
    40%, 80% { transform: translateX(3px); }
}

#call-modal.incoming .call-action.end:hover .call-action-icon {
    animation: decline-shake 0.5s ease-in-out;
}

/* ============================================
   響應式設計
   ============================================ */

@media (min-width: 768px) {
    .call-avatar {
        width: 180px;
        height: 180px;
    }
    
    .call-name {
        font-size: 34px;
    }
    
    .call-timer {
        font-size: 28px;
    }
    
    .call-action-icon {
        width: 70px;
        height: 70px;
    }
    
    .call-action.end .call-action-icon {
        width: 80px;
        height: 80px;
    }
    
    .local-video-wrapper {
        width: 180px;
        height: 240px;
    }
}

@media (max-height: 600px) {
    .call-content {
        padding: 30px 20px;
    }
    
    .call-avatar {
        width: 100px;
        height: 100px;
        margin-bottom: 16px;
    }
    
    .call-name {
        font-size: 22px;
    }
    
    .call-actions {
        padding: 20px;
    }
}

/* ============================================
   無障礙支援
   ============================================ */

.call-action:focus-visible .call-action-icon {
    outline: 3px solid var(--primary);
    outline-offset: 3px;
}

/* 降低動畫偏好 */
@media (prefers-reduced-motion: reduce) {
    .call-background::before,
    .call-background::after,
    .call-avatar::before,
    .call-avatar::after {
        animation: none;
    }
    
    #call-modal:not(.connected) .call-status {
        animation: none;
    }
    
    #call-modal.incoming .call-action.answer .call-action-icon {
        animation: none;
    }
}
