/* ============================================================
 * Approval Guru Concierge Widget
 * Self-contained, dark luxe theme, works on both marketing
 * and transactional pages without conflicts.
 * ============================================================ */

#ag-chat,
#ag-chat * {
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

#ag-chat {
    --ag-gold: #D4AF37;
    --ag-gold-bright: #F0CC60;
    --ag-gold-deep: #9C7E1A;
    --ag-gold-grad: linear-gradient(135deg, #F4D77D 0%, #D4AF37 50%, #9C7E1A 100%);
    --ag-bg: #0A0F1C;
    --ag-bg-elev: #161E2E;
    --ag-bg-soft: #1B2438;
    --ag-line: rgba(255,255,255,0.08);
    --ag-line-strong: rgba(255,255,255,0.14);
    --ag-text: #F2F5FA;
    --ag-text-mute: #A6AEBE;
    --ag-text-dim: #6B7387;
    --ag-success: #4ADE80;

    position: fixed;
    z-index: 9000;
    bottom: max(20px, env(safe-area-inset-bottom));
    right: max(20px, env(safe-area-inset-right));
    pointer-events: none;
}

#ag-chat * { pointer-events: auto; }

/* ===== Floating Action Button ===== */
.ag-fab {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--ag-gold-grad);
    border: 2px solid rgba(255,255,255,0.15);
    color: #1A1308;
    cursor: pointer;
    box-shadow:
        0 12px 28px -6px rgba(212,175,55,0.5),
        0 4px 12px rgba(0,0,0,0.25),
        inset 0 1px 0 rgba(255,255,255,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1), box-shadow 0.25s;
    position: relative;
    overflow: visible;
}
.ag-fab:hover {
    transform: scale(1.06);
    box-shadow:
        0 16px 36px -6px rgba(212,175,55,0.65),
        0 6px 14px rgba(0,0,0,0.3),
        inset 0 1px 0 rgba(255,255,255,0.45);
}
.ag-fab:active { transform: scale(0.97); }
.ag-fab svg { width: 26px; height: 26px; display: block; position: relative; z-index: 2; }

/* Pulse ring */
.ag-fab::before,
.ag-fab::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--ag-gold);
    opacity: 0;
}
.ag-fab.is-pulsing::before { animation: agPulse 2.4s cubic-bezier(0.4,0,0.2,1) infinite; }
.ag-fab.is-pulsing::after  { animation: agPulse 2.4s cubic-bezier(0.4,0,0.2,1) infinite 1.2s; }
@keyframes agPulse {
    0%   { transform: scale(0.95); opacity: 0.6; }
    100% { transform: scale(1.5);  opacity: 0; }
}

/* Welcome bubble (auto-pops on first visit) */
.ag-welcome {
    position: absolute;
    bottom: calc(100% + 14px);
    right: 0;
    background: var(--ag-bg-elev);
    color: var(--ag-text);
    border: 1px solid var(--ag-line-strong);
    border-radius: 14px;
    padding: 14px 38px 14px 16px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    width: 240px;
    box-shadow: 0 18px 40px -10px rgba(0,0,0,0.5);
    opacity: 0;
    transform: translateY(8px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}
.ag-welcome.is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.ag-welcome::after {
    content: '';
    position: absolute;
    bottom: -7px;
    right: 24px;
    width: 14px;
    height: 14px;
    background: var(--ag-bg-elev);
    border-right: 1px solid var(--ag-line-strong);
    border-bottom: 1px solid var(--ag-line-strong);
    transform: rotate(45deg);
}
.ag-welcome-close {
    position: absolute;
    top: 6px;
    right: 6px;
    background: none;
    border: none;
    color: var(--ag-text-dim);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    width: 24px; height: 24px;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
}
.ag-welcome-close:hover { color: var(--ag-text); background: rgba(255,255,255,0.06); }

/* ===== Panel ===== */
.ag-panel {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 380px;
    height: 580px;
    max-height: calc(100vh - 40px);
    background: linear-gradient(180deg, var(--ag-bg) 0%, #050810 100%);
    border: 1px solid var(--ag-line-strong);
    border-radius: 20px;
    box-shadow:
        0 30px 80px -20px rgba(0,0,0,0.7),
        0 8px 24px rgba(0,0,0,0.3);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.96);
    transform-origin: bottom right;
    opacity: 0;
    transition: opacity 0.28s cubic-bezier(0.4,0,0.2,1), transform 0.28s cubic-bezier(0.4,0,0.2,1);
}
#ag-chat.is-open .ag-panel {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}
#ag-chat.is-open .ag-fab { transform: scale(0.92); opacity: 0.6; }

/* ===== Header ===== */
.ag-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    background: linear-gradient(180deg, var(--ag-bg-elev) 0%, transparent 100%);
    border-bottom: 1px solid var(--ag-line);
    flex-shrink: 0;
}

.ag-avatar {
    position: relative;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--ag-gold-grad);
    color: #1A1308;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
    letter-spacing: 0.02em;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.15);
    box-shadow: 0 4px 12px -2px rgba(212,175,55,0.4);
}
.ag-online-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--ag-success);
    border: 2.5px solid var(--ag-bg-elev);
    box-shadow: 0 0 8px rgba(74,222,128,0.6);
}

