:root {
    --sky-400: #38bdf8;
    --sky-500: #0ea5e9;
    --sky-600: #0284c7;
    --blue-600: #2563eb;
    --messenger-blue: #0084ff;
    --messenger-light-blue: #e3f2fd;
    --messenger-gray: #f0f0f0;
    --messenger-dark-gray: #65676b;
    --messenger-text: #050505;
    --messenger-secondary-text: #65676b;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

.chat-container {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 2rem);
    max-width: 1024px;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    z-index: 25;
    background: white;
    border-radius: 1rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    -webkit-overflow-scrolling: touch;
    background: #f0f2f5;
    min-height: 0;
    scroll-behavior: smooth;
}

/* Mobile optimizations for chat messages */
@media (max-width: 768px) {
    .chat-messages {
        padding: 0.75rem;
    }

    .chat-container {
        width: calc(100%);
    }
}

.message {
    margin-bottom: 0.5rem;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    position: relative;
}

.message.user {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.message.bot {
    justify-content: flex-start;
}

.message-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transition: transform 0.2s ease;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--messenger-blue) 0%, #0073e6 100%);
    order: 1;
}

.message.bot .message-avatar {
    background: linear-gradient(135deg, #60a5fa 0%, var(--sky-500) 100%);
    background-image: url('/static/assets/image/chat/icon.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    order: 1;
}

.message-content {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 1.125rem;
    position: relative;
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 0.9375rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

/* Mobile optimizations for messages */
@media (max-width: 768px) {
    .message-content {
        max-width: 85%;
        padding: 0.625rem 0.875rem;
        font-size: 0.875rem;
    }

    .message-avatar {
        width: 1.75rem;
        height: 1.75rem;
    }
}

.message.user .message-content {
    background: var(--messenger-blue);
    color: white;
    border-bottom-right-radius: 0.25rem;
    margin-left: auto;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    order: 2;
}

.message.bot .message-content {
    background: white;
    color: var(--messenger-text);
    border-bottom-left-radius: 0.25rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    order: 2;
}

/* Stream animation for bot messages */
.message.bot .message-content.streaming {
    animation: messageAppear 0.3s ease-out;
}

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

/* Typing cursor animation */
.message.bot .message-content.streaming::after {
    content: '|';
    animation: blink 1s infinite;
    color: var(--messenger-blue);
    font-weight: bold;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Hover effects for messages */
.message-content:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.message-time {
    font-size: 0.6875rem;
    color: var(--messenger-secondary-text);
    margin-top: 0.25rem;
    text-align: right;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.message.user .message-time {
    text-align: left;
    order: 3;
}

.message.bot .message-time {
    text-align: right;
    order: 3;
}

.message:hover .message-time {
    opacity: 1;
}

.chat-input-container {
    background: white;
    border-top: 1px solid #e4e6eb;
    padding: 0.75rem 1rem;
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-shrink: 0;
    box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.05);
}

/* Mobile optimizations for input container */
@media (max-width: 768px) {
    .chat-input-container {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }
}

.chat-input {
    flex: 1;
    border: none;
    border-radius: 1.25rem;
    padding: 0.75rem 1rem;
    font-size: 0.9375rem;
    resize: none;
    outline: none;
    transition: all 0.2s ease;
    max-height: 120px;
    min-height: 44px;
    background: #f0f2f5;
    color: var(--messenger-text);
    appearance: none;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
}

/* Mobile optimizations for input */
@media (max-width: 768px) {
    .chat-input {
        padding: 0.625rem 0.875rem;
        font-size: 1rem;
        min-height: 40px;
        border-radius: 1.125rem;
    }
}

.chat-input:focus {
    background: white;
    box-shadow: 0 0 0 2px var(--messenger-blue), 0 2px 8px rgba(0, 132, 255, 0.1);
    transform: translateY(-1px);
}

.chat-input::placeholder {
    color: var(--messenger-secondary-text);
}

.send-button {
    background: var(--messenger-blue);
    color: white;
    border: none;
    border-radius: 50%;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    box-shadow: 0 2px 8px rgba(0, 132, 255, 0.3);
}

/* Mobile optimizations for send button */
@media (max-width: 768px) {
    .send-button {
        width: 2.25rem;
        height: 2.25rem;
        min-width: 2.25rem;
    }
}

.send-button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 132, 255, 0.4);
}

.send-button:active {
    transform: scale(0.95);
    box-shadow: 0 1px 4px rgba(0, 132, 255, 0.3);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    background: #e4e6eb;
    box-shadow: none;
}

/* Send button pulse effect when enabled */
.send-button:not(:disabled) {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 2px 8px rgba(0, 132, 255, 0.3);
    }
    50% {
        box-shadow: 0 2px 8px rgba(0, 132, 255, 0.5);
    }
    100% {
        box-shadow: 0 2px 8px rgba(0, 132, 255, 0.3);
    }
}

.start-conversation-button {
    background: var(--messenger-blue);
    color: white;
    border: none;
    border-radius: 1.25rem;
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    box-shadow: 0 4px 12px rgba(0, 132, 255, 0.3);
}

.start-conversation-button:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 16px rgba(0, 132, 255, 0.4);
}

