/* ═══════════════════════════════════════════════════════════════════════════
   Sara Chat Widget — CSS
   Scoped: all selectors under #sara-widget or prefixed sara-
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Variables (overridden by JS from SARA_CONFIG) ────────────────────── */
#sara-widget {
    --sara-brand: #F97316;
    --sara-brand-hover: #EA6A00;
    --sara-header: #2D2D2D;
    --sara-bg: #F5F5F5;
    --sara-white: #FFFFFF;
    --sara-text: #333333;
    --sara-text-light: #888888;
    --sara-shadow: 0 6px 30px rgba(0,0,0,.15);
    --sara-radius: 18px;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    z-index: 999999;
}

/* ── Bubble button ────────────────────────────────────────────────────── */
#sara-bubble {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 999999;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: var(--sara-header);
    color: var(--sara-brand);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    transition: transform .2s ease, box-shadow .2s ease;
}
#sara-bubble:hover {
    transform: scale(1.07);
    box-shadow: 0 6px 22px rgba(0,0,0,.3);
}
#sara-bubble .sara-icon-close { display: none; }
#sara-widget.sara-open #sara-bubble .sara-icon-chat { display: none; }
#sara-widget.sara-open #sara-bubble .sara-icon-close { display: block; color: var(--sara-white); }

/* Badge */
#sara-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--sara-brand);
    border: 2px solid var(--sara-header);
    animation: sara-pulse 2s infinite;
}
#sara-widget.sara-open #sara-badge,
#sara-widget.sara-seen #sara-badge { display: none; }

@keyframes sara-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.3); opacity: .7; }
}

/* ── Panel ────────────────────────────────────────────────────────────── */
#sara-panel {
    position: fixed;
    bottom: 96px;
    left: 24px;
    width: 360px;
    max-height: calc(100vh - 130px);
    border-radius: var(--sara-radius);
    box-shadow: var(--sara-shadow);
    background: var(--sara-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999998;
    transform-origin: bottom left;
    transition: transform .25s cubic-bezier(.4,.0,.2,1),
                opacity .25s cubic-bezier(.4,.0,.2,1);
}
#sara-panel.sara-hidden {
    transform: scale(.85) translateY(20px);
    opacity: 0;
    pointer-events: none;
}

/* ── Header ───────────────────────────────────────────────────────────── */
#sara-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--sara-header);
    color: var(--sara-white);
    flex-shrink: 0;
    border-radius: var(--sara-radius) var(--sara-radius) 0 0;
}
#sara-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
#sara-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--sara-brand);
    color: var(--sara-white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
}
#sara-agent-name {
    font-weight: 600;
    font-size: 15px;
}
#sara-status {
    font-size: 12px;
    color: rgba(255,255,255,.7);
    display: flex;
    align-items: center;
    gap: 5px;
}
#sara-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ADE80;
    display: inline-block;
}
#sara-close {
    background: none;
    border: none;
    color: rgba(255,255,255,.7);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: color .15s, background .15s;
}
#sara-close:hover {
    color: var(--sara-white);
    background: rgba(255,255,255,.12);
}

/* ── Messages area ────────────────────────────────────────────────────── */
#sara-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 200px;
    max-height: 400px;
    scroll-behavior: smooth;
}

/* Bubbles */
.sara-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.sara-msg-bot {
    align-self: flex-start;
    background: var(--sara-white);
    color: var(--sara-text);
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    border-bottom-left-radius: 4px;
}
.sara-msg-user {
    align-self: flex-end;
    background: var(--sara-header);
    color: var(--sara-white);
    border-bottom-right-radius: 4px;
}

