/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    width: 100%;
    display: flex;
    justify-content: center;
}

/* Container */
.container {
    max-width: 1200px;
    width: 100%;
    height: 100%;
    background: white;
    display: flex;
    flex-direction: column;
    position: relative;
}

@media (min-width: 769px) {
    body {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        padding: 20px;
        height: 100vh;
        align-items: center;
    }
    .container {
        height: calc(100% - 40px);
        border-radius: 20px;
        box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        overflow: hidden;
    }
}

/* Toast Notification System */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: #333;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-size: 14px;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 300px;
    pointer-events: auto;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.error { background: #ff4757; }
.toast.success { background: #2ed573; }
.toast.info { background: #667eea; }

/* Auth Section */
.auth-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
    text-align: center;
    width: 100%;
    height: 100%;
}

.auth-section h1 {
    color: white;
    margin-bottom: 30px;
    font-size: 2rem;
}

.auth-logo {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 15px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    background: white;
}

.auth-form {
    width: 100%;
    max-width: 350px;
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    position: relative;
}

.auth-tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 2px solid #eee;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: none;
    font-weight: 600;
    color: #888;
    cursor: pointer;
    transition: color 0.3s;
}

.auth-tab.active {
    color: #667eea;
    border-bottom: 2px solid #667eea;
    margin-bottom: -2px;
}

.input-group {
    margin-bottom: 15px;
    text-align: left;
}

.input-group label {
    display: block;
    font-size: 12px;
    color: #666;
    margin-bottom: 5px;
}

.input-group input {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s;
}

.input-group input:focus {
    border-color: #667eea;
}

.auth-btn {
    width: 100%;
    padding: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    margin-bottom: 10px;
}

.auth-btn:active { opacity: 0.8; }
.auth-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.auth-btn.secondary {
    background: #fff;
    color: #667eea;
    border: 1px solid #667eea;
}

.link-text {
    display: block;
    margin-top: 15px;
    font-size: 13px;
    color: #667eea;
    cursor: pointer;
    text-decoration: none;
}

.link-text:hover { text-decoration: underline; }

/* App Layout */
.app-section {
    display: none;
    height: 100%;
    width: 100%;
    flex: 1;
}

.app-container {
    display: flex;
    height: 100%;
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: #f9f9f9;
    border-right: 1px solid #eee;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100%;
}

.user-profile {
    padding: 15px;
    background: white;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: background 0.2s;
}

.user-profile:active { background: #f0f0f0; }

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
    overflow: hidden;
}

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

.avatar.large {
    width: 50px;
    height: 50px;
    font-size: 1.2rem;
}

.avatar.group-avatar { background: #ff9800; }

.user-info {
    flex: 1;
    overflow: hidden;
}

.user-info h3 {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 3px;
}

.status-toggle label {
    font-size: 11px;
    color: #666;
}

.settings-icon {
    font-size: 20px;
    opacity: 0.6;
}

/* Tabs */
.tabs {
    display: flex;
    background: white;
    border-bottom: 1px solid #eee;
}

.tab {
    flex: 1;
    padding: 12px 5px;
    text-align: center;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #666;
    transition: color 0.3s;
}

.tab.active {
    color: #667eea;
    border-bottom: 2px solid #667eea;
}

.tab-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* User Item Styles */
.user-item {
    padding: 12px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    position: relative;
    transition: background 0.2s;
}

.user-item:active { background: #e0e0e0; }
.user-item.active { background: #e8eaff; }

.user-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4caf50;
    margin-left: auto;
}

.user-status.offline { background: #ccc; }

.unread-badge {
    background: #ff4757;
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: bold;
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
}

.user-item.has-unread h4 { font-weight: 800; color: #333; }
.user-item.has-unread p { font-weight: 600; color: #444; }

.friend-request-badge {
    background: #ff4757;
    color: white;
    border-radius: 10px;
    padding: 1px 6px;
    font-size: 10px;
    margin-left: 5px;
}

.action-btn-sm {
    border: none;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 11px;
    cursor: pointer;
    margin-left: 5px;
}

.accept-sm { background: #4caf50; color: white; }
.reject-sm { background: #ff4757; color: white; }
.add-sm { background: #667eea; color: white; }

/* Group specific styles */
.group-item {
    padding: 12px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
}

.group-item:active { background: #e0e0e0; }

.group-badge {
    background: #ff9800;
    color: white;
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 10px;
    margin-left: 5px;
}

.member-count {
    font-size: 10px;
    color: #888;
    margin-top: 2px;
}

.create-group-btn {
    background: #4caf50;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 12px;
    margin: 10px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.create-group-btn:active { opacity: 0.8; }

.member-item {
    display: flex;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid #f0f0f0;
}

.member-checkbox {
    margin-right: 10px;
}

/* Main Chat */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: white;
    min-width: 0;
}

.chat-header {
    padding: 10px 15px;
    background: white;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    height: 60px;
    flex-shrink: 0;
}

.back-btn {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    margin-right: 10px;
    cursor: pointer;
    padding: 10px;
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    cursor: pointer;
    min-width: 0;
}

.chat-user-details {
    min-width: 0;
}

.typing-indicator {
    font-size: 11px;
    color: #667eea;
    font-style: italic;
    margin-top: 2px;
    display: none;
}

.call-btns {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: #f0f2f5;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #667eea;
    transition: background 0.2s;
}

.icon-btn:active { background: #d4d6db; }
.icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #f0f2f5;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #f9f9f9;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
}

.empty-state {
    text-align: center;
    color: #999;
    margin-top: 50px;
}

/* Message Styles */
.message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    position: relative;
}

.message.sent { align-self: flex-end; }
.message.received { align-self: flex-start; }

.message-content {
    padding: 8px 12px;
    border-radius: 15px;
    font-size: 14px;
    word-wrap: break-word;
    position: relative;
}

.message.sent .message-content {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 2px;
}

.message.received .message-content {
    background: white;
    border: 1px solid #eee;
    border-bottom-left-radius: 2px;
}

.message.deleted .message-content {
    background: #f0f0f0;
    color: #aaa;
    font-style: italic;
    border: none;
}

.message-time {
    font-size: 9px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
}

.message.sent .message-time { color: rgba(255,255,255,0.8); }

.status-tick { font-size: 10px; }
.status-tick.seen { color: #4fc3f7; }

.sender-name {
    font-size: 10px;
    font-weight: bold;
    margin-bottom: 2px;
    color: #666;
}

.message.sent .sender-name { display: none; }

.message-img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 10px;
    margin-bottom: 5px;
    cursor: pointer;
    display: block;
}

.msg-actions {
    position: absolute;
    top: -5px;
    right: -5px;
    background: white;
    border-radius: 10px;
    padding: 2px;
    display: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.message:hover .msg-actions { display: block; }

.del-btn {
    border: none;
    background: none;
    cursor: pointer;
    color: #ff4757;
    font-size: 12px;
    padding: 2px 5px;
}

/* Chat Input Area */
.chat-input-area {
    padding: 10px;
    background: white;
    border-top: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

#imageInput {
    display: none;
}

.chat-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 25px;
    outline: none;
    font-size: 15px;
    transition: border-color 0.3s;
}

.chat-input:focus {
    border-color: #667eea;
}

.send-btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.img-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    padding: 5px;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 25px;
    border-radius: 15px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-content.small {
    max-width: 300px;
    text-align: center;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
}

.modal-title {
    margin-bottom: 15px;
    color: #333;
}

.modal-input {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
}

.modal-save-btn {
    width: 100%;
    padding: 10px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 10px;
    transition: opacity 0.2s;
}

.modal-save-btn:active { opacity: 0.8; }

.modal-save-btn.logout-btn,
.modal-save-btn.leave-btn,
.danger-btn {
    background: #ff4757;
}

.member-list {
    max-height: 300px;
    overflow-y: auto;
    margin: 15px 0;
}

.info-text {
    font-size: 12px;
    color: #666;
    margin-bottom: 15px;
}

.email-label {
    font-weight: bold;
    color: #667eea;
    margin-bottom: 20px;
}

.friend-detail-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
}

.friend-status {
    font-size: 12px;
    color: #666;
}

.detail-item {
    font-size: 13px;
    color: #666;
    margin-top: 5px;
}

.group-info-members {
    font-size: 13px;
    color: #666;
    margin-bottom: 15px;
}

.warning-text {
    font-size: 13px;
    color: #666;
    margin: 15px 0;
}

.button-group {
    display: flex;
    gap: 10px;
}

.secondary-btn {
    flex: 1;
    padding: 10px;
    background: #ccc;
    color: #333;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.danger-btn {
    flex: 1;
    padding: 10px;
    background: #ff4757;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.divider {
    margin: 20px 0;
    border: 0;
    border-top: 1px solid #eee;
}

.preview-image {
    max-width: 90%;
    max-height: 90%;
    border-radius: 10px;
    cursor: pointer;
}

/* Video Call UI */
.video-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1a1a1a;
    z-index: 2000;
    display: none;
    flex-direction: column;
}

.video-grid {
    flex: 1;
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-box {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.video-label {
    position: absolute;
    bottom: 20px;
    left: 20px;
    color: white;
    font-size: 14px;
    background: rgba(0,0,0,0.6);
    padding: 5px 12px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.video-box.local-pip {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 120px;
    height: 170px;
    border-radius: 15px;
    border: 2px solid rgba(255,255,255,0.3);
    overflow: hidden;
    z-index: 10;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

.video-box.local-pip video {
    object-fit: cover;
}

.call-status-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 15;
    color: white;
    transition: opacity 0.3s;
}

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

.call-status-overlay h2 {
    margin-bottom: 10px;
    font-size: 24px;
}

.call-status-overlay p {
    opacity: 0.8;
    font-size: 14px;
}

.call-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 20;
    padding: 20px;
    display: flex;
    justify-content: center;
    gap: 25px;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
}

.control-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    font-size: 24px;
    cursor: pointer;
    background: rgba(255,255,255,0.15);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    transition: transform 0.1s, background 0.2s;
}

.control-btn:active { transform: scale(0.95); }
.control-btn.end { background: #ff4757; }
.control-btn.active { background: #fff; color: #333; }

.incoming-call-ui {
    text-align: center;
    padding: 30px;
}

.call-actions {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-top: 20px;
}

.answer-btn {
    background: #4caf50;
    color: white;
    padding: 12px 30px;
    border: none;
    border-radius: 30px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.decline-btn {
    background: #ff4757;
    color: white;
    padding: 12px 30px;
    border: none;
    border-radius: 30px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.answer-btn:active,
.decline-btn:active {
    opacity: 0.8;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 10;
        transition: transform 0.3s;
    }
    
    .main-content {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 20;
        transform: translateX(100%);
        transition: transform 0.3s;
        background: white;
    }
    
    .app-container.chat-open .sidebar {
        transform: translateX(-100%);
    }
    
    .app-container.chat-open .main-content {
        transform: translateX(0);
    }
    
    .back-btn {
        display: block;
    }
    
    .video-box.local-pip {
        top: 15px;
        right: 15px;
        width: 100px;
        height: 140px;
    }
}
