/* Variables y Reset */
:root {
    --primary-color: #00a884;
    --primary-dark: #008f72;
    --secondary-color: #f0f2f5;
    --chat-bg: #e5ddd5;
    --chat-bg-pattern: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect fill="%23e5ddd5" width="100" height="100"/><path fill="%23d4ccc4" d="M0 0h100v100H0z" opacity=".3"/></svg>');
    --text-primary: #111b21;
    --text-secondary: #667781;
    --message-out: #d9fdd3;
    --message-in: #ffffff;
    --border-color: #e9edef;
    --hover-bg: #f5f6f6;
    --sidebar-width: 380px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: linear-gradient(180deg, #00a884 0%, #00a884 150px, #d9dbd5 150px, #d9dbd5 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Login Screen */
.login-screen {
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #00a884 0%, #00a884 30%, #d9dbd5 30%, #d9dbd5 100%);
}

.login-container {
    background: white;
    padding: 50px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    text-align: center;
    max-width: 450px;
    width: 90%;
}

.login-logo img {
    width: 80px;
    margin-bottom: 15px;
}

.login-logo h1 {
    color: var(--text-primary);
    font-size: 28px;
    font-weight: 300;
    margin-bottom: 5px;
}

.login-logo p {
    color: var(--text-secondary);
    font-size: 14px;
}

.login-options {
    margin-top: 40px;
}

.login-option {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 14px 24px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 20px;
}

.login-option:hover {
    background: var(--hover-bg);
    border-color: var(--primary-color);
}

.login-option img {
    width: 20px;
    height: 20px;
}

.divider {
    display: flex;
    align-items: center;
    margin: 25px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.divider span {
    padding: 0 15px;
}

.phone-login {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.phone-input-container {
    display: flex;
    gap: 10px;
}

.phone-input-container select {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.phone-input-container input {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}

.phone-input-container input:focus {
    border-color: var(--primary-color);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.verification-container {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.verification-container input {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 18px;
    text-align: center;
    letter-spacing: 8px;
}

.hidden {
    display: none !important;
}

/* Chat Screen */
.chat-screen {
    width: 100%;
    height: 100vh;
    display: flex;
    background: white;
    max-width: 1600px;
    margin: 0 auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: white;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--secondary-color);
    height: 60px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    cursor: pointer;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(0,0,0,0.05);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
    fill: var(--text-secondary);
}

.search-container {
    padding: 8px 16px;
    background: white;
    border-bottom: 1px solid var(--border-color);
}

.search-box {
    display: flex;
    align-items: center;
    background: var(--secondary-color);
    border-radius: 8px;
    padding: 8px 12px;
}

.search-box input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    margin-left: 10px;
}

.search-icon {
    width: 20px;
    height: 20px;
    fill: var(--text-secondary);
}

/* Chat List */
.chat-list {
    flex: 1;
    overflow-y: auto;
    background: white;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid var(--border-color);
}

.chat-item:hover {
    background: var(--hover-bg);
}

.chat-item.active {
    background: var(--secondary-color);
}

.chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    margin-right: 15px;
    flex-shrink: 0;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-name {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 12px;
    color: var(--text-secondary);
}

.chat-preview {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-message {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.unread-badge {
    background: var(--primary-color);
    color: white;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    position: relative;
}

.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
}

.empty-content img {
    width: 300px;
    margin-bottom: 30px;
    opacity: 0.3;
}

.empty-content h2 {
    color: var(--text-secondary);
    font-size: 32px;
    font-weight: 300;
    margin-bottom: 15px;
}

.empty-content p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 30px;
}

.encryption-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 14px;
}

.encryption-notice svg {
    width: 16px;
    height: 16px;
    fill: var(--text-secondary);
}

/* Active Chat */
.active-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--secondary-color);
    border-left: 1px solid var(--border-color);
    height: 60px;
}

.contact-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
}

.contact-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.contact-details h3 {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
}

.status-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.chat-actions {
    display: flex;
    gap: 10px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--chat-bg-pattern);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    position: relative;
    word-wrap: break-word;
}

.message.sent {
    align-self: flex-end;
    background: var(--message-out);
    border-top-right-radius: 0;
}

.message.received {
    align-self: flex-start;
    background: var(--message-in);
    border-top-left-radius: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.message-content {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.4;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    float: right;
    margin-left: 8px;
    margin-top: 4px;
}

.message-status {
    display: inline-flex;
    margin-left: 4px;
}

.message-status svg {
    width: 14px;
    height: 14px;
    fill: #53bdeb;
}

/* Input Area */
.input-area {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: var(--secondary-color);
    gap: 10px;
    border-left: 1px solid var(--border-color);
}

.message-input-container {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 10px 16px;
}

.message-input-container input {
    width: 100%;
    border: none;
    outline: none;
    font-size: 15px;
}

.emoji-btn svg,
.attach-btn svg {
    fill: var(--text-secondary);
}

.voice-btn {
    background: var(--primary-color);
}

.voice-btn svg {
    fill: white;
    width: 20px;
    height: 20px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 500;
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.search-results {
    margin-top: 15px;
}

.user-result {
    display: flex;
    align-items: center;
    padding: 12px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}

.user-result:hover {
    background: var(--hover-bg);
}

.user-result img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 12px;
}

.user-result-info h4 {
    font-size: 15px;
    font-weight: 500;
}

.user-result-info p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Responsive */
@media (max-width: 900px) {
    .sidebar {
        width: 100%;
        min-width: 100%;
    }
    
    .chat-screen {
        max-width: 100%;
    }
}