/* chatbot.css */
:root {
    --chat-width: 400px;
    --chat-max-height: 600px;
}

/* Floating Action Button */
.chatbot-fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary), var(--primary-container));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 999;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chatbot-fab:hover {
    transform: scale(1.1);
}

/* Pulse animation triggered selectively via JS */
.chatbot-fab.pulse-glow {
    animation: biolumin-pulse 2s infinite;
}

@keyframes biolumin-pulse {
    0% { box-shadow: 0 0 0 0 rgba(156, 255, 147, 0.4); }
    70% { box-shadow: 0 0 0 20px rgba(156, 255, 147, 0); }
    100% { box-shadow: 0 0 0 0 rgba(156, 255, 147, 0); }
}

/* Frog+AI SVG icon sizing */
.chatbot-fab .chatbot-frog-icon {
    width: 36px;
    height: 36px;
    color: var(--on-primary);
}

.chatbot-header-title .chatbot-frog-icon {
    width: 24px;
    height: 24px;
    color: var(--primary);
    flex-shrink: 0;
}

/* The Panel Container */
.chatbot-panel {
    position: fixed;
    bottom: 6rem; /* Above FAB on desktop */
    right: 2rem;
    width: var(--chat-width);
    height: 65vh;
    max-height: var(--chat-max-height);
    background-color: rgba(11, 15, 11, 0.85); /* background with opacity */
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(69, 73, 68, 0.3); /* outline-variant */
    border-radius: 1.5rem;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chatbot-panel.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid rgba(69, 73, 68, 0.3);
    background: rgba(28, 33, 27, 0.5); /* surface-container-high */
    border-top-left-radius: 1.5rem;
    border-top-right-radius: 1.5rem;
}

.chatbot-header-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--primary);
}

.chatbot-close {
    background: none;
    border: none;
    color: var(--on-surface-variant);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
}

.chatbot-close:hover {
    background-color: var(--surface-container-highest);
    color: var(--on-surface);
}

/* Messages Area */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Scrollbar styling for messages */
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}
.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(156, 255, 147, 0.2);
    border-radius: 10px;
}

/* Single Message Bubble */
.chat-msg {
    max-width: 85%;
    padding: 1rem 1.25rem;
    line-height: 1.5;
    font-size: 0.95rem;
    animation: fadeInUp 0.3s ease forwards;
    opacity: 0;
    transform: translateY(10px);
}

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

.chat-msg p {
    margin: 0 0 0.5rem 0;
}
.chat-msg p:last-child {
    margin-bottom: 0;
}

.chat-msg a {
    color: var(--primary);
    text-decoration: underline;
    font-weight: bold;
}

.chat-msg strong {
    color: inherit;
    font-weight: 800;
}

/* Bot Message */
.chat-msg.bot {
    align-self: flex-start;
    background-color: var(--surface-container-low);
    color: var(--on-surface);
    border-radius: 1.25rem 1.25rem 1.25rem 0.25rem;
    border: 1px solid rgba(69, 73, 68, 0.2);
}

/* User Message */
.chat-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary), var(--primary-container));
    color: var(--on-primary);
    border-radius: 1.25rem 1.25rem 0.25rem 1.25rem;
}

/* Action Links inside Bot messages (e.g., fallback buttons) */
.chat-action-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    margin-right: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(156, 255, 147, 0.1);
    border: 1px solid rgba(156, 255, 147, 0.3);
    color: var(--primary) !important;
    text-decoration: none !important;
    border-radius: 2rem;
    font-weight: bold;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.chat-action-link:hover {
    background: var(--primary);
    color: var(--on-primary) !important;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.5rem 1rem;
    background-color: var(--surface-container-low);
    border-radius: 1.25rem 1.25rem 1.25rem 0.25rem;
    align-self: flex-start;
    width: fit-content;
    display: none;
}
.typing-indicator.active {
    display: flex;
}
.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--primary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
    opacity: 0.5;
}
.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; }

