/* ============================================
   AI Chat Widget Styles
   ============================================ */

.ai-chat-widget {
    position: fixed;
    bottom: 95px;
    left: 25px;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    transition: bottom 0.3s ease;
    display: none; /* Hidden by default — shown on large desktop and small mobile only */
}

/* Floating Toggle Button */
.ai-chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7d3cff 0%, #007bff 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(125, 60, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    color: white;
    position: relative;
}

.ai-chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(125, 60, 255, 0.5);
}

.ai-toggle-text {
    font-size: 16px;
    font-weight: 800;
    color: #fff;
    letter-spacing: 0.5px;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

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

.ai-chat-toggle-btn::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: inherit;
    animation: ai-pulse 2s infinite;
    z-index: -1;
}

@keyframes ai-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.25); opacity: 0; }
}

.ai-chat-tooltip {
    position: absolute;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
}

.ai-chat-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #333;
}

.ai-chat-toggle-btn:hover .ai-chat-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Chat Popup — float to the right of the AI icon on desktop */
.ai-chat-popup {
    position: absolute;
    bottom: 0;
    left: 75px;
    right: auto;
    width: 380px;
    max-width: calc(100vw - 120px);
    height: 550px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateX(20px) scale(0.95);
    transition: all 0.3s ease;
}

.ai-chat-popup.open {
    opacity: 1;
    visibility: visible;
    transform: translateX(0) scale(1);
}

/* Header */
.ai-chat-header {
    background: linear-gradient(135deg, #7d3cff 0%, #007bff 100%);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
}

.ai-chat-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-chat-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: cover;
    background: white;
    padding: 2px;
}

.ai-chat-logo-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-header-text h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.ai-chat-header-text p {
    margin: 2px 0 0 0;
    font-size: 12px;
    opacity: 0.9;
}

.ai-chat-header-actions {
    display: flex;
    gap: 8px;
}

.ai-chat-clear-btn,
.ai-chat-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

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

/* Messages Area */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8fafc;
    scroll-behavior: smooth;
}

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

.ai-chat-messages::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Message Styles */
.ai-chat-message {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    animation: slideIn 0.3s ease;
}

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

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

.ai-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-avatar {
    background: linear-gradient(135deg, #7d3cff 0%, #007bff 100%);
    color: white;
}

.ai-chat-message.user-message .ai-chat-avatar {
    background: #6366f1;
}

.ai-chat-content {
    max-width: 75%;
}

.ai-chat-bubble {
    background: white;
    padding: 12px 16px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    line-height: 1.5;
    font-size: 14px;
    color: #334155;
}

.ai-message .ai-chat-bubble {
    border-top-left-radius: 4px;
}

.ai-chat-message.user-message .ai-chat-bubble {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: white;
    border-top-right-radius: 4px;
}

.ai-chat-bubble p {
    margin: 0 0 8px 0;
}

.ai-chat-bubble p:last-child {
    margin: 0;
}

.ai-chat-bubble code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.ai-chat-message.user-message .ai-chat-bubble code {
    background: rgba(255, 255, 255, 0.2);
}

.ai-chat-bubble pre {
    background: rgba(0, 0, 0, 0.1);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.ai-chat-message.user-message .ai-chat-bubble pre {
    background: rgba(255, 255, 255, 0.2);
}

.ai-chat-bubble pre code {
    background: none;
    padding: 0;
}

.ai-chat-time {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 4px;
    display: block;
}

.ai-chat-message.user-message .ai-chat-time {
    text-align: right;
}

/* Typing Indicator */
.ai-chat-typing {
    display: flex;
    gap: 12px;
    padding: 0 20px 20px;
    animation: slideIn 0.3s ease;
}

.ai-chat-typing-dots {
    background: white;
    padding: 12px 20px;
    border-radius: 16px;
    border-top-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    gap: 4px;
    align-items: center;
}

.ai-chat-typing-dots span {
    width: 8px;
    height: 8px;
    background: #7d3cff;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.ai-chat-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-chat-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* Input Area */
.ai-chat-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e2e8f0;
}

.ai-chat-form {
    margin-bottom: 8px;
}

.ai-chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
}

.ai-chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.ai-chat-input:focus {
    border-color: #7d3cff;
}

.ai-chat-input::placeholder {
    color: #94a3b8;
}

.ai-chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7d3cff 0%, #007bff 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    position: relative;
}

.ai-chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(125, 60, 255, 0.4);
}

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

