/* AI Chat Widget — brand mascot styling (green/gold identity from the company emblem) */

.ai-chat-widget-root {
    position: relative;
}

/* ==========================================
   The Bot Button — a small mascot that lives inside
   a circular shell wearing the company emblem on its
   chest, and pops out to wave when greeted.
   ========================================== */
.ai-bot-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 72px;
    height: 72px;
    z-index: 1050;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    padding: 0;
    cursor: pointer;
    overflow: visible;
    background: radial-gradient(circle at 30% 25%, #2f9e6e, #1f6b4a 55%, #123524 100%);
    box-shadow: 0 10px 25px rgba(12, 33, 24, 0.4), 0 0 0 4px rgba(201, 162, 39, 0.12);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.4s ease;
    perspective: 400px;
}

.ai-bot-btn:hover,
.ai-bot-btn:focus-visible {
    transform: scale(1.06);
    box-shadow: 0 16px 34px rgba(12, 33, 24, 0.5), 0 0 0 6px rgba(201, 162, 39, 0.22);
}

/* Ambient pulse ring behind the bot, echoing "always listening" */
.bot-pulse {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 1.5px solid rgba(201, 162, 39, 0.45);
    animation: botPulse 2.6s ease-out infinite;
    pointer-events: none;
}

@keyframes botPulse {
    0% { transform: scale(0.85); opacity: 0.7; }
    100% { transform: scale(1.35); opacity: 0; }
}

/* The mascot figure — tucked mostly inside the shell at idle,
   only the antenna tip and top of the head peeking out. */
.bot-figure {
    position: absolute;
    left: 50%;
    bottom: 6px;
    width: 46px;
    transform: translateX(-50%) translateY(15px) rotateX(0deg);
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}

/* Pop the mascot up and out of the shell on hover/tap-greet, in 3D */
.ai-bot-btn:hover .bot-figure,
.ai-bot-btn.bot-greet .bot-figure {
    transform: translateX(-50%) translateY(-27px) rotateX(8deg);
}

.bot-antenna {
    position: relative;
    width: 3px;
    height: 9px;
    background: var(--gold, #c9a227);
    margin: 0 auto;
    border-radius: 2px;
}

.bot-antenna::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #ffe27a;
    box-shadow: 0 0 7px 2px rgba(255, 226, 122, 0.85);
    animation: antennaBlink 2s ease-in-out infinite;
}

@keyframes antennaBlink {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}

