/* Mobile Safari-specific override */
@media screen and (max-width: 768px) {
    /* Target Safari only */
    @supports (-webkit-touch-callout: none) {
        .chat-wrapper {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            display: grid;
            grid-template-rows: 60px 1fr auto 80px;
            height: 100vh;
            overflow: hidden;
        }
        
        .chat-header {
            grid-row: 1;
        }
        
        .messages-container {
            grid-row: 2;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
            padding-bottom: 10px;
        }
        
        .typing-indicator-container {
            grid-row: 3;
        }
        
        .input-container {
            grid-row: 4;
            position: relative !important;
            bottom: auto !important;
        }
    }
}

/* Keyboard open state for browsers that don't resize viewport */
body.keyboard-open .chat-container {
    height: 50vh !important;
}

body.keyboard-open .messages-container {
    max-height: calc(50vh - 120px);
}

body.keyboard-open .input-container {
    position: absolute;
    bottom: 50vh;
}

.last-seen {
    font-size: 0.75rem;
    color: var(--dark-text-secondary);
    margin-left: 0.5rem;
}

/* Message delivery animations */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes messagePopIn {
    0% {
        opacity: 0;
        transform: scale(0.8) translateY(10px);
    }
    60% {
        transform: scale(1.05) translateY(-2px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes reactionPop {
    0% {
        opacity: 0;
        transform: scale(0.3) rotate(-10deg);
    }
    50% {
        transform: scale(1.2) rotate(5deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

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

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Apply animations to messages */
.message {
    animation: messagePopIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.message.mine {
    animation: slideInRight 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.message.other {
    animation: slideInLeft 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* New message highlight animation */
.message.new-message {
    animation: messagePopIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.message.new-message.mine {
    animation: slideInRight 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.message.new-message.other {
    animation: slideInLeft 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Reaction animation */
.message-reaction {
    animation: reactionPop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Enhanced typing indicator */
.typing-indicator-container {
    animation: fadeInUp 0.3s ease-out;
}

.typing-text {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.typing-dots {
    display: flex;
    gap: 0.2rem;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--dark-text-secondary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

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

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}
:root {
    --ubuntu-orange: #E95420;
    --ubuntu-warm-grey: #AEA79F;
    --ubuntu-cool-grey: #333333;
    --ubuntu-purple: #772953;
    --ubuntu-purple-light: #924A68;
    --ubuntu-dark: #2C001E;
    --ubuntu-light: #F7F7F7;
    --success: #0E8420;
    --away: #FF6F00;
    
    /* Dark mode colors */
    --dark-bg: #1a1a1a;
    --dark-surface: #2d2d2d;
    --dark-surface-hover: #3a3a3a;
    --dark-text: #e0e0e0;
    --dark-text-secondary: #b0b0b0;
    --dark-border: #404040;
    --dark-purple-surface: #3d2a3a;
    --dark-purple-surface-hover: #4a3547;
}

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

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

body {
    font-family: 'Ubuntu', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--dark-bg);
    color: var(--dark-text);
}

/* Login Page Styles - Centered Dark Mode */
#loginPage {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--ubuntu-dark) 0%, var(--ubuntu-purple) 100%);
}

.login-container {
    background: var(--dark-surface);
    padding: 3rem;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    width: 90%;
    max-width: 400px;
    border: 1px solid var(--dark-border);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    color: var(--dark-text);
    font-size: 2rem;
    margin-bottom: 0.5rem;
    font-weight: 300;
    letter-spacing: 1px;
}

.login-header p {
    color: var(--ubuntu-orange);
    font-size: 0.9rem;
}

.login-form input {
    width: 100%;
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--dark-border);
    border-radius: 6px;
    font-size: 1rem;
    transition: all 0.3s;
    background: var(--dark-bg);
    color: var(--dark-text);
}

.login-form input:focus {
    outline: none;
    border-color: var(--ubuntu-purple);
    background: var(--dark-surface-hover);
    box-shadow: 0 0 0 2px rgba(119, 41, 83, 0.2);
}

.login-form button {
    width: 100%;
    padding: 1rem;
    background: var(--ubuntu-purple);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

.login-form button:hover {
    background: var(--ubuntu-purple-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(119, 41, 83, 0.3);
}

.error-message {
    color: #ff6b6b;
    text-align: center;
    margin-top: 1rem;
    padding: 0.5rem;
    background: rgba(255, 107, 107, 0.1);
    border-radius: 4px;
    display: none;
    font-size: 0.9rem;
    border: 1px solid rgba(255, 107, 107, 0.3);
}

/* Chat Page Styles - Dark Mode */
#chatPage {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: none;
}

.chat-container {
    width: 100vw;
    height: 100vh;
    background: var(--dark-bg);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.chat-header {
    background: linear-gradient(135deg, var(--ubuntu-purple) 0%, var(--ubuntu-purple-light) 100%);
    color: var(--dark-text);
    padding: 0.8rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ubuntu-warm-grey);
}

.status-indicator.online {
    background: var(--success);
    box-shadow: 0 0 4px var(--success);
}

.status-indicator.away {
    background: var(--away);
    box-shadow: 0 0 4px var(--away);
}

.typing-indicator-container {
    padding: 0;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-shrink: 0;
    position: relative;
    z-index: 5;
    min-height: 35px;
    padding-left: 3rem;
    pointer-events: none; /* Don't steal mouse events */
}

.typing-text {
    font-size: 0.85rem;
    color: var(--dark-text-secondary);
    font-style: italic;
    animation: pulse 1.5s infinite;
    background: rgba(45, 45, 45, 0.9);
    padding: 0.5rem 1rem;
    border-radius: 18px;
    border: 1px solid rgba(64, 64, 64, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    display: inline-block;
    max-width: fit-content;
    pointer-events: auto; /* Re-enable for the text bubble itself */
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

.header-buttons {
    display: flex;
    gap: 0.5rem;
}

.logout-btn, .clear-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--dark-text);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.4rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 0.9rem;
}

.logout-btn:hover, .clear-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-color: rgba(255, 255, 255, 0.3);
}

.clear-btn {
    background: rgba(233, 84, 32, 0.2);
    border-color: rgba(233, 84, 32, 0.3);
}

.clear-btn:hover {
    background: rgba(233, 84, 32, 0.3);
    border-color: rgba(233, 84, 32, 0.4);
}

.messages-container {
    flex: 1;
    overflow-y: scroll; /* Explicit scroll instead of auto */
    overflow-x: hidden;
    padding: 1.5rem;
    background: var(--dark-bg);
    display: block; /* Change back to block instead of flex */
    min-height: 0;
    scroll-behavior: smooth;
}

/* Center messages in wide screens */
.messages-wrapper {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: calc(100vh - 200px); /* Ensure minimum height for flex-end to work */
    justify-content: flex-end;
}

.message {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    position: relative;
    animation: messagePopIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0; /* Prevent messages from shrinking */
}

.message.mine {
    flex-direction: row-reverse;
}

.message-content {
    max-width: 70%;
    padding: 0.8rem 1rem;
    border-radius: 18px;
    position: relative;
    transition: transform 0.1s;
}

.message.mine .message-content {
    background: var(--ubuntu-purple);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.message.other .message-content {
    background: var(--dark-surface);
    color: var(--dark-text);
    border: 1px solid var(--dark-border);
    border-bottom-left-radius: 4px;
}

.message.other .message-content:hover {
    transform: scale(1.02);
    background: var(--dark-surface-hover);
}

/* Message hover and interaction animations */
.message-content {
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.message.other .message-content:hover {
    transform: scale(1.02);
    background: var(--dark-surface-hover);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.message.mine .message-content:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(119, 41, 83, 0.3);
}

/* Smooth message status transitions */
.message-status {
    transition: all 0.3s ease;
}

/* Edit indicator animation */
.edit-indicator {
    animation: fadeInUp 0.3s ease-out;
}

/* Popup menu animations */
.message-action-menu {
    animation: fadeInUp 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transform-origin: top center;
}

.action-menu-btn {
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.action-menu-btn:hover {
    transform: translateX(4px);
}

/* Reaction picker animations */
.reaction-picker {
    animation: fadeInUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.reaction-emoji {
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.reaction-emoji:hover {
    transform: scale(1.2) rotate(5deg);
}

.reaction-emoji:active {
    transform: scale(0.9) rotate(-2deg);
}

/* Input animation */
.message-input {
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.message-input:focus {
    transform: scale(1.01);
}

/* Button animations */
.send-btn, .image-btn {
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.send-btn:hover, .image-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(119, 41, 83, 0.4);
}

.send-btn:active, .image-btn:active {
    transform: scale(0.95);
}

/* Loading animation for image uploads */
@keyframes imageUploadPulse {
    0%, 100% {
        opacity: 0.6;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
}

.message-image.loading {
    animation: imageUploadPulse 1.5s infinite;
}

/* Smooth scrolling */
.messages-container {
    scroll-behavior: smooth;
}

/* Ubuntu-inspired color scheme - Dark Mode */
.message-text {
    margin-bottom: 0.3rem;
}

/* Load more messages button */
.load-more-btn {
    text-align: center;
    padding: 1rem;
    margin-bottom: 1rem;
}

.load-more-btn button {
    background: var(--dark-surface);
    border: 1px solid var(--dark-border);
    color: var(--dark-text);
    padding: 0.8rem 1.5rem;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 auto;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.load-more-btn button:hover:not(:disabled) {
    background: var(--dark-surface-hover);
    border-color: var(--ubuntu-purple);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.load-more-btn button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.load-more-text {
    font-weight: 500;
}

.load-more-icon {
    font-size: 1.1rem;
}

/* Message text content */
.message-text {
    margin-bottom: 0.3rem;
}

/* Large emoji for emoji-only messages */
.message-text.emoji-only {
    font-size: 4rem;
    line-height: 1.2;
    text-align: center;
    padding: 0.8rem;
    animation: emojiPop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes emojiPop {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Mobile adjustments for large emojis */
@media (max-width: 768px) {
    .message-text.emoji-only {
        font-size: 3.2rem;
        padding: 0.6rem;
    }
}

/* Clickable links in messages */
.message-link {
    color: var(--ubuntu-orange);
    text-decoration: underline;
    text-decoration-color: rgba(233, 84, 32, 0.6);
    text-underline-offset: 2px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    word-break: break-all;
    background: rgba(233, 84, 32, 0.1);
    padding: 1px 4px;
    border-radius: 4px;
    border: 1px solid rgba(233, 84, 32, 0.2);
}

.message-link:hover {
    color: #ff6b2b;
    text-decoration-color: #ff6b2b;
    background: rgba(233, 84, 32, 0.2);
    border-color: rgba(233, 84, 32, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(233, 84, 32, 0.2);
}

.message.mine .message-link {
    color: white;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    text-decoration-color: rgba(255, 255, 255, 0.7);
    font-weight: 600;
}

.message.mine .message-link:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
    text-decoration-color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Reply button */
.reply-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(119, 41, 83, 0.9);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    z-index: 10;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.reply-btn:hover {
    background: var(--ubuntu-purple);
    opacity: 1;
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(119, 41, 83, 0.4);
}

/* Reply indicator */
.reply-indicator {
    background: var(--dark-purple-surface);
    border: 1px solid var(--ubuntu-purple);
    border-radius: 8px 8px 0 0;
    padding: 0.8rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: fadeInUp 0.3s ease-out;
}

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

.reply-text {
    color: var(--ubuntu-orange);
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 0.2rem;
}

.reply-preview {
    color: var(--dark-text-secondary);
    font-size: 0.8rem;
    opacity: 0.8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-cancel {
    background: none;
    border: none;
    color: var(--dark-text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.2rem;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin-left: 1rem;
}

.reply-cancel:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--dark-text);
}

/* Reply to message display */
.reply-to-message {
    background: var(--dark-surface);
    border-left: 3px solid var(--ubuntu-purple);
    border-radius: 6px;
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.8rem;
    max-width: 100%;
}

.reply-author {
    color: var(--ubuntu-orange);
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: 0.2rem;
}

.reply-content {
    color: var(--dark-text-secondary);
    font-size: 0.8rem;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-icon {
    margin-right: 0.3rem;
}
.message-action-menu {
    position: fixed;
    background: var(--dark-surface);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    border: 1px solid var(--dark-border);
    overflow: hidden;
    min-width: 120px;
}

.action-menu-btn {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    width: 100%;
    background: none;
    border: none;
    color: var(--dark-text);
    padding: 0.8rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
    text-align: left;
}

.action-menu-btn:hover {
    background: var(--dark-surface-hover);
}

.action-menu-btn.delete-action:hover {
    background: rgba(255, 107, 107, 0.1);
    color: #ff6b6b;
}

.action-icon {
    font-size: 1.1rem;
    width: 20px;
    display: flex;
    justify-content: center;
}

.action-text {
    font-weight: 500;
}

/* Edit indicator */
.edit-indicator {
    background: var(--ubuntu-purple);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 8px 8px 0 0;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
}

.edit-indicator button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.2s;
}

.edit-indicator button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Edited indicator */
.edited-indicator {
    font-style: italic;
    opacity: 0.7;
    font-size: 0.7rem;
}

/* PDF embed styling */
.pdf-embed {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--dark-surface);
    border: 1px solid var(--dark-border);
    border-radius: 12px;
    padding: 1rem;
    margin-top: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    max-width: 300px;
}

.pdf-embed:hover {
    background: var(--dark-surface-hover);
    transform: scale(1.02);
}

.pdf-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

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

.pdf-name {
    font-weight: 500;
    color: var(--dark-text);
    font-size: 0.9rem;
    word-break: break-word;
    margin-bottom: 0.2rem;
}

.pdf-action {
    color: var(--ubuntu-orange);
    font-size: 0.8rem;
    font-weight: 500;
}

/* Image modal styling */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.3s ease-out;
}

.image-modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.modal-image {
    max-width: 100%;
    max-height: calc(90vh - 80px); /* Leave space for buttons */
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    animation: modalImagePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    animation: fadeInUp 0.4s ease-out 0.2s both;
}

.modal-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
    text-decoration: none;
}

.download-btn {
    background: var(--ubuntu-purple);
}

.download-btn:hover {
    background: var(--ubuntu-purple-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(119, 41, 83, 0.4);
}

.close-btn {
    background: var(--dark-surface);
    border: 1px solid var(--dark-border);
}

.close-btn:hover {
    background: var(--dark-surface-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes modalImagePop {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Mobile adjustments for modal */
@media (max-width: 768px) {
    .image-modal-content {
        max-width: 95vw;
        max-height: 95vh;
        gap: 0.8rem;
    }
    
    .modal-image {
        max-height: calc(95vh - 70px);
    }
    
    .modal-buttons {
        gap: 0.8rem;
    }
    
    .modal-btn {
        padding: 0.7rem 1.2rem;
        font-size: 0.85rem;
    }
    
    .pdf-embed {
        max-width: 100%;
        margin-top: 0.5rem;
    }
}

.message-image {
    max-width: 100%;
    max-height: 400px;
    border-radius: 12px;
    margin-top: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.message-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 0.3rem;
}

.message.other .message-time {
    color: var(--dark-text-secondary);
}

.message-status {
    font-size: 0.8rem;
    margin-left: 4px;
}

.message-reaction {
    position: absolute;
    bottom: -10px;
    right: 10px;
    background: rgba(45, 45, 45, 0.9);
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 1.2rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(64, 64, 64, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.message.mine .message-reaction {
    right: 10px;
    left: auto;
    background: rgba(45, 45, 45, 0.85);
    border: 1px solid rgba(119, 41, 83, 0.3);
}

/* Enhanced reaction picker with categories */
.reaction-picker {
    position: fixed;
    background: var(--dark-surface);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    border: 1px solid var(--dark-border);
    max-width: calc(100vw - 20px);
    min-width: 280px;
    overflow: hidden;
}

.reaction-tabs {
    display: flex;
    background: var(--dark-purple-surface);
    border-bottom: 1px solid var(--dark-border);
}

.reaction-tab {
    background: none;
    border: none;
    color: var(--dark-text-secondary);
    padding: 0.5rem 0.8rem;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    flex: 1;
    min-width: 0;
}

.reaction-tab:hover {
    background: var(--dark-surface-hover);
    color: var(--dark-text);
}

.reaction-tab.active {
    color: var(--ubuntu-orange);
    border-bottom-color: var(--ubuntu-orange);
    background: var(--dark-surface);
}

.reaction-content {
    padding: 1rem;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.reaction-emoji {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.2s;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reaction-emoji:hover {
    background: var(--dark-surface-hover);
    transform: scale(1.1);
}

.reaction-emoji:active {
    transform: scale(0.95);
}

/* Mobile-specific reaction picker styles */
@media (max-width: 768px) {
    .reaction-picker {
        min-width: 260px;
    }
    
    .reaction-content {
        grid-template-columns: repeat(4, 1fr);
        padding: 0.8rem;
    }
    
    .reaction-emoji {
        font-size: 1.3rem;
        padding: 0.4rem;
    }
    
    .reaction-tab {
        padding: 0.4rem 0.5rem;
        font-size: 0.75rem;
    }
}

.instagram-embed {
    margin-top: 0.5rem;
    padding: 0.8rem;
    background: var(--dark-surface);
    border-radius: 8px;
    text-align: center;
    border: 1px solid var(--dark-border);
}

.instagram-embed a {
    color: var(--ubuntu-orange);
    text-decoration: none;
    font-weight: bold;
}

.instagram-embed a:hover {
    text-decoration: underline;
}

/* Slimmer input container */
.input-container {
    padding: 0.8rem 1.5rem;
    background: linear-gradient(to right, var(--dark-purple-surface), var(--dark-surface));
    border-top: 1px solid var(--dark-border);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    min-height: 60px;
    width: 100%;
    flex-direction: column;
}

.input-wrapper {
    flex: 1;
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    width: 100%;
}

.message-input {
    flex: 1;
    padding: 0.6rem 1rem;
    border: 1px solid var(--dark-border);
    border-radius: 24px;
    font-size: 0.95rem;
    resize: none;
    max-height: 100px;
    transition: all 0.3s;
    line-height: 1.4;
    background: var(--dark-bg);
    color: var(--dark-text);
}

.message-input:focus {
    outline: none;
    border-color: var(--ubuntu-purple);
    background: var(--dark-surface-hover);
    box-shadow: 0 0 0 2px rgba(119, 41, 83, 0.2);
}

.message-input::placeholder {
    color: var(--dark-text-secondary);
}

.send-btn, .image-btn {
    background: var(--ubuntu-purple);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0;
    position: relative;
    box-shadow: 0 2px 8px rgba(119, 41, 83, 0.3);
}

.send-btn svg, .image-btn svg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.send-btn:hover, .image-btn:hover {
    background: var(--ubuntu-purple-light);
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(119, 41, 83, 0.4);
}

.send-btn:active, .image-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 4px rgba(119, 41, 83, 0.5);
}

.send-btn:hover, .image-btn:hover {
    background: var(--ubuntu-purple-light);
    transform: scale(1.05);
}

.send-btn:active, .image-btn:active {
    transform: scale(0.95);
}

.image-input {
    display: none;
}

/* Mobile-specific styles */
@media (max-width: 768px) {
    .chat-header {
        padding: 0.8rem 1rem;
    }
    
    .messages-container {
        padding: 1rem;
        padding-bottom: 80px; /* Fixed padding for input container only */
    }
    
    .input-container {
        padding: 0.6rem 1rem;
        position: fixed !important;
        bottom: 0 !important;
        left: 0;
        right: 0;
        z-index: 100;
        background: var(--dark-surface);
        border-top: 2px solid var(--ubuntu-purple);
        transform: translateZ(0); /* Force GPU acceleration */
        -webkit-transform: translateZ(0);
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .message-input {
        font-size: 16px; /* Prevents zoom on iOS */
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }
    
    /* Fix for Safari and Brave mobile */
    .chat-container {
        height: 100vh;
        height: -webkit-fill-available;
        height: 100dvh; /* Dynamic viewport height */
        overflow: hidden;
    }
    
    /* Ensure input stays above keyboard */
    .input-container {
        position: fixed !important;
        bottom: 0;
        bottom: env(safe-area-inset-bottom, 0);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    
    .typing-indicator-container {
        position: fixed !important;
        bottom: 65px !important;
        left: 0;
        right: 0;
        z-index: 99;
        background: transparent;
        border: none;
        min-height: 35px;
        padding: 0.3rem 1rem;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        pointer-events: none; /* Don't steal mouse events on mobile either */
    }
    
    .typing-text {
        background: rgba(45, 45, 45, 0.95);
        padding: 0.4rem 0.8rem;
        border-radius: 16px;
        margin-left: 1rem;
        pointer-events: auto; /* Re-enable for the text bubble */
    }
}

/* Safari mobile specific fixes */
@supports (-webkit-touch-callout: none) {
    /* Safari-only styles - using multiple detection methods */
    @media not all and (min-resolution:.001dpcm) {
        @supports (-webkit-appearance:none) and (stroke-color:transparent) {
            /* This targets Safari specifically */
            .chat-container {
                position: fixed !important;
                top: 0 !important;
                left: 0 !important;
                right: 0 !important;
                bottom: 0 !important;
                overflow: hidden !important;
                height: 100% !important;
                display: flex !important;
                flex-direction: column !important;
            }
            
            .messages-container {
                /* Calculate height minus header and input */
                height: calc(100vh - 60px - 80px) !important; /* header ~60px, input ~80px */
                max-height: calc(100vh - 60px - 80px) !important;
                overflow-y: auto !important;
                -webkit-overflow-scrolling: touch;
                overscroll-behavior: none !important;
                touch-action: pan-y !important;
                flex: 1 1 auto !important;
            }
            
            /* No extra padding needed since height is constrained */
            .messages-wrapper {
                padding-bottom: 20px !important;
            }
            
            /* Prevent input from moving */
            .input-container {
                position: fixed !important;
                bottom: 0 !important;
                left: 0 !important;
                right: 0 !important;
                height: 80px !important;
                min-height: 80px !important;
                max-height: 80px !important;
                transform: translate3d(0, 0, 0) !important;
                -webkit-transform: translate3d(0, 0, 0) !important;
                backface-visibility: hidden !important;
                -webkit-backface-visibility: hidden !important;
                z-index: 999 !important;
                touch-action: none !important;
            }
            
            /* When keyboard is open */
            .safari-keyboard-open .messages-container {
                height: calc(50vh - 60px - 80px) !important;
                max-height: calc(50vh - 60px - 80px) !important;
            }
            
            .safari-keyboard-open .input-container {
                position: fixed !important;
                bottom: 50vh !important;
                transform: translate3d(0, 0, 0) !important;
                -webkit-transform: translate3d(0, 0, 0) !important;
            }
            
            /* Ensure proper stacking */
            .chat-header {
                z-index: 998 !important;
                height: 60px !important;
                flex-shrink: 0 !important;
            }
            
            .typing-indicator-container {
                position: absolute !important;
                bottom: 80px !important;
                left: 0 !important;
                right: 0 !important;
                z-index: 997 !important;
            }
        }
    }
    
    /* General Safari styles */
    .chat-container {
        height: 100vh;
        height: -webkit-fill-available;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    .messages-container {
        -webkit-overflow-scrolling: touch;
        flex: 1 1 auto;
        min-height: 0;
        scroll-behavior: smooth;
    }
    
    .input-container {
        position: relative;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--dark-surface);
        border-top: 2px solid var(--ubuntu-purple);
        min-height: 60px;
        display: -webkit-flex;
        display: flex;
        -webkit-align-items: center;
        align-items: center;
        flex-shrink: 0;
    }
    
    .input-wrapper {
        display: -webkit-flex;
        display: flex;
        -webkit-flex: 1;
        flex: 1;
        -webkit-align-items: center;
        align-items: center;
        gap: 0.75rem;
    }
    
    .message-input {
        -webkit-appearance: none;
        border-radius: 24px !important;
        font-size: 16px !important;
    }
    
    .send-btn, .image-btn {
        -webkit-appearance: none;
        -webkit-tap-highlight-color: transparent;
        width: 40px !important;
        height: 40px !important;
        flex-shrink: 0;
    }
    
    /* Fix for Safari flex bug */
    .typing-indicator-container {
        flex-shrink: 0;
    }
    
    .chat-header {
        flex-shrink: 0;
    }
}

/* Desktop optimizations */
@media (min-width: 1200px) {
    .messages-container {
        padding: 2rem 3rem;
    }
    
    .messages-wrapper {
        max-width: 1000px;
    }
}

/* Dark scrollbar */
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: var(--dark-bg);
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--dark-border);
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--ubuntu-warm-grey);
}

.reaction-content::-webkit-scrollbar {
    width: 6px;
}

.reaction-content::-webkit-scrollbar-track {
    background: var(--dark-surface);
}

.reaction-content::-webkit-scrollbar-thumb {
    background: var(--dark-border);
    border-radius: 3px;
}
