/* ============================================
   FRIENDSTIME MESSENGER - MODERN DARK/LIGHT THEME
   Version: 2.0
   ============================================ */

/* ============================================
   CSS VARIABLES - THEME SYSTEM
   ============================================ */

:root {
    /* Light Theme Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f0f2f5;
    --bg-tertiary: #e4e6eb;
    --text-primary: #050505;
    --text-secondary: #65676b;
    --text-tertiary: #8a8d91;

    /* Message Bubbles */
    --msg-incoming-bg: #e4e6eb;
    --msg-incoming-text: #050505;
    --msg-outgoing-bg: #0084ff;
    --msg-outgoing-text: #ffffff;

    /* Borders & Shadows */
    --border-color: #e0e0e0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);

    /* Input & Buttons */
    --input-bg: #f0f2f5;
    --input-border: #e4e6eb;
    --input-focus: #0084ff;
    --btn-primary: #0084ff;
    --btn-primary-hover: #006fd6;
    --btn-secondary: #e4e6eb;
    --btn-secondary-hover: #d8dadf;

    /* Status Colors */
    --online: #31a24c;
    --offline: #8a8d91;
    --typing: #0084ff;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 16px;
    --spacing-xl: 24px;
}

/* Dark Theme */
[data-theme="dark"],
body.dark-mode {
    /* Dark Theme Colors */
    --bg-primary: #18191a;
    --bg-secondary: #242526;
    --bg-tertiary: #3a3b3c;
    --text-primary: #e4e6eb;
    --text-secondary: #b0b3b8;
    --text-tertiary: #8a8d91;

    /* Message Bubbles */
    --msg-incoming-bg: #3a3b3c;
    --msg-incoming-text: #e4e6eb;
    --msg-outgoing-bg: #0084ff;
    --msg-outgoing-text: #ffffff;

    /* Borders & Shadows */
    --border-color: #3a3b3c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.5);

    /* Input & Buttons */
    --input-bg: #3a3b3c;
    --input-border: #3a3b3c;
    --input-focus: #0084ff;
    --btn-primary: #0084ff;
    --btn-primary-hover: #0073e6;
    --btn-secondary: #3a3b3c;
    --btn-secondary-hover: #4e4f50;
}

/* ============================================
   CHAT CONTAINER
   ============================================ */

#chatMessagesArea {
    background: var(--bg-secondary);
    min-height: 400px;
    max-height: 600px;
    overflow-y: auto;
    padding: var(--spacing-lg);
    border-radius: 12px;
    transition: background 0.3s ease;
    scroll-behavior: smooth;
}

#chatMessagesArea::-webkit-scrollbar {
    width: 8px;
}

#chatMessagesArea::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

#chatMessagesArea::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 4px;
}

#chatMessagesArea::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================
   MESSAGE BUBBLES - INCOMING
   ============================================ */

