/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
    background-color: #ECE5DD;
    height: 100vh;
    overflow: hidden;
}

/* Authentication Container */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #ECE5DD;
}

.auth-form {
    background-color: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
}

.auth-form h1 {
    text-align: center;
    color: #128C7E;
    margin-bottom: 1.5rem;
}

.auth-form h2 {
    color: #075E54;
    margin-bottom: 1.5rem;
}

.input-group {
    margin-bottom: 1rem;
}

.input-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.btn-primary {
    width: 100%;
    padding: 0.75rem;
    background-color: #128C7E;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
}

.btn-primary:hover {
    background-color: #075E54;
}

.auth-switch {
    text-align: center;
    margin-top: 1rem;
}

.auth-switch a {
    color: #128C7E;
    text-decoration: none;
}

/* Main Application Container */
.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* Sidebar Styles */
.sidebar {
    width: 30%;
    min-width: 300px;
    background-color: #ECE5DD;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #ccc;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background-color: #F0F2F5;
    border-bottom: 1px solid #ccc;
}

.user-info {
    display: flex;
    align-items: center;
    flex: 1;
}

.user-info img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 1rem;
}

.user-details h3 {
    font-size: 1rem;
    color: #075E54;
}

.user-details p {
    font-size: 0.8rem;
    color: #667781;
}

.header-actions {
    display: flex;
    gap: 1rem;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #54656F;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.icon-btn:hover {
    background-color: #c2c2c2;
}

/* Dropdown menu styles */
.menu-container {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    background-color: white;
    min-width: 160px;
    box-shadow: 0px 8px 16px rgba(0,0,0,0.2);
    z-index: 1001;
    border-radius: 4px;
    overflow: hidden;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    width: 100%;
    padding: 12px 16px;
    border: none;
    background-color: white;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    color: #075E54;
}

.dropdown-item:hover {
    background-color: #f0f2f5;
}

.search-container {
    padding: 0.5rem 1rem;
    background-color: #F0F2F5;
}

.search-container input {
    width: 100%;
    padding: 0.5rem 1rem;
    border-radius: 18px;
    border: none;
    background-color: white;
    font-size: 0.9rem;
}

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

.chat-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f2f5;
}

.chat-item:hover {
    background-color: #f0f2f5;
}

.chat-item.active {
    background-color: #d9fdd3;
}

.chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    margin-right: 1rem;
}

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

.chat-info h4 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
    color: #075E54;
}

.chat-info p {
    font-size: 0.85rem;
    color: #667781;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.timestamp {
    font-size: 0.75rem;
    color: #667781;
}

.unread-count {
    background-color: #128C7E;
    color: white;
    font-size: 0.7rem;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.25rem;
}

/* Main Chat Area */
.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #ECE5DD;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%239C92AC' fill-opacity='0.05' fill-rule='evenodd'/%3E%3C/svg%3E");
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background-color: #F0F2F5;
    border-bottom: 1px solid #ccc;
}

.chat-header-info {
    display: flex;
    align-items: center;
}

.chat-header-info .chat-avatar {
    width: 40px;
    height: 40px;
    margin-right: 1rem;
}

.chat-details h3 {
    font-size: 1rem;
    color: #075E54;
}

.chat-details p {
    font-size: 0.8rem;
    color: #667781;
}

.messages-container {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.empty-chat-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: #667781;
    padding: 2rem;
}

.empty-chat-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.empty-chat-state h3 {
    color: #075E54;
    margin-bottom: 0.5rem;
}

.empty-chat-state p {
    color: #667781;
}

.message {
    display: flex;
    margin-bottom: 1rem;
}

.message-content {
    position: relative;
    padding: 0.75rem;
    border-radius: 0.75rem;
    max-width: 70%;
    word-wrap: break-word;
}

.message.received .message-content {
    background-color: white;
    border-bottom-left-radius: 0;
}

.message.sent .message-content {
    background-color: #DCF8C6;
    margin-left: auto;
    border-bottom-right-radius: 0;
}

.message p {
    margin-bottom: 0.25rem;
}

.timestamp {
    font-size: 0.7rem;
    color: #667781;
    text-align: right;
}

.status-icon {
    font-size: 0.7rem;
    color: #667781;
    position: absolute;
    right: 0.5rem;
    bottom: 0.25rem;
}

.message.sent .status-icon {
    color: #128C7E;
}

.message-input-container {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    background-color: #F0F2F5;
    border-top: 1px solid #ccc;
}

.input-actions {
    display: flex;
    gap: 0.5rem;
    margin-right: 0.5rem;
}

#message-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 20px;
    border: none;
    font-size: 1rem;
}

.send-btn {
    margin-left: 0.5rem;
}

/* Right Panel */
.right-panel {
    width: 30%;
    min-width: 300px;
    background-color: white;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #ccc;
    display: none; /* Hidden by default, shown on desktop */
}

.profile-header {
    text-align: center;
    padding: 2rem 1rem;
    background-color: #F0F2F5;
    border-bottom: 1px solid #ccc;
}

.profile-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    margin-bottom: 1rem;
}

.profile-header h2 {
    color: #075E54;
    margin-bottom: 0.5rem;
}

.profile-header p {
    color: #667781;
}

.profile-details {
    padding: 1.5rem;
    flex: 1;
}

.profile-details h3 {
    font-size: 0.9rem;
    color: #667781;
    margin: 1.5rem 0 0.5rem;
}

.profile-details p {
    margin-bottom: 1rem;
    color: #075E54;
}

.profile-actions {
    padding: 1rem;
    border-top: 1px solid #f0f2f5;
    display: flex;
    gap: 0.5rem;
}