.ai-chat-send-btn.ai-stop-mode {
    background: linear-gradient(135deg, #ff6b6b 0%, #ef4444 100%);
}

.ai-chat-send-btn.ai-stop-mode:hover {
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.ai-send-icon,
.ai-stop-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-footer {
    text-align: center;
}

.ai-chat-footer-text {
    font-size: 11px;
    color: #94a3b8;
}

/* Error Message */
.ai-chat-error {
    background: #fee2e2;
    color: #dc2626;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ============================================================
   MOBILE APP-LIKE RESPONSIVE
   ============================================================ */
@media (max-width: 640px) {
    .ai-chat-widget {
        bottom: 20px;
        left: 80px;
        right: auto;
        z-index: 999;
    }

    .ai-chat-toggle-btn {
        width: 56px;
        height: 56px;
        box-shadow: 0 6px 22px rgba(125, 60, 255, 0.45);
    }

    .ai-toggle-text {
        font-size: 14px;
    }

    .ai-chat-popup {
        position: fixed;
        bottom: 90px;
        left: 0;
        right: 0;
        margin: 0 auto;
        width: calc(100vw - 32px);
        max-width: 360px;
        height: 520px;
        max-height: calc(100vh - 140px);
        background: white;
        border-radius: 20px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
        opacity: 0;
        visibility: hidden;
        transform: translateY(20px) scale(0.95);
        transition: all 0.3s ease;
    }

    .ai-chat-popup.open {
        opacity: 1;
        visibility: visible;
        transform: translateY(0) scale(1);
    }

    .ai-chat-header {
        padding: 14px 16px 12px;
        border-radius: 20px 20px 0 0;
    }

    .ai-chat-header-content {
        gap: 10px;
    }

    .ai-chat-logo,
    .ai-chat-logo-placeholder {
        width: 42px;
        height: 42px;
        border-radius: 12px;
    }

    .ai-chat-header-text h3 {
        font-size: 16px;
        font-weight: 700;
    }

    .ai-chat-header-text p {
        font-size: 11px;
    }

    .ai-chat-header-actions {
        gap: 6px;
    }

    .ai-chat-clear-btn,
    .ai-chat-close-btn {
        width: 38px;
        height: 38px;
        border-radius: 10px;
    }

    .ai-chat-messages {
        flex: 1;
        padding: 16px;
    }

    .ai-chat-message {
        gap: 10px;
        margin-bottom: 14px;
    }

    .ai-chat-avatar {
        width: 34px;
        height: 34px;
        border-radius: 10px;
    }

    .ai-chat-content {
        max-width: 82%;
    }

    .ai-chat-bubble {
        padding: 12px 14px;
        font-size: 15px;
        border-radius: 18px;
        line-height: 1.45;
    }

    .ai-message .ai-chat-bubble {
        border-top-left-radius: 4px;
    }

    .ai-chat-message.user-message .ai-chat-bubble {
        border-top-right-radius: 4px;
    }

    .ai-chat-time {
        font-size: 10px;
    }

    .ai-chat-typing {
        padding: 0 16px 16px;
    }

    .ai-chat-input-area {
        flex-shrink: 0;
        padding: 12px 16px;
        background: white;
        border-top: 1px solid #e2e8f0;
        border-radius: 0 0 20px 20px;
    }

    .ai-chat-form {
        margin-bottom: 0;
    }

    .ai-chat-input-wrapper {
        gap: 8px;
    }

    .ai-chat-input {
        flex: 1;
        min-width: 0;
        padding: 12px 16px;
        font-size: 16px;
        border-radius: 24px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .ai-chat-input::placeholder {
        font-size: 16px;
    }

    .ai-chat-send-btn {
        width: 46px;
        height: 46px;
        flex-shrink: 0;
    }

    .ai-chat-footer {
        display: none;
    }

    .ai-chat-error {
        margin: 0 16px 14px;
    }
}

/* Copy Button */
.ai-chat-copy-btn {
    background: rgba(0, 0, 0, 0.1);
    border: none;
    color: inherit;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.2s ease;
}

.ai-chat-copy-btn:hover {
    background: rgba(0, 0, 0, 0.2);
}

.ai-chat-message.user-message .ai-chat-copy-btn {
    background: rgba(255, 255, 255, 0.2);
}

.ai-chat-message.user-message .ai-chat-copy-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Large desktop / big screens — show AI button above WhatsApp */
@media (min-width: 992px) {
    .ai-chat-widget {
        display: block;
        bottom: 95px;
        left: 25px;
    }
}

/* Small mobile — compact floating chat to the right of the AI icon */
@media (max-width: 576px) {
    .ai-chat-widget {
        display: block;
        bottom: 124px;
        left: 12px;
        z-index: 999;
    }

    .ai-chat-toggle-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        border-radius: 50% !important;
        aspect-ratio: 1 / 1;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
    }

    .ai-toggle-text {
        font-size: 12px;
        font-weight: 800;
        color: #fff;
        letter-spacing: 0.5px;
        line-height: 1;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
        pointer-events: none;
    }

    .ai-chat-toggle-btn:hover {
        transform: scale(1.05);
    }

    .ai-chat-widget.chat-open .ai-chat-toggle-btn {
        display: none;
    }

    /* Full-width floating panel to the right of the icon */
    .ai-chat-popup {
        position: fixed;
        bottom: 124px;
        left: 56px;
        right: 4px;
        margin: 0;
        width: auto;
        min-width: auto;
        max-width: none;
        height: 420px;
        max-height: calc(100vh - 150px);
        border-radius: 14px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
        transform: translateX(-8px) scale(0.97);
        opacity: 0;
        visibility: hidden;
        transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    .ai-chat-popup.open {
        transform: translateX(0) scale(1);
        opacity: 1;
        visibility: visible;
    }

    /* Hide drag handle bar — not needed for floating card */
    .ai-chat-popup::before {
        display: none;
    }

    .ai-chat-header {
        padding: 8px 10px 8px 12px;
        border-radius: 14px 14px 0 0;
        gap: 8px;
    }

    .ai-chat-logo,
    .ai-chat-logo-placeholder {
        width: 30px;
        height: 30px;
        border-radius: 8px;
    }

    .ai-chat-header-content {
        flex: 1;
        gap: 6px;
        min-width: 0;
    }

    .ai-chat-header-text {
        flex: 1;
        min-width: 0;
    }

    .ai-chat-header-text h3 {
        font-size: 13px;
        font-weight: 700;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .ai-chat-header-text p {
        display: none;
    }

    .ai-chat-header-actions {
        gap: 4px;
        flex-shrink: 0;
    }

    .ai-chat-clear-btn,
    .ai-chat-close-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.25);
    }

    .ai-chat-clear-btn:hover,
    .ai-chat-close-btn:hover {
        background: rgba(255, 255, 255, 0.4);
    }

    .ai-chat-clear-btn svg,
    .ai-chat-close-btn svg {
        width: 18px;
        height: 18px;
    }

    .ai-chat-messages {
        padding: 8px 10px;
        background: #f8fafc;
    }

    .ai-chat-message {
        gap: 5px;
        margin-bottom: 8px;
    }

    .ai-chat-avatar {
        width: 24px;
        height: 24px;
        border-radius: 7px;
    }

    .ai-chat-avatar svg {
        width: 13px;
        height: 13px;
    }

    .ai-chat-content {
        max-width: 88%;
    }

    .ai-chat-bubble {
        padding: 8px 11px;
        font-size: 12.5px;
        border-radius: 12px;
        line-height: 1.4;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    }

    .ai-message .ai-chat-bubble {
        background: #fff;
        border-top-left-radius: 3px;
    }

    .ai-chat-message.user-message .ai-chat-avatar {
        display: none;
    }

    .ai-chat-message.user-message .ai-chat-content {
        max-width: 88%;
    }

    .ai-chat-message.user-message .ai-chat-bubble {
        border-top-right-radius: 3px;
    }

    .ai-chat-time {
        font-size: 8.5px;
        margin-top: 2px;
    }

    .ai-chat-typing {
        padding: 0 10px 8px;
    }

    .ai-chat-typing-dots {
        padding: 8px 11px;
    }

    .ai-chat-typing-dots span {
        width: 5px;
        height: 5px;
    }

    .ai-chat-input-area {
        padding: 6px 10px 8px;
        background: transparent;
        border-top: none;
    }

    .ai-chat-form {
        margin-bottom: 0;
    }

    .ai-chat-input-wrapper {
        gap: 5px;
        align-items: center;
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 22px;
        padding: 4px 4px 4px 10px;
        box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.04), 0 1px 4px rgba(0, 0, 0, 0.03);
    }

    .ai-chat-input {
        flex: 1;
        padding: 0;
        font-size: 12.5px;
        border: none;
        background: transparent;
        border-radius: 0;
        min-height: 32px;
    }

    .ai-chat-input:focus {
        border: none;
        box-shadow: none;
    }

    .ai-chat-input::placeholder {
        font-size: 12.5px;
    }

    .ai-chat-send-btn {
        width: 34px;
        height: 34px;
        min-width: 34px;
        min-height: 34px;
    }

    .ai-chat-send-btn svg {
        width: 16px;
        height: 16px;
    }

    .ai-chat-footer {
        display: none;
    }

    .ai-chat-error {
        margin: 0 10px 8px;
        padding: 8px 10px;
        font-size: 11.5px;
    }
}

/* Extra small devices */
@media (max-width: 400px) {
    .ai-chat-popup {
        bottom: 124px;
        left: 56px;
        right: 4px;
        width: auto;
        min-width: auto;
        max-width: none;
        height: 400px;
        max-height: calc(100vh - 150px);
    }

    .ai-chat-header-text h3 {
        max-width: none;
    }

    .ai-chat-bubble {
        padding: 7px 10px;
        font-size: 12px;
    }

    .ai-chat-input::placeholder {
        font-size: 12px;
    }
}
