* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.app-container {
    display: flex;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
}

.sidebar {
    width: 300px;
    background: #2c3e50;
    color: white;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    background: #34495e;
    border-bottom: 1px solid #4a5f7a;
}

.sidebar-header h1 {
    font-size: 1.5rem;
    margin-bottom: 5px;
}

.sidebar-header p {
    font-size: 0.9rem;
    opacity: 0.8;
}

.contacts-list {
    flex: 1;
    overflow-y: auto;
}

.contact-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #34495e;
}

.contact-item:hover {
    background: #34495e;
}

.contact-item.active {
    background: #3498db;
}

.contact-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #3498db;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-right: 15px;
}

.contact-info h3 {
    font-size: 1rem;
    margin-bottom: 3px;
}

.contact-info p {
    font-size: 0.8rem;
    opacity: 0.7;
}

/* Google Auth Styles */
.auth-section {
    padding: 15px 20px;
    border-bottom: 1px solid #34495e;
    background: #34495e;
}

.sign-in-section {
    text-align: center;
}

.auth-title {
    color: white;
    font-size: 0.9rem;
    margin-bottom: 10px;
    opacity: 0.9;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #3498db;
    border-radius: 8px;
    margin-bottom: 10px;
}

.user-avatar {
    flex-shrink: 0;
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sign-out-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.sign-out-btn:hover {
    background: #c0392b;
}

/* Google Sign-In Button Styling */
.g_id_signin {
    margin: 10px 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Center the Google Sign-In button content */
.g_id_signin > div {
    margin: 0 auto;
}

/* Status Messages */
.auth-status {
    padding: 8px 12px;
    margin: 10px 0;
    border-radius: 4px;
    font-size: 0.8rem;
    text-align: center;
}

.auth-status.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.auth-status.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-header {
    background: #3498db;
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-user-info {
    display: flex;
    align-items: center;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #2980b9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-right: 15px;
}

.chat-user-details h2 {
    font-size: 1.1rem;
    margin-bottom: 2px;
}

.chat-user-details p {
    font-size: 0.8rem;
    opacity: 0.9;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-menu { position: relative; }
.chat-menu-dropdown {
    position: absolute;
    right: 0;
    top: 28px;
    background: #2c3e50;
    border: 1px solid #34495e;
    border-radius: 8px;
    padding: 8px;
    display: none;
    z-index: 20;
}
.header-call-btn {
    background: transparent;
    border: none;
    border-radius: 18px;
    margin-right: 8px;
}
.header-call-btn img {
    filter: brightness(0) invert(1);
}
.header-call-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.chat-menu-dropdown .btn { width: 120px; text-align: left; }

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #27ae60;
}

.status-indicator.offline {
    background: #95a5a6;
}

.status-indicator.ringing {
    background: #f39c12;
    animation: pulse 1s infinite;
}

.status-indicator.connecting {
    background: #3498db;
    animation: pulse 1s infinite;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
}

.message {
    display: flex;
    margin-bottom: 15px;
    align-items: flex-end;
}

.message.sent {
    justify-content: flex-end;
}

.message.received {
    justify-content: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    margin: 0 8px;
}

.message.sent .message-avatar {
    background: #3498db;
    order: 2;
}

.message.received .message-avatar {
    background: #95a5a6;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
}

.message.sent .message-content {
    background: #3498db;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received .message-content {
    background: white;
    color: #2c3e50;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 4px;
}

.video-call-container {
    position: relative;
    background: #000;
    border-radius: 15px;
    overflow: hidden;
    margin: 20px;
    display: none;
    min-height: 300px;
}

.video-call-container.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#trump-video {
    width: 100%;
    height: auto;
    max-height: 400px;
    object-fit: contain;
    background: #000;
}

.caption-overlay {
    position: absolute;
    bottom: 90px;
    left: 0;
    right: 0;
    padding: 20px 20px 10px 20px;
    pointer-events: none;
    z-index: 10;
}

.caption-text {
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    text-shadow: 
        2px 2px 4px rgba(0, 0, 0, 0.9),
        0 0 8px rgba(0, 0, 0, 0.7),
        0 0 12px rgba(0, 0, 0, 0.5);
    line-height: 1.4;
    max-width: 100%;
    word-wrap: break-word;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease-in-out;
    margin-bottom: 10px;
}

.caption-text.show {
    opacity: 1;
    transform: translateY(0);
}

.caption-text.typing {
    opacity: 0.7;
    animation: captionPulse 1.5s infinite;
}

@keyframes captionPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.user-video-preview {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 100px;
    height: 75px;
    border-radius: 8px;
    border: 2px solid white;
    background: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: white;
}

.chat-input {
    padding: 20px;
    background: white;
    border-top: 1px solid #e1e8ed;
    display: flex;
    align-items: center;
    gap: 15px;
}

.input-container {
    flex: 1;
    position: relative;
}

.message-input {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #e1e8ed;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.message-input:focus {
    border-color: #3498db;
}


.action-buttons {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-success {
    background: #27ae60;
    color: white;
}

.btn-success:hover {
    background: #229954;
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

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

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

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 15px;
    background: white;
    border-radius: 18px;
    margin-bottom: 15px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #95a5a6;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.hidden {
    display: none !important;
}

#deleting-overlay {
    display: none;
}

.call-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 15px;
}

.call-btn {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s;
}
.call-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.call-btn.end {
    background: #e74c3c;
    color: white;
}

.call-btn.mic {
    background: #3498db;
    color: white;
}

.call-btn.mic.listening {
    background: #f39c12;
    animation: pulse 1s infinite;
}

.call-btn.mic.continuous {
    background: #27ae60;
    animation: pulse 2s infinite;
}

/* Temporarily hidden lipsync button styles */
.call-btn.lipsync-toggle {
    display: none !important;
}

.call-btn.lipsync-toggle.active {
    display: none !important;
}

.call-btn.lipsync-toggle:hover {
    display: none !important;
}

.call-btn.lipsync-toggle.active:hover {
    display: none !important;
}


.permission-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.permission-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    max-width: 400px;
    margin: 20px;
}

