/**
 * ZSMH AI Chatbot — Frontend styles
 *
 * Namespace: .zsmh-chat-*
 * Colors:    Orange #f19e00, Dark #1a1a1a, Light #f5f5f7
 *
 * @since 4.0.0
 */

/* ═══════════════════════════════════════════════════════════════
 * CSS VARIABLES
 * ═══════════════════════════════════════════════════════════════ */

:root {
    --zsmh-chat-orange: #f19e00;
    --zsmh-chat-orange-dark: #d68b00;
    --zsmh-chat-dark: #1a1a1a;
    --zsmh-chat-gray: #666;
    --zsmh-chat-light: #f5f5f7;
    --zsmh-chat-border: #e5e5e5;
    --zsmh-chat-white: #fff;
    --zsmh-chat-radius: 16px;
    --zsmh-chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    --zsmh-chat-font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --zsmh-chat-font-heading: 'Trebuchet MS', 'Lucida Grande', sans-serif;
}


/* ═══════════════════════════════════════════════════════════════
 * BUBBLE BUTTON — floating circle, bottom-right
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 100001;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.zsmh-chat-bubble:hover {
    transform: scale(1.08);
}

.zsmh-chat-bubble:active {
    transform: scale(0.95);
}

/* First visit pulse animation */
.zsmh-chat-bubble.is-pulsing {
    animation: zsmhChatPulse 2s ease-in-out 3;
}

@keyframes zsmhChatPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}

/* Bubble badge */
.zsmh-chat-bubble-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #e74c3c;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    font-family: var(--zsmh-chat-font-body);
    line-height: 20px;
    text-align: center;
}


/* ═══════════════════════════════════════════════════════════════
 * CHAT CONTAINER — wraps side-eMil + chat window
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-container {
    position: fixed;
    bottom: 88px;
    right: 24px;
    z-index: 100002;
    display: flex;
    align-items: flex-end;
    gap: 0;
    animation: zsmhChatSlideUp 0.3s ease-out;
    font-family: var(--zsmh-chat-font-body);
}

/* ═══════════════════════════════════════════════════════════════
 * SIDE eMil AVATAR — left of chat window, tracks last bot msg
 * Desktop only — hidden on mobile (falls back to header)
 * ═══════════════════════════════════════════════════════════════ */

.emil-side-avatar {
    width: 110px;
    height: 110px;
    flex-shrink: 0;
    overflow: visible;
    position: relative;
    align-self: flex-end;
    margin-bottom: 60px; /* default: near input area; JS overrides */
    margin-right: -8px; /* slight overlap with window */
    z-index: 3;
    transition: margin-bottom 0.3s ease-out;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.15));
}

.emil-side-avatar svg {
    width: 110px;
    height: 110px;
    display: block;
    overflow: visible;
}

/* ═══════════════════════════════════════════════════════════════
 * CHAT WINDOW — popup above bubble
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-window {
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 120px);
    border-radius: var(--zsmh-chat-radius);
    background: var(--zsmh-chat-white);
    box-shadow: var(--zsmh-chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Desktop: hide header avatar (eMil is on the side) */
.emil-header-avatar {
    display: none;
}

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

/* Closing animation class (added by JS before hiding) */
.zsmh-chat-container.is-closing {
    animation: zsmhChatSlideDown 0.2s ease-in forwards;
}

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


/* ═══════════════════════════════════════════════════════════════
 * HEADER — orange gradient bar with 70px eMil avatar + title + controls
 * Variant E: static large avatar, no expand/collapse
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px 6px 6px;
    background: linear-gradient(135deg, var(--zsmh-chat-orange) 0%, var(--zsmh-chat-orange-dark) 100%);
    color: #fff;
    flex-shrink: 0;
    min-height: 0;
    overflow: visible;
    position: relative;
    z-index: 2;
}

.zsmh-chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0; /* allow shrinking */
}

