/* CannaRelief Chat widget
   Restrained clinical palette: deep green + teal accent, on soft white.
   Inherits Poppins from the theme; falls back to system sans. */

.crchat {
    --crchat-green: #103b2d;
    --crchat-teal: #1a8a8c;
    --crchat-teal-700: #127b7d;
    --crchat-tint: #eef6f2;
    --crchat-line: rgba(16, 59, 45, 0.12);
    --crchat-ink: #1f3b30;
    --crchat-muted: #5d7068;
    --crchat-radius: 16px;
    --crchat-shadow: 0 18px 48px rgba(16, 59, 45, 0.22);
    font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    box-sizing: border-box;
}
.crchat *, .crchat *::before, .crchat *::after { box-sizing: inherit; }

/* Launcher bubble */
.crchat-launcher {
    position: fixed;
    bottom: 22px;
    z-index: 99999;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 13px 18px 13px 15px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--crchat-teal), var(--crchat-green));
    color: #fff;
    font: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    box-shadow: var(--crchat-shadow);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.crchat-launcher:hover { transform: translateY(-2px); }
.crchat-launcher:focus-visible { outline: 3px solid var(--crchat-teal); outline-offset: 3px; }
.crchat-launcher svg { width: 20px; height: 20px; flex: none; }
.crchat[data-position="bottom-right"] .crchat-launcher { right: 22px; }
.crchat[data-position="bottom-left"]  .crchat-launcher { left: 22px; }

/* Panel */
.crchat-panel {
    position: fixed;
    bottom: 22px;
    z-index: 100000;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 44px);
    display: none;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--crchat-line);
    border-radius: var(--crchat-radius);
    box-shadow: var(--crchat-shadow);
    overflow: hidden;
}
.crchat[data-position="bottom-right"] .crchat-panel { right: 22px; }
.crchat[data-position="bottom-left"]  .crchat-panel { left: 22px; }
.crchat.is-open .crchat-panel { display: flex; }

/* Transient top-of-panel notice (file rejected, too big, etc). Overlays the
   log without affecting layout, and is hidden/shown purely via opacity so it
   never shifts the composer or message list. */
.crchat-toast {
    position: absolute;
    top: 60px;
    left: 10px;
    right: 10px;
    z-index: 5;
    background: var(--crchat-ink);
    color: #fff;
    font-size: 0.78rem;
    line-height: 1.4;
    padding: 9px 12px;
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(16, 59, 45, 0.28);
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}
.crchat-toast.is-visible { opacity: 1; transform: translateY(0); }
.crchat.is-open .crchat-launcher { display: none; }

/* Inline (shortcode) variant sits in the page flow */
.crchat-inline-host { position: static; }
.crchat-inline-host .crchat-panel {
    position: static;
    display: flex;
    width: 100%;
    max-width: 640px;
    height: 540px;
    margin: 1.5rem auto;
}
.crchat-inline-host .crchat-launcher { display: none; }

/* Header */
.crchat-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--crchat-teal), var(--crchat-green));
    color: #fff;
}
.crchat-head h3 { margin: 0; font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }
.crchat-head .crchat-dot { width: 8px; height: 8px; border-radius: 50%; background: #9be7a8; flex: none; }
.crchat-close {
    margin-left: auto;
    width: 30px; height: 30px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}
.crchat-close:hover { background: rgba(255, 255, 255, 0.28); }
.crchat-close:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* Messages */
.crchat-log {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--crchat-tint);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.crchat-msg { max-width: 86%; font-size: 0.92rem; line-height: 1.5; }
.crchat-msg p { margin: 0 0 0.5em; }
.crchat-msg p:last-child { margin-bottom: 0; }
.crchat-msg ul, .crchat-msg ol { margin: 0 0 0.5em; padding-left: 1.25em; }
.crchat-msg ul:last-child, .crchat-msg ol:last-child { margin-bottom: 0; }
.crchat-msg li { margin: 0 0 0.25em; }
.crchat-msg li:last-child { margin-bottom: 0; }
.crchat-msg strong { font-weight: 700; }
.crchat-msg a { color: var(--crchat-teal-700); text-decoration: underline; word-break: break-word; }
.crchat-msg.user a { color: #fff; }

.crchat-msg.bot {
    align-self: flex-start;
    background: #fff;
    color: var(--crchat-ink);
    border: 1px solid var(--crchat-line);
    border-radius: 4px 14px 14px 14px;
    padding: 11px 13px;
}
.crchat-msg.user {
    align-self: flex-end;
    background: var(--crchat-green);
    color: #fff;
    border-radius: 14px 14px 4px 14px;
    padding: 11px 13px;
}

/* Source links */
.crchat-sources {
    margin-top: 9px;
    padding-top: 8px;
    border-top: 1px dashed var(--crchat-line);
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.crchat-sources .crchat-src-label { font-size: 0.72rem; color: var(--crchat-muted); }
.crchat-sources a {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--crchat-teal-700);
    text-decoration: none;
    background: var(--crchat-tint);
    border: 1px solid var(--crchat-line);
    padding: 3px 9px;
    border-radius: 999px;
}
.crchat-sources a:hover { background: #fff; text-decoration: underline; }

/* Typing indicator */
.crchat-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.crchat-typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--crchat-teal);
    opacity: 0.4;
    animation: crchat-bounce 1.2s infinite ease-in-out;
}
.crchat-typing span:nth-child(2) { animation-delay: 0.15s; }
.crchat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes crchat-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.4; } 40% { transform: translateY(-4px); opacity: 1; } }

