/* TOD AI Assistant — Frontend Widget */

.tod-ai-widget {
    --tod-ai-color: #1e7a4d;
    --tod-ai-width: 380px;
    --tod-ai-height: 520px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    z-index: 999999;
}

/* ── Bubble button ───────────────────────────────────────── */
.tod-ai-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 16px rgba(0,0,0,0.22);
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 999999;
    flex-shrink: 0;
}
.tod-ai-bubble:hover {
    box-shadow: 0 6px 24px rgba(0,0,0,0.3);
}
.tod-ai-widget[data-position="bottom-left"] .tod-ai-bubble { right: auto; left: 24px; }
.tod-ai-widget[data-position="bottom-left"] .tod-ai-panel  { right: auto; left: 24px; }

/* ── Chat panel — desktop ────────────────────────────────── */
.tod-ai-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: var(--tod-ai-width);
    height: var(--tod-ai-height);
    max-height: calc(100dvh - 120px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999998;
    /* Hidden by default via pointer-events + visibility — no display toggle = no flicker */
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.97);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
    pointer-events: none;
}
.tod-ai-panel--open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Inline / shortcode mode ─────────────────────────────── */
.tod-ai-inline .tod-ai-panel {
    position: relative;
    bottom: auto;
    right: auto;
    width: 100%;
    max-height: none;
    height: var(--tod-ai-height);
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    display: flex;
    animation: none;
}

/* ── Header ──────────────────────────────────────────────── */
.tod-ai-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    color: #fff;
    flex-shrink: 0;
}
.tod-ai-header-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}
.tod-ai-avatar-img { width: 100%; height: 100%; object-fit: cover; }
.tod-ai-avatar-icon { font-size: 16px; }
.tod-ai-header-info { flex: 1; min-width: 0; }
.tod-ai-header-info strong { display: block; font-size: 14px; font-weight: 600; }
.tod-ai-header-info span   { font-size: 12px; opacity: 0.85; }
.tod-ai-close-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.15s;
    line-height: 1;
    flex-shrink: 0;
}
.tod-ai-close-btn:hover { opacity: 1; }

/* ── Messages area ───────────────────────────────────────── */
.tod-ai-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
    background: #f9f9f9;
    -webkit-overflow-scrolling: touch;
}
.tod-ai-msg { display: flex; }
.tod-ai-msg--bot  { justify-content: flex-start; }
.tod-ai-msg--user { justify-content: flex-end; }
.tod-ai-msg-bubble {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: break-word;
}
.tod-ai-msg--bot .tod-ai-msg-bubble {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
    color: #1d2327;
}
.tod-ai-msg--user .tod-ai-msg-bubble {
    background: var(--tod-ai-color);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Rich text inside bot bubbles */
.tod-ai-msg--bot .tod-ai-msg-bubble p {
    margin: 0 0 8px;
    line-height: 1.55;
}
.tod-ai-msg--bot .tod-ai-msg-bubble p:last-child { margin-bottom: 0; }
.tod-ai-msg--bot .tod-ai-msg-bubble ul {
    margin: 4px 0 8px;
    padding-left: 18px;
}
.tod-ai-msg--bot .tod-ai-msg-bubble li {
    margin-bottom: 4px;
    line-height: 1.5;
}
.tod-ai-msg--bot .tod-ai-msg-bubble strong { font-weight: 600; }
.tod-ai-msg--bot .tod-ai-msg-bubble a {
    color: var(--tod-ai-color);
    text-decoration: underline;
    word-break: break-word;
    font-weight: 500;
}
.tod-ai-msg--bot .tod-ai-msg-bubble a:hover { opacity: 0.8; }

/* Typing dots */
.tod-ai-typing .tod-ai-msg-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
}
.tod-ai-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #bbb;
    animation: tod-ai-bounce 1.2s infinite ease-in-out;
}
.tod-ai-dot:nth-child(2) { animation-delay: 0.2s; }
.tod-ai-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes tod-ai-bounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40%           { transform: scale(1.1); opacity: 1; }
}

/* ── Input row ───────────────────────────────────────────── */
.tod-ai-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-top: 1px solid #e0e0e0;
    background: #fff;
    flex-shrink: 0;
}
.tod-ai-input {
    flex: 1;
    border: 1px solid #dcdcde;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 14px;
    outline: none;
    background: #f6f7f7;
    color: #1d2327;
    transition: border-color 0.15s;
    min-width: 0;
}
.tod-ai-input:focus { border-color: var(--tod-ai-color); background: #fff; }
.tod-ai-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    transition: transform 0.15s;
}
.tod-ai-send:hover  { transform: scale(1.08); }
.tod-ai-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── Footer ──────────────────────────────────────────────── */
.tod-ai-footer {
    font-size: 11px;
    color: #999;
    text-align: center;
    padding: 5px;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}