.zsmh-chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.zsmh-chat-header-title {
    font-family: var(--zsmh-chat-font-heading);
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.zsmh-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.zsmh-chat-header-actions button {
    background: none;
    border: none;
    padding: 6px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.8);
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    line-height: 0;
}

.zsmh-chat-header-actions button:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}


/* ═══════════════════════════════════════════════════════════════
 * MESSAGES AREA — scrollable container
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--zsmh-chat-light);
    scroll-behavior: smooth;
}

/* Custom scrollbar */
.zsmh-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.zsmh-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.zsmh-chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.zsmh-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}


/* ═══════════════════════════════════════════════════════════════
 * MESSAGE BUBBLES — user (right, orange) + bot (left, white)
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: zsmhChatMsgIn 0.2s ease-out;
}

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

/* Bot message — left aligned, column layout for feedback below bubble */
.zsmh-chat-msg-bot {
    align-self: flex-start;
    flex-direction: column;
    gap: 0;
}

.zsmh-chat-msg-bot .zsmh-chat-msg-content {
    background: var(--zsmh-chat-white);
    color: var(--zsmh-chat-dark);
    border: 1px solid var(--zsmh-chat-border);
    border-radius: 4px 12px 12px 12px;
    padding: 10px 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
}

/* User message — right aligned */
.zsmh-chat-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.zsmh-chat-msg-user .zsmh-chat-msg-content {
    background: var(--zsmh-chat-orange);
    color: #fff;
    border-radius: 12px 2px 12px 12px;
    padding: 10px 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
}

/* System message (welcome, error) */
.zsmh-chat-msg-system {
    align-self: center;
    max-width: 100%;
    text-align: center;
}

.zsmh-chat-msg-system .zsmh-chat-msg-content {
    background: transparent;
    color: var(--zsmh-chat-gray);
    font-size: 13px;
    line-height: 1.5;
    padding: 8px;
}

/* Welcome message with eMil */
.zsmh-chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 16px 8px;
    text-align: center;
}

.zsmh-chat-welcome-text {
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--zsmh-chat-dark);
    max-width: 300px;
}

/* Error message */
.zsmh-chat-msg-error .zsmh-chat-msg-content {
    background: #fff5f5;
    border: 1px solid #fecaca;
    color: #b91c1c;
}


/* ═══════════════════════════════════════════════════════════════
 * TYPING INDICATOR — eMil thinking dots
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-typing {
    display: flex;
    align-items: center;
    gap: 0;
    align-self: flex-start;
    padding: 4px 0;
}

.zsmh-chat-typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--zsmh-chat-white);
    border: 1px solid var(--zsmh-chat-border);
    border-radius: 2px 12px 12px 12px;
    padding: 10px 16px;
}

.zsmh-chat-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--zsmh-chat-orange);
    animation: zsmhChatTypingBounce 1.2s ease-in-out infinite;
}

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

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

@keyframes zsmhChatTypingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}


/* ═══════════════════════════════════════════════════════════════
 * SUGGESTED CHIPS — clickable pill buttons
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    padding: 4px 0 8px;
}

.zsmh-chat-chip {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 16px;
    border: 1px solid var(--zsmh-chat-border);
    background: var(--zsmh-chat-white);
    color: var(--zsmh-chat-dark);
    font-family: var(--zsmh-chat-font-body);
    font-size: 12px;
    line-height: 1.3;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.zsmh-chat-chip:hover {
    border-color: var(--zsmh-chat-orange);
    background: #fef7e8;
    color: var(--zsmh-chat-orange-dark);
}

.zsmh-chat-chip:active {
    background: var(--zsmh-chat-orange);
    color: #fff;
    border-color: var(--zsmh-chat-orange);
}


/* ═══════════════════════════════════════════════════════════════
 * LOGIN PROMPT — banner above input (for visitors after N msgs)
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-login-prompt {
    padding: 8px 16px;
    background: #fef7e8;
    border-top: 1px solid #fde68a;
    font-size: 12px;
    color: var(--zsmh-chat-gray);
    text-align: center;
    flex-shrink: 0;
}

.zsmh-chat-login-prompt a {
    color: var(--zsmh-chat-orange);
    font-weight: 600;
    text-decoration: none;
}

.zsmh-chat-login-prompt a:hover {
    text-decoration: underline;
}


/* ═══════════════════════════════════════════════════════════════
 * INPUT AREA — textarea + send button
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--zsmh-chat-border);
    background: var(--zsmh-chat-white);
    flex-shrink: 0;
}

.zsmh-chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--zsmh-chat-border);
    border-radius: 12px;
    padding: 10px 14px;
    font-family: var(--zsmh-chat-font-body);
    font-size: 14px;
    line-height: 1.4;
    color: var(--zsmh-chat-dark);
    background: var(--zsmh-chat-light);
    outline: none;
    transition: border-color 0.15s;
    max-height: 80px;
    overflow-y: auto;
    /* Prevent iOS zoom on focus */
    -webkit-text-size-adjust: 100%;
}