.start-conversation-button:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(0, 132, 255, 0.3);
}

/* Enhanced typing indicator like Messenger */
.typing-indicator {
    display: flex;
    margin-bottom: 0.5rem;
    align-items: flex-end;
    gap: 0.5rem;
    position: relative;
}

.typing-indicator .message-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transition: transform 0.2s ease;
    background: linear-gradient(135deg, #60a5fa 0%, var(--sky-500) 100%);
    background-image: url('/static/assets/image/chat/icon.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    order: 1;
}

.typing-indicator .typing-content {
    background: white;
    border-radius: 1.125rem;
    border-bottom-left-radius: 0.25rem;
    padding: 0.75rem 1rem;
    max-width: 70%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    animation: typingAppear 0.3s ease-out;
    order: 2;
}

/* Mobile optimizations for typing indicator */
@media (max-width: 768px) {
    .typing-indicator .typing-content {
        max-width: 85%;
        padding: 0.625rem 0.875rem;
    }
    
    .typing-indicator .message-avatar {
        width: 1.75rem;
        height: 1.75rem;
    }
}

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

.typing-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--messenger-secondary-text);
    animation: typing 1.4s infinite ease-in-out;
}

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

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

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

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

.welcome-message {
    text-align: center;
    padding: 2rem;
    color: var(--messenger-secondary-text);
}

/* Mobile optimizations for welcome message */
@media (max-width: 768px) {
    .welcome-message {
        padding: 1.5rem 1rem;
    }

    .welcome-icon {
        width: 3rem;
        height: 3rem;
    }

    .welcome-message h3 {
        font-size: 1rem;
    }

    .welcome-message p {
        font-size: 0.875rem;
    }
}

.welcome-icon {
    width: 4rem;
    height: 4rem;
    margin: 0 auto 1rem;
    background: var(--messenger-blue);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 132, 255, 0.3);
}

.chat-header {
    background: white;
    color: var(--messenger-text);
    padding: 1rem;
    text-align: center;
    border-bottom: 1px solid #e4e6eb;
    border-radius: 1rem 1rem 0 0;
    flex-shrink: 0;
    font-weight: 600;
    font-size: 1.125rem;
}

/* Mobile optimizations for header */
@media (max-width: 768px) {
    .chat-header {
        padding: 0.875rem;
        border-radius: 1rem 1rem 0 0;
    }

    .chat-header h1 {
        font-size: 1rem;
    }

    .chat-header p {
        font-size: 0.875rem;
    }
}

.chat-header h1 {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
    color: var(--messenger-text);
}

.chat-header p {
    font-size: 0.875rem;
    color: var(--messenger-secondary-text);
    margin: 0.25rem 0 0 0;
}

/* Message group spacing */
.message + .message {
    margin-top: 0.25rem;
}

/* Different spacing for different senders */
.message.user + .message.user {
    margin-top: 0.125rem;
}

.message.bot + .message.bot {
    margin-top: 0.125rem;
}

/* Avatar hover effects */
.message-avatar:hover {
    transform: scale(1.1);
}

/* Enhanced scrollbar for chat messages */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Message content link styling */
.message-content a {
    color: var(--messenger-blue);
    text-decoration: underline;
}

.message.user .message-content a {
    color: rgba(255, 255, 255, 0.9);
}

/* Loading state for messages */
.message-content.loading {
    position: relative;
    overflow: hidden;
}

.message-content.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* Enhanced mobile responsiveness */
@media (max-width: 480px) {
    .message-content {
        max-width: 90%;
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
    }
    
    .chat-input {
        font-size: 1rem;
        padding: 0.5rem 0.75rem;
    }
    
    .send-button {
        width: 2rem;
        height: 2rem;
        min-width: 2rem;
    }
    
    .message-avatar {
        width: 1.5rem;
        height: 1.5rem;
    }
}