.btn-secondary {
    flex: 1;
    padding: 0.75rem;
    background-color: #F0F2F5;
    color: #075E54;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.btn-secondary:hover {
    background-color: #e0e2e5;
}

/* Responsive Design */
@media (max-width: 1023px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: 100vh;
        min-height: auto;
        display: flex;
        flex-direction: column;
        position: relative;
    }

    .main-chat {
        width: 100%;
        height: 100vh;
        position: absolute;
        top: 0;
        left: 0;
        display: flex;
        flex-direction: column;
        z-index: 10;
        background-color: #ECE5DD;
        background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%239C92AC' fill-opacity='0.05' fill-rule='evenodd'/%3E%3C/svg%3E");
    }

    .right-panel {
        display: none;
    }

    .chat-header, .message-input-container {
        padding: 0.5rem;
    }

    .message-content {
        max-width: 85%;
    }

    .sidebar-header {
        padding: 0.5rem;
    }

    .search-container {
        padding: 0.25rem 0.5rem;
    }

    .chat-item {
        padding: 0.5rem;
    }

    .chat-avatar {
        width: 40px;
        height: 40px;
        margin-right: 0.75rem;
    }

    /* Mobile-specific chat header styles */
    .chat-header {
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .chat-header .header-actions:first-child {
        display: flex;
        margin-right: 0.5rem;
    }

    /* Back button styling */
    #back-to-chats-btn {
        display: none; /* Hidden by default, shown on mobile when in conversation view */
    }

    /* Mobile chat list view - show only chat list */
    .mobile-chat-list-view .main-chat {
        display: none;
    }

    /* Mobile chat conversation view - show only conversation */
    .mobile-chat-conversation-view .sidebar {
        display: none;
    }
}

@media (min-width: 1024px) {
    .right-panel {
        display: flex;
    }
}

/* Additional mobile-specific styles */
@media (max-width: 480px) {
    .auth-form {
        margin: 1rem;
        padding: 1.5rem;
    }

    .message-content {
        max-width: 90%;
        padding: 0.5rem;
    }

    .message-input-container {
        padding: 0.5rem;
    }

    #message-input {
        padding: 0.5rem;
    }

    .chat-header-info .chat-avatar {
        width: 30px;
        height: 30px;
    }

    .user-info img {
        width: 30px;
        height: 30px;
    }

    .chat-item {
        align-items: flex-start;
    }

    .chat-info h4 {
        font-size: 0.9rem;
    }

    .chat-info p {
        font-size: 0.75rem;
    }

    .timestamp {
        font-size: 0.65rem;
    }
}

/* Mobile keyboard visibility handling */
@media (max-width: 1023px) {
    .main-chat.keyboard-visible .messages-container {
        padding-bottom: 80px; /* Space for the fixed input field */
        height: calc(100vh - 160px); /* Adjust height to account for header and input */
    }

    .main-chat.keyboard-visible .message-input-container {
        position: fixed !important;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        background-color: #F0F2F5;
        border-top: 1px solid #ccc;
        padding: 0.75rem;
    }

    .main-chat.keyboard-visible .chat-header {
        position: relative; /* Change from sticky when keyboard is visible */
    }
}

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

.modal-content {
    background-color: white;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #eee;
}

.modal-header h2 {
    color: #075E54;
    margin: 0;
}

.close {
    font-size: 1.5rem;
    cursor: pointer;
    color: #aaa;
}

.close:hover {
    color: #000;
}

.modal-body {
    padding: 1rem;
}

.new-chat-options {
    display: flex;
    margin-bottom: 1rem;
    border-bottom: 1px solid #eee;
}

.chat-option-btn {
    flex: 1;
    padding: 0.75rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 1rem;
    color: #667781;
}

.chat-option-btn.active {
    color: #128C7E;
    border-bottom: 2px solid #128C7E;
}

.new-chat-form {
    margin-top: 1rem;
}

.search-results {
    max-height: 200px;
    overflow-y: auto;
    margin-top: 0.5rem;
    border: 1px solid #eee;
    border-radius: 4px;
    display: none;
}

.search-results.show {
    display: block;
}

.search-result-item {
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
}

.search-result-item:hover {
    background-color: #f0f2f5;
}

.search-result-item:last-child {
    border-bottom: none;
}

.result-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin-right: 0.75rem;
}

.result-info {
    flex: 1;
}

.result-info h4 {
    font-size: 0.9rem;
    margin: 0 0 0.25rem 0;
    color: #075E54;
}

.result-info p {
    font-size: 0.8rem;
    margin: 0;
    color: #667781;
}

.selected-members {
    margin: 1rem 0;
    max-height: 150px;
    overflow-y: auto;
}

.selected-member {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    background-color: #f0f2f5;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.selected-member:last-child {
    margin-bottom: 0;
}

.selected-member .result-avatar {
    width: 30px;
    height: 30px;
    margin-right: 0.5rem;
}

.selected-member-info {
    flex: 1;
}

.selected-member-info h4 {
    font-size: 0.9rem;
    margin: 0 0 0.25rem 0;
    color: #075E54;
}

.selected-member-info p {
    font-size: 0.8rem;
    margin: 0;
    color: #667781;
}

.remove-member {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 1.2rem;
}

.remove-member:hover {
    color: #ff0000;
}

/* Responsive modal styles */
@media (max-width: 480px) {
    .modal-content {
        width: 95%;
        margin: 0.5rem;
    }

    .modal-body {
        padding: 0.75rem;
    }

    .search-result-item {
        padding: 0.5rem;
    }
}