/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
}

/* Screen Management */
.screen {
    display: none;
    width: 100%;
    height: 100vh;
}

.screen.active {
    display: flex;
}

/* ============================================
   LOGIN SCREEN
   ============================================ */
#login-screen {
    justify-content: center;
    align-items: center;
}

.login-container {
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.app-logo {
    font-size: 80px;
    margin-bottom: 20px;
}

.login-container h1 {
    color: #075e54;
    margin-bottom: 10px;
}

.login-container p {
    color: #666;
    margin-bottom: 30px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.login-form input {
    padding: 12px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border 0.3s;
}

.login-form input:focus {
    outline: none;
    border-color: #075e54;
}

.btn-primary, .btn-secondary {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: #075e54;
    color: white;
}

.btn-primary:hover {
    background: #128c7e;
}

.btn-secondary {
    background: white;
    color: #075e54;
    border: 2px solid #075e54;
}

.btn-secondary:hover {
    background: #f0f0f0;
}

/* ============================================
   CHAT SCREEN
   ============================================ */
#chat-screen {
    flex-direction: column;
    background: #f0f2f5;
}

/* Header */
.chat-header {
    background: #075e54;
    color: white;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid white;
}

.header-info {
    display: flex;
    flex-direction: column;
}

.header-info h3 {
    font-size: 16px;
    font-weight: 600;
}

.status-text {
    font-size: 12px;
    opacity: 0.8;
}

.icon-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px 15px;
    border-radius: 5px;
    font-size: 14px;
    transition: background 0.3s;
}

.icon-btn:hover {
    background: rgba(255,255,255,0.1);
}

/* Main Container */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ============================================
   SIDEBAR - USERS LIST
   ============================================ */
.sidebar {
    width: 350px;
    background: white;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 15px 20px;
    background: #f0f2f5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e0e0e0;
}

.sidebar-header h2 {
    font-size: 20px;
    color: #333;
}

.search-box {
    padding: 10px;
    background: #f0f2f5;
}

.search-box input {
    width: 100%;
    padding: 10px 15px;
    border: none;
    border-radius: 8px;
    background: white;
    font-size: 14px;
}

.users-list {
    flex: 1;
    overflow-y: auto;
}

.user-item {
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
}

.user-item:hover {
    background: #f5f5f5;
}

.user-item.active {
    background: #e8f5e9;
}

.user-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.user-item-name {
    font-weight: 600;
    color: #333;
    font-size: 15px;
}

.user-item-last-msg {
    font-size: 13px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-item-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ccc;
}

.user-item-status.online {
    background: #4caf50;
}

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: #666;
}

/* ============================================
   CHAT AREA
   ============================================ */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #e5ddd5;
    position: relative;
}

/* Chat Area Background Pattern */
.chat-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect fill="%23e5ddd5" width="100" height="100"/><circle fill="%23d1c4b8" cx="10" cy="10" r="1.5"/></svg>');
    opacity: 0.3;
    pointer-events: none;
}

.chat-user-header {
    background: white;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    border-bottom: 1px solid #e0e0e0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    position: relative;
    z-index: 1;
}

.chat-user-info {
    display: flex;
    flex-direction: column;
}

.chat-user-info h3 {
    font-size: 16px;
    color: #333;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #666;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
}

.status-indicator.online .status-dot {
    background: #4caf50;
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
    z-index: 1;
}

.empty-chat-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: #666;
}

.empty-icon {
    font-size: 80px;
    margin-bottom: 20px;
}

.empty-chat-state h3 {
    color: #075e54;
    margin-bottom: 10px;
}

.features-list {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.feature {
    background: white;
    padding: 10px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 10px;
    max-width: 70%;
    animation: messageAppear 0.3s ease;
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.received {
    align-self: flex-start;
}

.message-bubble {
    background: white;
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    position: relative;
    max-width: 100%;
    word-wrap: break-word;
}

.message.sent .message-bubble {
    background: #dcf8c6;
    border-bottom-right-radius: 2px;
}

.message.received .message-bubble {
    background: white;
    border-bottom-left-radius: 2px;
}

.message-text {
    font-size: 14px;
    color: #333;
    line-height: 1.4;
}

.message-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 5px;
    margin-top: 5px;
    font-size: 11px;
    color: #667781;
}

.message-time {
    font-size: 11px;
}

.message-status {
    display: flex;
    align-items: center;
    font-size: 14px;
}

.message-status.delivered {
    color: #999;
}

.message-status.seen {
    color: #4fc3f7;
}

/* Voice Message Styling */
.voice-message {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 200px;
}

.voice-play-btn {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: #075e54;
    color: white;
    border: none;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.voice-waveform {
    flex: 1;
    height: 30px;
    background: #e0e0e0;
    border-radius: 15px;
    position: relative;
    overflow: hidden;
}

.voice-duration {
    font-size: 11px;
    color: #667781;
}

/* ============================================
   MESSAGE INPUT AREA
   ============================================ */
.message-input-area {
    background: #f0f2f5;
    padding: 10px 20px;
    position: relative;
    z-index: 2;
}

.input-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

#message-input {
    flex: 1;
    padding: 10px 15px;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    background: white;
}

#message-input:focus {
    outline: none;
}

.btn-send {
    background: #075e54;
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.3s;
}

.btn-send:hover {
    background: #128c7e;
}

/* Emoji Picker */
.emoji-picker-container {
    position: absolute;
    bottom: 70px;
    left: 20px;
    z-index: 10;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    border-radius: 10px;
    overflow: hidden;
}

/* Voice Recording UI */
.voice-recording-ui {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px;
    background: #fff3cd;
    border-radius: 10px;
}

.recording-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.recording-dot {
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

#recording-time {
    font-weight: 600;
    color: #dc3545;
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 768px) {
    body {
        overflow: auto;
        height: auto;
    }

    .screen.active {
        flex-direction: column;
        height: 100%;
        min-height: 100vh;
    }

    .main-container {
        position: relative;
        overflow: hidden;
        flex: 1;
    }

    .sidebar {
        width: 100%;
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 10;
        transform: translateX(0);
        transition: transform 0.3s;
        pointer-events: all;
    }

    .sidebar.hide-mobile {
        transform: translateX(-100%);
        pointer-events: none;
    }

    .chat-area {
        width: 100%;
        min-width: 100%;
        height: 100%;
    }

    #message-input {
        font-size: 16px;
    }

    .message-input-area {
        padding-bottom: 10px;
        position: sticky;
        bottom: 0;
    }

    .message {
        max-width: 85%;
    }

    #back-btn {
        display: inline-block !important;
    }
}

/* ============================================
   LOADING & UTILITY CLASSES
   ============================================ */
.loading {
    display: flex;
    justify-content: center;
    padding: 20px;
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #075e54;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}
