:root {
    --primary-color: #16a34a;
    --secondary-color: #14532d;
    --accent-color: #15803d;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --success-color: #16a34a;
    --bg-gradient: linear-gradient(135deg, #22c55e, #15803d);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    --border-radius: 14px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', Arial, sans-serif;
}

body {
    line-height: 1.6;
    font-family: 'Poppins', Arial, sans-serif;
}

.chat-container {
    max-width: 380px;
    margin: 20px auto;
    position: relative;
}

/* ---- Floating launcher button ---- */
.chat-button {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background: var(--bg-gradient);
    border: none;
    border-radius: 50%;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.2s ease, visibility 0.2s ease;
}

/* Gentle pulse ring to invite a first click; harmless once dismissed */
.chat-button::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    opacity: 0.55;
    animation: chatPulse 2.6s ease-out infinite;
    pointer-events: none;
}

@keyframes chatPulse {
    0% {
        transform: scale(0.85);
        opacity: 0.55;
    }
    80%, 100% {
        transform: scale(1.35);
        opacity: 0;
    }
}

.chat-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 34px rgba(22, 163, 74, 0.28);
}

.chat-button:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
}

.chat-button.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(0.8);
}

.chat-button i {
    color: white;
    font-size: 24px;
    transition: transform 0.3s ease;
}

.chat-button:hover i {
    transform: scale(1.15);
}

/* ---- Chat window ---- */
.chat-window {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 400px;
    height: min(500px, 78vh);
    z-index: 101;
    background: white;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    display: none;
    flex-direction: column;
    transition: height 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.chat-window.active,
.chat-window.closing {
    display: flex;
}

.chat-window.active {
    animation: slideUp 0.35s ease forwards;
}

.chat-window.closing {
    animation: slideDown 0.28s ease forwards;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes slideDown {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(16px) scale(0.98);
    }
}

/* Minimized: collapse to just the header bar */
.chat-window.minimized {
    height: 68px !important;
}

.chat-window.minimized .chat-body,
.chat-window.minimized .faq-toggle,
.chat-window.minimized .faq-section,
.chat-window.minimized .chat-footer {
    display: none;
}

.chat-header {
    flex-shrink: 0;
    padding: 15px 20px;
    background: var(--bg-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header-info {
    display: flex;
    align-items: center;
    min-width: 0;
}

.chat-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 50%;
    background: white;
    margin-right: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-avatar i {
    color: var(--primary-color);
    font-size: 20px;
}

.chat-avatar-status {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    background: #4ade80;
    border: 2px solid #fff;
    border-radius: 50%;
}

.chat-title {
    font-size: 18px;
    font-weight: 600;
}

.chat-subtitle {
    font-size: 12px;
    opacity: 0.9;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.chat-controls {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.chat-icon-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.chat-icon-btn:hover {
    background: rgba(255, 255, 255, 0.28);
    transform: scale(1.1);
}

.chat-icon-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Match the site's slim brand-colored scrollbar */
.chat-body::-webkit-scrollbar,
.faq-section::-webkit-scrollbar {
    width: 8px;
}

.chat-body::-webkit-scrollbar-track,
.faq-section::-webkit-scrollbar-track {
    background: transparent;
}

.chat-body::-webkit-scrollbar-thumb,
.faq-section::-webkit-scrollbar-thumb {
    background: rgba(22, 163, 74, 0.35);
    border-radius: 20px;
}

.message-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 100%;
}

.message-row.user {
    justify-content: flex-end;
}

.msg-avatar {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--bg-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.chat-message {
    max-width: 78%;
    padding: 12px 16px;
    border-radius: 18px;
    animation: fadeIn 0.3s forwards;
    position: relative;
    line-height: 1.5;
    overflow-wrap: break-word;
    word-break: break-word;
}

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

.bot-message {
    background-color: #f1f1f1;
    color: var(--dark-color);
    border-top-left-radius: 4px;
}

.user-message {
    background: var(--bg-gradient);
    color: white;
    border-top-right-radius: 4px;
    text-align: right;
}

.message-time {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 5px;
    display: block;
}

/* Clickable links inside bot messages */
.chat-link {
    color: var(--accent-color);
    font-weight: 600;
    text-decoration: underline;
    overflow-wrap: anywhere;
}

.chat-link:hover {
    color: var(--secondary-color);
}

.user-message .chat-link {
    color: #fff;
}

/* ---- Proactive teaser bubble ---- */
.chat-teaser {
    position: fixed;
    bottom: 40px;
    right: 100px;
    max-width: 240px;
    background: #fff;
    color: var(--dark-color);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 16px;
    border-bottom-right-radius: 4px;
    box-shadow: var(--shadow);
    padding: 12px 34px 12px 16px;
    font-size: 14px;
    line-height: 1.45;
    cursor: pointer;
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
}

.chat-teaser.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.chat-teaser:hover {
    border-color: rgba(22, 163, 74, 0.4);
}

.chat-teaser-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--muted, #6b7280);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    transition: background 0.2s ease, color 0.2s ease;
}

.chat-teaser-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--dark-color);
}

.thinking {
    display: flex;
    gap: 5px;
    padding: 10px 14px;
    background-color: #f1f1f1;
    border-radius: 18px;
    align-self: flex-start;
    width: fit-content;
    margin-left: 34px; /* line up with bot bubbles, which sit after the avatar */
}

.thinking-dot {
    width: 8px;
    height: 8px;
    background-color: #aaa;
    border-radius: 50%;
    animation: thinking 1.4s infinite;
}

.thinking-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes thinking {
    0% {
        transform: translateY(0);
        background-color: #aaa;
    }
    50% {
        transform: translateY(-5px);
        background-color: var(--primary-color);
    }
    100% {
        transform: translateY(0);
        background-color: #aaa;
    }
}

.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 4px;
    margin-left: 34px;
}

.quick-reply {
    background-color: white;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    font-family: inherit;
}

.quick-reply:hover {
    background-color: var(--primary-color);
    color: white;
    transform: translateY(-2px);
}

.chat-footer {
    flex-shrink: 0;
    padding: 15px 20px;
    padding-bottom: max(15px, env(safe-area-inset-bottom));
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-input {
    flex: 1;
    min-width: 0;
    padding: 12px 15px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 24px;
    /* 16px prevents iOS Safari from auto-zooming the page on focus */
    font-size: 16px;
    outline: none;
    transition: all 0.3s ease;
    font-family: inherit;
}

.chat-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.12);
}

