/* TMM Chat Shell — outer container, FAB, panel, header, message scroller, input.
   Brand color is set via --tmm-chat-brand by JS from server config.            */

.tmm-public-chat {
    --tmm-chat-brand: #2c5f47;
    --tmm-chat-accent: #b09660;
    --tmm-chat-brand-fg: #fff;
    --tmm-chat-bg: #fff;
    --tmm-chat-bg-alt: #f8faf9;
    --tmm-chat-border: #e3e4e6;
    --tmm-chat-text: #1d2327;
    --tmm-chat-text-mute: #50575e;
    --tmm-chat-radius: 14px;
    --tmm-chat-shadow: 0 12px 40px rgba(0,0,0,.18);
    position: fixed;
    z-index: 99999;
    bottom: 24px;
    right: 24px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--tmm-chat-text);
    line-height: 1.5;
}

/* FAB */
.tmm-public-chat-fab {
    width: 58px; height: 58px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--tmm-chat-brand) 0%, color-mix(in srgb, var(--tmm-chat-brand) 70%, white) 100%);
    color: var(--tmm-chat-brand-fg);
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    cursor: pointer;
    position: relative;
    display: flex; align-items: center; justify-content: center;
    transition: transform .18s ease, box-shadow .18s ease;
}
.tmm-public-chat-fab:hover { transform: translateY(-2px); }
.tmm-public-chat-fab:focus-visible { outline: 3px solid var(--tmm-chat-accent); outline-offset: 2px; }
.tmm-public-chat-fab-icon { font-size: 24px; }
.tmm-public-chat-fab-badge {
    position: absolute; top: -2px; right: -2px;
    background: #f59e0b; color: #fff;
    font-size: 10px; font-weight: 700;
    padding: 2px 6px; border-radius: 10px;
    border: 2px solid #fff;
}