/* Composer */
.crchat-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--crchat-line);
    background: #fff;
}
.crchat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--crchat-line);
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit;
    font-size: 0.92rem;
    line-height: 1.4;
    max-height: 120px;
    color: var(--crchat-ink);
}
.crchat-input:focus { outline: none; border-color: var(--crchat-teal); box-shadow: 0 0 0 3px rgba(26, 138, 140, 0.15); }
.crchat-send {
    flex: none;
    width: 42px; height: 42px;
    border: none;
    border-radius: 12px;
    background: var(--crchat-teal);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.crchat-send:hover { background: var(--crchat-teal-700); }
.crchat-send:disabled { opacity: 0.5; cursor: not-allowed; }
.crchat-send:focus-visible { outline: 3px solid var(--crchat-teal); outline-offset: 2px; }
.crchat-send svg { width: 18px; height: 18px; }

.crchat-disclaimer {
    font-size: 0.68rem;
    color: var(--crchat-muted);
    text-align: center;
    padding: 0 12px 10px;
    background: #fff;
}

@media (prefers-reduced-motion: reduce) {
    .crchat-launcher, .crchat-typing span { transition: none; animation: none; }
}

@media (max-width: 480px) {
    .crchat-panel {
        top: 16px;
        bottom: 12px;
        width: auto;
        max-width: none;
        height: auto;
        max-height: none;
        border-radius: var(--crchat-radius);
    }
    .crchat[data-position] .crchat-panel { right: 12px; left: 12px; }

    /* Icon-only launcher on mobile — no title text, just the round bubble. */
    .crchat-launcher {
        width: 52px;
        height: 52px;
        padding: 0;
        gap: 0;
        justify-content: center;
    }
    .crchat-launcher span { display: none; }
}

/* File upload UI */
.crchat-controls { display: flex; gap: 8px; align-items: flex-end; }
.crchat-file { display: none; }
.crchat-attach {
    flex: none; width: 42px; height: 42px;
    border: 1px solid var(--crchat-line); border-radius: 12px;
    background: #fff; color: var(--crchat-teal-700);
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.crchat-attach:hover { background: var(--crchat-tint); }
.crchat-attach:focus-visible { outline: 3px solid var(--crchat-teal); outline-offset: 2px; }
.crchat-attach svg { width: 18px; height: 18px; }

.crchat-attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.crchat-chip {
    display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
    background: var(--crchat-tint); border: 1px solid var(--crchat-line);
    border-radius: 10px; padding: 4px 6px 4px 4px; font-size: 0.76rem; color: var(--crchat-ink);
}
.crchat-chip-thumb { width: 26px; height: 26px; border-radius: 6px; object-fit: cover; flex: none; }
.crchat-chip-ico {
    width: 26px; height: 26px; border-radius: 6px; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--crchat-teal); color: #fff; font-size: 0.6rem; font-weight: 700;
}
.crchat-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.crchat-chip-x {
    flex: none; border: none; background: transparent; cursor: pointer;
    color: var(--crchat-muted); width: 18px; height: 18px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
}
.crchat-chip-x svg { width: 12px; height: 12px; }

/* Attachments shown inside a sent user bubble */
.crchat-msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.crchat-msg-img { max-width: 140px; max-height: 140px; border-radius: 8px; display: block; }
.crchat-msg-file {
    font-size: 0.74rem; background: rgba(255,255,255,0.18);
    border-radius: 8px; padding: 3px 8px;
}

/* ---- Check Eligibility call-to-action ---- */
.crchat-cta { margin-top: 10px; }
.crchat-cta-btn {
    display: inline-block;
    padding: 9px 18px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--crchat-teal), var(--crchat-green));
    color: #fff !important;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
.crchat-cta-btn:hover,
.crchat-cta-btn:focus {
    filter: brightness(1.05);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
    color: #fff;
}
