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

html,
body {
    width: 100%;
    height: 100%;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background: #111b21;
    color: #e9edef;
    overflow: hidden;
}

button {
    border: none;
    background: none;
    cursor: pointer;
}

.app {
    width: 100%;
    height: 100vh;
    display: flex;
}

/* =========================================
   SIDEBAR
========================================= */

.sidebar {
    width: 380px;
    min-width: 280px;
    background: #111b21;
    border-right: 1px solid #2a3942;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    height: 70px;
    min-height: 70px;
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #202c33;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #e9edef;
    font-size: 20px;
    font-weight: bold;
}

.brand-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: #00a884;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
}

.header-buttons {
    display: flex;
    align-items: center;
    gap: 18px;
}

.header-buttons button {
    width: 34px;
    height: 34px;
    color: #aebac1;
    font-size: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.header-buttons button:hover {
    background: #2a3942;
}

/* =========================================
   SEARCH
========================================= */

.search-area {
    padding: 10px 12px;
    background: #111b21;
}

.search-area input {
    width: 100%;
    height: 40px;
    border: none;
    outline: none;
    border-radius: 8px;
    background: #202c33;
    color: #e9edef;
    padding: 0 15px;
    font-size: 14px;
}

.search-area input::placeholder {
    color: #8696a0;
}

/* =========================================
   CHAT LIST
========================================= */

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

.chat-item {
    min-height: 72px;
    padding: 10px 14px;
    display: flex;
    gap: 12px;
    cursor: pointer;
    border-bottom: 1px solid #202c33;
}

.chat-item:hover,
.chat-item.active {
    background: #202c33;
}

.avatar {
    width: 50px;
    height: 50px;
    min-width: 50px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #6b7c85;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-top,
.chat-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-width: 0;
}

.chat-top strong {
    color: #e9edef;
    font-size: 16px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat-top span {
    color: #8696a0;
    font-size: 12px;
    flex-shrink: 0;
    margin-left: 8px;
}

.chat-bottom {
    margin-top: 7px;
    color: #8696a0;
    font-size: 14px;
}

.chat-bottom span:first-child {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.unread {
    background: #00a884;
    color: white;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    margin-left: 5px;
    flex-shrink: 0;
}

.contacts-empty {
    padding: 40px 20px;
    text-align: center;
    color: #8696a0;
    font-size: 14px;
    line-height: 22px;
}

/* =========================================
   CHAT AREA
========================================= */

.chat {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #0b141a;
}

.chat-header {
    height: 70px;
    min-height: 70px;
    background: #202c33;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
}

.chat-user {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.chat-user > div:last-child {
    min-width: 0;
}

.chat-user strong {
    color: #e9edef;
    font-size: 16px;
}

.chat-user p {
    color: #8696a0;
    font-size: 13px;
    margin-top: 4px;
}

.chat-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.chat-actions button {
    color: #aebac1;
    font-size: 24px;
}

/* =========================================
   MESSAGES
========================================= */

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 25px 8%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    display: flex;
    width: 100%;
}

.message.sent {
    justify-content: flex-end;
}

.bubble {
    max-width: 65%;
    padding: 9px 12px 7px;
    border-radius: 8px;
    color: #e9edef;
    font-size: 14px;
    line-height: 20px;
    position: relative;
    overflow-wrap: anywhere;
}

.received .bubble {
    background: #202c33;
}

.sent .bubble {
    background: #005c4b;
}

.time {
    color: #8696a0;
    font-size: 10px;
    margin-left: 8px;
    white-space: nowrap;
}

/* =========================================
   MESSAGE COMPOSER
========================================= */

.composer {
    min-height: 70px;
    background: #202c33;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
}

.composer button {
    color: #aebac1;
    font-size: 24px;
    flex-shrink: 0;
}

.composer input {
    flex: 1;
    min-width: 0;
    height: 45px;
    border: none;
    outline: none;
    border-radius: 8px;
    background: #2a3942;
    color: #e9edef;
    padding: 0 15px;
    font-size: 15px;
}

.composer input::placeholder {
    color: #8696a0;
}

#sendButton {
    width: 45px;
    height: 45px;
    min-width: 45px;
    border-radius: 50%;
    background: #00a884;
    color: white;
    font-size: 20px;
}

#sendButton:hover {
    background: #06b995;
}

#sendButton:disabled {
    opacity: 0.6;
    cursor: default;
}

