/* ==========================================================================
   Fuzzitech AI Chatbot Widget
   Matches theme palette: navy (#031C48), red (#DC143C), Inter font.
   ========================================================================== */

#fz-chat-bubble,
#fz-chat-panel {
    /* brand palette */
    --fz-navy:       #031C48;
    --fz-navy-dark:  #081D50;
    --fz-navy-light: #16327A;
    --fz-red:        #DC143C;
    --fz-red-dark:   #B91130;
    --fz-gray-50:    #F9FAFB;
    --fz-gray-100:   #F3F4F6;
    --fz-gray-200:   #E5E7EB;
    --fz-gray-300:   #D1D5DB;
    --fz-gray-400:   #9CA3AF;
    --fz-gray-700:   #374151;
    --fz-gray-900:   #111827;

    /* admin-overridable primary colour */
    --fz-primary:    var(--fz-chat-colour, var(--fz-navy));

    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    box-sizing: border-box;
}

#fz-chat-bubble *,
#fz-chat-panel * {
    box-sizing: border-box;
}

/* ==========================================================================
   BUBBLE
   ========================================================================== */
#fz-chat-bubble {
    position: fixed;
    z-index: 999999;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--fz-navy-light) 0%, var(--fz-primary) 100%);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    color: #fff;
    box-shadow:
        0 10px 30px -8px rgba(3, 28, 72, 0.45),
        0 4px 12px rgba(0, 0, 0, 0.12);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-radius 0.2s ease;
}

#fz-chat-bubble:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow:
        0 14px 36px -8px rgba(3, 28, 72, 0.55),
        0 6px 16px rgba(0, 0, 0, 0.18);
}

#fz-chat-bubble:focus-visible {
    outline: 3px solid var(--fz-red);
    outline-offset: 3px;
}

#fz-chat-bubble.fz-pos-bottom-left {
    right: auto;
    left: 24px;
}

.fz-bubble-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#fz-chat-bubble svg {
    width: 26px;
    height: 26px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

#fz-chat-bubble .fz-bubble-label {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    margin-left: 10px;
    font-family: inherit;
    color: #fff;
}

#fz-chat-bubble.fz-has-label {
    width: auto;
    height: 56px;
    border-radius: 28px;
    padding: 0 22px 0 18px;
    gap: 0;
}

/* Pulse (opt-in only) */
@keyframes fz-chat-pulse {
    0%   { box-shadow: 0 10px 30px -8px rgba(3,28,72,0.45), 0 0 0 0 rgba(220,20,60,0.5); }
    70%  { box-shadow: 0 10px 30px -8px rgba(3,28,72,0.45), 0 0 0 14px rgba(220,20,60,0); }
    100% { box-shadow: 0 10px 30px -8px rgba(3,28,72,0.45), 0 0 0 0 rgba(220,20,60,0); }
}

#fz-chat-bubble.fz-anim-pulse {
    animation: fz-chat-pulse 2.2s infinite;
}

/* Hide bubble when panel open */
#fz-chat-bubble.fz-bubble-hidden {
    transform: scale(0) translateY(20px);
    pointer-events: none;
    opacity: 0;
}

/* ==========================================================================
   PANEL
   ========================================================================== */
#fz-chat-panel {
    position: fixed;
    z-index: 999998;
    bottom: 24px;
    right: 24px;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 48px);
    background: #fff;
    border-radius: 18px;
    box-shadow:
        0 24px 56px -12px rgba(3, 28, 72, 0.35),
        0 8px 20px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1),
                opacity 0.2s ease;
    color: var(--fz-gray-900);
}

#fz-chat-panel.fz-pos-bottom-left {
    right: auto;
    left: 24px;
    transform-origin: bottom left;
}

#fz-chat-panel.fz-hidden {
    transform: scale(0.9) translateY(16px);
    opacity: 0;
    pointer-events: none;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
#fz-chat-header {
    position: relative;
    background: linear-gradient(135deg, var(--fz-navy-light) 0%, var(--fz-primary) 100%);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    overflow: hidden;
}

/* Decorative gradient glow overlay */
#fz-chat-header::after {
    content: '';
    position: absolute;
    top: -40px;
    right: -40px;
    width: 140px;
    height: 140px;
    background: radial-gradient(circle, rgba(220,20,60,0.25) 0%, transparent 70%);
    pointer-events: none;
}