.ag-titles { flex: 1; min-width: 0; }
.ag-titles strong {
    display: block;
    font-size: 15px;
    color: var(--ag-text);
    font-weight: 700;
    letter-spacing: -0.01em;
}
.ag-titles span {
    display: block;
    font-size: 12.5px;
    color: var(--ag-text-mute);
    margin-top: 2px;
}

.ag-close {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--ag-line);
    color: var(--ag-text-mute);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}
.ag-close:hover {
    color: var(--ag-text);
    background: rgba(255,255,255,0.08);
    border-color: var(--ag-line-strong);
}

/* ===== Body ===== */
.ag-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.ag-body::-webkit-scrollbar { width: 6px; }
.ag-body::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
}

/* ===== Messages ===== */
.ag-msg {
    display: flex;
    gap: 10px;
    max-width: 86%;
    animation: agMsgIn 0.3s cubic-bezier(0.4,0,0.2,1);
}
@keyframes agMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ag-msg-bot { align-self: flex-start; }
.ag-msg-user { align-self: flex-end; flex-direction: row-reverse; }

.ag-msg-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--ag-gold-grad);
    color: #1A1308;
    font-size: 11px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: auto;
}

.ag-bubble {
    padding: 11px 15px;
    border-radius: 16px;
    font-size: 14.5px;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.ag-msg-bot .ag-bubble {
    background: var(--ag-bg-elev);
    color: var(--ag-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--ag-line);
}
.ag-msg-user .ag-bubble {
    background: var(--ag-gold-grad);
    color: #1A1308;
    border-bottom-right-radius: 4px;
    font-weight: 600;
}

/* Typing indicator */
.ag-typing { display: flex; gap: 4px; padding: 4px 0; }
.ag-typing span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--ag-text-dim);
    animation: agTyping 1.2s infinite ease-in-out;
}
.ag-typing span:nth-child(2) { animation-delay: 0.15s; }
.ag-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes agTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ===== Quick Replies ===== */
.ag-quick {
    padding: 0 18px 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
}
.ag-quick:empty { display: none; }

.ag-chip {
    padding: 9px 14px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--ag-line-strong);
    color: var(--ag-text);
    border-radius: 999px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}
.ag-chip:hover {
    background: rgba(212,175,55,0.1);
    border-color: var(--ag-gold);
    color: var(--ag-gold-bright);
}
.ag-chip:active { transform: scale(0.97); }

.ag-cta-wa {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px 20px;
    background: var(--ag-gold-grad);
    color: #1A1308;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 8px 22px -6px rgba(212,175,55,0.5), inset 0 1px 0 rgba(255,255,255,0.3);
    font-family: inherit;
    text-decoration: none;
    margin: 8px 0 4px;
    min-height: 50px;
}
.ag-cta-wa:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 28px -6px rgba(212,175,55,0.65), inset 0 1px 0 rgba(255,255,255,0.35);
}
.ag-cta-wa:active { transform: translateY(0); }
.ag-cta-wa svg { width: 20px; height: 20px; flex-shrink: 0; }

/* ===== Input ===== */
.ag-input-row {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--ag-line);
    background: var(--ag-bg);
    flex-shrink: 0;
}

.ag-input {
    flex: 1;
    padding: 12px 14px;
    background: var(--ag-bg-elev);
    border: 1px solid var(--ag-line-strong);
    border-radius: 999px;
    color: var(--ag-text);
    /* 16px prevents iOS zoom on focus */
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
    min-height: 44px;
}
.ag-input:focus { border-color: var(--ag-gold); }
.ag-input::placeholder { color: var(--ag-text-dim); }

.ag-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--ag-gold-grad);
    color: #1A1308;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, opacity 0.15s;
    box-shadow: 0 4px 12px -2px rgba(212,175,55,0.4);
}
.ag-send:hover { transform: scale(1.05); }
.ag-send:active { transform: scale(0.95); }
.ag-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.ag-send svg { width: 18px; height: 18px; }

/* ===== Footer ===== */
.ag-foot {
    padding: 8px 16px 12px;
    text-align: center;
    font-size: 11px;
    color: var(--ag-text-dim);
    background: var(--ag-bg);
    flex-shrink: 0;
    letter-spacing: 0.02em;
}
.ag-foot strong { color: var(--ag-text-mute); font-weight: 600; }

/* ===== Mobile ===== */
@media (max-width: 480px) {
    #ag-chat {
        bottom: max(16px, env(safe-area-inset-bottom));
        right: max(16px, env(safe-area-inset-right));
    }
    .ag-fab { width: 58px; height: 58px; }
    .ag-fab svg { width: 24px; height: 24px; }
    .ag-panel {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: auto;
        height: 90vh;
        max-height: 100vh;
        border-radius: 20px 20px 0 0;
    }
    .ag-welcome { width: 220px; font-size: 13.5px; }
}
