@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: #f3f4f6;
    display: flex;
    justify-content: center;
    align-items: center;
}

.chat-container {
    display: flex;
    width: 100%;
    height: 100%;
    max-width: 1280px;
    margin: auto;
    box-shadow: 0 0 25px rgba(0,0,0,0.1);
    overflow: hidden;
    background-color: white;
}

.sidebar {
    width: 350px;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease-in-out;
}

.main-chat-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.main-chat, .placeholder-area {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    height: 100%;
}

.main-chat.hidden, .placeholder-area.hidden {
    display: none;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.message-wrapper {
    display: flex;
    margin-bottom: 0.5rem;
    position: relative;
}

.message-wrapper.sent {
    justify-content: flex-end;
}

.message-wrapper.received {
    justify-content: flex-start;
}

.message {
    max-width: 75%;
    padding: 0.5rem 0.75rem;
    border-radius: 1.25rem;
    position: relative;
    display: flex;
    flex-direction: column;
}

.message.sent {
    background-color: #3b82f6;
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message.received {
    background-color: #e5e7eb;
    color: #1f2937;
    border-bottom-left-radius: 0.25rem;
}

.message.system {
    align-self: center;
    background-color: #d1d5db;
    color: #4b5563;
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    margin: 0.5rem 0;
    max-width: 90%;
    text-align: center;
}

.time-status-container {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.7);
    text-align: right;
    margin-top: 0.25rem;
    margin-left: 1rem;
    align-self: flex-end;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    height: 1rem;
}

.message.received .time-status-container {
    color: #6b7280;
}

.date-separator {
    text-align: center;
    margin: 1rem 0;
}

.date-separator span {
    background-color: #d1d5db;
    color: #4b5563;
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
}

.last-message {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 2rem);
}

.avatar-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.avatar-circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.message-image-container img {
    max-width: 100%;
    border-radius: 1rem;
    cursor: pointer;
}

.image-caption {
    margin-top: 0.25rem;
    font-size: 0.875rem;
    padding: 0 0.25rem;
}

.message.received .image-caption {
    color: #374151;
}

.quoted-message-wrapper {
    cursor: pointer;
    margin-bottom: 0.25rem;
}

.quoted-message {
    background: rgba(0,0,0,0.1);
    border-left: 3px solid #3b82f6;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
}

.message.received .quoted-message {
    background: rgba(255,255,255,0.4);
    border-left-color: #34d399;
}

.quoted-message .author {
    font-weight: bold;
    font-size: 0.8rem;
}

.message.received .quoted-message .author {
    color: #34d399;
}

.quoted-message .text {
    font-size: 0.8rem;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-edited-indicator {
    font-size: 0.65rem;
    opacity: 0.7;
}

.caption-viewer {
    background: rgba(0,0,0,0.5);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 1rem;
    display: inline-block;
}

.enlarged-avatar {
    width: 50vw;
    height: 50vw;
    max-width: 300px;
    max-height: 300px;
    border-radius: 50%;
}

.highlight {
    animation: highlight-anim 1.5s ease-out;
}

@keyframes highlight-anim {
    0% { background-color: rgba(59, 130, 246, 0.3); }
    100% { background-color: transparent; }
}

.message-wrapper .sent.highlight {
    animation: highlight-anim-sent 1.5s ease-out;
}

@keyframes highlight-anim-sent {
    0% { background-color: rgba(96, 165, 250, 0.8); }
    100% { background-color: #3b82f6; }
}

.swipe-reply-icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%) scale(0.5);
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    background-color: #3b82f6;
    border-radius: 50%;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-wrapper.sent .swipe-reply-icon {
    right: 100%;
    margin-right: 0.5rem;
}

.message-wrapper.received .swipe-reply-icon {
    left: 100%;
    margin-left: 0.5rem;
}

.sticky-date-header {
    position: sticky;
    top: 0;
    z-index: 10;
    text-align: center;
    padding: 0.5rem 0;
    transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}

.sticky-date-header.visible {
    transform: translateY(0);
    opacity: 1;
}

.sticky-date-header span {
    background-color: rgba(209, 213, 219, 0.9);
    backdrop-filter: blur(5px);
    color: #4b5563;
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
}

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 40;
        width: 100%;
        margin-left: -100%;
    }
    .chat-container.chat-view .sidebar {
        margin-left: -100%;
    }
    .chat-container:not(.chat-view) .sidebar {
        margin-left: 0;
    }
    .main-chat-wrapper {
        width: 100%;
    }
}