/**
 * Shois Chat Button — Widget Base Styles
 *
 * Core structural CSS shared by all templates.
 * Templates only need to define CSS custom property overrides.
 *
 * @package ShoisChatButton
 */

/* ─── Default Custom Properties ─────────────────────── */
.shcb-widget {
    --scb-primary: #25D366;
    --scb-secondary: #128C7E;
    --scb-bg: #ffffff;
    --shcb-header-bg: #25D366;
    --shcb-header-text: #ffffff;
    --scb-text: #333333;
    --scb-text-light: #666666;
    --shcb-cta-bg: #25D366;
    --shcb-cta-text: #ffffff;
    --shcb-btn-size: 60px;
    --shcb-popup-width: 360px;
    --shcb-popup-max-height: 520px;
    --scb-radius-btn: 50%;
    --scb-radius-popup: 16px;
    --scb-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    --scb-font-size: 14px;
    --scb-line-height: 1.5;
    --scb-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    --scb-shadow-btn: 0 4px 16px rgba(37, 211, 102, 0.35);
    --scb-offset-x: 24px;
    --scb-offset-y: 24px;
    --scb-icon-size: 24px;
    --scb-icon-color: #ffffff;
}

/* ─── Position ──────────────────────────────────────── */
.shcb-widget {
    position: fixed;
    z-index: 999999;
    font-family: var(--scb-font);
    font-size: var(--scb-font-size);
    line-height: var(--scb-line-height);
    box-sizing: border-box;
}

.shcb-widget *,
.shcb-widget *::before,
.shcb-widget *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.shcb-pos-bottom-right {
    right: var(--scb-offset-x);
    bottom: var(--scb-offset-y);
}

.shcb-pos-bottom-left {
    left: var(--scb-offset-x);
    bottom: var(--scb-offset-y);
}

.shcb-pos-top-right {
    right: var(--scb-offset-x);
    top: var(--scb-offset-y);
}

.shcb-pos-top-left {
    left: var(--scb-offset-x);
    top: var(--scb-offset-y);
}

/* Safe area for mobile notch */
@supports (padding-bottom: env(safe-area-inset-bottom)) {

    .shcb-pos-bottom-right,
    .shcb-pos-bottom-left {
        bottom: calc(var(--scb-offset-y) + env(safe-area-inset-bottom));
    }
}

/* ─── Trigger Button ────────────────────────────────── */
.shcb-trigger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--shcb-btn-size);
    height: var(--shcb-btn-size);
    border: none;
    border-radius: var(--scb-radius-btn);
    background: var(--scb-primary);
    color: #ffffff;
    cursor: pointer;
    box-shadow: var(--scb-shadow-btn);
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    min-width: 44px;
    min-height: 44px;
}

.shcb-trigger-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(37, 211, 102, 0.45);
}

.shcb-trigger-btn:focus-visible {
    outline: 3px solid var(--scb-primary);
    outline-offset: 3px;
}

.shcb-trigger-btn:active {
    transform: scale(0.96);
}

.shcb-trigger-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.shcb-trigger-icon svg {
    width: var(--scb-icon-size);
    height: var(--scb-icon-size);
    fill: var(--scb-icon-color);
}

.shcb-trigger-label {
    display: none;
    margin-left: 8px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

/* With label visible */
.shcb-widget[data-show-label="true"] .shcb-trigger-btn {
    width: auto;
    border-radius: 30px;
    padding: 0 20px;
}

.shcb-widget[data-show-label="true"] .shcb-trigger-label {
    display: inline;
}

/* ─── Badge ─────────────────────────────────────────── */
.shcb-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    color: #fff;
    background: #ef4444;
    border-radius: 10px;
    border: 2px solid #fff;
    animation: shcb-badge-bounce 0.5s ease;
}

@keyframes shcb-badge-bounce {
    0% {
        transform: scale(0);
    }

    60% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

/* ─── Pulse Ring ────────────────────────────────────── */
.shcb-pulse-ring {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: var(--scb-radius-btn);
    border: 2px solid var(--scb-primary);
    animation: shcb-pulse-ring-anim 2s ease-out infinite;
    pointer-events: none;
}

@keyframes shcb-pulse-ring-anim {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }

    100% {
        transform: scale(1.6);
        opacity: 0;
    }
}

/* ─── Popup ─────────────────────────────────────────── */
.shcb-popup {
    position: absolute;
    width: var(--shcb-popup-width);
    max-height: var(--shcb-popup-max-height);
    background: var(--scb-bg);
    border-radius: var(--scb-radius-popup);
    box-shadow: var(--scb-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: scale(0.85) translateY(10px);
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}

.shcb-popup.shcb-popup-visible {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

.shcb-popup.shcb-hidden {
    display: none;
}

/* Position the popup based on widget position. */
.shcb-pos-bottom-right .shcb-popup {
    bottom: calc(var(--shcb-btn-size) + 16px);
    right: 0;
    transform-origin: bottom right;
}

.shcb-pos-bottom-left .shcb-popup {
    bottom: calc(var(--shcb-btn-size) + 16px);
    left: 0;
    transform-origin: bottom left;
}

.shcb-pos-top-right .shcb-popup {
    top: calc(var(--shcb-btn-size) + 16px);
    right: 0;
    transform-origin: top right;
}

.shcb-pos-top-left .shcb-popup {
    top: calc(var(--shcb-btn-size) + 16px);
    left: 0;
    transform-origin: top left;
}

/* ─── Popup Header ──────────────────────────────────── */
.shcb-popup-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--shcb-header-bg);
    color: var(--shcb-header-text);
}