/* Popup styles */
.disclaimer-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.disclaimer-content {
    background: white;
    border-radius: 1rem;
    padding: 2rem;
    max-width: 90%;
    width: 400px;
    text-align: center;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.disclaimer-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--messenger-text);
    margin: 0 0 1rem 0;
}

.disclaimer-text {
    font-size: 1rem;
    color: var(--messenger-secondary-text);
    margin: 0 0 2rem 0;
    line-height: 1.5;
}

.disclaimer-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.disclaimer-button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 100px;
}

.disclaimer-button.accept {
    background: var(--messenger-blue);
    color: white;
}

.disclaimer-button.accept:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 132, 255, 0.3);
}

.disclaimer-button.decline {
    background: #f0f2f5;
    color: var(--messenger-secondary-text);
    border: 1px solid #e4e6eb;
}

.disclaimer-button.decline:hover {
    background: #e4e6eb;
    transform: scale(1.05);
}

/* Limit reached popup styles */
.limit-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.limit-content {
    background: white;
    border-radius: 1rem;
    padding: 2rem;
    max-width: 90%;
    width: 400px;
    text-align: center;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.limit-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--messenger-text);
    margin: 0 0 1rem 0;
}

.limit-text {
    font-size: 1rem;
    color: var(--messenger-secondary-text);
    margin: 0 0 2rem 0;
    line-height: 1.5;
}

.limit-button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--messenger-blue);
    color: white;
    text-decoration: none;
    display: inline-block;
}

.limit-button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 132, 255, 0.3);
}

/* Mobile optimizations for popups */
@media (max-width: 768px) {
    .disclaimer-content,
    .limit-content {
        padding: 1.5rem;
        margin: 1rem;
    }

    .disclaimer-title,
    .limit-title {
        font-size: 1.125rem;
    }

    .disclaimer-text,
    .limit-text {
        font-size: 0.875rem;
    }

    .disclaimer-buttons {
        flex-direction: column;
        gap: 0.75rem;
    }

    .disclaimer-button {
        width: 100%;
        padding: 0.875rem 1rem;
    }
}

/* Error message styles */
.error-message {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
    padding: 0.75rem;
    border-radius: 0.5rem;
    margin: 0.75rem 1rem;
    display: none;
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 2rem);
    max-width: calc(1024px - 2rem);
    z-index: 11;
}

/* Mobile optimizations for error message */
@media (max-width: 768px) {
    .error-message {
        top: 80px;
        width: calc(100% - 1rem);
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
}

/* Navigation styles */
.nav-item.active {
    color: var(--messenger-blue);
}

.nav-item.active svg {
    color: var(--messenger-blue);
}

/* Mobile optimizations for navigation */
@media (max-width: 768px) {
    nav {
        height: 4rem;
        border-radius: 0;
    }

    .nav-item svg {
        width: 1.5rem;
        height: 1.5rem;
    }

    .nav-item span {
        font-size: 0.625rem;
    }
}

/* PWA Install Button Styles */
.pwa-install-btn {
    position: fixed !important;
    top: 1rem !important;
    right: 1rem !important;
    width: 3rem !important;
    height: 3rem !important;
    border-radius: 50% !important;
    background: var(--messenger-blue) !important;
    color: white !important;
    border: none !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 4px 12px rgba(0, 132, 255, 0.3) !important;
    transition: all 0.2s !important;
    z-index: 1000 !important;
}

.pwa-install-btn:hover {
    transform: scale(1.1) !important;
    box-shadow: 0 6px 16px rgba(0, 132, 255, 0.4) !important;
}

.pwa-install-btn:active {
    transform: scale(0.95) !important;
}

/* Mobile optimizations for PWA install button */
@media (max-width: 768px) {
    .pwa-install-btn {
        top: 0.75rem !important;
        right: 0.75rem !important;
        width: 2.5rem !important;
        height: 2.5rem !important;
    }
}

/* Dark mode support (if needed in future) */
@media (prefers-color-scheme: dark) {
    :root {
        --messenger-text: #ffffff;
        --messenger-secondary-text: #b0b3b8;
        --messenger-gray: #3a3b3c;
    }
    
    .chat-messages {
        background: #18191a;
    }
    
    .message.bot .message-content {
        background: #242526;
        color: var(--messenger-text);
    }
    
    .chat-input {
        background: #3a3b3c;
        color: var(--messenger-text);
    }
    
    .chat-input:focus {
        background: #242526;
    }
    
    .typing-indicator {
        background: #242526;
        border-color: #3a3b3c;
    }
    
    .typing-indicator::before {
        border-top-color: #242526;
    }
}
