@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ─── Scope Reset ─────────────────────────────────────────────────────────── */
#peace-ai-widget,
#peace-ai-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

#peace-ai-widget {
    font-family: var(--font-body, 'Inter'), system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOGGLE BUTTON — fixed bottom-right
═══════════════════════════════════════════════════════════════════════════ */
#peace-ai-fab {
    position: fixed;
    bottom: 32px;
    right: 100px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--navy-accent, #3F5E96), var(--accent-blue, #4f8ef7));
    box-shadow: 0 8px 22px rgba(63, 94, 150, 0.45), 0 0 16px rgba(0, 212, 255, 0.14);
    color: white;
    font-size: 22px;
    cursor: pointer;
    border: none;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.3s ease;
    outline: none;
}

#peace-ai-fab:hover {
    transform: translateY(-3px) scale(1.07);
}

#peace-ai-fab:active {
    transform: scale(0.95);
}

#peace-ai-fab svg {
    width: 24px;
    height: 24px;
    fill: #fff;
    position: absolute;
    transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#peace-ai-fab svg.icon-chat {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

#peace-ai-fab svg.icon-close {
    opacity: 0;
    transform: scale(0.3) rotate(90deg);
}

#peace-ai-fab.open svg.icon-chat {
    opacity: 0;
    transform: scale(0.3) rotate(-90deg);
}

#peace-ai-fab.open svg.icon-close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

/* ═══════════════════════════════════════════════════════════════════════════
   CHAT WINDOW — Desktop: 360 × 560px
═══════════════════════════════════════════════════════════════════════════ */
#peace-ai-window {
    position: fixed;
    bottom: 96px;
    right: 100px;
    width: 376px;
    height: 600px;
    max-height: calc(100vh - 116px); /* never clip on short screens */
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42), 0 0 20px rgba(63, 94, 150, 0.16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(13, 21, 32, 0.9) 0%, rgba(10, 17, 27, 0.95) 100%);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    isolation: isolate;
    z-index: 99998;
    /* closed state */
    transform: scale(0.9) translateY(16px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
        opacity 0.25s ease,
        visibility 0s linear 0.35s;
    transform-origin: bottom right;
}

#peace-ai-window::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 18% 8%, rgba(79, 142, 247, 0.2) 0%, transparent 42%),
        radial-gradient(circle at 86% 82%, rgba(124, 58, 237, 0.16) 0%, transparent 36%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, rgba(255, 255, 255, 0) 34%);
    pointer-events: none;
    z-index: 0;
}

#peace-ai-window::after {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 0 24px rgba(79, 142, 247, 0.14);
    pointer-events: none;
    z-index: 0;
}

#peace-ai-window > * {
    position: relative;
    z-index: 1;
}

#peace-ai-window.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: all;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
        opacity 0.25s ease,
        visibility 0s linear 0s;
}

/* ─── Header ──────────────────────────────────────────────────────────────── */
.pi-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 52px;
    padding: 7px 12px;
    background: linear-gradient(120deg, rgba(63, 94, 150, 0.92) 0%, rgba(30, 45, 72, 0.94) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.06);
}

.pi-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #ffffff;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3px;
}

.pi-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    border-radius: 50%;
}

.pi-header-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.pi-header-name {
    color: #ffffff;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.2;
}

.pi-header-status {
    color: #7cf6d9;
    font-size: 10px;
    margin-top: 1px;
}

.pi-header-close {
    margin-left: auto;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: #ffffff;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.2s ease, transform 0.2s ease;
    outline: none;
    flex-shrink: 0;
}

.pi-header-close:hover {
    background: rgba(255, 255, 255, 0.16);
    transform: rotate(90deg);
}

/* ─── Messages Area ───────────────────────────────────────────────────────── */
.pi-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 0;
    background:
        linear-gradient(180deg, rgba(8, 14, 24, 0.68) 0%, rgba(8, 14, 24, 0.86) 100%),
        radial-gradient(circle at 20% 0%, rgba(79, 142, 247, 0.08) 0%, transparent 35%);
    min-height: 0;
    scroll-behavior: smooth;
}

.pi-messages::-webkit-scrollbar {
    width: 4px;
}

.pi-messages::-webkit-scrollbar-track {
    background: transparent;
}

.pi-messages::-webkit-scrollbar-thumb {
    background: rgba(91, 126, 199, 0.38);
    border-radius: 4px;
}

.pi-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(91, 126, 199, 0.56);
}

/* message row wrapper */
.pi-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: pi-msg-in 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    padding: 0 4px;
    margin-bottom: 12px;
}

.pi-msg:last-child {
    margin-bottom: 0;
}

