/* Chat Ranger3D Styles */
:root {
    --primary: #128C7E;
    --primary-dark: #075E54;
    --secondary: #25D366;
    --bg: #dadbd3;
    --chat-bg: #e5ddd5;
    --panel-bg: #ffffff;
    --incoming: #ffffff;
    --outgoing: #dcf8c6;
    --text: #111b21;
    --text-secondary: #667781;
    --border: #d1d7db;
    --danger: #ea4335;
    --shadow: 0 1px 3px rgba(0,0,0,0.12);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* Auth Pages */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
}

.auth-box {
    background: white;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 400px;
}

.auth-box h1 {
    text-align: center;
    color: var(--primary-dark);
    margin-bottom: 8px;
    font-size: 28px;
}

.auth-box .subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}
.form-group input, .form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    transition: border 0.2s;
}
.form-group input:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-primary {
    background: var(--primary);
    color: white;
    width: 100%;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #f0f2f5; color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-secondary);
}
.auth-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
}

/* Chat App */
.app { display: flex; height: 100vh; }
.hidden { display: none !important; }

/* Sidebar */
.sidebar {
    width: 380px;
    min-width: 300px;
    background: var(--panel-bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.sidebar-header {
    padding: 12px 16px;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    object-fit: cover;
    flex-shrink: 0;
}
.avatar-lg { width: 80px; height: 80px; font-size: 32px; }
.avatar-sm { width: 32px; height: 32px; font-size: 14px; }

.user-name {
    font-weight: 600;
    font-size: 15px;
}

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

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 20px;
    transition: background 0.2s;
}
.icon-btn:hover { background: #f0f2f5; }

.search-box {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.search-box input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: none;
    border-radius: 8px;
    background: #f0f2f5;
    font-size: 14px;
}
.search-box { position: relative; }
.search-box::before {
    content: "🔍";
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    opacity: 0.5;
}

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

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid #f0f2f5;
}
.conversation-item:hover, .conversation-item.active {
    background: #f0f2f5;
}

.conv-info { flex: 1; min-width: 0; }
.conv-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.conv-name {
    font-weight: 500;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-time {
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.conv-preview {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-preview.unread { color: var(--text); font-weight: 500; }

.badge {
    background: var(--secondary);
    color: white;
    font-size: 12px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    font-weight: 500;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    position: relative;
}

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

.chat-contact {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-contact-info .name {
    font-weight: 500;
    font-size: 16px;
}
.chat-contact-info .status {
    font-size: 13px;
    color: var(--text-secondary);
}
.chat-contact-info .status.online { color: var(--secondary); }

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 8%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14.5px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
}
.message.incoming {
    background: var(--incoming);
    align-self: flex-start;
    border-top-left-radius: 0;
}
.message.outgoing {
    background: var(--outgoing);
    align-self: flex-end;
    border-top-right-radius: 0;
}
.message.deleted {
    font-style: italic;
    color: var(--text-secondary);
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
    font-size: 11px;
    color: #8696a0;
}

.msg-status {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-left: 4px;
}
.status-circle {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
}
/* sending - red empty circle */
.status-circle.sending {
    border: 2px solid #ea4335;
    background: transparent;
}
/* sent - grey empty circle */
.status-circle.sent {
    border: 2px solid #8696a0;
    background: transparent;
}
/* delivered - grey filled circle */
.status-circle.delivered {
    border: 2px solid #8696a0;
    background: #8696a0;
}
/* read - green filled circle */
.status-circle.read {
    border: 2px solid #25D366;
    background: #25D366;
}

.message.edited::after {
    content: " (edited)";
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
}

.message-actions {
    position: absolute;
    top: -28px;
    right: 0;
    display: none;
    background: white;
    border-radius: 6px;
    box-shadow: var(--shadow);
    overflow: hidden;
    z-index: 10;
}
.message:hover .message-actions { display: flex; }
.message-actions button {
    border: none;
    background: white;
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    color: var(--text);
}
.message-actions button:hover { background: #f0f2f5; }

.message-reply {
    font-size: 12px;
    color: var(--text-secondary);
    border-left: 3px solid var(--primary);
    padding-left: 8px;
    margin-bottom: 6px;
    background: rgba(0,0,0,0.03);
    padding: 4px 8px;
    border-radius: 4px;
}

.message-media {
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 6px;
    cursor: pointer;
}
.message-media img, .message-media video {
    max-width: 100%;
    max-height: 300px;
    display: block;
    border-radius: 6px;
}
.message-media audio { width: 250px; }

.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: rgba(0,0,0,0.04);
    border-radius: 8px;
    margin-bottom: 6px;
    text-decoration: none;
    color: var(--text);
}
.message-file:hover { background: rgba(0,0,0,0.08); }

.message-location {
    width: 250px;
    height: 150px;
    background: #ddd;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 6px;
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
}

/* Input Area */
.input-area {
    padding: 10px 16px;
    background: var(--panel-bg);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.attach-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 22px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.attach-btn:hover { color: var(--text); }

.input-wrapper {
    flex: 1;
    background: #f0f2f5;
    border-radius: 20px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
}

.input-wrapper input, .input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 15px;
    resize: none;
    max-height: 120px;
    outline: none;
    font-family: inherit;
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.reply-bar {
    background: var(--panel-bg);
    padding: 8px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.reply-bar.hidden { display: none; }

.typing-indicator {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 4px 16px;
    height: 24px;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.modal-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h2 { font-size: 18px; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Profile */
.profile-header {
    text-align: center;
    padding: 20px;
}
.profile-header .avatar {
    margin: 0 auto 12px;
}
.profile-details {
    padding: 0 16px 16px;
}
.detail-row {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.detail-row label {
    font-size: 13px;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 4px;
}
.detail-row .value {
    font-size: 15px;
    color: var(--text);
}

/* Attach menu */
.attach-menu {
    position: absolute;
    bottom: 70px;
    left: 16px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 8px 0;
    min-width: 180px;
    z-index: 100;
}
.attach-menu.hidden { display: none; }
.attach-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
}
.attach-menu-item:hover { background: #f0f2f5; }
.attach-menu-item .icon { font-size: 20px; width: 24px; text-align: center; }

/* Empty state */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-align: center;
    padding: 40px;
}
.empty-state h2 {
    font-size: 32px;
    margin-bottom: 16px;
    font-weight: 300;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a8a8a8; }

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* Media query for mobile */
@media (max-width: 768px) {
    .sidebar { width: 100%; position: absolute; z-index: 10; }
    .chat-area { width: 100%; }
    .sidebar.hidden-mobile { display: none; }
    .messages-container { padding: 16px; }
    .message { max-width: 85%; }
}

/* Media Lightbox */
.media-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    padding: 20px;
}
.media-modal.hidden { display: none; }
.media-modal-content {
    max-width: 90vw;
    max-height: 90vh;
    position: relative;
}
.media-modal-content img,
.media-modal-content video {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
    display: block;
}
.media-modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: white;
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
}
.media-modal-download {
    position: absolute;
    bottom: -40px;
    right: 0;
    color: white;
    text-decoration: none;
    font-size: 14px;
    background: rgba(255,255,255,0.15);
    padding: 8px 16px;
    border-radius: 20px;
}
.media-modal-download:hover { background: rgba(255,255,255,0.25); }