/* =========================================
   SCROLLBARS
========================================= */

.chat-list::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.contact-box::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.contact-box::-webkit-scrollbar-thumb {
    background: #374045;
    border-radius: 10px;
}

/* =========================================
   TABLET
========================================= */

@media (max-width: 1000px) {
    .sidebar {
        width: 320px;
        min-width: 320px;
    }

    .messages {
        padding-left: 5%;
        padding-right: 5%;
    }

    .bubble {
        max-width: 75%;
    }
}

/* =========================================
   MOBILE
========================================= */

@media (max-width: 700px) {

    body {
        overflow: hidden;
    }

    .app {
        position: relative;
        width: 100%;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        height: 100dvh;
        border-right: none;
        display: flex;
    }

    .sidebar-header {
        height: 60px;
        min-height: 60px;
        padding: 0 12px;
    }

    .header-buttons {
        gap: 12px;
    }

    .header-buttons button {
        font-size: 22px;
    }

    .search-area {
        padding: 8px;
    }

    .chat-item {
        min-height: 68px;
        padding: 9px 10px;
    }

    .chat {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100dvh;
        display: none;
        z-index: 100;
    }

    .chat-header {
        height: 64px;
        min-height: 64px;
        padding: 0 12px;
    }

    .chat-user {
        min-width: 0;
        flex: 1;
    }

    .chat-user strong {
        display: block;
        max-width: 180px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-actions {
        gap: 12px;
        flex-shrink: 0;
    }

    .chat-actions button {
        font-size: 21px;
    }

    .messages {
        padding: 15px 10px;
        gap: 6px;
    }

    .bubble {
        max-width: 85%;
        font-size: 14px;
    }

    .message {
        max-width: 100%;
    }

    .composer {
        min-height: 62px;
        padding: 8px;
        gap: 6px;
        flex-shrink: 0;
    }

    .composer button {
        font-size: 21px;
    }

    .composer input {
        height: 42px;
        font-size: 14px;
    }

    #sendButton {
        width: 42px;
        height: 42px;
        min-width: 42px;
        font-size: 18px;
    }

    #mobileBackButton {
        display: flex;
    }
}

/* =========================================
   SMALL PHONES
========================================= */

@media (max-width: 420px) {

    .sidebar-header {
        padding: 10px 12px;
    }

    .brand span {
        font-size: 18px;
    }

    .header-buttons {
        gap: 8px;
    }

    .header-buttons button {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }

    .search-area {
        padding: 8px 10px;
    }

    .chat-header {
        padding: 8px 10px;
    }

    .chat-user .avatar {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }

    .chat-user strong {
        max-width: 140px;
    }

    .chat-actions button {
        width: 36px;
        height: 36px;
    }

    .message {
        max-width: 100%;
    }

    .bubble {
        max-width: 88%;
        padding: 8px 10px;
        font-size: 14px;
    }

    .composer {
        gap: 5px;
    }

    .composer button {
        width: 38px;
        height: 38px;
        min-width: 38px;
    }
}

/* =========================================
   VERY SMALL PHONES
========================================= */

@media (max-width: 360px) {

    .brand span {
        font-size: 16px;
    }

    .header-buttons {
        gap: 2px;
    }

    .header-buttons button {
        width: 32px;
        height: 32px;
    }

    .chat-actions button {
        width: 32px;
        height: 32px;
    }

    .composer button {
        width: 35px;
        height: 35px;
        min-width: 35px;
    }

    .bubble {
        font-size: 13px;
    }
}