.zsmh-chat-input:focus {
    border-color: var(--zsmh-chat-orange);
}

.zsmh-chat-input::placeholder {
    color: #aaa;
}

.zsmh-chat-send {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: var(--zsmh-chat-orange);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s, opacity 0.15s;
    padding: 0;
    line-height: 0;
}

.zsmh-chat-send:hover:not(:disabled) {
    background: var(--zsmh-chat-orange-dark);
}

.zsmh-chat-send:active:not(:disabled) {
    transform: scale(0.92);
}

.zsmh-chat-send:disabled {
    opacity: 0.35;
    cursor: default;
}


/* ═══════════════════════════════════════════════════════════════
 * eMil HEADER AVATAR — mobile only (desktop uses side avatar)
 * ═══════════════════════════════════════════════════════════════ */

/* .emil-header-avatar display:none set above for desktop;
   shown via @media below for mobile */
.emil-header-avatar svg {
    width: 96px;
    height: 96px;
    display: block;
    filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.18));
    overflow: visible;
}


/* ═══════════════════════════════════════════════════════════════
 * FORMATTING inside bot messages (markdown-like)
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-msg-bot .zsmh-chat-msg-content p {
    margin: 0 0 8px;
}

.zsmh-chat-msg-bot .zsmh-chat-msg-content p:last-child {
    margin-bottom: 0;
}

.zsmh-chat-msg-bot .zsmh-chat-msg-content ul {
    margin: 4px 0 8px;
    padding-left: 20px;
    list-style-type: disc !important;  /* Divi reset override */
}

.zsmh-chat-msg-bot .zsmh-chat-msg-content ol {
    margin: 4px 0 8px;
    padding-left: 20px;
    list-style-type: decimal !important;  /* Divi reset override */
}

.zsmh-chat-msg-bot .zsmh-chat-msg-content li {
    margin-bottom: 2px;
    display: list-item !important;  /* Divi reset override */
}

.zsmh-chat-msg-bot .zsmh-chat-msg-content strong,
.zsmh-chat-msg-bot .zsmh-chat-msg-content b {
    font-weight: 600;
}

.zsmh-chat-msg-bot .zsmh-chat-msg-content a {
    color: var(--zsmh-chat-orange);
    text-decoration: none;
}

.zsmh-chat-msg-bot .zsmh-chat-msg-content a:hover {
    text-decoration: underline;
}