.fz-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 1;
}

.fz-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.fz-header-avatar svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: #fff;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.fz-header-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.fz-header-text h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.01em;
    font-family: inherit;
}

.fz-header-status {
    margin: 2px 0 0;
    font-size: 11px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.fz-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
    display: inline-block;
    animation: fz-pulse-dot 2s ease-in-out infinite;
}

@keyframes fz-pulse-dot {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.55; }
}

#fz-chat-close {
    position: relative;
    z-index: 1;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
}

#fz-chat-close:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

#fz-chat-close svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}

/* Header actions (expand + close buttons) */
.fz-header-actions {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#fz-chat-expand {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
}

#fz-chat-expand:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

#fz-chat-expand svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    display: block;
}

/* Expanded (full-screen-ish) mode: takes ~90% of viewport */
#fz-chat-panel.fz-expanded {
    width: min(960px, calc(100vw - 48px));
    height: calc(100vh - 48px);
    max-height: calc(100vh - 48px);
    border-radius: 18px;
}

/* ==========================================================================
   MESSAGES
   ========================================================================== */
#fz-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background:
        radial-gradient(at 30% 10%, rgba(22, 50, 122, 0.04) 0%, transparent 50%),
        radial-gradient(at 80% 90%, rgba(220, 20, 60, 0.03) 0%, transparent 50%),
        #fff;
    /* Firefox scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--fz-chat-colour, var(--fz-primary)) transparent;
}

/* Scrollbar (WebKit) - matches the chatbot theme colour */
#fz-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#fz-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#fz-chat-messages::-webkit-scrollbar-thumb {
    background: var(--fz-chat-colour, var(--fz-primary));
    border-radius: 3px;
    opacity: 0.6;
}

#fz-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--fz-chat-colour, var(--fz-primary));
    opacity: 1;
}

/* Bubbles */
.fz-msg {
    max-width: 82%;
    padding: 11px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: fz-msg-in 0.25s cubic-bezier(0.22, 1, 0.36, 1);
    font-family: inherit;
}

@keyframes fz-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fz-msg-user {
    background: linear-gradient(135deg, var(--fz-red) 0%, var(--fz-red-dark) 100%);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px -4px rgba(220, 20, 60, 0.35);
}

.fz-msg-assistant {
    background: var(--fz-gray-100);
    color: var(--fz-gray-900);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--fz-gray-200);
}

.fz-msg-assistant a {
    color: var(--fz-red);
    text-decoration: underline;
    font-weight: 500;
    word-break: break-word;
}
.fz-msg-assistant a:hover { color: var(--fz-red-dark); text-decoration: none; }
.fz-msg-assistant strong { font-weight: 600; }
.fz-msg-assistant code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Typing indicator */
.fz-typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 12px 14px;
    background: var(--fz-gray-100);
    border: 1px solid var(--fz-gray-200);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    width: auto;
}

.fz-typing span {
    width: 7px;
    height: 7px;
    background: var(--fz-gray-400);
    border-radius: 50%;
    animation: fz-bounce 1.2s infinite;
    flex-shrink: 0;
}

.fz-typing span:nth-child(2) { animation-delay: 0.15s; }
.fz-typing span:nth-child(3) { animation-delay: 0.30s; }

@keyframes fz-bounce {
    0%, 60%, 100% { transform: translateY(0);     opacity: 0.5; }
    30%           { transform: translateY(-5px);  opacity: 1;   }
}

/* Error */
.fz-error-msg {
    align-self: center;
    font-size: 12px;
    color: var(--fz-red-dark);
    background: rgba(220, 20, 60, 0.08);
    border: 1px solid rgba(220, 20, 60, 0.2);
    padding: 8px 12px;
    border-radius: 8px;
    max-width: 90%;
    text-align: center;
}

/* ==========================================================================
   LEAD PROMPT
   ========================================================================== */
#fz-chat-lead-prompt {
    display: none;
    padding: 14px 16px;
    background: linear-gradient(135deg, rgba(3,28,72,0.04) 0%, rgba(220,20,60,0.04) 100%);
    border-top: 1px solid var(--fz-gray-200);
    font-size: 13px;
    flex-shrink: 0;
}