@keyframes pi-msg-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pi-msg.user {
    flex-direction: row-reverse;
}

/* mini bot avatar left of bot bubble */
.pi-msg-mini-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-end;
    overflow: hidden;
    padding: 2px;
}

.pi-msg-mini-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    border-radius: 50%;
}

.pi-msg.user .pi-msg-mini-avatar {
    display: none;
}

/* bubble column (bubble + timestamp) */
.pi-bubble-col {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-width: 82%;
}

.pi-msg.user .pi-bubble-col {
    max-width: 75%;
    align-items: flex-end;
    margin-left: auto;
}

/* bot bubble */
.pi-msg.bot .pi-bubble {
    background: linear-gradient(150deg, rgba(30, 45, 72, 0.72) 0%, rgba(20, 30, 48, 0.82) 100%);
    color: #e8f0ff;
    border: 1px solid rgba(91, 126, 199, 0.35);
    border-radius: 14px;
    padding: 14px 17px;
    font-size: 13.5px;
    line-height: 1.68;
    letter-spacing: 0.01em;
    margin-bottom: 2px;
    display: inline-block;
    word-wrap: break-word;
    word-break: break-word;
    box-shadow: 0 8px 22px rgba(7, 12, 20, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* user bubble */
.pi-msg.user .pi-bubble {
    background: linear-gradient(135deg, var(--navy-accent, #3F5E96), var(--accent-blue, #4f8ef7));
    color: #ffffff;
    border: 1px solid rgba(0, 212, 255, 0.22);
    border-radius: 14px;
    padding: 14px 17px;
    font-size: 13.5px;
    line-height: 1.66;
    letter-spacing: 0.01em;
    display: block;
    margin-left: auto;
    word-wrap: break-word;
    word-break: break-word;
    box-shadow: 0 8px 20px rgba(15, 26, 44, 0.36), 0 0 12px rgba(0, 212, 255, 0.15);
}

/* timestamp */
.pi-timestamp {
    font-size: 10px;
    color: rgba(148, 163, 184, 0.72);
    padding: 0 4px;
    margin-top: 1px;
    white-space: nowrap;
}

.pi-msg.user .pi-timestamp {
    text-align: right;
}

/* typing indicator */
.pi-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 0;
}

.pi-typing span {
    width: 6px;
    height: 6px;
    background: #7c3aed;
    border-radius: 50%;
    animation: pi-bounce 1.4s ease-in-out infinite;
    opacity: 0.5;
}

.pi-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.pi-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pi-bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ─── Suggestion Chips In Message Flow ──────────────────────────────────── */
.pi-msg-suggestions {
    align-items: flex-start;
}

.pi-msg.bot .pi-bubble.pi-suggest-bubble {
    padding: 12px 13px;
    border-radius: 14px;
    background: linear-gradient(150deg, rgba(26, 39, 64, 0.66) 0%, rgba(17, 27, 43, 0.8) 100%);
}

.pi-suggest-label {
    font-size: 11px;
    color: rgba(203, 213, 225, 0.88);
    margin-bottom: 9px;
    letter-spacing: 0.02em;
}

.pi-suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pi-quick-replies {
    display: none !important;
}

.pi-qr {
    background: rgba(63, 94, 150, 0.18);
    border: 1px solid rgba(91, 126, 199, 0.4);
    color: rgba(225, 235, 255, 0.82);
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 11px;
    line-height: 1.25;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
    outline: none;
    white-space: nowrap;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.pi-qr:hover {
    background: rgba(63, 94, 150, 0.32);
    border-color: rgba(0, 212, 255, 0.38);
    color: #ffffff;
    transform: translateY(-1px) scale(1.03);
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.16);
}

.pi-qr:active {
    transform: scale(0.96);
}

/* ─── Input Area ──────────────────────────────────────────────────────────── */
.pi-input-area {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px 14px;
    background: linear-gradient(180deg, rgba(12, 20, 32, 0.9) 0%, rgba(10, 17, 27, 0.96) 100%);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.pi-input-wrap {
    flex: 1;
    border: 1px solid rgba(91, 126, 199, 0.42);
    border-radius: 14px;
    background: rgba(30, 45, 72, 0.52);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;
    min-width: 0;
    min-height: 50px;
    box-shadow: inset 0 2px 4px rgba(2, 6, 23, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.015);
}

.pi-input-wrap:focus-within {
    border-color: rgba(0, 212, 255, 0.55);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.12);
}

.pi-input {
    display: block;
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: #e2e8f0;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.6;
    padding: 14px 16px !important;
    resize: none;
    min-height: 50px;
    max-height: 96px;
}

.pi-input::placeholder {
    color: #64748b;
}

.pi-send {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--navy-accent, #3F5E96), var(--accent-blue, #4f8ef7));
    border: none;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    outline: none;
    border: 1px solid rgba(0, 212, 255, 0.24);
    margin-right: 0;
    transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
        box-shadow 0.22s ease;
}

.pi-send:hover {
    transform: translateY(-2px) scale(1.08);
    box-shadow: 0 8px 18px rgba(63, 94, 150, 0.45), 0 0 14px rgba(0, 212, 255, 0.24);
}

.pi-send:focus-visible {
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.22), 0 8px 18px rgba(63, 94, 150, 0.45);
}

.pi-send:active {
    transform: scale(0.95);
}

.pi-send:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.pi-send svg {
    width: 17px;
    height: 17px;
    fill: #fff;
}

/* ─── Lead Banner ─────────────────────────────────────────────────────────── */
.pi-lead-banner {
    flex-shrink: 0;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: 10px;
    padding: 10px 14px;
    color: #4ade80;
    font-size: 13px;
    font-weight: 500;
    margin: 8px 14px 0;
    text-align: center;
}

/* ─── WhatsApp CTA ───────────────────────────────────────────────────────── */
.pi-wa-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
    padding: 11px 16px;
    background: #25D366;
    color: #ffffff;
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 600;
    font-family: 'Inter', system-ui, sans-serif;
    border-radius: 10px;
    margin-top: 8px;
    transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 3px 12px rgba(37, 211, 102, 0.35);
}

.pi-wa-btn:hover {
    background: #1ebe57;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.45);
}

.pi-wa-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
    flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE ≤ 768px — full-screen widget
═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    #peace-ai-fab {
        bottom: calc(16px + env(safe-area-inset-bottom));
        right: calc(16px + env(safe-area-inset-right));
        width: 48px;
        height: 48px;
    }

    #peace-ai-fab.open {
        display: none;
    }

    #peace-ai-fab svg {
        width: 22px;
        height: 22px;
    }

    #peace-ai-window {
        /* fullscreen on mobile — keyboard-aware via 100dvh */
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        /* 100dvh shrinks automatically when virtual keyboard appears,
           so the window never gets pushed or resized awkwardly */
        height: 100dvh;
        /* Fallback for browsers that don't support dvh */
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        border: none;
        transform-origin: bottom center;
        box-shadow: none;
        /* Lock the layout: header fixed top, input fixed bottom,
           messages scroll in between */
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .pi-header {
        flex-shrink: 0;
        min-height: 54px;
        padding: 10px 14px;
        /* Push content below status bar on notch devices */
        padding-top: calc(10px + env(safe-area-inset-top));
    }

    .pi-messages {
        /* Fills all available space between header and input */
        flex: 1;
        min-height: 0;   /* critical — prevents flex child from overflowing */
        overflow-y: auto;
        /* generous top padding so first message isn't jammed under header */
        padding: 20px 14px 18px;
    }

    .pi-bubble-col {
        max-width: 92%;
    }

    .pi-msg.user .pi-bubble-col {
        max-width: 88%;
    }

    .pi-msg.bot .pi-bubble,
    .pi-msg.user .pi-bubble {
        font-size: 14px;
        line-height: 1.7;
        padding: 13px 15px;
        border-radius: 13px;
    }

    .pi-msg-mini-avatar {
        width: 24px;
        height: 24px;
    }

    .pi-timestamp {
        font-size: 9.5px;
        margin-top: 0;
    }

    .pi-msg.bot .pi-bubble.pi-suggest-bubble {
        padding: 11px 12px;
    }

    .pi-suggest-label {
        margin-bottom: 8px;
    }

    .pi-suggestion-chips {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .pi-qr {
        width: 100%;
        justify-content: center;
        font-size: 10px;
        padding: 8px 10px;
    }

    .pi-input-area {
        flex-shrink: 0;
        padding: 11px 12px calc(14px + env(safe-area-inset-bottom));
    }

    .pi-lead-banner {
        margin: 8px 12px 0;
        border-radius: 12px;
    }
}

/* ≤ 480px — very small phones */
@media (max-width: 480px) {
    #peace-ai-fab {
        bottom: calc(14px + env(safe-area-inset-bottom));
        right: calc(14px + env(safe-area-inset-right));
    }

    .pi-header-name {
        font-size: 13px;
    }

    .pi-header-status {
        font-size: 9.5px;
    }

    .pi-messages {
        padding: 14px 12px 16px;
    }

    .pi-suggestion-chips {
        grid-template-columns: 1fr 1fr;
    }

    .pi-input {
        font-size: 13.5px;
    }
}