.shcb-brand-logo {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.shcb-header-text {
    flex: 1;
    min-width: 0;
}

.shcb-header-title {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.3;
}

.shcb-header-subtitle {
    font-size: 12px;
    opacity: 0.85;
    margin-top: 2px;
}

.shcb-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
    min-width: 44px;
    min-height: 44px;
}

.shcb-close-btn:hover {
    background: rgba(255, 255, 255, 0.35);
}

.shcb-close-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ─── Popup Body ────────────────────────────────────── */
.shcb-popup-body {
    padding: 16px 20px;
}

.shcb-welcome-message {
    margin-bottom: 12px;
}

.shcb-welcome-message p {
    color: var(--scb-text);
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
}

/* ─── Quick Reply Chips ─────────────────────────────── */
.shcb-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.shcb-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 500;
    color: var(--scb-primary);
    background: rgba(37, 211, 102, 0.08);
    border: 1px solid rgba(37, 211, 102, 0.25);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--scb-font);
    white-space: nowrap;
}

.shcb-chip:hover {
    background: rgba(37, 211, 102, 0.15);
    border-color: var(--scb-primary);
}

.shcb-chip:focus-visible {
    outline: 2px solid var(--scb-primary);
    outline-offset: 2px;
}

/* ─── Agent Cards ───────────────────────────────────── */
.shcb-agents {
    max-height: 380px;
    overflow-y: auto;
    padding: 0 20px 12px;
    scrollbar-width: thin;
}

.shcb-agents::-webkit-scrollbar {
    width: 5px;
}

.shcb-agents::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.shcb-agent-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    margin-bottom: 12px;
    background: var(--scb-bg, #ffffff);
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    pointer-events: auto !important;
    user-select: none;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.shcb-agent-card:last-child {
    margin-bottom: 0;
}

.shcb-agent-card:hover {
    border-color: var(--scb-primary);
    box-shadow: 0 10px 15px -3px rgba(37, 211, 102, 0.1), 0 4px 6px -2px rgba(37, 211, 102, 0.05);
    transform: translateY(-2px);
}

.shcb-agent-card:active {
    transform: scale(0.985);
}

/* Avatar */
.shcb-agent-avatar-wrap {
    flex-shrink: 0;
}

.shcb-agent-avatar {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    object-fit: cover;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.shcb-avatar-initials {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: #ffffff;
}

/* Agent Info */
.shcb-agent-info {
    flex: 1;
    min-width: 0;
}

.shcb-agent-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--scb-text);
}

.shcb-agent-title {
    font-size: 12px;
    color: #64748b;
    margin-top: 2px;
}

.shcb-agent-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #94a3b8;
    margin-top: 4px;
}

.shcb-agent-status .shcb-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.shcb-status-online {
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.15);
}

.shcb-status-offline {
    background: #94a3b8;
}

/* ─── Platform Buttons ──────────────────────────────── */
.shcb-agent-platforms,
.shcb-platforms-direct {
    display: flex;
    align-items: center;
    gap: 8px;
}

.shcb-agent-card .shcb-agent-platforms {
    margin-top: 0;
    flex-shrink: 0;
}

.shcb-platform-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--shcb-platform-color, #25D366);
    color: #ffffff;
    text-decoration: none;
    transition: all 0.2s;
}

.shcb-platform-btn .shcb-platform-name {
    display: none;
}

.shcb-platform-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.shcb-platform-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.shcb-platform-btn:focus-visible {
    outline: 3px solid var(--shcb-platform-color, var(--scb-primary));
    outline-offset: 2px;
}

.shcb-platform-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.shcb-platform-icon svg {
    width: 20px;
    height: 20px;
    fill: #ffffff;
}

.shcb-platform-name {
    display: none;
}

/* Direct platforms (no agents) — wider buttons with names */
.shcb-platforms-direct .shcb-platform-btn {
    width: auto;
    border-radius: 10px;
    padding: 10px 16px;
    gap: 8px;
}

.shcb-platforms-direct .shcb-platform-name {
    display: inline;
    font-size: 13px;
    font-weight: 600;
}

/* Snapchat dark icon override */
.shcb-platform-snapchat .shcb-platform-icon svg {
    fill: #000000;
}

/* ─── Offline State ─────────────────────────────────── */
.shcb-offline-state {
    padding: 24px 20px;
    text-align: center;
}

.shcb-offline-message {
    color: var(--scb-text);
    font-size: 14px;
    margin-bottom: 6px;
}

.shcb-next-available {
    color: var(--scb-text-light);
    font-size: 13px;
}

/* ─── Footer ────────────────────────────────────────── */
.shcb-popup-footer {
    padding: 10px 20px;
    text-align: center;
    border-top: 1px solid #f0f0f0;
}

.shcb-powered-by {
    font-size: 10px;
    color: #b0b0b0;
    letter-spacing: 0.3px;
}

/* ─── Reduced Motion ────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {

    .shcb-trigger-btn,
    .shcb-popup,
    .shcb-platform-btn,
    .shcb-chip,
    .shcb-agent-card {
        transition: none !important;
        animation: none !important;
    }

    .shcb-pulse-ring {
        display: none;
    }
}

/* ─── Mobile Bottom Sheet ───────────────────────────── */
@media (max-width: 767px) {
    .shcb-popup {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 20px 20px 0 0;
        max-height: 85vh;
        transform-origin: bottom center;
    }

    .shcb-popup.shcb-popup-visible {
        transform: translateY(0);
    }

    .shcb-popup:not(.shcb-popup-visible) {
        transform: translateY(100%);
    }

    /* Drag handle indicator */
    .shcb-popup-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 4px;
    }

    .shcb-popup-header {
        position: relative;
        padding-top: 20px;
    }
}