/* Global Styles */
:root {
    --primary-color: #9D1AA3;
    /* Areena Purple */
    --secondary-color: #f0f2f5;
    /* Light Grey Background */
    --white: #ffffff;
    --message-out: #fae6fc;
    /* Light Purple for sent messages */
    --message-in: #ffffff;
    --text-primary: #111b21;
    --text-secondary: #667781;
    --border-color: #e9edef;
    --hover-bg: #f5f6f6;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

body {
    background-color: #f3e5f5;
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Auth Container (Login/Register) */
.auth-container {
    background: var(--white);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.auth-header {
    margin-bottom: 2rem;
}

.auth-header h1 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.form-group {
    margin-bottom: 1rem;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: var(--white);
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
    font-size: 1rem;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-primary:hover {
    background-color: #7C1081;
}

.auth-footer {
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.auth-footer a {
    color: var(--primary-color);
    text-decoration: none;
}

/* Chat Interface */
.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    background: var(--white);
    overflow: hidden;
    max-width: 1600px;
    /* Limit width on very large screens */
    margin: 0 auto;
    /* Center it */
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

/* Sidebar */
.sidebar {
    width: 30%;
    min-width: 300px;
    /* Minimum width to prevent crushing */
    max-width: 450px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--white);
}

/* Main Chat Area */
.chat-area {
    flex: 1;
    /* Take remaining space */
    display: flex;
    flex-direction: column;
    background-image: url('../images/bg-chat.png');
    background-color: #efeae2;
    position: relative;
    width: auto;
    /* Allow flex to control width */
}

.sidebar-header {
    padding: 10px 16px;
    background: var(--secondary-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.sidebar-actions button {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-secondary);
    cursor: pointer;
    margin-left: 15px;
}

.search-bar {
    padding: 10px;
    background: var(--white);
    border-bottom: 1px solid var(--border-color);
}

.search-input {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--secondary-color);
    border: none;
    outline: none;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    display: flex;
    padding: 12px 16px;
    align-items: center;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
}

.chat-item:hover {
    background-color: var(--hover-bg);
}

.chat-item.active {
    background-color: #e9edef;
}

.chat-info {
    flex: 1;
    margin-left: 15px;
}

.chat-name {
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
}

.chat-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.chat-preview {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}



.chat-header {
    padding: 10px 16px;
    background: var(--secondary-color);
    display: flex;
    align-items: center;
    height: 60px;
    border-bottom: 1px solid var(--border-color);
}

.chat-header-info {
    flex: 1;
    margin-left: 15px;
}

.chat-header-name {
    font-weight: 600;
    color: var(--text-primary);
}

.chat-header-status {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.message {
    max-width: 60%;
    padding: 8px 12px;
    border-radius: 8px;
    margin-bottom: 10px;
    position: relative;
    font-size: 0.9rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.message.sent {
    align-self: flex-end;
    background-color: var(--message-out);
    border-top-right-radius: 0;
}

.message.received {
    align-self: flex-start;
    background-color: var(--message-in);
    border-top-left-radius: 0;
}

.message-time {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-align: right;
    margin-top: 4px;
}

.chat-input-area {
    padding: 10px 16px;
    background: var(--secondary-color);
    display: flex;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    border: none;
    outline: none;
    margin: 0 10px;
    font-size: 0.95rem;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px;
}

/* Mobile Bottom Navigation */
.mobile-nav {
    display: none;
}

/* Responsive Mobile UI */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        border-radius: 0;
        max-width: 100%;
    }

    .sidebar {
        width: 100%;
        max-width: 100%;
        height: 100%;
        display: flex;
        /* Initially show sidebar */
    }

    .chat-area {
        width: 100%;
        height: 100%;
        display: none;
        /* Hide chat area initially on mobile */
        position: absolute;
        top: 0;
        left: 0;
        z-index: 10;
    }

    .chat-area.active {
        display: flex;
    }

    /* Mobile Bottom Navigation */
    .mobile-nav {
        display: flex;
        justify-content: space-around;
        background: var(--white);
        padding: 10px;
        border-top: 1px solid var(--border-color);
        position: fixed;
        bottom: 0;
        width: 100%;
        z-index: 101;
    }

    .nav-item.active {
        color: var(--primary-color);
    }
}

/* Video Call Modal */
.call-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.call-modal.active {
    display: flex;
}

.video-container {
    position: relative;
    width: 80%;
    max-width: 800px;
    height: 60vh;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
}

#remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#local-video {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 150px;
    height: 100px;
    background: #333;
    border: 2px solid #fff;
    border-radius: 8px;
    object-fit: cover;
}

.call-controls {
    margin-top: 20px;
    display: flex;
    gap: 20px;
}

.call-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
}

.btn-mute {
    background-color: #666;
}

.btn-end {
    background-color: #ff3b30;
}

.btn-answer {
    background-color: #28a745;
}

/* Ticks Status */
.msg-status {
    display: inline-block;
    margin-left: 5px;
    font-size: 0.7rem;
}

.status-sent {
    color: #888;
    /* One gray tick */
}

.status-delivered {
    color: #888;
    /* Two gray ticks (for future use) */
}

.status-read {
    color: #9D1AA3;
    /* Purple ticks */
}

/* Modal Styles */
.modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Stay in place */
    z-index: 2000;
    /* Sit on top */
    left: 0;
    top: 0;
    width: 100%;
    /* Full width */
    height: 100%;
    /* Full height */
    overflow: auto;
    /* Enable scroll if needed */
    background-color: rgb(0, 0, 0);
    /* Fallback color */
    background-color: rgba(0, 0, 0, 0.4);
    /* Black w/ opacity */
}

.modal-content {
    background-color: #fefefe;
    margin: 15% auto;
    /* 15% from top and centered */
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    /* Could be more or less, depending on screen size */
    max-width: 500px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    position: relative;
    animation: modalSlideIn 0.3s;
}

@keyframes modalSlideIn {
    from {
        top: -100px;
        opacity: 0;
    }

    to {
        top: 0;
        opacity: 1;
    }
}

.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-modal:hover,
.close-modal:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

/* Spinner */
.loading-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: var(--primary-color);
    font-size: 1.2rem;
}

/* Sidebar Header Fixes */
.sidebar-header {
    flex-wrap: nowrap;
    /* Prevent wrapping */
}

.sidebar-actions {
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.user-profile {
    display: flex;
    align-items: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    cursor: pointer;
    flex-grow: 1;
    /* Allow it to take space but not too much */
    margin-right: 10px;
}

.user-profile span {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Notification Badge */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: red;
    color: white;
    border-radius: 50%;
    padding: 2px 5px;
    font-size: 0.7rem;
    min-width: 15px;
    text-align: center;
}