/* ============================================
   CSS RESET & ROOT VARIABLES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* WhatsApp exact colors */
    --wa-green: #00a884;
    --wa-green-dark: #008069;
    --wa-green-light: #d9fdd3;
    --wa-teal: #008069;
    --wa-header-bg: #202c33;
    --wa-sidebar-bg: #111b21;
    --wa-chat-bg: #0b141a;
    --wa-msg-incoming: #202c33;
    --wa-msg-outgoing: #005c4b;
    --wa-hover: #2a3942;
    --wa-active: #2a3942;
    --wa-search-bg: #202c33;
    --wa-search-input: #2a3942;
    --wa-border: #222d34;
    --wa-text-primary: #e9edef;
    --wa-text-secondary: #8696a0;
    --wa-text-meta: #667781;
    --wa-input-bg: #2a3942;
    --wa-panel-bg: #0b141a;
    --wa-unread-badge: #00a884;
    --wa-date-bubble: #182229;
    --wa-dropdown-bg: #233138;
    --wa-icon-color: #aebac1;
    --wa-link-color: #53bdeb;
    --wa-wallpaper: #0b141a;
    /* Dark theme specific */
    --wa-default-bg: #222e35;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
    background-color: #111b21;
    color: var(--wa-text-primary);
}

/* ============================================
   MAIN APP CONTAINER
   ============================================ */
.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    overflow: hidden;
    position: relative;
}

/* ============================================
   LEFT SIDEBAR
   ============================================ */
.sidebar {
    width: 30%;
    min-width: 340px;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    background-color: var(--wa-sidebar-bg);
    border-right: 1px solid var(--wa-border);
    height: 100vh;
}

/* Sidebar Header */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background-color: var(--wa-header-bg);
    height: 59px;
    min-height: 59px;
}

.sidebar-header-left {
    display: flex;
    align-items: center;
}

.user-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
}

.sidebar-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--wa-icon-color);
    font-size: 18px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s;
}

.icon-btn:hover {
    background-color: var(--wa-hover);
}

/* Search Container */
.search-container {
    display: flex;
    align-items: center;
    padding: 7px 12px;
    background-color: var(--wa-sidebar-bg);
    gap: 4px;
}

.search-bar {
    display: flex;
    align-items: center;
    flex: 1;
    background-color: var(--wa-search-input);
    border-radius: 8px;
    padding: 0 12px;
    height: 35px;
}

.search-icon {
    color: var(--wa-text-secondary);
    font-size: 13px;
    margin-right: 16px;
}

.search-bar input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--wa-text-primary);
    font-size: 14px;
    height: 100%;
}

.search-bar input::placeholder {
    color: var(--wa-text-secondary);
    font-size: 13px;
}