/* ═══════════════════════════════════════════════════════════════
 * RATE LIMIT / ERROR STATE
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-input-wrap.is-disabled {
    opacity: 0.5;
    pointer-events: none;
}


/* ═══════════════════════════════════════════════════════════════
 * RESPONSIVE — Mobile fullscreen ≤480px
 * ═══════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    .zsmh-chat-bubble {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
    }

    /* Mobile: container becomes full-width overlay */
    .zsmh-chat-container {
        bottom: 0;
        right: 0;
        left: 0;
    }

    /* Mobile: hide side avatar, show header avatar instead */
    .emil-side-avatar {
        display: none;
    }

    .emil-header-avatar {
        display: block;
        width: 96px;
        height: 96px;
        flex-shrink: 0;
        overflow: visible;
        position: relative;
    }

    .zsmh-chat-window {
        width: 100%;
        height: calc(100vh - 60px);
        max-height: none;
        border-radius: 16px 16px 0 0;
    }

    .zsmh-chat-messages {
        padding: 12px;
    }

    .zsmh-chat-msg {
        max-width: 92%;
    }

    .zsmh-chat-input {
        font-size: 16px; /* prevent iOS zoom */
    }

    .zsmh-chat-chip {
        font-size: 11px;
        padding: 5px 12px;
    }

    .zsmh-chat-header-title {
        font-size: 12px;
    }
}

/* Tablet adjustments */
@media (min-width: 481px) and (max-width: 768px) {
    .zsmh-chat-window {
        width: 340px;
        height: 500px;
    }
}


/* ═══════════════════════════════════════════════════════════════
 * BACK-TO-TOP BUTTON — align above eMil bubble, matching style
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-bubble ~ .zsmh-back-to-top,
body:has(.zsmh-chat-bubble) .zsmh-back-to-top {
    /* Position directly above the floating eMil button, centered
       Bubble: 60px wide at right:24 → center at 54px from right edge
       TOP btn: 38px wide → right = 54 - 19 = 35px */
    bottom: 92px !important;
    right: 35px !important;
    width: 38px !important;
    height: 38px !important;
    /* Rounded rectangle matching eMil's style instead of circle */
    border-radius: 12px !important;
    font-size: 16px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12) !important;
}

@media (max-width: 480px) {
    .zsmh-chat-bubble ~ .zsmh-back-to-top,
    body:has(.zsmh-chat-bubble) .zsmh-back-to-top {
        /* Bubble: 50px at right:16 → center at 41px; TOP: 34px → right = 41-17 = 24 */
        bottom: 74px !important;
        right: 24px !important;
        width: 34px !important;
        height: 34px !important;
    }
}


/* ═══════════════════════════════════════════════════════════════
 * FEEDBACK BUTTONS — thumbs up/down on bot messages
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-chat-feedback {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    padding-left: 2px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.zsmh-chat-msg-bot:hover .zsmh-chat-feedback,
.zsmh-chat-feedback:focus-within {
    opacity: 1;
}

.zsmh-fb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    line-height: 1;
}

.zsmh-fb-btn:hover {
    background: #f0f0f0;
    border-color: var(--zsmh-chat-border);
}

.zsmh-fb-btn:active {
    transform: scale(0.9);
}

.zsmh-fb-btn.is-active {
    background: #fef7e8;
    border-color: var(--zsmh-chat-orange);
}

.zsmh-fb-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.zsmh-fb-btn:disabled:not(.is-active) {
    opacity: 0.25;
}

.zsmh-fb-thanks {
    font-size: 11px;
    color: var(--zsmh-chat-gray);
    margin-left: 4px;
    animation: zsmhFbFadeIn 0.3s ease;
}

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

/* On mobile: always show feedback (no hover) */
@media (max-width: 480px) {
    .zsmh-chat-feedback {
        opacity: 1;
    }
}


/* ═══════════════════════════════════════════════════════════════
 * STREAMING CURSOR
 * ═══════════════════════════════════════════════════════════════ */

.zsmh-stream-cursor {
    display: inline;
    color: var(--zsmh-chat-orange);
    animation: zsmhStreamBlink 0.8s step-end infinite;
    font-weight: 400;
    margin-left: 1px;
}

@keyframes zsmhStreamBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.zsmh-chat-msg-streaming .zsmh-chat-msg-content {
    min-height: 1.4em;
}

/* ═══════════════════════════════════════════════════════════════
 * PRINT — hide everything
 * ═══════════════════════════════════════════════════════════════ */

@media print {
    .zsmh-chat-bubble,
    .zsmh-chat-window {
        display: none !important;
    }
}