@keyframes typing {
    0%, 100% { transform: translateY(0); opacity: 0.5; }
    50% { transform: translateY(-4px); opacity: 1; }
}

/* Suggestions Container */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0 1.5rem 1rem 1.5rem;
}
.chat-suggestion-chip {
    background: rgba(156, 255, 147, 0.05);
    border: 1px solid rgba(156, 255, 147, 0.2);
    color: var(--primary);
    padding: 0.4rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.chat-suggestion-chip:hover {
    background: rgba(156, 255, 147, 0.15);
    border-color: var(--primary);
}

/* Input Area */
.chatbot-input-area {
    padding: 1rem;
    background: rgba(28, 33, 27, 0.5); /* surface-container-high */
    border-top: 1px solid rgba(69, 73, 68, 0.3);
    border-bottom-left-radius: 1.5rem;
    border-bottom-right-radius: 1.5rem;
}

.chatbot-input-wrapper {
    display: flex;
    align-items: center;
    background: var(--surface-container-low);
    border-radius: 2rem;
    padding: 0.25rem 0.25rem 0.25rem 1rem;
    border: 1px solid rgba(69, 73, 68, 0.4);
    transition: border-color 0.2s;
}

.chatbot-input-wrapper:focus-within {
    border-color: var(--primary);
}

.chatbot-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--on-surface);
    font-size: 0.95rem;
    padding: 0.5rem 0;
    max-height: 80px;
    resize: none;
    font-family: inherit;
    outline: none;
}

.chatbot-input::placeholder {
    color: var(--on-surface-variant);
}

.chatbot-send {
    background: var(--primary);
    color: var(--on-primary);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
    flex-shrink: 0;
    margin-left: 0.5rem;
}
.chatbot-send:hover {
    transform: scale(1.05);
    background: var(--primary-container);
}
.chatbot-send:disabled {
    background: var(--surface-container-highest);
    color: var(--on-surface-variant);
    cursor: not-allowed;
    transform: none;
}

.chatbot-footer {
    text-align: center;
    font-size: 0.65rem;
    color: var(--on-surface-variant);
    padding-top: 0.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.25rem;
}
.chatbot-footer a {
    text-decoration: underline;
    opacity: 0.7;
}

/* Markdown parsing overrides inside chat */
.chat-msg ul {
    margin: 0.5rem 0 0.5rem 1.2rem;
    list-style-type: disc;
}
.chat-msg li {
    margin-bottom: 0.25rem;
}

/* Mobile specific styling */
@media (max-width: 768px) {
    .chatbot-fab {
        bottom: 5.5rem; /* Pushed up to sit above mobile bottom nav */
        right: 1.5rem;
        width: 56px;
        height: 56px;
    }
    
    .chatbot-panel {
        width: 100%;
        height: 70vh;
        max-height: calc(100vh - 6rem);
        bottom: 0;
        right: 0;
        border-radius: 2rem 2rem 0 0;
        border-bottom: none;
        border-left: none;
        border-right: none;
    }
    
    .chatbot-input-area {
        border-radius: 0;
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
    
        border-radius: 2rem 2rem 0 0;
    }
}

/* Escalation Form Styles */
.chat-escalation-form {
    align-self: flex-start;
    background-color: var(--surface-container-low);
    color: var(--on-surface);
    border-radius: 1.25rem;
    border: 1px solid var(--primary);
    padding: 1.25rem;
    margin-top: 0.5rem;
    max-width: 90%;
    animation: fadeInUp 0.3s ease forwards;
}

.esc-intro {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    font-weight: 500;
}

.esc-input {
    width: 100%;
    background: rgba(28, 33, 27, 0.8);
    border: 1px solid rgba(156, 255, 147, 0.2);
    color: var(--on-surface);
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.esc-input:focus {
    border-color: var(--primary);
}

.esc-submit {
    width: 100%;
    background: var(--primary);
    color: var(--on-primary);
    border: none;
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: opacity 0.2s;
}

.esc-submit:hover {
    opacity: 0.9;
}

.esc-success {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary);
    font-weight: bold;
}