.filter-btn {
    background: none;
    border: none;
    color: var(--wa-icon-color);
    font-size: 16px;
    width: 30px;
    height: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.filter-btn:hover {
    background-color: var(--wa-hover);
}

/* ============================================
   CHAT LIST
   ============================================ */
.chat-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Scrollbar styling */
.chat-list::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-list::-webkit-scrollbar-thumb {
    background-color: rgba(134, 150, 160, 0.3);
    border-radius: 4px;
}

.chat-list::-webkit-scrollbar-thumb:hover {
    background-color: rgba(134, 150, 160, 0.5);
}

/* Individual Chat Item */
.chat-item {
    display: flex;
    align-items: center;
    padding: 0 15px;
    height: 72px;
    cursor: pointer;
    transition: background-color 0.15s;
    position: relative;
}

.chat-item:hover {
    background-color: var(--wa-hover);
}

.chat-item.active {
    background-color: var(--wa-active);
}

.chat-item-avatar {
    width: 49px;
    height: 49px;
    border-radius: 50%;
    margin-right: 13px;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-item-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.chat-item-content {
    flex: 1;
    min-width: 0;
    padding: 13px 0;
    border-bottom: 1px solid var(--wa-border);
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.chat-item:last-child .chat-item-content {
    border-bottom: none;
}

.chat-item-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 2px;
}

.chat-item-name {
    font-size: 16px;
    font-weight: 400;
    color: var(--wa-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 70%;
}

.chat-item-time {
    font-size: 12px;
    color: var(--wa-text-meta);
    flex-shrink: 0;
    margin-left: 6px;
}

.chat-item-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-item-preview {
    font-size: 13px;
    color: var(--wa-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 8px;
    line-height: 20px;
}

.chat-item-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.unread-badge {
    background-color: var(--wa-unread-badge);
    color: var(--wa-sidebar-bg);
    font-size: 11px;
    font-weight: 500;
    min-width: 20px;
    height: 20px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

/* Loading State */
.loading-chats {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--wa-text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--wa-border);
    border-top-color: var(--wa-green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   RIGHT SIDE - CHAT AREA
   ============================================ */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--wa-chat-bg);
    position: relative;
    min-width: 0;
}

/* Default State (no chat selected) */
.default-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--wa-default-bg);
    border-bottom: 6px solid var(--wa-green);
}

.default-content {
    text-align: center;
    max-width: 560px;
    padding: 28px;
}

.default-icon {
    margin-bottom: 28px;
    opacity: 0.95;
}

.default-icon img {
    filter: grayscale(0.2) opacity(0.4);
}

.default-content h1 {
    font-size: 32px;
    font-weight: 300;
    color: var(--wa-text-primary);
    margin-bottom: 16px;
}

.default-content p {
    font-size: 14px;
    color: var(--wa-text-secondary);
    line-height: 20px;
    margin-bottom: 8px;
}

.encryption-note {
    margin-top: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: var(--wa-text-meta);
    font-size: 13px;
}

.encryption-note i {
    font-size: 11px;
}

/* ============================================
   ACTIVE CHAT
   ============================================ */
.active-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background-color: var(--wa-header-bg);
    height: 59px;
    min-height: 59px;
    cursor: pointer;
}

.back-btn {
    display: none;
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 13px;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-info h3 {
    font-size: 16px;
    font-weight: 400;
    color: var(--wa-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-info p {
    font-size: 13px;
    color: var(--wa-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-actions {
    display: flex;
    gap: 2px;
}

/* ============================================
   MESSAGES CONTAINER
   ============================================ */
.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    /* WhatsApp wallpaper pattern */
    background-color: var(--wa-wallpaper);
    background-image: url("data:image/svg+xml,%3Csvg width='400' height='400' viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M20 20h12v12H20zM60 40h8v8h-8zM100 20h6v6h-6zM160 60h10v10h-10zM200 30h8v8h-8zM280 50h12v12h-12zM340 20h6v6h-6zM380 70h8v8h-8zM40 100h10v10H40zM120 90h8v8h-8zM180 120h12v12h-12zM240 80h6v6h-6zM320 110h10v10h-10zM20 160h8v8h-8zM80 180h12v12H80zM160 150h6v6h-6zM220 190h8v8h-8zM300 170h10v10h-10zM360 140h8v8h-8zM50 220h12v12H50zM110 250h8v8h-8zM200 230h10v10h-10zM260 210h6v6h-6zM340 240h12v12h-12zM30 290h8v8h-8zM90 310h10v10H90zM170 280h12v12h-12zM240 320h8v8h-8zM310 300h6v6h-6zM380 280h10v10h-10zM60 350h8v8h-8zM140 370h12v12h-12zM220 360h6v6h-6zM280 340h10v10h-10zM350 380h8v8h-8z'/%3E%3C/g%3E%3C/svg%3E");
    position: relative;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background-color: rgba(134, 150, 160, 0.3);
    border-radius: 4px;
}

.messages-wrapper {
    padding: 10px 63px;
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

/* Date Separator */
.date-separator {
    display: flex;
    justify-content: center;
    margin: 12px 0;
}

.date-bubble {
    background-color: var(--wa-date-bubble);
    color: var(--wa-text-secondary);
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 12.5px;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

/* Message Bubbles */
.message-row {
    display: flex;
    margin-bottom: 2px;
    position: relative;
}

.message-row.incoming {
    justify-content: flex-start;
}

.message-row.outgoing {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 65%;
    padding: 6px 7px 8px 9px;
    border-radius: 7.5px;
    position: relative;
    font-size: 14.2px;
    line-height: 19px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.message-row.incoming .message-bubble {
    background-color: var(--wa-msg-incoming);
    border-top-left-radius: 0;
}

.message-row.outgoing .message-bubble {
    background-color: var(--wa-msg-outgoing);
    border-top-right-radius: 0;
}

/* Message tail (the little triangle) */
.message-row.incoming.has-tail .message-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border-top: 0 solid transparent;
    border-bottom: 13px solid transparent;
    border-right: 8px solid var(--wa-msg-incoming);
}

.message-row.outgoing.has-tail .message-bubble::after {
    content: '';
    position: absolute;
    top: 0;
    right: -8px;
    width: 0;
    height: 0;
    border-top: 0 solid transparent;
    border-bottom: 13px solid transparent;
    border-left: 8px solid var(--wa-msg-outgoing);
}

/* Sender name in group chats */
.msg-sender-name {
    font-size: 12.5px;
    font-weight: 500;
    margin-bottom: 2px;
    color: var(--wa-link-color);
}

/* Message text */
.msg-text {
    color: var(--wa-text-primary);
    white-space: pre-wrap;
    padding-right: 48px;
}

/* Message metadata (time + check marks) */
.msg-meta {
    float: right;
    display: flex;
    align-items: center;
    gap: 3px;
    margin-top: -10px;
    margin-left: 12px;
    position: relative;
    top: 6px;
}

.msg-time {
    font-size: 11px;
    color: rgba(134, 150, 160, 0.85);
}

.msg-status {
    font-size: 14px;
    color: var(--wa-link-color);
}

/* Attachment indicator */
.msg-attachment {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    font-size: 12px;
    color: var(--wa-text-secondary);
    margin-bottom: 4px;
}

.msg-attachment i {
    font-size: 14px;
}

/* Subject line */
.msg-subject {
    font-weight: 600;
    font-size: 13px;
    color: var(--wa-text-primary);
    margin-bottom: 4px;
    opacity: 0.9;
}

/* ============================================
   MESSAGE INPUT AREA
   ============================================ */
.message-input-area {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    background-color: var(--wa-header-bg);
    gap: 5px;
    min-height: 62px;
}

.input-wrapper {
    flex: 1;
    background-color: var(--wa-input-bg);
    border-radius: 8px;
    padding: 9px 12px;
}

.input-wrapper input {
    width: 100%;
    background: none;
    border: none;
    outline: none;
    color: var(--wa-text-primary);
    font-size: 15px;
}

.input-wrapper input::placeholder {
    color: var(--wa-text-secondary);
}

.input-wrapper input:disabled {
    cursor: default;
}

/* ============================================
   CONTACT INFO PANEL
   ============================================ */
.contact-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: 30%;
    min-width: 340px;
    max-width: 500px;
    height: 100vh;
    background-color: var(--wa-sidebar-bg);
    border-left: 1px solid var(--wa-border);
    z-index: 100;
    display: flex;
    flex-direction: column;
    animation: slideInRight 0.2s ease;
}

@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.contact-panel-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background-color: var(--wa-header-bg);
    height: 59px;
    gap: 20px;
}

.contact-panel-header h3 {
    font-size: 16px;
    font-weight: 500;
    color: var(--wa-text-primary);
}

.contact-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 28px 30px;
    text-align: center;
}

.contact-panel-body .contact-avatar {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    margin: 0 auto 16px;
}

.contact-panel-body .contact-name {
    font-size: 22px;
    color: var(--wa-text-primary);
    margin-bottom: 4px;
}

.contact-panel-body .contact-email {
    font-size: 14px;
    color: var(--wa-text-secondary);
    margin-bottom: 20px;
}

.contact-panel-body .contact-info-section {
    text-align: left;
    padding: 14px 0;
    border-top: 1px solid var(--wa-border);
}

.contact-panel-body .contact-info-section h4 {
    font-size: 14px;
    color: var(--wa-green);
    margin-bottom: 8px;
    font-weight: 400;
}

.contact-panel-body .contact-info-section p {
    font-size: 14px;
    color: var(--wa-text-primary);
}

/* ============================================
   NO MESSAGES STATE
   ============================================ */
.no-messages {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--wa-text-secondary);
    font-size: 14px;
}

/* Loading messages */
.loading-messages {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    flex: 1;
    color: var(--wa-text-secondary);
}

/* ============================================
   SCROLL TO BOTTOM BUTTON
   ============================================ */
.scroll-to-bottom {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 42px;
    height: 42px;
    background-color: var(--wa-header-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
    border: none;
    color: var(--wa-icon-color);
    font-size: 18px;
    z-index: 10;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.2s;
    pointer-events: none;
}

.scroll-to-bottom.visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.scroll-to-bottom:hover {
    background-color: var(--wa-hover);
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media screen and (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-width: unset;
        max-width: unset;
    }

    .chat-area {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 50;
        display: none;
    }

    .chat-area.mobile-active {
        display: flex;
    }

    .back-btn {
        display: flex !important;
        margin-right: 4px;
    }

    .messages-wrapper {
        padding: 10px 16px;
    }

    .message-bubble {
        max-width: 85%;
    }

    .default-state {
        display: none;
    }

    .contact-panel {
        width: 100%;
        min-width: unset;
        max-width: unset;
    }
}

@media screen and (min-width: 769px) and (max-width: 1100px) {
    .messages-wrapper {
        padding: 10px 30px;
    }
    
    .sidebar {
        min-width: 300px;
        width: 35%;
    }
}

/* ============================================
   UTILITIES
   ============================================ */
.hidden {
    display: none !important;
}

/* Highlight for search */
.highlight {
    background-color: rgba(0, 168, 132, 0.3);
    border-radius: 2px;
    padding: 0 1px;
}

/* Empty state for search */
.no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--wa-text-secondary);
    font-size: 14px;
    text-align: center;
}

.no-results i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.4;
}

/* Message count indicator in sidebar */
.msg-count-indicator {
    font-size: 11px;
    color: var(--wa-text-meta);
}