.tod-ai-footer a { color: #999; text-decoration: none; }
.tod-ai-footer a:hover { text-decoration: underline; }

/* ── Clear bar ───────────────────────────────────────────── */
.tod-ai-clear-bar {
    font-size: 11px;
    color: #94a3b8;
    text-align: center;
    padding: 5px 10px;
    border-bottom: 1px solid #f0f0f0;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}
.tod-ai-clear-btn {
    font-size: 11px;
    color: var(--tod-ai-color);
    background: none;
    border: 1px solid var(--tod-ai-color);
    border-radius: 10px;
    padding: 2px 8px;
    cursor: pointer;
    line-height: 1.4;
}
.tod-ai-clear-btn:hover { opacity: 0.75; }

/* ── Mobile — full screen takeover ──────────────────────── */
@media (max-width: 600px) {

    .tod-ai-bubble {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }

    .tod-ai-widget[data-position="bottom-left"] .tod-ai-bubble {
        left: 16px;
        right: auto;
    }

    /* Full-screen panel on mobile */
    .tod-ai-panel {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        z-index: 9999999 !important;
        transform: translateY(100%) !important;
        transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s !important;
    }
    .tod-ai-panel--open {
        transform: translateY(0) !important;
    }

    /* Slightly larger text and touch targets on mobile */
    .tod-ai-msg-bubble { font-size: 15px; }
    .tod-ai-input { font-size: 16px; } /* 16px prevents iOS zoom on focus */
    .tod-ai-send  { width: 42px; height: 42px; }

    .tod-ai-messages { padding: 10px; gap: 10px; }
    .tod-ai-input-row { padding: 10px; gap: 8px; }
}

/* ── Bubble icon overrides ───────────────────────────────── */
.tod-ai-bubble {
    width: 60px !important;
    height: 60px !important;
    padding: 0;
}
.tod-ai-bubble svg {
    color: #fff;
    flex-shrink: 0;
}

/* ── Teaser bubble ───────────────────────────────────────── */
.tod-ai-teaser {
    position: fixed;
    bottom: 96px;   /* sit just above the 60px bubble + 16px gap + 20px buffer */
    right: 16px;
    display: none;
    align-items: flex-end;
    gap: 8px;
    z-index: 999997;
    cursor: pointer;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    max-width: 280px;
    /* Ensure it never overlaps the bubble */
    pointer-events: auto;
}
.tod-ai-widget[data-position="bottom-left"] .tod-ai-teaser {
    right: auto;
    left: 16px;
    flex-direction: row-reverse;
}
.tod-ai-teaser--visible {
    opacity: 1;
    transform: translateY(0);
}
.tod-ai-teaser-img {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    object-position: top center;
    flex-shrink: 0;
    filter: drop-shadow(0 2px 8px rgba(0,0,0,0.2));
    align-self: flex-end;
}
.tod-ai-teaser-body {
    background: #fff;
    border-radius: 14px 14px 4px 14px;
    padding: 10px 30px 10px 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    position: relative;
    max-width: 200px;
    flex-shrink: 1;
}
.tod-ai-widget[data-position="bottom-left"] .tod-ai-teaser-body {
    border-radius: 14px 14px 14px 4px;
}
.tod-ai-teaser-msg {
    margin: 0;
    font-size: 13px;
    line-height: 1.45;
    color: #1d2327;
    word-break: break-word;
}
.tod-ai-teaser-close {
    position: absolute;
    top: 5px;
    right: 8px;
    background: none;
    border: none;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    color: #94a3b8;
    padding: 2px;
    z-index: 1;
}
.tod-ai-teaser-close:hover { color: #1d2327; }

/* ── Mobile teaser adjustments ───────────────────────────── */
@media (max-width: 600px) {
    .tod-ai-teaser {
        bottom: 90px;
        right: 12px;
        max-width: 240px;
    }
    .tod-ai-widget[data-position="bottom-left"] .tod-ai-teaser {
        left: 12px;
        right: auto;
    }
    .tod-ai-teaser-img { width: 44px; height: 44px; }
    .tod-ai-teaser-body { max-width: 175px; padding: 8px 28px 8px 10px; }
}
