/* ── SteamShop AI Chat Widget CSS ──────────────────────────── */
/* Brand: #DE3431 */

.ssai-widget *,
.ssai-toggle * {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
}

/* ── Toggle bubble ─────────────────────────────────────────── */
.ssai-toggle {
    position: fixed !important;
    bottom: 24px !important;
    left: 24px !important;
    width: 58px !important;
    height: 58px !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    box-shadow: 0 4px 16px rgba(222,52,49,.35) !important;
    z-index: 999999 !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    background: #DE3431 !important;
    color: #fff !important;
    padding: 0 !important;
    border: none !important;
    margin: 0 !important;
    outline: none !important;
    -webkit-tap-highlight-color: transparent;
    /* iOS safe area — prevent hiding behind home indicator */
    bottom: calc(24px + env(safe-area-inset-bottom, 0px)) !important;
    left: calc(24px + env(safe-area-inset-left, 0px)) !important;
}
.ssai-toggle:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 24px rgba(222,52,49,.45);
}
.ssai-toggle:active { transform: scale(0.97); }

/* ── Notification badge ────────────────────────────────────── */
.ssai-toggle__badge {
    position: absolute !important;
    top: -4px !important;
    right: -4px !important;
    min-width: 20px !important;
    height: 20px !important;
    background: #fff !important;
    color: #DE3431 !important;
    border-radius: 10px !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    display: none !important;  /* hidden by default, shown via JS */
    align-items: center !important;
    justify-content: center !important;
    padding: 0 5px !important;
    box-shadow: 0 2px 6px rgba(0,0,0,.2) !important;
    animation: ssai-badge-pop 0.3s ease;
    line-height: 1 !important;
}
/* When badge has content, JS sets display:flex */
.ssai-toggle__badge--visible {
    display: flex !important;
}
@keyframes ssai-badge-pop {
    0% { transform: scale(0); }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Toggle pulse when badge is visible */
.ssai-toggle--has-notification {
    animation: ssai-toggle-pulse 2s ease infinite;
}
@keyframes ssai-toggle-pulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(222,52,49,.35); }
    50% { box-shadow: 0 4px 24px rgba(222,52,49,.6), 0 0 0 8px rgba(222,52,49,.15); }
}

/* ── Widget container ──────────────────────────────────────── */
.ssai-widget {
    position: fixed;
    bottom: 94px;
    left: 24px;
    width: 390px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 12px 48px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.08);
    z-index: 99999;
    background: #fff;
    animation: ssai-slide-up 0.3s cubic-bezier(.21,1.02,.73,1);
}
@keyframes ssai-slide-up {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Header ────────────────────────────────────────────────── */
.ssai-widget__header {
    background: #DE3431;
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 12px;
}
.ssai-widget__header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.ssai-widget__avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,.18);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ssai-widget__header-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.ssai-widget__title {
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ssai-widget__status {
    font-size: 11px;
    opacity: .85;
    display: flex;
    align-items: center;
    gap: 5px;
    line-height: 1;
    margin-top: 2px;
}
.ssai-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    flex-shrink: 0;
}
.ssai-status-dot--waiting {
    background: #fbbf24;
    animation: ssai-pulse-dot 1.2s infinite;
}
.ssai-status-dot--offline { background: #94a3b8; }
@keyframes ssai-pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: .3; }
}
.ssai-widget__header-right {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.ssai-header-btn {
    background: rgba(255,255,255,.15);
    border: none;
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
.ssai-header-btn:hover { background: rgba(255,255,255,.28); }

/* ── Messages body ─────────────────────────────────────────── */
.ssai-widget__body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #f5f6f8;
}
.ssai-widget__loading {
    text-align: center;
    color: #999;
    font-size: 13px;
    padding: 40px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.ssai-loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #e0e0e0;
    border-top-color: #DE3431;
    border-radius: 50%;
    animation: ssai-spin 0.7s linear infinite;
}
@keyframes ssai-spin { to { transform: rotate(360deg); } }

/* ── Message bubbles ───────────────────────────────────────── */
.ssai-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
}
.ssai-msg--user {
    align-self: flex-end;
    background: #DE3431;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ssai-msg--assistant,
.ssai-msg--agent {
    align-self: flex-start;
    background: #fff;
    color: #1a1a1a;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.ssai-msg--system {
    align-self: center;
    background: transparent;
    color: #888;
    font-size: 12px;
    font-style: italic;
    padding: 6px 0;
    text-align: center;
    max-width: 90%;
}
.ssai-msg__sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 3px;
    opacity: .6;
}
.ssai-msg--assistant .ssai-msg__sender,
.ssai-msg--agent .ssai-msg__sender {
    color: #DE3431;
    opacity: 1;
}
.ssai-msg__time {
    font-size: 10px;
    opacity: .45;
    margin-top: 4px;
    text-align: right;
}

