/* Theme Variables fallback */
:root {
    --gsc-navy: #151B4D;
    --gsc-navy-deep: #10143C;
    --gsc-blue: #2563EB;
    --gsc-orange: #F97316;
    --gsc-border: #E5E7EB;
    --gsc-text: #1F2937;
    --gsc-text-muted: #6B7280;
}

/* Floating Action Button (FAB 3 bulles) */
.fab-widget {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 96;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    --fab-icon-size: 24px;
}
.fab-options {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(14px) scale(0.95);
    pointer-events: none;
    transition: opacity .25s ease, transform .25s ease, visibility .25s ease;
}
.fab-widget.open .fab-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.fab-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: #ffffff;
    color: #1F2937;
    padding: 8px 16px 8px 10px;
    border-radius: 999px;
    box-shadow: 0 10px 28px rgba(21, 27, 77, 0.14);
    border: 1px solid #E5E7EB;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 600;
    transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease;
}
.fab-pill:hover {
    transform: translateX(-3px) scale(1.03);
    box-shadow: 0 14px 34px rgba(21, 27, 77, 0.2);
    background: #fafcff;
}
.fab-pill-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: filter .18s ease;
}
.fab-icon-blue { background: #2563EB; }
.fab-icon-orange { background: #F97316; }
.fab-icon-slate { background: #151B4D; }

.fab-toggle {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #151B4D;
    color: #ffffff;
    border: none;
    box-shadow: 0 8px 24px rgba(21, 27, 77, 0.28);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform .2s ease, box-shadow .2s ease, background-color .2s ease;
}
.fab-toggle:hover {
    background: #E8792E;
    transform: scale(1.08);
    box-shadow: 0 12px 30px rgba(232, 121, 46, 0.4);
}
.fab-icon-default, .fab-icon-close {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--fab-icon-size, 24px);
    height: var(--fab-icon-size, 24px);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .2s ease, transform .2s ease;
}
.fab-icon-default { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.fab-icon-close { transform: translate(-50%, -50%) scale(.6); opacity: 0; }

.fab-widget.open .fab-icon-default { transform: translate(-50%, -50%) scale(.6); opacity: 0; }
.fab-widget.open .fab-icon-close { transform: translate(-50%, -50%) scale(1); opacity: 1; }

@media (max-width: 640px) {
    .fab-widget {
        right: 14px !important;
        bottom: calc(14px + env(safe-area-inset-bottom, 16px)) !important;
        left: auto !important;
        width: auto !important;
        align-items: flex-end !important;
    }
    .fab-options {
        flex-direction: column !important;
        align-items: flex-end !important;
        width: auto !important;
        background: transparent !important;
        padding: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        border: none !important;
    }
    .fab-pill {
        flex: initial !important;
        box-shadow: 0 10px 28px rgba(21, 27, 77, 0.18) !important;
        background: #ffffff !important;
        padding: 8px 16px 8px 10px !important;
        font-size: 0.88rem !important;
        border: 1px solid #E5E7EB !important;
        border-radius: 999px !important;
    }
    .fab-pill-icon {
        width: 32px !important;
        height: 32px !important;
    }
    .fab-toggle {
        display: flex !important;
        width: 48px !important;
        height: 48px !important;
    }
}

/* Chat Widget */
.chat-widget { position: fixed; left: 22px; bottom: 22px; z-index: 95; --chat-icon-size: 24px; }
.chat-widget.pos-right { left: auto; right: 22px; bottom: 96px; }
.chat-widget.pos-right .chat-panel { left: auto; right: 0; }
.chat-widget.pos-right .chat-attention-bubble { left: auto; right: 0; }

.chat-toggle {
    width: 56px; height: 56px; border-radius: 50%; background: #2563EB; color: #fff; border: none;
    box-shadow: 0 10px 28px rgba(37, 99, 235, 0.3); cursor: pointer; display: flex; align-items: center; justify-content: center; position: relative;
    transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease;
}
.chat-toggle:hover { background: #151B4D; transform: scale(1.07); box-shadow: 0 16px 36px rgba(21,27,77,.32); }
.chat-toggle-icon-default, .chat-toggle-icon-close {
    position: absolute; top: 50%; left: 50%; width: var(--chat-icon-size, 24px); height: var(--chat-icon-size, 24px);
    display: flex; align-items: center; justify-content: center;
    transition: opacity .2s ease, transform .2s ease;
}
.chat-toggle .icon { width: 100%; height: 100%; display: block; }

.chat-toggle::before {
    content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid #2563EB;
    opacity: 0; pointer-events: none;
}
.chat-widget.attention-pulse .chat-toggle::before { animation: chat-pulse-ring 1.8s ease-out 3; }
.chat-toggle.has-unread::after {
    content: ""; position: absolute; top: 2px; right: 2px; width: 12px; height: 12px; border-radius: 50%;
    background: #F97316; border: 2px solid #fff; animation: chat-unread-pulse 1.4s ease-in-out infinite;
}
@keyframes chat-unread-pulse { 50% { transform: scale(1.25); } }
@keyframes chat-pulse-ring {
    0% { transform: scale(.85); opacity: .7; }
    100% { transform: scale(1.35); opacity: 0; }
}

.chat-attention-bubble {
    position: absolute; bottom: 70px; left: 0; width: 240px; background: #fff; border-radius: 14px;
    box-shadow: 0 18px 40px rgba(0,0,0,.2); padding: 12px 32px 12px 14px; font-size: .85rem; line-height: 1.4; color: #1F2937;
    opacity: 0; visibility: hidden; transform: translateY(10px); transition: opacity .3s ease, transform .3s ease, visibility .3s ease;
}
.chat-attention-bubble.visible { opacity: 1; visibility: visible; transform: translateY(0); }
.chat-attention-bubble::after {
    content: ""; position: absolute; bottom: -7px; left: 22px; width: 14px; height: 14px; background: #fff;
    transform: rotate(45deg); box-shadow: 3px 3px 6px rgba(0,0,0,.06);
}
.chat-widget.pos-right .chat-attention-bubble::after { left: auto; right: 22px; }
.chat-attention-close {
    position: absolute; top: 6px; right: 8px; border: none; background: none; color: #6B7280;
    font-size: 1rem; line-height: 1; cursor: pointer; padding: 2px 4px;
}
.chat-attention-close:hover { color: #1F2937; }
.chat-toggle-icon-default { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.chat-toggle-icon-close { transform: translate(-50%, -50%) scale(.6); opacity: 0; }
.chat-widget.open .chat-toggle-icon-default { transform: translate(-50%, -50%) scale(.6); opacity: 0; }
.chat-widget.open .chat-toggle-icon-close { transform: translate(-50%, -50%) scale(1); opacity: 1; }

.chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 27, 45, 0.15);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 94;
    transition: opacity 0.25s ease;
}

.chat-panel {
    position: absolute; bottom: 70px; left: 0; width: 340px; max-width: calc(100vw - 40px); height: 480px; max-height: 70vh;
    background: #fff; border-radius: 16px; box-shadow: 0 30px 70px rgba(0,0,0,.28);
    display: flex; flex-direction: column; overflow: hidden;
    opacity: 0; visibility: hidden; transform: translateY(16px);
    transition: opacity .25s ease, transform .25s ease, visibility .25s ease;
}
.chat-widget.open .chat-panel { opacity: 1; visibility: visible; transform: translateY(0); }

.chat-widget.is-centered .chat-panel {
    position: fixed !important;
    bottom: 50% !important;
    left: 50% !important;
    transform: translate(-50%, 50%) scale(1) !important;
    margin: 0 !important;
    z-index: 95 !important;
    box-shadow: 0 30px 70px rgba(15, 27, 45, 0.28) !important;
    width: 440px !important;
    max-width: 90vw !important;
    height: 520px !important;
    max-height: 80vh !important;
}
.chat-widget.is-centered .chat-panel-header {
    padding: 16px 20px !important;
}
.chat-widget.is-centered .chat-toggle {
    display: none !important;
}

@media (max-width: 640px) {
    .chat-overlay {
        display: none !important;
    }
    .chat-widget.is-centered .chat-panel {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        transform: none !important;
        width: 100% !important;
        max-width: 100vw !important;
        height: 62vh !important;
        max-height: 62vh !important;
        border-radius: 20px 20px 0 0 !important;
        border-bottom: none !important;
        box-shadow: 0 -10px 40px rgba(15, 27, 45, 0.18) !important;
    }
}
.chat-panel-header { background: #151B4D; color: #fff; padding: 14px 16px; display: flex; align-items: center; gap: 10px; font-weight: 700; flex-shrink: 0; }
.chat-messages { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; background: #F4F5F8; }
.chat-message { max-width: 82%; padding: 9px 13px; border-radius: 14px; font-size: .88rem; line-height: 1.45; white-space: pre-wrap; }
.chat-message-assistant { background: #fff; border: 1px solid #E5E7EB; align-self: flex-start; border-bottom-left-radius: 4px; color: #1F2937; }
.chat-message-user { background: #2563EB; color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-message-error { background: #fde8e8; color: #8a1f1f; align-self: center; text-align: center; font-size: .82rem; }
.chat-message-escalate { background: #eff6ff; border: 1px solid #2563EB; align-self: stretch; text-align: center; font-size: .85rem; }
.chat-message-system { background: transparent; color: #6B7280; align-self: center; text-align: center; font-size: .78rem; font-style: italic; max-width: 100%; }
.chat-message-admin { background: #151B4D; color: #fff; align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-message-label { display: block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #F97316; margin-bottom: 3px; }
.chat-escalate-actions { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.chat-escalate-actions .btn { padding: 7px 14px; font-size: .8rem; text-decoration: none; border-radius: 8px; }
.chat-typing { display: flex; gap: 4px; padding: 2px 0; }
.chat-typing span { width: 6px; height: 6px; border-radius: 50%; background: #6B7280; animation: chat-typing-bounce 1s infinite ease-in-out; }
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chat-typing-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-4px); opacity: 1; } }
.chat-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid #E5E7EB; background: #fff; flex-shrink: 0; }
.chat-input-row input { flex: 1; border: 1px solid #E5E7EB; border-radius: 999px; padding: 9px 14px; font-size: .88rem; font-family: inherit; min-width: 0; }
.chat-input-row input:focus { outline: 2px solid #2563EB; outline-offset: 1px; }
.chat-input-row button {
    width: 38px; height: 38px; border-radius: 50%; background: #2563EB; color: #fff; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background-color .18s ease;
}
.chat-input-row button:hover { background: #151B4D; }
@media (max-width: 480px) {
    .chat-widget { left: 14px; bottom: 14px; }
    .chat-widget.pos-right { left: auto; right: 14px; bottom: 86px; }
    .chat-panel { width: calc(100vw - 28px); height: 65vh; }
}