.send-button {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: white;
}

.send-button:hover {
    background: var(--accent-color);
    transform: rotate(15deg);
}

.send-button:focus-visible,
.chat-input:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.faq-toggle {
    flex-shrink: 0;
    width: 100%;
    padding: 10px 0;
    text-align: center;
    background: #f1f1f1;
    font-size: 14px;
    cursor: pointer;
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    transition: background 0.3s ease;
    font-family: inherit;
    color: var(--dark-color);
}

.faq-toggle:hover {
    background: #e5e5e5;
}

.faq-section {
    flex-shrink: 0;
    max-height: 0;
    overflow: hidden;
    overflow-y: auto;
    transition: max-height 0.4s ease;
    background: #f9f9f9;
}

.faq-section.active {
    max-height: min(300px, 40vh);
    padding: 15px;
}

.faq-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.faq-item {
    background: white;
    padding: 10px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 13px;
    text-align: center;
    font-family: inherit;
    color: var(--dark-color);
}

.faq-item:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ---- Responsive: tablets / small laptops ---- */
@media (max-width: 900px) {
    .chat-window {
        width: min(380px, 92vw);
    }
}

/* ---- Responsive: phones — full-screen chat experience ---- */
@media (max-width: 768px) {
    .chat-container {
        margin: 0;
        max-width: 100%;
    }

    .chat-window {
        width: 100%;
        height: 100vh;
        height: 100dvh; /* accounts for mobile browser toolbars */
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
        border-radius: 0;
        border: none;
    }

    .chat-window.minimized {
        height: 64px !important;
    }

    .chat-header {
        padding-top: max(15px, env(safe-area-inset-top));
    }

    .chat-button {
        bottom: max(20px, env(safe-area-inset-bottom));
        right: 20px;
    }

    /* Sit the teaser above the launcher on phones so it can't overflow sideways */
    .chat-teaser {
        right: 16px;
        bottom: calc(96px + env(safe-area-inset-bottom));
        max-width: calc(100vw - 32px);
        border-bottom-right-radius: 16px;
    }

    .faq-section.active {
        max-height: min(240px, 34vh);
    }
}

/* Narrow phones: single-column FAQ grid so labels aren't cramped */
@media (max-width: 380px) {
    .faq-list {
        grid-template-columns: 1fr;
    }
}

/* Short / landscape phones: trim vertical padding so the input stays visible above the keyboard */
@media (max-height: 480px) {
    .chat-header {
        padding: 10px 16px;
    }

    .chat-body {
        padding: 12px;
        gap: 10px;
    }

    .chat-footer {
        padding: 10px 16px;
    }

    .faq-section.active {
        max-height: 30vh;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-button::before {
        animation: none;
        display: none;
    }

    .chat-window.active,
    .chat-window.closing,
    .chat-message,
    .thinking-dot {
        animation: none !important;
    }

    * {
        transition-duration: 0.01ms !important;
    }
}
