/* Uses the real Keraton site tokens from public/css/style.css /
   bootstrap.min.css: --primary #AB7442, --light #f5f5f5, --dark #353535,
   body text #555, borders #ced4da, headings in Roboto/700, body in Open
   Sans - so the widget reads as part of the site, not a bolted-on tool. */

#chat-widget {
    position: fixed;
    /* The theme's own "back to top" button sits at right:45/bottom:45,
       48x48px (see .back-to-top / .btn-lg-square in style.css) - stacking
       above it, not on top of it, avoids the two colliding in the corner. */
    right: 24px;
    bottom: 108px;
    z-index: 1050;
    font-family: "Open Sans", sans-serif;
}

#chat-bubble {
    position: relative;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: #ab7442;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(171, 116, 66, 0.4);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
#chat-bubble:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(171, 116, 66, 0.5);
}
#chat-bubble svg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
#chat-bubble svg.hidden { display: none; }
#chat-bubble:focus-visible {
    outline: 2px solid #ab7442;
    outline-offset: 3px;
}

#chat-panel {
    position: absolute;
    right: 0;
    bottom: 72px;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#chat-panel.hidden { display: none; }

#chat-panel-header {
    background: #ab7442;
    color: #fff;
    padding: 16px 18px;
    flex-shrink: 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}
#chat-panel-title {
    margin: 0;
    font-family: "Roboto", sans-serif;
    font-weight: 700;
    font-size: 15px;
}
#chat-talk-to-human {
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}
#chat-talk-to-human:hover { background: rgba(255, 255, 255, 0.26); }

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f5f5f5;
}

#chat-greeting {
    background: #fff;
    border: 1px solid rgba(171, 116, 66, 0.25);
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 13.5px;
    color: #555;
}
#chat-greeting p { margin: 0 0 10px; }
#chat-greeting.hidden { display: none; }

/* Skeleton shown while /chat/history is in flight, so an existing
   conversation eases in instead of popping in all at once. */
#chat-history-loading {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#chat-history-loading.hidden { display: none; }
.chat-skeleton-row { display: flex; }
.chat-skeleton-row.user { justify-content: flex-end; }
.chat-skeleton-row.assistant { justify-content: flex-start; }
.chat-skeleton-bubble {
    display: block;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0.06) 25%, rgba(0, 0, 0, 0.12) 37%, rgba(0, 0, 0, 0.06) 63%);
    background-size: 400% 100%;
    animation: chat-skeleton-pulse 1.4s ease infinite;
}
.chat-skeleton-row.assistant .chat-skeleton-bubble { width: 70%; }
.chat-skeleton-row.user .chat-skeleton-bubble { width: 50%; }
@keyframes chat-skeleton-pulse {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* Each message (skeleton-resolved history, or a fresh reply) eases in
   rather than appearing instantly. */
.chat-bubble-row.fade-in { animation: chat-bubble-fade-in 0.25s ease; }
@keyframes chat-bubble-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
    .chat-skeleton-bubble { animation: none; }
    .chat-bubble-row.fade-in { animation: none; }
}

#chat-suggestions { display: flex; flex-direction: column; gap: 6px; }
.chat-suggestion-btn {
    text-align: left;
    background: rgba(171, 116, 66, 0.08);
    border: 1px solid rgba(171, 116, 66, 0.25);
    color: #ab7442;
    border-radius: 4px;
    padding: 7px 10px;
    font-size: 12.5px;
    cursor: pointer;
}
.chat-suggestion-btn:hover { background: rgba(171, 116, 66, 0.18); }

.chat-bubble-row { display: flex; }
.chat-bubble-row.user { justify-content: flex-end; }
.chat-bubble-row.assistant { justify-content: flex-start; }

.chat-msg {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 10px;
    font-size: 13.5px;
    line-height: 1.5;
    white-space: pre-wrap;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.chat-bubble-row.user .chat-msg {
    background: #ab7442;
    color: #fff;
    border-bottom-right-radius: 3px;
}
.chat-bubble-row.assistant .chat-msg {
    background: #fff;
    color: #555;
    border: 1px solid #ced4da;
    border-bottom-left-radius: 3px;
}

.chat-escalate-card {
    background: #fff;
    border: 1px solid rgba(171, 116, 66, 0.25);
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 13px;
    max-width: 90%;
    align-self: flex-start;
}
.chat-escalate-card p { margin: 0 0 10px; color: #555; }
.chat-escalate-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chat-escalate-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    font-size: 12.5px;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 4px;
    border: 1px solid transparent;
}
.chat-escalate-btn.whatsapp { background: #25d366; color: #fff; }
.chat-escalate-btn.email { background: rgba(171, 116, 66, 0.08); color: #ab7442; border-color: rgba(171, 116, 66, 0.25); }

#chat-typing.hidden { display: none; }
.chat-typing-msg {
    display: flex;
    gap: 4px;
    align-items: center;
    padding-top: 12px;
    padding-bottom: 12px;
}
.chat-typing-msg span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(171, 116, 66, 0.5);
    animation: chat-typing-bounce 1.2s infinite ease-in-out;
}
.chat-typing-msg span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-msg span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
    30% { transform: translateY(-4px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .chat-typing-msg span { animation: none; }
}

#chat-error {
    margin: 0;
    padding: 6px 16px;
    font-size: 12px;
    color: #b3261e;
    flex-shrink: 0;
}
#chat-error.hidden { display: none; }

#chat-form {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #ced4da;
    flex-shrink: 0;
}
#chat-input {
    flex: 1;
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 9px 14px;
    font-size: 13.5px;
    color: #555;
    outline: none;
}
#chat-input:focus { border-color: #ab7442; }
#chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: #ab7442;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
#chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 480px) {
    #chat-panel { width: calc(100vw - 24px); right: -8px; }
}
