* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
}

:root {
    --primary: #25D366;
    --primary-dark: #128C7E;
    --header-bg: #075E54;
    --chat-bg: #ECE5DD;
    --my-bubble: #DCF8C6;
    --other-bubble: #FFFFFF;
    --text-dark: #111B21;
    --text-gray: #667781;
    --border-color: #e9edef;
}

/* ============ AUTH PAGES ============ */
.auth-body {
    background: var(--header-bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-container {
    background: #fff;
    border-radius: 12px;
    padding: 40px 35px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.auth-logo { margin-bottom: 10px; }

.auth-container h1 {
    color: var(--header-bg);
    margin-bottom: 5px;
    font-size: 28px;
}

.auth-subtitle {
    color: var(--text-gray);
    margin-bottom: 25px;
    font-size: 14px;
}

.form-group {
    text-align: left;
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border 0.2s;
}

.form-group input:focus {
    border-color: var(--primary);
}

.form-group small {
    display: block;
    color: var(--text-gray);
    font-size: 11px;
    margin-top: 4px;
}

.btn-primary {
    width: 100%;
    padding: 13px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 5px;
}

.btn-primary:hover { background: var(--primary-dark); }

.auth-footer {
    margin-top: 18px;
    font-size: 13px;
    color: var(--text-gray);
}

.auth-footer a {
    color: var(--primary-dark);
    text-decoration: none;
    font-weight: 600;
}

.alert {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 18px;
    font-size: 13px;
    text-align: left;
}

.alert-error {
    background: #fde8e8;
    color: #c0392b;
    border: 1px solid #f5c6cb;
}

.alert-success {
    background: #e6f7ed;
    color: #1e7e34;
    border: 1px solid #c3e6cb;
}

/* ============ CHAT APP LAYOUT ============ */
.app-container {
    display: flex;
    height: 100vh;
    background: #fff;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 100%;
    max-width: 420px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: #fff;
}

.sidebar-header {
    background: var(--header-bg);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header .user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    color: var(--header-bg);
    flex-shrink: 0;
}

.avatar.small { width: 36px; height: 36px; font-size: 15px; }

.sidebar-header h3 { font-size: 16px; }
.sidebar-header .sub { font-size: 12px; opacity: 0.85; }

.logout-btn {
    color: #fff;
    background: rgba(255,255,255,0.15);
    border: none;
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    text-decoration: none;
}

.search-box {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
}

.search-box input {
    width: 100%;
    padding: 10px 16px;
    border-radius: 20px;
    border: none;
    background: #f0f2f5;
    font-size: 14px;
    outline: none;
}

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

.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f5f5f5;
    transition: background 0.15s;
    text-decoration: none;
    color: inherit;
}

.contact-item:hover, .contact-item.active {
    background: #f0f2f5;
}

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

.contact-details .name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-dark);
}

.contact-details .last-msg {
    font-size: 13px;
    color: var(--text-gray);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-meta {
    text-align: right;
    flex-shrink: 0;
}

.contact-meta .time {
    font-size: 11px;
    color: var(--text-gray);
}

.unread-badge {
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 4px;
    padding: 0 5px;
}

.empty-state {
    text-align: center;
    color: var(--text-gray);
    padding: 40px 20px;
    font-size: 14px;
}

/* Chat Window */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
}

.chat-header {
    background: var(--header-bg);
    color: #fff;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header .back-btn {
    display: none;
    color: #fff;
    text-decoration: none;
    font-size: 22px;
}

.chat-header .user-info { flex: 1; }
.chat-header h3 { font-size: 16px; }
.chat-header .status { font-size: 12px; opacity: 0.85; }

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

.msg-row {
    display: flex;
    margin-bottom: 2px;
}

.msg-row.sent { justify-content: flex-end; }
.msg-row.received { justify-content: flex-start; }

.msg-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.msg-row.sent .msg-bubble {
    background: var(--my-bubble);
    border-top-right-radius: 0;
}

.msg-row.received .msg-bubble {
    background: var(--other-bubble);
    border-top-left-radius: 0;
}

.msg-bubble img {
    max-width: 100%;
    border-radius: 6px;
    margin-bottom: 4px;
    cursor: pointer;
    display: block;
}

.msg-time {
    font-size: 11px;
    color: var(--text-gray);
    text-align: right;
    margin-top: 2px;
}

.date-divider {
    text-align: center;
    margin: 14px 0;
}

.date-divider span {
    background: #fff;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-gray);
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

/* Message Input */
.message-input-area {
    background: #f0f2f5;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.message-input-area input[type="text"] {
    flex: 1;
    padding: 12px 16px;
    border-radius: 22px;
    border: none;
    background: #fff;
    font-size: 14px;
    outline: none;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 22px;
    color: var(--text-gray);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.send-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#image-preview-container {
    display: none;
    padding: 10px 14px;
    background: #f0f2f5;
    align-items: center;
    gap: 10px;
}

#image-preview-container img {
    max-height: 70px;
    border-radius: 6px;
}

#image-preview-container .remove-preview {
    background: #e74c3c;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
}

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--chat-bg);
    color: var(--text-gray);
    text-align: center;
    padding: 20px;
}

.welcome-screen h2 {
    margin-top: 20px;
    color: var(--text-dark);
}

/* New Chat Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal-box {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-box h3 {
    margin-bottom: 14px;
    color: var(--text-dark);
}

.modal-box .close-modal {
    align-self: flex-end;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-gray);
}

.modal-results {
    overflow-y: auto;
    margin-top: 10px;
}

.fab-new-chat {
    position: absolute;
    bottom: 24px;
    right: 24px;
    background: var(--primary);
    color: #fff;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    font-size: 26px;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
    .sidebar {
        max-width: 100%;
        position: relative;
    }

    .app-container.chat-open .sidebar {
        display: none;
    }

    .app-container:not(.chat-open) .chat-window {
        display: none;
    }

    .chat-header .back-btn {
        display: inline-block;
    }
}

@media (min-width: 769px) {
    .chat-header .back-btn { display: none; }
    .chat-window { display: flex !important; }
    .sidebar { display: flex !important; }
}
