/* Chat Widget Container */
.chat-widget {
    position: fixed;
    bottom: 2.5rem;
    left: 3rem;
    z-index: 9999;
}

/* Chat Card */
.chat-card {
    width: 380px;
    max-width: calc(100vw - 2rem);
    max-height: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    margin-bottom: 1rem;
    overflow: hidden;
    transform: translateY(20px);
    opacity: 0;
    animation: slideUp 0.3s ease forwards;
}

@keyframes slideUp {
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, #eac766, #9ca24b);
    color: white;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid white;
}

.chat-title {
    font-weight: 600;
    font-size: clamp(1rem, 2.5vw, 1.1rem);
    flex: 1;
}

.chat-subtitle {
    font-size: clamp(0.8rem, 2vw, 0.9rem);
    color: rgba(255, 255, 255, 0.8);
}

.close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Messages Area */
.chat-messages {
    flex: 1;
    height: 400px;
    min-height: 300px;
    max-height: calc(100vh - 250px);
    padding: 1.5rem;
    overflow-y: auto;
    background: #f8f9fa;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #dee2e6;
    border-radius: 2px;
}

.empty-messages {
    height: inherit;
    min-height: 300px;
    padding: clamp(1rem, 5vw, 2.5rem);
    display: flex;
    flex-direction: column;
    align-content: center;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* Message Bubbles */
.message {
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

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

.message-stream > p {
    margin: 0 !important;
    padding: 0 !important;
}

.message-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    font-size: clamp(0.875rem, 2vw, 1rem);
    line-height: 1.5;
}

.message.ai .message-bubble {
    background: #e3f2fd;
    color: #1565c0;
    border-bottom-left-radius: 4px;
}

.message.user .message-bubble {
    background: #eac766;
    color: white;
    border-bottom-right-radius: 4px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #6c757d;
    flex-shrink: 0;
}

.message.ai .message-avatar {
    background: white;
    color: white;
}

.message.user .message-avatar {
    background: #fff;
    color: #eac766;
}

/* Input Area */
.chat-input {
    padding: 1rem;
    background: white;
    border-top: 1px solid #e9ecef;
}

.input-group {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
}

.message-input {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    border: 1px solid #dee2e6;
    border-radius: 24px;
    outline: none;
    font-size: clamp(0.875rem, 2vw, 0.95rem);
    transition: border-color 0.2s;
}

.message-input:focus {
    border-color: #eac766;
}

.send-btn {
    width: 48px;
    height: 48px;
    background: #eac766;
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: #5a6fd8;
    transform: scale(1.05);
}

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

/* Toggle Button */
.chat-toggle {
    width: 60px;
    height: 60px;
    background: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    animation: pulse 2s infinite;
}

.chat-toggle:hover {
    transform: scale(1.1);
    animation-play-state: paused;
}

.chat-toggle:active {
    transform: scale(0.95);
}

.chat-toggle img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

/* Processing Animation */
.processing {
    --speed-of-animation: 0.9s;
    --gap: 6px;
    --first-color: #4c86f9;
    --second-color: #49a84c;
    --third-color: #f6bb02;
    --fourth-color: #f6bb02;
    --fifth-color: #2196f3;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100px;
    gap: 6px;
}

.processing span {
    width: 4px;
    height: 50px;
    background: var(--first-color);
    animation: scale var(--speed-of-animation) ease-in-out infinite;
}

.processing span:nth-child(2) {
    background: var(--second-color);
    animation-delay: -0.8s;
}

.processing span:nth-child(3) {
    background: var(--third-color);
    animation-delay: -0.7s;
}

.processing span:nth-child(4) {
    background: var(--fourth-color);
    animation-delay: -0.6s;
}

.processing span:nth-child(5) {
    background: var(--fifth-color);
    animation-delay: -0.5s;
}

@keyframes scale {
    0%,
    40%,
    100% {
        transform: scaleY(0.05);
    }

    20% {
        transform: scaleY(1);
    }
}

@keyframes pulse {
    0%,
    100% {
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15),
            0 0 0 0 rgba(102, 126, 234, 0.4);
    }
    50% {
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15),
            0 0 0 20px rgba(102, 126, 234, 0);
    }
}

