/**
 * TGM ChatBot — Widget Styles v1.2.0 (Phase 1.6: Granular Visual Controls)
 *
 * All colours, sizes, and fonts use CSS custom properties injected by PHP
 * in <style id="tgm-chatbot-vars"> on the .jc-launcher / .jc-window scope.
 * All classes prefixed with jc- to prevent theme conflicts.
 */

/* ── Reset & Base ──────────────────────────── */
.jc-launcher,
.jc-window,
.jc-window * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--tgm-font-body, sans-serif);
    font-weight: var(--tgm-font-body-weight, 400);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ══════════════════════════════════════════════
   LAUNCHER — shared base
   ══════════════════════════════════════════════ */
.jc-launcher {
    position: fixed;
    bottom: 24px;
    z-index: 999999;
    border: none;
    background: var(--tgm-launcher-bg, #3498db);
    color: var(--tgm-launcher-icon, #fff);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 14px var(--tgm-launcher-shadow, rgba(0,0,0,0.18));
    transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1),
                box-shadow 0.25s ease;
}
.jc-launcher:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px var(--tgm-launcher-shadow, rgba(0,0,0,0.22));
}
.jc-launcher:active {
    transform: scale(0.95);
}
.jc-launcher:focus-visible {
    outline: 3px solid var(--tgm-header-bg, #2c3e50);
    outline-offset: 3px;
}
.jc-pos-right { right: 24px; }
.jc-pos-left  { left: 24px; }

/* ── Launcher shape: ROUND (icon only) ── */
.jc-launcher--round {
    width: var(--tgm-launcher-size, 60px);
    height: var(--tgm-launcher-size, 60px);
    border-radius: 50%;
}

/* ── Launcher shape: PILL (text, or text + icon) ── */
.jc-launcher--pill {
    height: var(--tgm-launcher-size, 52px);
    min-width: var(--tgm-launcher-size, 52px);
    padding: 0 22px;
    border-radius: calc(var(--tgm-launcher-size, 52px) / 2);
    gap: 10px;
}
.jc-launcher--pill.jc-icon-right {
    flex-direction: row-reverse;
}

/* ── Launcher text (pill only) ── */
.jc-launcher-text {
    color: var(--tgm-launcher-text, #fff);
    font-size: var(--tgm-launcher-text-size, 15px);
    font-weight: var(--tgm-launcher-text-weight, 600);
    white-space: nowrap;
    line-height: 1;
    transition: opacity 0.2s ease, max-width 0.3s ease;
}

/* When the chat window opens, the launcher collapses back to a round X button.
   Text hides, and pill shrinks back to the round footprint. */
.jc-launcher.jc-open.jc-launcher--pill {
    width: var(--tgm-launcher-size, 60px);
    min-width: 0;
    padding: 0;
    border-radius: 50%;
    gap: 0;
}
.jc-launcher.jc-open .jc-launcher-text {
    opacity: 0;
    max-width: 0;
    overflow: hidden;
}

/* ── Launcher icons ── */
.jc-launcher-icon {
    transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1),
                opacity 0.25s ease;
    flex-shrink: 0;
}
/* SVG icons (the default close X, and any SVG chat icon) use absolute overlay */
svg.jc-launcher-icon {
    position: absolute;
    pointer-events: none;
}
/* Emoji and image icons are inline (not absolute) so the pill layout flows */
.jc-icon-emoji {
    font-size: 28px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.jc-icon-image {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

/* Round launcher: SVG chat icon stays absolute-centered */
.jc-launcher--round svg.jc-icon-chat {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* Close SVG: hidden by default, shown when .jc-open */
.jc-icon-close {
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
}

/* When chat is open: swap to close icon, hide chat icon */
.jc-launcher.jc-open .jc-icon-chat {
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
}
.jc-launcher.jc-open .jc-icon-close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    position: absolute;
}

/* Ping / pulse animation — stops via .jc-pinged class */
.jc-launcher-ping {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--tgm-launcher-bg, #3498db);
    opacity: 0;
    pointer-events: none;
    animation: jc-ping 2s cubic-bezier(0,0,0.2,1) infinite;
}
.jc-launcher.jc-pinged .jc-launcher-ping {
    animation: none;
    display: none;
}
@keyframes jc-ping {
    0%   { transform: scale(1); opacity: 0.45; }
    100% { transform: scale(1.7); opacity: 0; }
}

/* ══════════════════════════════════════════════
   CHAT WINDOW
   ══════════════════════════════════════════════ */
.jc-window {
    position: fixed;
    bottom: 100px;
    z-index: 999998;
    width: 420px;
    max-height: calc(100vh - 120px);
    background: var(--tgm-window-bg, #f9f9f9);
    border: 1px solid var(--tgm-window-border, #e0e0e0);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.15),
                0 2px 8px rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Spring animation */
    transform-origin: bottom right;
    opacity: 0;
    transform: scale(0.6) translateY(20px);
    transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1),
                opacity 0.25s ease;
    pointer-events: none;
    visibility: hidden;
}
.jc-window.jc-pos-right { right: 24px; }
.jc-window.jc-pos-left  { left: 24px; transform-origin: bottom left; }

/* Open state */
.jc-window.jc-visible {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
    visibility: visible;
}

/* ══════════════════════════════════════════════
   HEADER
   ══════════════════════════════════════════════ */
.jc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: var(--tgm-header-bg, #2c3e50);
    color: var(--tgm-header-title, #fff);
    flex-shrink: 0;
    font-family: var(--tgm-font-header, var(--tgm-font-body, sans-serif));
}
.jc-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.jc-header-avatar {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background: rgba(255,255,255,0.15);
    border-radius: 50%;
    flex-shrink: 0;
}
.jc-avatar-img {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
}
.jc-header-info {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}
.jc-header-name {
    font-weight: var(--tgm-font-header-weight, 700);
    font-size: var(--tgm-size-header, 18px);
    color: var(--tgm-header-title, #fff);
    font-family: var(--tgm-font-header, var(--tgm-font-body, sans-serif));
}
.jc-header-status {
    font-size: 13px;
    color: var(--tgm-header-subtitle, #bdc3c7);
    display: flex;
    align-items: center;
    gap: 5px;
}
.jc-status-dot {
    width: 8px;
    height: 8px;
    background: #4caf50;
    border-radius: 50%;
    display: inline-block;
    animation: jc-pulse 1.5s ease-in-out infinite;
}
@keyframes jc-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.4; transform: scale(0.85); }
}
.jc-close {
    background: none;
    border: none;
    color: var(--tgm-header-close, #fff);
    font-size: 26px;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
    opacity: 0.75;
    border-radius: 6px;
    transition: opacity 0.15s, background 0.15s;
}
.jc-close:hover {
    opacity: 1;
    background: rgba(255,255,255,0.15);
}

/* ══════════════════════════════════════════════
   MESSAGES AREA
   ══════════════════════════════════════════════ */
.jc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 140px;
    scroll-behavior: smooth;
}

/* Custom scrollbar */
.jc-messages::-webkit-scrollbar {
    width: 5px;
}
.jc-messages::-webkit-scrollbar-track {
    background: transparent;
}
.jc-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 10px;
}
.jc-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.25);
}

/* ── Message Bubbles ──────────────────────── */
.jc-msg {
    max-width: 85%;
    padding: 11px 16px;
    border-radius: 16px;
    font-size: var(--tgm-size-message, 15px);
    line-height: 1.55;
    word-wrap: break-word;
    animation: jc-msg-in 0.35s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes jc-msg-in {
    from { opacity: 0; transform: translateY(12px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.jc-msg-bot {
    align-self: flex-start;
    background: var(--tgm-bot-bg, #ecf0f1);
    color: var(--tgm-bot-text, #333);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.jc-msg-bot a {
    color: var(--tgm-bot-link, #3498db);
    text-decoration: underline;
}
.jc-msg-user {
    align-self: flex-end;
    background: var(--tgm-user-bg, #d5f5e3);
    color: var(--tgm-user-text, #333);
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* ── Images inside bot messages (Phase 1.6 data layer) ── */
.jc-msg img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 6px 0;
    display: block;
}

/* ── Typing Indicator ─────────────────────── */
.jc-typing {
    display: inline-flex;
    gap: 5px;
    padding: 12px 16px;
    align-self: flex-start;
    background: var(--tgm-bot-bg, #ecf0f1);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    animation: jc-msg-in 0.3s ease both;
}
.jc-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--tgm-ai-typing, #aaa);
    border-radius: 50%;
    animation: jc-bounce 1.4s ease-in-out infinite;
}
.jc-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.jc-typing-dot:nth-child(3) { animation-delay: 0.32s; }
@keyframes jc-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-8px); opacity: 1; }
}

/* ══════════════════════════════════════════════
   REPLIES AREA (Q&A buttons)
   ══════════════════════════════════════════════ */
.jc-replies {
    padding: 8px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    animation: jc-replies-in 0.3s ease both;
}
@keyframes jc-replies-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Stacked layout (default) */
.jc-replies .jc-reply-btn {
    display: block;
    width: 100%;
    padding: 13px 18px;
    border: 2px solid var(--tgm-qa-border, #3498db);
    border-radius: 12px;
    background: var(--tgm-qa-bg, #fff);
    color: var(--tgm-qa-text, #2c3e50);
    font-size: var(--tgm-size-qa-btn, 15px);
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    font-family: var(--tgm-font-body, sans-serif);
    transition: background 0.2s ease,
                color 0.2s ease,
                transform 0.15s ease,
                box-shadow 0.2s ease;
}
.jc-replies .jc-reply-btn:hover {
    background: var(--tgm-qa-hover-bg, #3498db);
    color: var(--tgm-qa-hover-text, #fff);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}
.jc-replies .jc-reply-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

/* Pill grid layout */
.jc-replies.jc-pill-grid {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
}
.jc-pill-grid .jc-reply-btn {
    width: auto;
    flex: 0 0 auto;
    padding: 8px 18px;
    border-radius: 22px;
    font-size: 13px;
}

/* Back to Main Menu — visually muted */
.jc-replies .jc-reply-back {
    border-style: dashed;
    border-color: #aaa;
    color: #888;
    opacity: 0.7;
    font-weight: 400;
    font-size: 13px;
    margin-top: 4px;
}
.jc-replies .jc-reply-back:hover {
    opacity: 1;
    border-color: var(--tgm-qa-border, #3498db);
    color: var(--tgm-qa-text, #2c3e50);
    background: var(--tgm-qa-bg, #fff);
}

/* ══════════════════════════════════════════════
   CTA BUTTONS (inside contact card)
   ══════════════════════════════════════════════ */
.jc-cta-card .jc-cta-btn {
    background: var(--tgm-cta-bg, #e67e22);
    color: var(--tgm-cta-text, #fff);
    border: none;
    transition: background 0.2s ease, color 0.2s ease;
}
.jc-cta-card .jc-cta-btn:hover {
    background: var(--tgm-cta-hover-bg, #d35400);
    color: var(--tgm-cta-hover-text, #fff);
}

/* ══════════════════════════════════════════════
   INLINE CTA (appended after AI responses)
   ══════════════════════════════════════════════ */
.jc-inline-cta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px 4px;
    animation: jcFadeIn 0.3s ease;
}
.jc-inline-cta .jc-cta-contact-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 20px;
    background: var(--tgm-cta-bg, #e67e22);
    color: var(--tgm-cta-text, #fff);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--tgm-font-body, sans-serif);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.jc-inline-cta .jc-cta-contact-btn:hover {
    background: var(--tgm-cta-hover-bg, #d35400);
    color: var(--tgm-cta-hover-text, #fff);
    transform: translateY(-1px);
}
.jc-inline-cta .jc-cta-contact-btn svg {
    flex-shrink: 0;
}

/* ══════════════════════════════════════════════
   INLINE CONTACT FORM (in chat messages area)
   ══════════════════════════════════════════════ */
.jc-contact-form {
    padding: 10px 12px;
    animation: jcFadeIn 0.3s ease;
}
.jc-contact-field {
    margin-bottom: 8px;
}
.jc-contact-input {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--tgm-input-border, rgba(0,0,0,0.15));
    border-radius: 8px;
    font-size: 13px;
    font-family: var(--tgm-font-body, sans-serif);
    background: var(--tgm-input-bg, #fff);
    color: var(--tgm-input-text, #333);
    outline: none;
    transition: border-color 0.15s;
    box-sizing: border-box;
}
.jc-contact-input:focus {
    border-color: var(--tgm-qa-border, #3498db);
    box-shadow: 0 0 0 2px rgba(0,0,0,0.05);
}
.jc-contact-input::placeholder {
    color: var(--tgm-input-placeholder, #aaa);
}
.jc-contact-textarea {
    resize: vertical;
    min-height: 60px;
}
.jc-contact-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 4px;
}
.jc-contact-submit {
    flex: 1;
}
.jc-contact-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}
.jc-contact-cancel {
    background: none;
    border: none;
    color: var(--tgm-input-placeholder, #999);
    font-size: 13px;
    cursor: pointer;
    padding: 8px 12px;
    font-family: var(--tgm-font-body, sans-serif);
    transition: color 0.15s;
}
.jc-contact-cancel:hover {
    color: var(--tgm-input-text, #333);
}
.jc-contact-status {
    font-size: 12px;
    min-height: 16px;
    padding: 4px 2px 0;
    font-family: var(--tgm-font-body, sans-serif);
}

/* ══════════════════════════════════════════════
   FREE-TEXT INPUT BAR
   ══════════════════════════════════════════════ */
.jc-input-bar {
    display: flex;
    border-top: 1px solid var(--tgm-window-border, #e8e8e8);
    padding: 10px 14px;
    gap: 8px;
    background: var(--tgm-input-bg, #fff);
    flex-shrink: 0;
    border-radius: 0 0 16px 16px;
}
.jc-input {
    flex: 1;
    border: 1.5px solid var(--tgm-input-border, #ddd);
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 14px;
    color: var(--tgm-input-text, #2c3e50);
    background: var(--tgm-input-bg, #fff);
    font-family: var(--tgm-font-body, sans-serif);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.jc-input:focus {
    border-color: var(--tgm-qa-border, #3498db);
    box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}
.jc-input::placeholder {
    color: var(--tgm-input-placeholder, #aaa);
}
.jc-send {
    background: var(--tgm-header-bg, #2c3e50);
    border: none;
    border-radius: 10px;
    padding: 9px 12px;
    color: var(--tgm-header-title, #fff);
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: transform 0.15s ease, opacity 0.15s;
}
.jc-send:hover {
    opacity: 0.85;
    transform: scale(1.05);
}
.jc-send:active {
    transform: scale(0.95);
}

/* ══════════════════════════════════════════════
   MOBILE RESPONSIVE
   ══════════════════════════════════════════════ */
@media (max-width: 420px) {
    .jc-window {
        width: calc(100vw - 16px);
        right: 8px !important;
        left: 8px !important;
        bottom: 90px;
        max-height: calc(100vh - 100px);
        border-radius: 14px;
    }
    .jc-launcher {
        bottom: 16px;
    }
    .jc-launcher--round {
        width: calc(var(--tgm-launcher-size, 60px) * 0.93);
        height: calc(var(--tgm-launcher-size, 60px) * 0.93);
    }
    .jc-pos-right.jc-launcher { right: 16px; }
    .jc-pos-left.jc-launcher  { left: 16px; }

    .jc-header { padding: 12px 14px; }
    .jc-messages { padding: 12px; }
    .jc-replies { padding: 6px 12px 12px; }

    .jc-replies .jc-reply-btn {
        padding: 12px 14px;
        font-size: 15px;
        min-height: 44px;
    }
    .jc-cta-card .jc-cta-btn {
        padding: 13px 14px;
        min-height: 44px;
    }
}

/* ══════════════════════════════════════════════
   ACCESSIBILITY
   ══════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
    .jc-launcher,
    .jc-launcher-icon,
    .jc-launcher-ping,
    .jc-launcher-text,
    .jc-window,
    .jc-msg,
    .jc-typing-dot,
    .jc-status-dot,
    .jc-replies,
    .jc-cta-card,
    .jc-replies .jc-reply-btn,
    .jc-cta-card .jc-cta-btn {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ══════════════════════════════════════════════
   EMAIL CAPTURE (Kit Integration)
   ══════════════════════════════════════════════ */
.jc-email-capture {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 0;
}

.jc-email-input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--tgm-input-border, rgba(0, 0, 0, 0.15));
    border-radius: 8px;
    font-size: 14px;
    font-family: var(--tgm-font-body, sans-serif);
    background: var(--tgm-input-bg, #fff);
    color: var(--tgm-input-text, #333);
    outline: none;
    transition: border-color 0.15s;
}

.jc-email-input:focus {
    border-color: var(--tgm-qa-border, #3498db);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

.jc-email-input::placeholder {
    color: var(--tgm-input-placeholder, #aaa);
}

.jc-email-submit {
    background: var(--tgm-cta-bg, #e67e22) !important;
    color: var(--tgm-cta-text, #fff) !important;
    border-color: var(--tgm-cta-bg, #e67e22) !important;
    font-weight: 600;
}

.jc-email-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.jc-email-status {
    font-size: 12px;
    min-height: 16px;
    padding: 0 2px;
    font-family: var(--tgm-font-body, sans-serif);
}