.bot-head {
    width: 36px;
    height: 25px;
    margin: 1px auto 0;
    border-radius: 13px 13px 9px 9px;
    background: linear-gradient(150deg, #f6faf7, #d6e7dd);
    box-shadow: inset 0 -3px 4px rgba(12, 33, 24, 0.12), 0 3px 6px rgba(0, 0, 0, 0.3);
    position: relative;
    /* JS-driven gaze: the head turns toward the cursor (var set on the button) */
    transform: rotate(var(--head-rot, 0deg));
    transform-origin: 50% 100%;
    will-change: transform;
}

.bot-visor {
    position: absolute;
    inset: 6px 4px auto 4px;
    height: 11px;
    background: #0c2118;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.bot-eye {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #7fd4ab;
    box-shadow: 0 0 4px 1px rgba(127, 212, 171, 0.85);
    animation: eyeBlink 3.4s ease-in-out infinite;
    /* JS-driven gaze: pupils drift toward the cursor. Blink animates
       height/opacity so it never fights this transform. */
    transform: translate(var(--eye-x, 0px), var(--eye-y, 0px));
    will-change: transform;
}

@keyframes eyeBlink {
    0%, 90%, 100% { opacity: 1; height: 5px; }
    95% { opacity: 0.3; height: 1px; }
}

/* Mouth: a tiny neutral line that curves into a smile when the bot is happy */
.bot-mouth {
    position: absolute;
    left: 50%;
    bottom: 2px;
    transform: translateX(-50%);
    width: 7px;
    height: 2px;
    border-radius: 2px;
    background: rgba(12, 33, 24, 0.45);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ai-bot-btn:hover .bot-mouth,
.ai-bot-btn.bot-greet .bot-mouth,
.ai-bot-btn.bot-happy .bot-mouth {
    width: 13px;
    height: 7px;
    background: transparent;
    border-bottom: 2.5px solid #0c2118;
    border-radius: 0 0 12px 12px;
}

/* Wink: one eye closes for a beat when the bot is clicked */
.ai-bot-btn.bot-wink .bot-eye:first-child {
    animation: none;
    height: 1.5px;
    opacity: 0.9;
}

/* Happy hop: a squash-and-stretch jump when the chat opens */
.ai-bot-btn.bot-jump {
    animation: botJump 0.55s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes botJump {
    0% { transform: translateY(0) scale(1, 1); }
    28% { transform: translateY(3px) scale(1.08, 0.9); }
    55% { transform: translateY(-16px) scale(0.95, 1.08); }
    78% { transform: translateY(1px) scale(1.04, 0.94); }
    100% { transform: translateY(0) scale(1); }
}

.bot-shoulders {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    margin-top: 3px;
}

/* The chest emblem — the company logo worn like a large, clearly visible badge */
.bot-emblem {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #ffffff;
    padding: 1.5px;
    border: 1.5px solid var(--gold, #c9a227);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.bot-emblem img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.bot-arm {
    width: 7px;
    height: 14px;
    border-radius: 5px;
    background: linear-gradient(150deg, #eaf5ee, #c3d8cd);
    transform-origin: top center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    margin-bottom: 6px;
}

.bot-arm-left { transform: rotate(16deg); }
.bot-arm-right { transform: rotate(-16deg); }

/* Waving hand animation on greet */
.ai-bot-btn:hover .bot-arm-right,
.ai-bot-btn.bot-greet .bot-arm-right {
    animation: waveArm 0.8s ease-in-out infinite;
}

@keyframes waveArm {
    0%, 100% { transform: rotate(-16deg); }
    50% { transform: rotate(62deg); }
}

/* Speech bubble greeting */
.bot-bubble {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 16px;
    background: #ffffff;
    color: #123524;
    font-family: 'Cairo', sans-serif;
    font-size: 0.78rem;
    font-weight: 800;
    padding: 8px 14px;
    border-radius: 14px;
    white-space: nowrap;
    box-shadow: 0 10px 22px rgba(12, 33, 24, 0.25);
    opacity: 0;
    transform: translateY(8px) scale(0.9);
    transform-origin: bottom right;
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}

.bot-bubble::after {
    content: '';
    position: absolute;
    bottom: -5px;
    right: 20px;
    width: 10px;
    height: 10px;
    background: #ffffff;
    transform: rotate(45deg);
}

.ai-bot-btn:hover .bot-bubble,
.ai-bot-btn.bot-greet .bot-bubble {
    opacity: 1;
    transform: translateY(0) scale(1);
}

[data-bs-theme="dark"] .bot-bubble { background: #123524; color: #eaf5ee; }
[data-bs-theme="dark"] .bot-bubble::after { background: #123524; }

/* ==========================================
   Chat Window
   ========================================== */
#ai-chat-window {
    position: fixed;
    bottom: 106px;
    right: 30px;
    width: 380px;
    max-height: calc(100vh - 130px);
    height: 600px;
    z-index: 1050;
    border-radius: 24px;
    /* visible so the balloon tail below can poke out; corners are rounded
       on the header/footer themselves instead */
    overflow: visible;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(31, 107, 74, 0.12);
    box-shadow: 0 20px 50px rgba(12, 33, 24, 0.2);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: 90% 100%; /* inflate from where the robot stands */
}

/* Speech-balloon tail pointing down at the robot */
#ai-chat-window::after {
    content: '';
    position: absolute;
    bottom: -9px;
    right: 34px;
    width: 22px;
    height: 22px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 0 0 5px 0;
    transform: rotate(45deg);
    z-index: -1;
}

#ai-chat-window.d-none {
    transform: scale(0.8) translateY(20px);
    opacity: 0;
    pointer-events: none;
    display: flex !important; /* Keep flex for transition but hide with scale/opacity */
}

/* Balloon inflate: after the robot's hop, the chat blows up out of it
   like a balloon — tiny, overshoots, wobbles, settles. */
#ai-chat-window:not(.d-none) {
    animation: balloonInflate 0.7s cubic-bezier(0.34, 1.3, 0.64, 1) 0.3s backwards;
}

@keyframes balloonInflate {
    0% { transform: scale(0.05) translateY(46px); opacity: 0; }
    55% { transform: scale(1.07) translateY(-6px); opacity: 1; }
    78% { transform: scale(0.97) translateY(2px); }
    100% { transform: scale(1) translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    #ai-chat-window:not(.d-none) { animation: none; }
    .ai-bot-btn.bot-jump { animation: none; }
}

/* Header Styling */
.ai-chat-header {
    background: linear-gradient(135deg, #123524, #1f6b4a);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 24px 24px 0 0; /* window overflow is visible now */
}

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

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

/* Messages Area */
#ai-chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background-image: radial-gradient(#dce9e2 1px, transparent 1px);
    background-size: 20px 20px;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

#ai-chat-messages::-webkit-scrollbar {
    display: none; /* Chrome, Safari and Opera */
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    animation: messageIn 0.3s ease-out;
}

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

.message-ai {
    align-self: flex-start;
    background: white;
    color: #14251c;
    border-bottom-left-radius: 4px;
    box-shadow: 0 4px 6px -1px rgba(12, 33, 24, 0.08);
}

.message-user {
    align-self: flex-end;
    background: #1f6b4a;
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 10px 15px -3px rgba(31, 107, 74, 0.25);
}

/* Typing Indicator */
.typing {
    display: flex;
    gap: 4px;
    padding: 8px;
}

.typing span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-5px); }
}

/* Input Area */
.ai-chat-footer {
    padding: 15px;
    background: white;
    border-top: 1px solid #eef5f0;
    border-radius: 0 0 24px 24px; /* window overflow is visible now */
}

.chat-input-wrapper {
    display: flex;
    background: #f6faf7;
    border-radius: 15px;
    padding: 5px;
    border: 1px solid #e2e8f0;
    transition: border-color 0.3s;
}

.chat-input-wrapper:focus-within {
    border-color: #1f6b4a;
}

#ai-chat-input {
    border: none;
    background: transparent;
    box-shadow: none;
    padding: 8px 15px;
    /* 16px minimum — iOS Safari auto-zooms the whole page on focus for any
       input with a smaller computed font-size than this. */
    font-size: 16px;
}

