/* ==========================================================================
   Slimme Medewerker — AI chat conversation UI (pure CSS, no Bootstrap)

   Paired with js/ai-chat.js. Shared across:
     - templates/modal-chat-wrapper.php  (button → modal variant)
     - templates/inline-chat-wrapper.php (inline, no-click variant)
   Extends the base modal styles in modal-trigger.css.
   ========================================================================== */

/* Shared flex layout for both the modal body and the inline container */
.smw-modal--chat .smw-modal-body,
.smw-inline-chat {
    display: flex;
    flex-direction: column;
    padding: 0;
    min-height: 480px;
}

/* Inline-only chrome: give the section a standalone card look so it reads
   as a separate block in the flow of a page. */
.smw-inline-chat {
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    overflow: hidden;
    max-width: 720px;
    margin: 24px auto;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

/* In inline mode the scrollable pane is bounded by the section, not by the
   viewport. The template sets --smw-inline-chat-height from the PHP height arg. */
.smw-inline-chat .smw-chat-messages {
    max-height: var(--smw-inline-chat-height, 480px);
}

/* Scrollable message list */
.smw-chat-messages {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 18px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
    max-height: calc(80vh - 140px);
}

.smw-chat-messages::-webkit-scrollbar {
    width: 6px;
}
.smw-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* Message bubbles */
.smw-chat-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    animation: smw-chat-fade-in 180ms ease-out;
}

.smw-chat-bot {
    align-self: flex-start;
    background: var(--smw-chat-bot-bg, #f1f5f9);
    color: var(--smw-chat-bot-text, #0f172a);
    border-bottom-left-radius: 4px;
}

.smw-chat-bot a {
    color: var(--smw-chat-link, #0d6efd);
    text-decoration: underline;
}

.smw-chat-user {
    align-self: flex-end;
    background: var(--smw-chat-user-bg, #0d6efd);
    color: var(--smw-chat-user-text, #ffffff);
    border-bottom-right-radius: 4px;
}

/* Bot message with global avatar: wrapper holds <img> + the bubble div */
.smw-chat-bot-row {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 85%;
    animation: smw-chat-fade-in 180ms ease-out;
}

.smw-chat-bot-row .smw-chat-message {
    /* Row already constrains total width, let bubble use whatever it needs */
    max-width: none;
    animation: none;
}

.smw-chat-bot-avatar {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    background: #f1f5f9;
}

.smw-chat-error {
    align-self: center;
    max-width: 90%;
    text-align: center;
    background: #fef3c7;
    color: #92400e;
    border-radius: 10px;
    font-size: 0.875rem;
    padding: 8px 12px;
}

@keyframes smw-chat-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Typing indicator */
.smw-chat-typing {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--smw-chat-bot-bg, #f1f5f9);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.smw-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: smw-typing-bounce 1.3s ease-in-out infinite;
}

.smw-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.smw-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes smw-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* Input area */
.smw-chat-input-area {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    background: #fafafa;
}

.smw-chat-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 10px 14px;
    font: inherit;
    font-size: 0.95rem;
    color: #0f172a;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    outline: none;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.smw-chat-input:focus {
    border-color: var(--smw-chat-user-bg, #0d6efd);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.smw-chat-input:disabled {
    background: #f1f5f9;
    cursor: not-allowed;
}

.smw-chat-send {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--smw-chat-user-bg, #0d6efd);
    color: var(--smw-chat-user-text, #ffffff);
    cursor: pointer;
    transition: transform 150ms ease, box-shadow 150ms ease, opacity 150ms ease;
}

.smw-chat-send:hover,
.smw-chat-send:focus-visible {
    outline: none;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.smw-chat-send:active {
    transform: translateY(0);
}

.smw-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Narrow-viewport polish: the base modal already switches to bottom-sheet
   layout on <600px (see modal-trigger.css). We just need the chat body to
   fill available height. */
@media (max-width: 600px) {
    .smw-modal--chat .smw-modal-body,
    .smw-inline-chat {
        min-height: 0;
    }
    .smw-modal--chat .smw-chat-messages {
        max-height: calc(92vh - 160px);
    }
    .smw-chat-bot-avatar {
        width: 36px;
        height: 36px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .smw-chat-message,
    .smw-typing-dot,
    .smw-chat-send,
    .smw-chat-input {
        animation: none !important;
        transition: none !important;
    }
}