/* Tablet Devices (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .chat-widget {
        bottom: 2rem;
        left: 2rem;
    }

    .chat-card {
        width: 360px;
    }
}

/* Tablet Portrait (481px - 768px) */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 1rem;
        left: 1rem;
        right: 1rem;
    }

    .chat-card {
        width: calc(100vw - 2rem);
        max-width: 500px;
        border-radius: 12px;
        max-height: calc(100vh - 100px);
    }

    .chat-header {
        padding: 0.875rem 1.25rem;
    }

    .chat-header img {
        width: 36px;
        height: 36px;
    }

    .chat-messages {
        height: 350px;
        padding: 1rem;
    }

    .empty-messages {
        min-height: 250px;
    }

    .message-bubble {
        max-width: 80%;
    }

    .chat-toggle {
        width: 56px;
        height: 56px;
    }

    .chat-toggle img {
        width: 32px;
        height: 32px;
    }
}

/* Mobile Landscape (481px - 767px) */
@media (max-width: 767px) and (orientation: landscape) {
    .chat-card {
        max-height: calc(100vh - 80px);
    }

    .chat-messages {
        height: calc(100vh - 250px);
        min-height: 200px;
    }
}

/* Mobile Portrait (320px - 480px) */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 0.75rem;
        left: 0.75rem;
        right: 0.75rem;
    }

    .chat-card {
        width: calc(100vw - 1.5rem);
        border-radius: 12px;
        max-height: calc(100vh - 80px);
    }

    .chat-header {
        padding: 0.75rem 1rem;
        gap: 8px;
    }

    .chat-header img {
        width: 32px;
        height: 32px;
    }

    .close-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .chat-messages {
        height: 300px;
        padding: 0.875rem;
    }

    .empty-messages {
        min-height: 200px;
        padding: 1rem;
    }

    .message {
        gap: 6px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .message-bubble {
        max-width: 85%;
        padding: 10px 14px;
    }

    .chat-input {
        padding: 0.75rem;
    }

    .message-input {
        padding: 10px 14px;
        font-size: 14px;
    }

    .send-btn {
        width: 44px;
        height: 44px;
    }

    .chat-toggle {
        width: 50px;
        height: 50px;
    }

    .chat-toggle img {
        width: 28px;
        height: 28px;
    }

    .processing {
        width: 80px;
        gap: 4px;
    }

    .processing span {
        width: 3px;
        height: 40px;
    }
}

/* Extra Small Mobile (max-width: 360px) */
@media (max-width: 360px) {
    .chat-widget {
        bottom: 0.5rem;
        left: 0.5rem;
        right: 0.5rem;
    }

    .chat-card {
        width: calc(100vw - 1rem);
        max-height: calc(100vh - 60px);
    }

    .chat-header {
        padding: 0.625rem 0.875rem;
    }

    .chat-messages {
        height: 250px;
        padding: 0.75rem;
    }

    .message-bubble {
        padding: 8px 12px;
        max-width: 90%;
    }

    .send-btn {
        width: 40px;
        height: 40px;
    }

    .chat-toggle {
        width: 46px;
        height: 46px;
    }

    .chat-toggle img {
        width: 26px;
        height: 26px;
    }
}

/* Large Desktop (1440px+) */
@media (min-width: 1440px) {
    .chat-widget {
        bottom: 3rem;
        left: 4rem;
    }

    .chat-card {
        width: 420px;
        max-height: 650px;
    }

    .chat-messages {
        height: 450px;
    }

    .chat-toggle {
        width: 64px;
        height: 64px;
    }

    .chat-toggle img {
        width: 38px;
        height: 38px;
    }
}

/* Hidden state */
.hidden {
    display: none;
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .send-btn,
    .close-btn,
    .chat-toggle {
        min-width: 44px;
        min-height: 44px;
    }

    .message-input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .chat-card {
        animation: none;
        opacity: 1;
        transform: none;
    }

    .chat-toggle {
        animation: none;
    }

    .send-btn:hover,
    .chat-toggle:hover {
        transform: none;
    }
}