#fz-chat-lead-prompt.fz-visible {
    display: block;
    animation: fz-msg-in 0.25s ease;
}

#fz-chat-lead-prompt p {
    margin: 0 0 10px;
    color: var(--fz-gray-700);
    font-weight: 500;
    font-family: inherit;
}

.fz-lead-field {
    display: flex;
    gap: 6px;
}

#fz-chat-lead-email {
    flex: 1;
    padding: 9px 11px;
    border: 1px solid var(--fz-gray-300);
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    background: #fff;
    font-family: inherit;
    color: var(--fz-gray-900);
    transition: border-color 0.15s, box-shadow 0.15s;
}

#fz-chat-lead-email:focus {
    border-color: var(--fz-primary);
    box-shadow: 0 0 0 3px rgba(3, 28, 72, 0.08);
}

#fz-chat-lead-submit {
    padding: 9px 16px;
    background: var(--fz-red);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
    font-family: inherit;
}

#fz-chat-lead-submit:hover {
    background: var(--fz-red-dark);
    transform: translateY(-1px);
}

.fz-lead-skip {
    margin-top: 8px;
    background: none;
    border: none;
    color: var(--fz-gray-400);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 0;
    font-family: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.fz-lead-skip:hover {
    color: var(--fz-gray-700);
}

/* ==========================================================================
   INPUT AREA
   ========================================================================== */
#fz-chat-input-area {
    padding: 12px 14px;
    border-top: 1px solid var(--fz-gray-200);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: #fff;
}

#fz-chat-input {
    flex: 1;
    border: 1px solid var(--fz-gray-300);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: var(--fz-gray-50);
    color: var(--fz-gray-900);
}

#fz-chat-input::placeholder {
    color: var(--fz-gray-400);
}

#fz-chat-input:focus {
    border-color: var(--fz-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(3, 28, 72, 0.08);
}

#fz-chat-send {
    background: linear-gradient(135deg, var(--fz-red) 0%, var(--fz-red-dark) 100%);
    color: #fff;
    border: none;
    border-radius: 12px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
    box-shadow: 0 4px 10px -2px rgba(220, 20, 60, 0.4);
}

#fz-chat-send:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px -2px rgba(220, 20, 60, 0.5);
}

#fz-chat-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}

#fz-chat-send svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    stroke: none;
    transform: translateX(1px);
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
#fz-chat-footer {
    padding: 8px 14px;
    background: var(--fz-gray-50);
    border-top: 1px solid var(--fz-gray-200);
    text-align: center;
    font-size: 10px;
    color: var(--fz-gray-400);
    letter-spacing: 0.03em;
    font-family: inherit;
    flex-shrink: 0;
}

#fz-chat-footer strong {
    color: var(--fz-gray-700);
    font-weight: 600;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 480px) {
    #fz-chat-bubble {
        bottom: 18px;
        right: 18px;
        width: 54px;
        height: 54px;
    }
    #fz-chat-bubble.fz-pos-bottom-left {
        left: 18px;
        right: auto;
    }
    #fz-chat-panel {
        width: calc(100vw - 16px);
        height: calc(100vh - 90px);
        bottom: 14px;
        right: 8px;
        border-radius: 16px;
    }
    #fz-chat-panel.fz-pos-bottom-left {
        left: 8px;
        right: auto;
    }
    .fz-msg {
        max-width: 88%;
    }
}

/* ==========================================================================
   SUGGESTED QUESTIONS
   ========================================================================== */
.fz-suggested-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    align-self: flex-start;
    padding: 4px 0 2px;
    max-width: 92%;
    animation: fz-msg-in 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.fz-suggested-btn {
    background: #fff;
    border: 1.5px solid var(--fz-primary);
    color: var(--fz-primary);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.3;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    text-align: left;
}

.fz-suggested-btn:hover {
    background: var(--fz-primary);
    color: #fff;
}

/* ==========================================================================
   REDUCED MOTION
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    #fz-chat-bubble,
    #fz-chat-panel,
    .fz-msg,
    .fz-suggested-questions,
    .fz-status-dot,
    .fz-typing span,
    #fz-chat-send,
    #fz-chat-lead-submit,
    .fz-suggested-btn {
        animation: none !important;
        transition: none !important;
    }
}