/* =========================================
   AUTH / LOGIN PAGE
========================================= */

.auth-container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: #111b21;
}

.auth-box {
    width: 100%;
    max-width: 420px;
    padding: 35px;
    border-radius: 14px;
    background: #202c33;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

.auth-box .brand {
    justify-content: center;
    margin-bottom: 25px;
}

.auth-box h2 {
    text-align: center;
    color: #e9edef;
    margin-bottom: 8px;
}

.auth-box > p {
    text-align: center;
    color: #8696a0;
    margin-bottom: 22px;
}

#authForm {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#authForm input {
    width: 100%;
    height: 48px;
    border: 1px solid #2a3942;
    outline: none;
    border-radius: 8px;
    background: #111b21;
    color: #e9edef;
    padding: 0 14px;
    font-size: 15px;
}

#authForm input:focus {
    border-color: #00a884;
}

#authForm button {
    width: 100%;
    height: 48px;
    border-radius: 8px;
    background: #00a884;
    color: white;
    font-size: 16px;
    font-weight: bold;
}

#authForm button:hover {
    background: #06b995;
}

#authMessage {
    min-height: 22px;
    margin-top: 15px;
    color: #00a884;
}

.toggle-button {
    width: 100%;
    margin-top: 12px;
    color: #00a884;
    font-size: 14px;
}

@media (max-width: 500px) {

    .auth-container {
        padding: 12px;
    }

    .auth-box {
        padding: 25px 18px;
        border-radius: 10px;
    }
}

/* =========================================
   MOBILE CHAT BACK BUTTON
========================================= */

#mobileBackButton {
    width: 42px;
    height: 42px;
    border: none;
    background: transparent;
    color: #aebac1;
    font-size: 28px;
    font-weight: 500;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 50%;
    transition: background 0.2s ease;
}

#mobileBackButton:hover {
    background: rgba(255, 255, 255, 0.08);
}

#mobileBackButton:active {
    transform: scale(0.92);
}

/* =========================================
   NEW CONTACT MODAL
========================================= */

.contact-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}

.contact-box {
    width: min(480px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    background: #202c33;
    border: 1px solid #2a3942;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.contact-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    border-bottom: 1px solid #2a3942;
}

.contact-header button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: #aebac1;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.contact-header button:hover {
    background: #2a3942;
}

.contact-header strong {
    display: block;
    font-size: 18px;
    color: #e9edef;
}

.contact-header p {
    margin-top: 4px;
    font-size: 13px;
    color: #8696a0;
}

.contact-form {
    display: flex;
    gap: 10px;
    padding: 18px 20px;
}

.contact-form input {
    flex: 1;
    min-width: 0;
    height: 44px;
    padding: 0 14px;
    border: 1px solid #2a3942;
    border-radius: 10px;
    outline: none;
    background: #111b21;
    color: #e9edef;
    font-size: 14px;
}

.contact-form input::placeholder {
    color: #8696a0;
}

.contact-form input:focus {
    border-color: #00a884;
}

.contact-form button {
    height: 44px;
    border-radius: 10px;
    padding: 0 16px;
    background: #00a884;
    color: white;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
}

.contact-form button:hover {
    background: #06b995;
}

.contact-results {
    padding: 0 20px 20px;
}

.contact-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    margin-top: 8px;
}

.contact-result-item:hover {
    background: #2a3942;
}

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