/* ── Typing indicator ──────────────────────────────────────── */
.ssai-typing {
    align-self: flex-start;
    background: #fff;
    padding: 12px 18px;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    display: flex;
    align-items: center;
    gap: 5px;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.ssai-typing__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #aaa;
    animation: ssai-typing-bounce 1.4s infinite;
}
.ssai-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.ssai-typing__dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes ssai-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Agent request bar ─────────────────────────────────────── */
.ssai-widget__agent-bar {
    padding: 8px 14px;
    flex-shrink: 0;
    border-top: 1px solid #eaeaea;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #fff;
}
.ssai-btn-agent {
    color: #DE3431;
    background: transparent;
    border: none;
    padding: 6px 16px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
    transition: background .15s;
}
.ssai-btn-agent:hover { background: #fef2f2; }
.ssai-btn-agent:disabled { opacity: .5; cursor: default; }

/* ── Input area ────────────────────────────────────────────── */
.ssai-widget__input-area {
    display: flex;
    align-items: flex-end;
    padding: 10px 12px 12px;
    border-top: 1px solid #eaeaea;
    background: #fff;
    flex-shrink: 0;
    gap: 8px;
}
.ssai-widget__input {
    flex: 1;
    border: 1.5px solid #e0e0e0;
    border-radius: 12px;
    padding: 9px 14px;
    font-size: 13.5px;
    resize: none;
    max-height: 80px;
    line-height: 1.4;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
    background: #fafafa;
}
.ssai-widget__input:focus {
    border-color: #DE3431;
    box-shadow: 0 0 0 3px rgba(222,52,49,.1);
    background: #fff;
}
.ssai-widget__send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, transform .1s, opacity .15s;
    background: #DE3431;
    color: #fff;
}
.ssai-widget__send-btn:hover:not(:disabled) { background: #c72e2b; }
.ssai-widget__send-btn:active:not(:disabled) { transform: scale(0.93); }
.ssai-widget__send-btn:disabled { opacity: .35; cursor: default; background: #ccc; }
.ssai-widget__send-btn svg { fill: currentColor; }

/* ── Modal ─────────────────────────────────────────────────── */
.ssai-modal {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(2px);
}
.ssai-modal__content {
    background: #fff;
    border-radius: 16px;
    padding: 28px 24px;
    max-width: 280px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.ssai-modal__icon { margin-bottom: 12px; display: flex; justify-content: center; }
.ssai-modal__content p { margin: 0 0 20px; font-size: 14px; color: #333; line-height: 1.5; }
.ssai-modal__actions { display: flex; gap: 10px; justify-content: center; }
.ssai-btn {
    border: none;
    padding: 9px 20px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: opacity .15s, transform .1s;
}
.ssai-btn:active { transform: scale(0.96); }
.ssai-btn--primary { background: #DE3431; color: #fff; }
.ssai-btn--primary:hover { background: #c72e2b; }
.ssai-btn--secondary { background: #f0f0f0; color: #555; }
.ssai-btn--secondary:hover { background: #e5e5e5; }

/* ── Waiting indicator ─────────────────────────────────────── */
.ssai-waiting-indicator {
    align-self: center;
    font-size: 12px;
    color: #888;
    padding: 8px 0;
    display: flex;
    align-items: center;
    gap: 6px;
    animation: ssai-pulse 1.5s infinite;
}
@keyframes ssai-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .4; }
}

/* ── Welcome ──────────────────────────────────────────────── */
.ssai-welcome {
    text-align: center;
    padding: 20px 10px 10px;
}
.ssai-welcome__icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #fef2f2;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
}
.ssai-welcome__title { font-size: 15px; font-weight: 600; color: #1a1a1a; margin-bottom: 4px; }
.ssai-welcome__text { font-size: 12.5px; color: #888; line-height: 1.4; }

/* ── Scrollbar ─────────────────────────────────────────────── */
.ssai-widget__body::-webkit-scrollbar { width: 5px; }
.ssai-widget__body::-webkit-scrollbar-track { background: transparent; }
.ssai-widget__body::-webkit-scrollbar-thumb { background: #d0d0d0; border-radius: 3px; }
.ssai-widget__body::-webkit-scrollbar-thumb:hover { background: #bbb; }

/* ── Mobile ────────────────────────────────────────────────── */
/* ── Guest login prompt ───────────────────────────────────── */
.ssai-guest-prompt__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px 24px;
}
.ssai-guest-prompt__body svg { margin-bottom: 14px; }
.ssai-guest-prompt__body p {
    margin: 0 0 20px;
    color: #444;
    font-size: 14.5px;
    line-height: 1.5;
}
.ssai-guest-prompt__btn {
    width: auto;
    min-width: 160px;
    padding: 11px 28px;
    font-size: 14px;
    border-radius: 8px;
}

@media (max-width: 767px) {
    /* Leave a tappable edge around the panel so the backdrop can close it. */
    .ssai-widget {
        bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important;
        left: 12px !important;
        right: 12px !important;
        width: auto !important;
        height: min(620px, calc(100vh - 104px)) !important;
        max-height: calc(100vh - 104px) !important;
        border-radius: 16px !important;
    }
}

@media (max-width: 480px) {
    .ssai-toggle {
        bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
        left: calc(16px + env(safe-area-inset-left, 0px)) !important;
        width: 52px !important;
        height: 52px !important;
    }
}

/* ── Loading error/retry ───────────────────────────────────── */
.ssai-load-error {
    margin: auto;
    padding: 24px;
    max-width: 290px;
    color: #555;
    text-align: center;
    font-size: 13px;
    line-height: 1.5;
}
.ssai-load-error p { margin: 0 0 14px; }

/* ── Selectable chat-history panel ─────────────────────────── */
.ssai-history-panel {
    position: absolute;
    inset: 0;
    z-index: 20;
    flex-direction: column;
    background: #fff;
    color: #222;
}
.ssai-history-panel__header {
    min-height: 58px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 9px;
    flex-shrink: 0;
    border-bottom: 1px solid #ececec;
    background: #fff;
}
.ssai-history-panel__header strong {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    font-weight: 650;
    color: #222;
}
.ssai-history-back,
.ssai-history-close {
    border: 0;
    background: transparent;
    color: #444;
    padding: 7px 8px;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
}
.ssai-history-back {
    color: #DE3431;
    font-size: 12px;
    white-space: nowrap;
}
.ssai-history-close {
    width: 32px;
    height: 32px;
    font-size: 23px;
    line-height: 1;
}
.ssai-history-back:hover,
.ssai-history-close:hover { background: #f5f5f5; }
.ssai-history-panel__content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px;
    background: #f7f7f8;
}
.ssai-history-list { display: flex; flex-direction: column; gap: 9px; }
.ssai-history-item {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 13px;
    border: 1px solid #e8e8e8;
    border-radius: 12px;
    background: #fff;
    color: #222;
    text-align: left;
    cursor: pointer;
    font: inherit;
}
.ssai-history-item:hover { border-color: rgba(222,52,49,.45); box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.ssai-history-item__top,
.ssai-history-message__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.ssai-history-item__top strong { font-size: 12.5px; color: #252525; }
.ssai-history-item__top time,
.ssai-history-message__meta time { color: #999; font-size: 10px; font-weight: 400; }
.ssai-history-item__preview {
    overflow: hidden;
    color: #707070;
    font-size: 12px;
    line-height: 1.45;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.ssai-history-item__count { color: #aaa; font-size: 10px; }
.ssai-history-loading,
.ssai-history-empty {
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 24px;
    color: #888;
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
}
.ssai-history-transcript { display: flex; flex-direction: column; gap: 9px; }
.ssai-history-message {
    max-width: 88%;
    padding: 9px 11px;
    border-radius: 12px;
    background: #fff;
    color: #222;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.ssai-history-message--user {
    align-self: flex-end;
    background: #DE3431;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ssai-history-message--assistant,
.ssai-history-message--agent { align-self: flex-start; border-bottom-left-radius: 4px; }
.ssai-history-message--system {
    align-self: center;
    max-width: 96%;
    padding: 5px 8px;
    background: transparent;
    color: #888;
    box-shadow: none;
    text-align: center;
    font-style: italic;
}
.ssai-history-message__meta { margin-bottom: 4px; }
.ssai-history-message__meta strong { font-size: 10px; font-weight: 650; color: #DE3431; }
.ssai-history-message--user .ssai-history-message__meta strong,
.ssai-history-message--user .ssai-history-message__meta time { color: rgba(255,255,255,.8); }
.ssai-history-message__content {
    font-size: 12.5px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.ssai-history-panel__content::-webkit-scrollbar { width: 5px; }
.ssai-history-panel__content::-webkit-scrollbar-thumb { background: #d0d0d0; border-radius: 3px; }

/* ── Outside-click backdrop and enforced visible chat header ─ */
.ssai-chat-backdrop {
    position: fixed;
    inset: 0;
    z-index: 999998;
    display: none;
    background: rgba(14, 18, 28, .48);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.ssai-chat-backdrop--visible { display: block !important; }
#ssai-widget .ssai-widget__header {
    position: relative !important;
    z-index: 25 !important;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    flex: 0 0 auto !important;
    min-height: 64px;
    background: #DE3431 !important;
    color: #fff !important;
}
#ssai-widget .ssai-widget__header-left,
#ssai-widget .ssai-widget__header-right,
#ssai-widget .ssai-widget__title,
#ssai-widget .ssai-widget__status {
    visibility: visible !important;
    opacity: 1 !important;
}
#ssai-widget .ssai-widget__header-left,
#ssai-widget .ssai-widget__header-info,
#ssai-widget .ssai-widget__header-right { display: flex !important; }
#ssai-widget .ssai-widget__header-info { flex-direction: column !important; }
#ssai-widget .ssai-widget__title { display: block !important; color: #fff !important; }
#ssai-widget .ssai-widget__status { display: flex !important; color: #fff !important; }
#ssai-widget #ssai-btn-minimize {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}
.ssai-header-btn--close {
    width: 36px !important;
    height: 36px !important;
    flex: 0 0 36px;
    border: 1px solid rgba(255,255,255,.32) !important;
    border-radius: 9px !important;
    background: rgba(255,255,255,.2) !important;
    color: #fff !important;
}
.ssai-header-btn--close:hover { background: rgba(255,255,255,.32) !important; }