#ai-chat-send {
    background: #1f6b4a;
    border-color: #1f6b4a;
    border-radius: 12px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

#ai-chat-send:hover {
    background: #164f37;
    border-color: #164f37;
}

/* Dark Mode Support */
[data-bs-theme="dark"] #ai-chat-window {
    background: rgba(12, 26, 20, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #f1f5f9;
}

[data-bs-theme="dark"] #ai-chat-window::after {
    background: rgba(12, 26, 20, 0.96);
}

[data-bs-theme="dark"] .message-ai {
    background: #0e2019;
    color: #f1f5f9;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
}

[data-bs-theme="dark"] #ai-chat-messages {
    background-image: radial-gradient(#1c3a2c 1px, transparent 1px);
}

[data-bs-theme="dark"] .ai-chat-footer {
    background: #0c2118;
    border-top-color: #16332a;
}

[data-bs-theme="dark"] .chat-input-wrapper {
    background: #123524;
    border-color: #1c4632;
}

[data-bs-theme="dark"] #ai-chat-input {
    color: white;
}

/* Mobile Adjustments — keep the bot clear of the floating bottom dock */
@media (max-width: 767px) {
    .ai-bot-btn {
        bottom: 100px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .bot-figure { width: 38px; }
    .bot-head { width: 30px; height: 21px; }
    .bot-emblem { width: 20px; height: 20px; }
}

@media (max-width: 576px) {
    #ai-chat-window {
        width: calc(100% - 32px);
        bottom: 168px;
        right: 16px;
        height: 60vh;
    }
}

/* Markdown Link Styling */
.chat-markdown-link {
    color: #1f6b4a;
    text-decoration: underline;
    font-weight: bold;
    transition: color 0.2s;
}

.chat-markdown-link:hover {
    color: #123524;
    text-decoration: none;
}

[data-bs-theme="dark"] .chat-markdown-link {
    color: #7fd4ab;
}

[data-bs-theme="dark"] .chat-markdown-link:hover {
    color: #a9e6c4;
}