/* Panel */
.tmm-public-chat-panel {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 100px);
    background: var(--tmm-chat-bg);
    border-radius: var(--tmm-chat-radius);
    box-shadow: var(--tmm-chat-shadow);
    display: flex; flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--tmm-chat-border);
    animation: tmmPcPanelIn .25s cubic-bezier(.2,0,0,1);
}
.tmm-public-chat-panel[hidden] { display: none; }
@keyframes tmmPcPanelIn {
    from { transform: translateY(16px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* Header */
.tmm-public-chat-header {
    display: flex; align-items: center;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--tmm-chat-brand) 0%, color-mix(in srgb, var(--tmm-chat-brand) 70%, white) 100%);
    color: var(--tmm-chat-brand-fg);
    min-height: 52px;
}
.tmm-pc-back {
    background: transparent; border: none; color: inherit;
    font-size: 18px; cursor: pointer; padding: 4px 8px;
    border-radius: 8px;
    transition: background .15s ease;
}
.tmm-pc-back:hover { background: rgba(255,255,255,.18); }
.tmm-pc-back:focus-visible { outline: 2px solid var(--tmm-chat-accent); outline-offset: 1px; }
.tmm-public-chat-title {
    flex: 1; font-weight: 600; font-size: 15px; padding: 0 8px;
    margin: 0; line-height: 1.3;
    overflow: hidden;
    display: flex; flex-direction: column; align-items: flex-start;
}
.tmm-pc-brand {
    font-weight: 600;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
}
.tmm-pc-step-label {
    font-size: 12px; font-weight: 400; opacity: .85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: inline-block;
}
.tmm-public-chat-close {
    background: transparent; border: none; color: inherit;
    font-size: 24px; line-height: 1; cursor: pointer; padding: 0 4px;
    border-radius: 8px;
    /* Phase 8 fix C12 + #3: WCAG 44×44 touch target */
    min-width: 44px; min-height: 44px;
    display: inline-flex; align-items: center; justify-content: center;
}
.tmm-public-chat-close:hover { opacity: .8; }
.tmm-public-chat-close:focus-visible { outline: 2px solid var(--tmm-chat-accent); outline-offset: 1px; }

/* Progress bar */
.tmm-pc-progress {
    height: 3px;
    background: var(--tmm-chat-border);
}
.tmm-pc-progress > i {
    display: block;
    height: 100%;
    background: var(--tmm-chat-accent);
    transition: width .25s ease-out;
}

/* Messages */
.tmm-public-chat-messages {
    flex: 1; overflow-y: auto;
    padding: 12px;
    background: var(--tmm-chat-bg-alt);
    display: flex; flex-direction: column; gap: 8px;
    scroll-behavior: smooth;
}
.tmm-pc-msg { display: flex; flex-direction: column; max-width: 88%; }
.tmm-pc-msg-user { align-self: flex-end; align-items: flex-end; }
.tmm-pc-msg-assistant { align-self: flex-start; align-items: flex-start; }
.tmm-pc-bubble {
    padding: 8px 12px; border-radius: 14px;
    font-size: 14px; word-wrap: break-word; white-space: pre-line;
    animation: tmmPcBubbleIn .15s ease-out;
}
.tmm-pc-msg-user .tmm-pc-bubble {
    background: var(--tmm-chat-brand);
    color: var(--tmm-chat-brand-fg);
    border-bottom-right-radius: 4px;
}
.tmm-pc-msg-assistant .tmm-pc-bubble {
    background: color-mix(in srgb, var(--tmm-chat-brand) 12%, white);
    color: var(--tmm-chat-text);
    border-bottom-left-radius: 4px;
}
.tmm-pc-error .tmm-pc-bubble { background: #fff5f5; color: #a94442; border: 1px solid #fbb; }
.tmm-pc-error-retry {
    margin-left: 8px; padding: 4px 10px;
    background: transparent; border: 1px solid currentColor; border-radius: 6px;
    cursor: pointer; font-size: 12px; font-family: inherit; color: inherit;
}
@keyframes tmmPcBubbleIn {
    from { transform: scale(.96); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

/* Typing indicator */
.tmm-pc-typing .tmm-pc-bubble {
    display: inline-flex; align-items: center; gap: 4px; padding: 12px;
}
.tmm-pc-typing span {
    width: 6px; height: 6px;
    background: var(--tmm-chat-text-mute);
    border-radius: 50%;
    animation: tmmPcBounce 1.2s ease-in-out infinite;
}
.tmm-pc-typing span:nth-child(2) { animation-delay: .15s; }
.tmm-pc-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes tmmPcBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: .5; }
    40% { transform: translateY(-4px); opacity: 1; }
}

/* Input form */
.tmm-public-chat-form {
    display: flex; align-items: end; gap: 8px;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--tmm-chat-border);
    background: var(--tmm-chat-bg);
}
.tmm-public-chat-input {
    flex: 1;
    border: 1px solid #c3c4c7;
    border-radius: 18px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    /* Phase 8 fix C12: removed `outline: none` — left textarea with no visible
       focus indicator for keyboard users. Now relies on :focus-visible below
       to draw a clear ring while suppressing the indicator on mouse click. */
    transition: border-color .15s ease, box-shadow .15s ease;
    min-height: 22px;
}
.tmm-public-chat-input:focus-visible {
    border-color: var(--tmm-chat-brand);
    outline: 2px solid var(--tmm-chat-brand);
    outline-offset: 2px;
}
.tmm-public-chat-send {
    background: var(--tmm-chat-brand);
    color: var(--tmm-chat-brand-fg);
    border: none;
    width: 44px; height: 44px;            /* WCAG 44×44 touch target */
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 14px;
    display: flex; align-items: center; justify-content: center;
}
.tmm-public-chat-send:disabled { opacity: .4; cursor: not-allowed; }
.tmm-public-chat-send:focus-visible { outline: 2px solid var(--tmm-chat-accent); outline-offset: 2px; }

/* Quick reply chips */
.tmm-pc-quick-replies {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin: 4px 0 8px; align-self: flex-start;
}
.tmm-pc-quick-reply {
    background: var(--tmm-chat-bg);
    border: 1px solid var(--tmm-chat-brand);
    color: var(--tmm-chat-brand);
    border-radius: 18px;
    padding: 10px 14px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s ease;
    line-height: 1.3;
    /* Phase 9 fix #7: WCAG 44×44 at all sizes (was 36px on tablet) */
    min-height: 44px;
}
.tmm-pc-quick-reply:hover { background: var(--tmm-chat-brand); color: var(--tmm-chat-brand-fg); }
.tmm-pc-quick-reply:focus-visible { outline: 2px solid var(--tmm-chat-accent); outline-offset: 1px; }
.tmm-pc-quick-replies-stale { opacity: .45; pointer-events: none; }

/* Honeypot */
.tmm-public-chat-honeypot {
    position: absolute !important; left: -10000px !important;
    width: 1px !important; height: 1px !important;
    opacity: 0 !important; pointer-events: none !important;
}

/* Inline mode */
.tmm-public-chat-mode-inline {
    position: relative; bottom: auto; right: auto;
}
.tmm-public-chat-mode-inline .tmm-public-chat-fab { display: none; }
.tmm-public-chat-mode-inline .tmm-public-chat-panel {
    position: relative; bottom: auto; right: auto;
    width: 100%; max-width: 600px; height: 600px;
    animation: none;
}

/* Screen reader only */
.tmm-chat-sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Mobile 360px */
@media (max-width: 600px) {
    .tmm-public-chat { bottom: 12px; right: 12px; }
    .tmm-public-chat-panel {
        width: calc(100vw - 24px);
        height: calc(100vh - 80px);
        max-height: 95vh;
        /* Phase 9 fix #6: respect iOS Safari notch + bottom bar so input row
           isn't occluded when chrome collapses. */
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    /* Touch targets — promote 36px to WCAG 44×44 on mobile */
    .tmm-pc-quick-reply { min-height: 44px; }
    /* Phase 9 fix C12: 16px on mobile prevents iOS auto-zoom on textarea focus */
    .tmm-public-chat-input { font-size: 16px; }
}
@media (max-width: 380px) {
    .tmm-public-chat { bottom: 0; right: 0; left: 0; }
    /* Promote panel from absolute to fixed so it anchors to viewport, not the
       fixed parent which may zero-collapse on some browsers. */
    .tmm-public-chat-panel {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        bottom: 0; right: 0;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .tmm-public-chat-panel,
    .tmm-pc-bubble { animation: none; }
    .tmm-pc-progress > i { transition: none; }
    .tmm-pc-typing span { animation: none; }
    /* Suppress FAB hover lift + mic pulse to honour the reduce-motion contract. */
    .tmm-public-chat-fab,
    .tmm-public-chat-fab:hover { transform: none; transition: none; }
    .tmm-public-chat-mic.is-listening { animation: none; }
}

/* Phase 54 — Mic button */
/* Phase 28: respect [hidden] attribute (default off — admin enables via tmm_chat_voice_enabled) */
.tmm-public-chat-mic[hidden] { display: none !important; }
.tmm-public-chat-mic {
    background: #fff;
    color: #2c5f47;
    border: 1px solid #2c5f47;
    width: 44px; height: 44px;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 16px;
    margin-right: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}
.tmm-public-chat-mic.is-listening {
    background: #c62828;
    color: #fff;
    border-color: #c62828;
    animation: tmmMicPulse 1s ease-in-out infinite;
}
@keyframes tmmMicPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.1); }
}
@media (prefers-reduced-motion: reduce) {
    .tmm-public-chat-mic.is-listening { animation: none; }
}