.contact-result-info strong {
    display: block;
    color: #e9edef;
    font-size: 15px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.contact-result-info span {
    display: block;
    margin-top: 3px;
    font-size: 12px;
    color: #8696a0;
}

.add-contact-button {
    border: none;
    border-radius: 8px;
    padding: 8px 14px;
    background: #00a884;
    color: white;
    cursor: pointer;
    font-weight: 600;
}

.add-contact-button:hover {
    background: #06b995;
}

.add-contact-button:disabled {
    cursor: default;
    opacity: 0.7;
}

.add-contact-button.added {
    background: #374045;
    color: #aebac1;
}

.contacts-empty,
.contact-loading,
.contact-empty,
.contact-error {
    padding: 30px 20px;
    text-align: center;
    font-size: 14px;
    color: #8696a0;
}

/* =========================================
   MOBILE CONTACT MODAL
========================================= */

@media (max-width: 700px) {

    .contact-modal {
        align-items: flex-end;
        padding: 0;
    }

    .contact-box {
        width: 100%;
        max-height: 92vh;
        border-radius: 18px 18px 0 0;
    }

    .contact-form {
        flex-direction: column;
    }

    .contact-form button {
        width: 100%;
        height: 44px;
    }

    .contact-result-item {
        padding: 12px 8px;
    }
}
/* =========================================
   FINAL RESPONSIVE FIX
========================================= */

/* Desktop */
.app {
    width: 100%;
    height: 100vh;
    display: flex;
    overflow: hidden;
}

.sidebar {
    width: 380px;
    min-width: 280px;
    height: 100vh;
}

.chat {
    flex: 1;
    min-width: 0;
    height: 100vh;
}

/* Tablet */
@media screen and (max-width: 900px) {

    .sidebar {
        width: 320px;
        min-width: 320px;
    }

    .messages {
        padding-left: 4%;
        padding-right: 4%;
    }

    .bubble {
        max-width: 75%;
    }
}

/* =========================================
   MOBILE
========================================= */

@media screen and (max-width: 700px) {

    html,
    body {
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    .app {
        position: relative;
        width: 100%;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
        display: block;
    }

    /* CHAT LIST SCREEN */
    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        min-width: 100%;
        height: 100dvh;
        display: flex;
        z-index: 1;
        border-right: none;
    }

    /* CHAT SCREEN */
    .chat {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        min-width: 100%;
        height: 100dvh;
        display: none;
        z-index: 10;
        background: #0b141a;
    }

    /* Header */
    .sidebar-header {
        height: 60px;
        min-height: 60px;
        padding: 0 12px;
    }

    .brand {
        font-size: 18px;
    }

    .brand-icon {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    .header-buttons {
        gap: 8px;
    }

    .header-buttons button {
        width: 36px;
        height: 36px;
        font-size: 21px;
    }

    /* Search */
    .search-area {
        padding: 8px 10px;
    }

    .search-area input {
        height: 42px;
    }

    /* Chat list */
    .chat-list {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    .chat-item {
        width: 100%;
        min-height: 68px;
        padding: 9px 10px;
    }

    /* Chat header */
    .chat-header {
        width: 100%;
        height: 64px;
        min-height: 64px;
        padding: 0 8px;
        flex-shrink: 0;
    }

    .chat-user {
        flex: 1;
        min-width: 0;
    }

    .chat-user .avatar {
        width: 42px;
        height: 42px;
        min-width: 42px;
    }

    .chat-user strong {
        display: block;
        max-width: 160px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    .chat-actions {
        gap: 8px;
        flex-shrink: 0;
    }

    .chat-actions button {
        width: 36px;
        height: 36px;
        font-size: 21px;
    }

    /* Messages */
    .messages {
        width: 100%;
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding: 12px 8px;
        gap: 6px;
    }

    .message {
        width: 100%;
        max-width: 100%;
    }

    .bubble {
        max-width: 85%;
        font-size: 14px;
        line-height: 19px;
        padding: 8px 10px;
    }

    /* Composer */
    .composer {
        width: 100%;
        min-height: 62px;
        padding: 8px;
        gap: 6px;
        flex-shrink: 0;
    }

    .composer input {
        min-width: 0;
        width: 100%;
        height: 42px;
        font-size: 14px;
    }

    .composer button {
        width: 38px;
        height: 38px;
        min-width: 38px;
        font-size: 20px;
    }

    #sendButton {
        width: 42px;
        height: 42px;
        min-width: 42px;
        flex-shrink: 0;
    }

    /* Back button */
    #mobileBackButton {
        display: flex;
        width: 40px;
        height: 40px;
        min-width: 40px;
        font-size: 26px;
    }
}

/* =========================================
   SMALL PHONE
========================================= */

@media screen and (max-width: 420px) {

    .brand {
        font-size: 17px;
    }

    .brand-icon {
        width: 34px;
        height: 34px;
        min-width: 34px;
    }

    .header-buttons {
        gap: 4px;
    }

    .header-buttons button {
        width: 34px;
        height: 34px;
    }

    .chat-header {
        padding: 0 5px;
    }

    .chat-user .avatar {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }

    .chat-user strong {
        max-width: 130px;
    }

    .chat-actions {
        gap: 3px;
    }

    .chat-actions button {
        width: 34px;
        height: 34px;
    }

    .messages {
        padding: 10px 6px;
    }

    .bubble {
        max-width: 90%;
        font-size: 13px;
    }

    .composer {
        padding: 6px;
        gap: 4px;
    }

    .composer button {
        width: 35px;
        min-width: 35px;
    }

    #sendButton {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }
}
/* =====================================================
   FINAL RESPONSIVE LAYOUT
   ===================================================== */

.app {
    width: 100%;
    min-width: 0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    overflow: hidden;
}

.sidebar,
.chat {
    min-width: 0;
}

/* Desktop */
@media (min-width: 701px) {

    .sidebar {
        display: flex !important;
        width: 350px;
        flex: 0 0 350px;
    }

    .chat {
        display: flex !important;
        flex: 1 1 auto;
        width: auto;
    }

    .mobile-hidden {
        display: flex !important;
    }

    .mobile-visible {
        display: flex !important;
    }
}

/* Mobile */
@media (max-width: 700px) {

    .app {
        position: relative;
        display: block;
        width: 100%;
        height: 100dvh;
        overflow: hidden;
    }

    .sidebar {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        display: flex;
        z-index: 10;
    }

    .chat {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        display: none;
        z-index: 20;
    }

    .sidebar.mobile-hidden {
        display: none !important;
    }

    .chat.mobile-visible {
        display: flex !important;
    }
}

/* Very small phones */
@media (max-width: 400px) {

    .chat-header {
        padding-left: 10px;
        padding-right: 10px;
    }

    .message-input {
        min-width: 0;
    }
}
 /* =========================================
   PROFILE MODAL
========================================= */

.profile-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 99999;
}

.profile-modal.show {
    display: flex !important;
}

.profile-box {
    width: 420px;
    max-width: 92%;
    background: #202c33;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.profile-header {
    height: 70px;
    padding: 0 18px;
    display: flex;
    align-items: center;
    gap: 15px;
    background: #00a884;
}

.profile-header button {
    width: 40px;
    height: 40px;
    color: white;
    font-size: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-header strong {
    display: block;
    color: white;
    font-size: 18px;
}

.profile-header p {
    margin-top: 4px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
}

.profile-content {
    padding: 30px 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

.profile-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: #6b7c85;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 45px;
}

#profileUsername {
    width: 100%;
    height: 45px;
    padding: 0 14px;
    border: 1px solid #2a3942;
    border-radius: 7px;
    outline: none;
    background: #111b21;
    color: #e9edef;
    font-size: 15px;
}

#profileUsername::placeholder {
    color: #8696a0;
}

#saveProfileButton {
    width: 100%;
    height: 45px;
    border: none;
    border-radius: 7px;
    background: #00a884;
    color: white;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
}

#saveProfileButton:hover {
    opacity: 0.9;
}

#profileMessage {
    min-height: 18px;
    font-size: 13px;
    color: #00a884;
    text-align: center;
}