/* Typing indicator */
.sara-typing {
    align-self: flex-start;
    display: flex;
    gap: 5px;
    padding: 12px 18px;
    background: var(--sara-white);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.sara-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #bbb;
    animation: sara-bounce .6s infinite alternate;
}
.sara-typing span:nth-child(2) { animation-delay: .15s; }
.sara-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes sara-bounce {
    from { transform: translateY(0); }
    to   { transform: translateY(-6px); background: #888; }
}

/* ── Collection link ──────────────────────────────────────────────────── */
.sara-collection-link {
    align-self: flex-start;
    display: inline-block;
    font-size: 13px;
    color: var(--sara-brand);
    text-decoration: none;
    padding: 2px 0;
}
.sara-collection-link:hover {
    text-decoration: underline;
}

/* ── Quick replies ────────────────────────────────────────────────────── */
.sara-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 0 4px;
    align-self: flex-start;
    max-width: 100%;
}
.sara-qr-btn {
    background: transparent;
    border: 1.5px solid var(--sara-brand);
    color: var(--sara-brand);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.sara-qr-btn:hover {
    background: var(--sara-brand);
    color: var(--sara-white);
}

/* ── Product cards ────────────────────────────────────────────────────── */
.sara-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    align-self: flex-start;
    max-width: 100%;
    padding: 4px 0;
}
.sara-card {
    background: var(--sara-white);
    border-radius: 10px;
    overflow: hidden;
    border: 1.5px solid #e5e5e5;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
    text-decoration: none;
    color: inherit;
    display: block;
}
.sara-card:hover {
    border-color: var(--sara-brand);
    box-shadow: 0 2px 8px rgba(249,115,22,.15);
}
.sara-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}
.sara-card-body {
    padding: 5px 6px;
}
.sara-card-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--sara-text);
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.sara-card-label {
    font-size: 10px;
    color: var(--sara-text-light);
    margin-top: 1px;
}

/* ── Swatches ─────────────────────────────────────────────────────────── */
.sara-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-self: flex-start;
    padding: 4px 0;
    max-width: 100%;
}
.sara-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid #e0e0e0;
    cursor: pointer;
    transition: transform .15s, border-color .15s;
    background-size: cover;
    background-position: center;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}
.sara-swatch:hover {
    transform: scale(1.12);
    border-color: var(--sara-brand);
}
.sara-swatch img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

/* Swatch tooltip */
.sara-swatch[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--sara-header);
    color: var(--sara-white);
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 6px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
}

/* ── Swatch popup overlay ─────────────────────────────────────────────── */
#sara-swatch-popup {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    animation: sara-fade-in .2s ease;
}
@keyframes sara-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.sara-popup-card {
    background: var(--sara-white);
    border-radius: 14px;
    overflow: hidden;
    width: 240px;
    box-shadow: 0 8px 30px rgba(0,0,0,.25);
}
.sara-popup-card img {
    width: 100%;
    display: block;
}
.sara-popup-info {
    padding: 12px 14px;
}
.sara-popup-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--sara-text);
    margin-bottom: 8px;
}
.sara-popup-btn {
    display: inline-block;
    background: var(--sara-brand);
    color: var(--sara-white);
    padding: 7px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background .15s;
}
.sara-popup-btn:hover {
    background: var(--sara-brand-hover);
}
.sara-popup-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,.5);
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Input area ───────────────────────────────────────────────────────── */
#sara-input-area {
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    background: var(--sara-white);
    border-top: 1px solid #eee;
    flex-shrink: 0;
}
#sara-input {
    flex: 1;
    border: 1.5px solid #ddd;
    border-radius: 22px;
    padding: 9px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color .15s;
    font-family: inherit;
    color: var(--sara-text);
    background: var(--sara-bg);
}
#sara-input:focus {
    border-color: var(--sara-brand);
}
#sara-input::placeholder {
    color: #aaa;
}
#sara-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--sara-brand);
    color: var(--sara-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
}
#sara-send:hover {
    background: var(--sara-brand-hover);
}
#sara-send:active {
    transform: scale(.93);
}
#sara-send:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* ── Footer ───────────────────────────────────────────────────────────── */
#sara-footer {
    text-align: center;
    padding: 6px 14px 10px;
    font-size: 11px;
    color: var(--sara-text-light);
    background: var(--sara-white);
    flex-shrink: 0;
}

/* ── Mobile responsive ────────────────────────────────────────────────── */
@media (max-width: 420px) {
    #sara-panel {
        width: calc(100vw - 20px);
        left: 10px;
        bottom: 90px;
        max-height: calc(100vh - 110px);
    }
    #sara-bubble {
        left: 16px;
        bottom: 18px;
        width: 52px;
        height: 52px;
    }
    .sara-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}