/* Phase 64 — Cookie consent banner */
.tmm-consent-banner {
    position: fixed;
    bottom: 16px;
    left: 16px;
    right: 16px;
    max-width: 720px;
    margin: 0 auto;
    background: rgba(20, 30, 25, 0.96);
    color: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    z-index: 9999;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.tmm-consent-text { flex: 1; line-height: 1.4; }
.tmm-consent-text a { color: #b09660; text-decoration: underline; }
.tmm-consent-accept {
    background: #b09660;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    min-height: 36px;
    flex-shrink: 0;
}
.tmm-consent-accept:hover { background: #a08550; }
.tmm-consent-decline {
    background: transparent;
    color: #aaa;
    border: 1px solid #555;
    /* Phase 8 fix #5: WCAG 44×44 touch target (was 32×32) */
    min-width: 44px; min-height: 44px;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 14px;
}
.tmm-consent-decline:focus-visible,
.tmm-consent-accept:focus-visible {
    outline: 2px solid var(--tmm-chat-accent);
    outline-offset: 2px;
}
@media (max-width: 600px) {
    .tmm-consent-banner { font-size: 13px; gap: 8px; padding: 10px 12px; }
}
/* Phase 8 fix #13: at narrow widths, wrap so long Vietnamese text isn't squeezed
   between the buttons */
@media (max-width: 480px) {
    .tmm-consent-banner { flex-wrap: wrap; }
    .tmm-consent-text { flex: 0 0 100%; }
}

/* ═══════════════════════════════════════════════════════════════════
   Phase 19 — Universal chat enhancements
   ═══════════════════════════════════════════════════════════════════ */

/* Phase 19.4: on WC cart/checkout pages, move FAB up to avoid overlap with
   sticky "Proceed to Checkout" CTA on mobile. */
@media (max-width: 600px) {
    body.woocommerce-cart .tmm-public-chat,
    body.woocommerce-checkout .tmm-public-chat {
        bottom: 80px;
    }
}

/* Phase 19.7: Silent mode — checkout page. FAB stays but no proactive
   notification badge auto-pop. Badge only shows when user adds via chat. */
body.woocommerce-checkout .tmm-pc-cart-badge {
    /* Hide badge on checkout (user is mid-purchase, don't distract) */
    display: none !important;
}

/* Phase 19.7: shrink FAB on checkout for less visual weight */
body.woocommerce-checkout .tmm-public-chat-fab {
    width: 48px; height: 48px;
    opacity: 0.85;
    transition: opacity .2s ease;
}
body.woocommerce-checkout .tmm-public-chat-fab:hover {
    opacity: 1;
}