.incoming_msg {
    margin-bottom: var(--spacing-lg);
    display: flex;
    align-items: flex-end;
    animation: slideInLeft 0.3s ease;
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translate3d(-20px, 0, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

.incoming_msg_img {
    flex-shrink: 0;
    margin-right: var(--spacing-md);
}

.incoming_msg_img img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
    transition: transform 0.2s ease;
}

.incoming_msg_img img:hover {
    transform: scale(1.1);
}

.received_msg {
    flex: 1;
    max-width: 70%;
}

.received_withd_msg {
    background: var(--msg-incoming-bg);
    border-radius: 18px;
    padding: 10px 15px;
    position: relative;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
}

.received_withd_msg:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.received_withd_msg p {
    margin: 0;
    color: var(--msg-incoming-text);
    font-size: 15px;
    line-height: 1.4;
}

.received_withd_msg .time_date {
    display: block;
    margin-top: var(--spacing-xs);
    font-size: 11px;
    color: var(--text-tertiary);
    opacity: 0.8;
}

/* ============================================
   MESSAGE BUBBLES - OUTGOING
   ============================================ */

.outgoing_msg {
    margin-bottom: var(--spacing-lg);
    display: flex;
    justify-content: flex-end;
    animation: slideInRight 0.3s ease;
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translate3d(20px, 0, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

.sent_msg {
    max-width: 70%;
}

.sent_msg p {
    background: var(--msg-outgoing-bg);
    color: var(--msg-outgoing-text);
    border-radius: 18px;
    padding: 10px 15px;
    margin: 0;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
}

.sent_msg p:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.sent_msg .time_date {
    display: block;
    margin-top: var(--spacing-xs);
    font-size: 11px;
    color: var(--text-tertiary);
    text-align: right;
    opacity: 0.8;
}

/* ============================================
   MESSAGE INPUT AREA
   ============================================ */

.type_msg {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: var(--spacing-md);
    border-radius: 0 0 12px 12px;
}

.input_msg_write {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    background: var(--input-bg);
    border-radius: 24px;
    padding: var(--spacing-sm) var(--spacing-md);
    transition: all 0.3s ease;
}

.input_msg_write:focus-within {
    background: var(--bg-primary);
    box-shadow: 0 0 0 2px var(--input-focus);
}

.input_msg_write input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 15px;
    padding: var(--spacing-sm) 0;
}

.input_msg_write input::placeholder {
    color: var(--text-tertiary);
}

.msg_send_btn {
    background: var(--btn-primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.msg_send_btn:hover {
    background: var(--btn-primary-hover);
    transform: scale(1.1);
}

.msg_send_btn:active {
    transform: scale(0.95);
}

.msg_send_btn i {
    font-size: 16px;
}

/* ============================================
   FILE ATTACHMENTS & MEDIA
   ============================================ */

.message-attachment {
    margin-top: var(--spacing-sm);
    border-radius: 12px;
    overflow: hidden;
    max-width: 100%;
}

.message-attachment img {
    max-width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
    transition: transform 0.3s ease;
}

.message-attachment img:hover {
    transform: scale(1.02);
    cursor: pointer;
}

.message-attachment-file {
    background: var(--bg-tertiary);
    padding: var(--spacing-md);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    transition: all 0.3s ease;
}

.message-attachment-file:hover {
    background: var(--border-color);
    cursor: pointer;
}

.message-attachment-icon {
    font-size: 24px;
    color: var(--text-secondary);
}

.message-attachment-info {
    flex: 1;
}

.message-attachment-name {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: var(--spacing-xs);
}

.message-attachment-size {
    color: var(--text-tertiary);
    font-size: 12px;
}

/* ============================================
   TYPING INDICATOR
   ============================================ */

.typing-indicator {
    display: flex;
    align-items: center;
    padding: var(--spacing-md);
    color: var(--typing);
    font-size: 14px;
    gap: var(--spacing-sm);
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--typing);
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ============================================
   ONLINE STATUS INDICATOR
   ============================================ */

.user-status-online {
    position: relative;
}

.user-status-online::after {
    content: '';
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    background: var(--online);
    border-radius: 50%;
    border: 2px solid var(--bg-primary);
}

.user-status-offline::after {
    background: var(--offline);
}

/* ============================================
   VOICE MESSAGE
   ============================================ */

.voice-message {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-sm);
    background: var(--bg-tertiary);
    border-radius: 24px;
    max-width: 300px;
}

.voice-message-play {
    background: var(--btn-primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.voice-message-play:hover {
    background: var(--btn-primary-hover);
    transform: scale(1.05);
}

.voice-message-waveform {
    flex: 1;
    height: 30px;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 30"><path d="M 0,15 L 10,5 L 20,20 L 30,10 L 40,15 L 50,8 L 60,22 L 70,12 L 80,18 L 90,7 L 100,15" fill="none" stroke="%230084ff" stroke-width="2"/></svg>') center/contain no-repeat;
    opacity: 0.6;
}

.voice-message-duration {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ============================================
   REACTIONS
   ============================================ */

.message-reactions {
    display: flex;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-xs);
    flex-wrap: wrap;
}

.message-reaction {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.message-reaction:hover {
    background: var(--bg-tertiary);
    transform: scale(1.05);
}

.message-reaction-emoji {
    font-size: 16px;
}

.message-reaction-count {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
    .received_msg,
    .sent_msg {
        max-width: 85%;
    }

    #chatMessagesArea {
        padding: var(--spacing-md);
        max-height: 500px;
    }

    .input_msg_write {
        padding: var(--spacing-sm);
    }

    .msg_send_btn {
        width: 32px;
        height: 32px;
    }
}

@media (max-width: 480px) {
    .received_msg,
    .sent_msg {
        max-width: 90%;
    }

    .incoming_msg_img img {
        width: 28px;
        height: 28px;
    }

    .received_withd_msg,
    .sent_msg p {
        font-size: 14px;
        padding: 8px 12px;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --msg-incoming-bg: #000000;
        --msg-incoming-text: #ffffff;
        --msg-outgoing-bg: #0066cc;
        --msg-outgoing-text: #ffffff;
        --border-color: #000000;
    }
}