.permission-content h2 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.permission-content p {
    color: #7f8c8d;
    margin-bottom: 10px;
    line-height: 1.5;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
    margin-left: 10px;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.user-video-preview {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 100px;
    height: 75px;
    border-radius: 8px;
    border: 2px solid white;
    background: #333;
    overflow: hidden;
}

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

.permission-modal.hidden {
    display: none;
}

/* Mobile Contact List Styles */
.mobile-contact-list {
    display: none;
    width: 100%;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    overflow-y: auto;
}

/* Desktop: Hide mobile contact list and back button */
@media (min-width: 769px) {
    .mobile-contact-list {
        display: none !important;
    }
    
    .mobile-back-btn {
        display: none !important;
    }
    
    .main-chat {
        display: flex !important;
        flex-direction: column;
    }
}

.mobile-header {
    padding: 30px 20px 25px 20px;
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.mobile-header h1 {
    margin: 0 0 8px 0;
    font-size: 1.8rem;
    color: white;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.mobile-header p {
    margin: 0;
    color: rgba(255, 255, 255, 0.8);
    font-size: 1rem;
    font-weight: 300;
}

.mobile-contacts-list {
    padding: 10px 0;
}

.mobile-contact-item {
    display: flex;
    align-items: center;
    padding: 20px;
    margin: 10px 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.mobile-contact-item:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.mobile-contact-item:active {
    transform: scale(0.98);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.mobile-contact-item .contact-avatar {
    margin-right: 15px;
}

.mobile-contact-item .contact-info {
    flex: 1;
}

.mobile-contact-item .contact-info h3 {
    margin: 0 0 5px 0;
    font-size: 1.2rem;
    color: white;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.mobile-contact-item .contact-info p {
    margin: 0;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.95rem;
    font-weight: 300;
}

.contact-arrow {
    font-size: 1.8rem;
    color: rgba(255, 255, 255, 0.6);
    margin-left: 15px;
    transition: all 0.2s ease;
}

.mobile-contact-item:hover .contact-arrow {
    color: rgba(255, 255, 255, 0.9);
    transform: translateX(3px);
}

.mobile-back-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 1.8rem;
    font-weight: bold;
    padding: 12px 16px;
    margin-right: 15px;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.mobile-back-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.mobile-back-btn:active {
    transform: scale(0.95);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        min-height: 100vh;
    }
    
    /* Show mobile contact list by default on mobile */
    .mobile-contact-list {
        display: block;
    }
    
    /* Hide desktop sidebar on mobile */
    .sidebar {
        display: none;
    }
    
    /* Hide main chat initially on mobile */
    .main-chat {
        display: none;
        order: 1;
        min-height: 100vh;
        width: 100%;
    }
    
    /* Show main chat when in chat mode */
    .main-chat.mobile-chat-active {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
    }
    
    /* Show back button on mobile */
    .mobile-back-btn {
        display: flex !important;
    }
    
    /* Ensure chat header has proper flex layout for back button */
    .chat-header {
        display: flex;
        align-items: center;
    }
    
    .sidebar-header {
        padding: 15px;
    }
    
    .sidebar-header h1 {
        font-size: 1.2rem;
    }
    
    .contact-item {
        padding: 10px 15px;
    }
    
    .contact-avatar {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }
    
    .auth-section {
        padding: 20px;
        background: rgba(255, 255, 255, 0.05);
        margin: 15px;
        border-radius: 12px;
        backdrop-filter: blur(5px);
    }
    
    /* Ensure Google Sign-In button is centered on mobile */
    .g_id_signin {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
    }
    
    .g_id_signin > div {
        margin: 0 auto !important;
    }
    
    .user-info {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }
    
    .user-details {
        text-align: center;
    }
    
    .sign-out-btn {
        width: 100%;
        padding: 12px 16px;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        color: white;
        border-radius: 8px;
        font-weight: 500;
        transition: all 0.2s ease;
    }
    
    .sign-out-btn:hover {
        background: rgba(255, 255, 255, 0.2);
        transform: translateY(-1px);
    }
    
    .chat-header {
        padding: 15px;
    }
    
    .chat-avatar {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
    
    .chat-user-details h2 {
        font-size: 1rem;
    }
    
    .chat-messages {
        padding: 15px;
    }
    
    .message-content {
        max-width: 85%;
        padding: 10px 14px;
    }
    
    .chat-input {
        padding: 15px;
        flex-direction: column;
        gap: 10px;
    }
    
    .input-container {
        width: 100%;
    }
    
    .action-buttons {
        width: 100%;
        justify-content: center;
        display: flex !important;
        gap: 10px;
        margin-top: 10px;
    }
    
    /* Ensure buttons are visible on mobile */
    #call-button,
    #test-mic-button {
        display: inline-block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 16px;
        min-height: 44px; /* iOS touch target minimum */
    }
    
    .voice-button {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    .video-call-container {
        margin: 10px;
        min-height: 250px;
    }
    
    #trump-video {
        max-height: 300px;
    }
    
    .user-video-preview {
        width: 80px;
        height: 60px;
        top: 10px;
        right: 10px;
    }
    
    /* Fill mobile call area vertically without top/bottom bars */
    .video-call-container.active {
        align-items: stretch;
    }
    
    /* Ensure the main call video fills height and crops sides if needed */
    #trump-video {
        width: 100%;
        height: 100%;
        max-height: none;
        object-fit: cover;
        background: #000;
    }
    
    .call-controls {
        bottom: 15px;
    }
    
    .caption-overlay {
        bottom: 80px;
        padding: 15px 15px 8px 15px;
    }
    
    .caption-text {
        font-size: 1rem;
        font-weight: 600;
    }
    
    .call-btn {
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
    }
    
    .permission-content {
        padding: 20px;
        margin: 15px;
        max-width: 90%;
    }
    
    .permission-content h2 {
        font-size: 1.3rem;
    }
    
    /* Touch-friendly improvements */
    .contact-item:active {
        background: #34495e;
        transform: scale(0.98);
    }
    
    .btn:active {
        transform: scale(0.95);
    }
    
    .voice-button:active {
        transform: scale(0.9);
    }
    
    .call-btn:active {
        transform: scale(0.9);
    }
}

@media (max-width: 480px) {
    .sidebar {
        max-height: 25vh;
    }
    
    .main-chat {
        height: 75vh;
    }
    
    .chat-header {
        padding: 10px;
    }
    
    .chat-messages {
        padding: 10px;
    }
    
    .chat-input {
        padding: 10px;
    }
    
    .message-content {
        max-width: 90%;
        padding: 8px 12px;
    }
    
    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .video-call-container {
        margin: 5px;
    }
    
    #trump-video {
        height: 200px;
    }
    
    .user-video-preview {
        width: 70px;
        height: 50px;
        top: 8px;
        right: 8px;
    }
}
