/**
 * Storefront chat widget — theme via CSS variables (set from admin config on .tm-chatbot).
 * Override in your theme without editing the module, e.g.:
 *   .tm-chatbot { --tm-chatbot-primary: #0ea5e9; }
 */
.tm-chatbot {
    --tm-chatbot-primary: #3b82f6;
    --tm-chatbot-primary-end: #2563eb;
    --tm-chatbot-primary-foreground: #ffffff;
    --tm-chatbot-bot-avatar-bg: #3b82f6;
    --tm-chatbot-messages-bg: #f4f7fb;
    --tm-chatbot-card: #ffffff;
    --tm-chatbot-muted-foreground: #64748b;
    --tm-chatbot-border: rgba(15, 23, 42, 0.12);
    --tm-chatbot-input-bg: #ffffff;
    --tm-chatbot-radius: 1rem;
    --tm-chatbot-launcher-size: 4rem;
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 900;
    font-family: inherit;
    color: #0f172a;
}

.tm-chatbot__toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--tm-chatbot-primary), var(--tm-chatbot-primary-end));
    color: var(--tm-chatbot-primary-foreground);
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(37, 99, 235, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tm-chatbot__toggle:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 32px rgba(37, 99, 235, 0.42);
}

.tm-chatbot--launcher-icon-only .tm-chatbot__toggle {
    width: var(--tm-chatbot-launcher-size);
    height: var(--tm-chatbot-launcher-size);
    padding: 0;
}

.tm-chatbot--launcher-with-label .tm-chatbot__toggle {
    min-height: var(--tm-chatbot-launcher-size);
    padding: 0.75rem 1.1rem;
}

.tm-chatbot--launcher-icon-only .tm-chatbot__toggle-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.tm-chatbot__toggle::after {
    content: "";
    position: absolute;
    inset: -0.4rem;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.22);
    pointer-events: none;
    z-index: -1;
}

.tm-chatbot__toggle-pulse {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: var(--tm-chatbot-primary);
    opacity: 0.35;
    animation: tm-chatbot-launcher-pulse 2.5s ease-out infinite;
    pointer-events: none;
}

.tm-chatbot.is-open .tm-chatbot__toggle-pulse {
    animation: none;
    opacity: 0;
}

.tm-chatbot__toggle-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    flex-shrink: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.tm-chatbot__icon-svg {
    display: block;
    width: 1.75rem;
    height: 1.75rem;
}

.tm-chatbot__toggle-icon--close {
    position: absolute;
    opacity: 0;
    transform: scale(0.6) rotate(-90deg);
}

.tm-chatbot__toggle-icon--chat {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.tm-chatbot.is-open .tm-chatbot__toggle-icon--chat {
    opacity: 0;
    transform: scale(0.6) rotate(90deg);
}

.tm-chatbot.is-open .tm-chatbot__toggle-icon--close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.tm-chatbot__badge {
    position: absolute;
    top: -0.05rem;
    right: -0.05rem;
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.35rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.45);
    border: 2px solid var(--tm-chatbot-primary-foreground);
    z-index: 2;
}

.tm-chatbot__panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.85rem);
    width: min(20rem, calc(100vw - 2rem));
    height: min(28rem, calc(100vh - 6rem));
    border: 1px solid var(--tm-chatbot-border);
    border-radius: var(--tm-chatbot-radius);
    background: var(--tm-chatbot-card);
    box-shadow: 0 20px 48px rgba(15, 23, 42, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tm-chatbot__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1rem 0.95rem;
    background: linear-gradient(90deg, var(--tm-chatbot-primary), var(--tm-chatbot-primary-end));
    color: var(--tm-chatbot-primary-foreground);
}

.tm-chatbot__header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.tm-chatbot__header-copy {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.tm-chatbot__title {
    font-weight: 600;
    font-size: 1rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tm-chatbot__subtitle {
    font-size: 0.8rem;
    line-height: 1.3;
    opacity: 0.92;
}

.tm-chatbot__status {
    font-size: 0.72rem;
    opacity: 0.8;
}

.tm-chatbot__header-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.tm-chatbot__reset,
.tm-chatbot__close {
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font: inherit;
    opacity: 0.9;
}

.tm-chatbot__reset {
    font-size: 0.72rem;
    padding: 0.2rem 0.35rem;
}

.tm-chatbot__close {
    font-size: 1.35rem;
    line-height: 1;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.35rem;
}

.tm-chatbot__reset:hover,
.tm-chatbot__close:hover {
    opacity: 1;
}

.tm-chatbot__shopper-banner {
    padding: 0.45rem 1rem;
    font-size: 0.78rem;
    color: var(--tm-chatbot-muted-foreground);
    background: #f8fafc;
    border-bottom: 1px solid var(--tm-chatbot-border);
}

.tm-chatbot__messages {
    flex: 1;
    min-height: 10rem;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    background: var(--tm-chatbot-messages-bg);
}

.tm-chatbot__message-row {
    display: flex;
    gap: 0.65rem;
    align-items: flex-end;
    max-width: 100%;
}

.tm-chatbot__message-row--user {
    flex-direction: row-reverse;
}

.tm-chatbot__avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 600;
    overflow: hidden;
}

.tm-chatbot__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tm-chatbot__avatar--user {
    background: var(--tm-chatbot-primary);
    color: var(--tm-chatbot-primary-foreground);
}

.tm-chatbot__avatar--bot,
.tm-chatbot__avatar--human {
    background: var(--tm-chatbot-bot-avatar-bg);
    color: var(--tm-chatbot-primary-foreground);
}

.tm-chatbot__header-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 999px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.18);
}

.tm-chatbot__header-avatar--bot,
.tm-chatbot__avatar--bot-icon {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 58% 58%;
}

.tm-chatbot__message-stack {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    max-width: min(78%, 15rem);
}

.tm-chatbot__message-row--user .tm-chatbot__message-stack {
    align-items: flex-end;
}

.tm-chatbot__sender {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--tm-chatbot-muted-foreground);
    padding: 0 0.25rem;
}

.tm-chatbot__bubble {
    border-radius: 1rem;
    padding: 0.65rem 0.9rem;
    font-size: 0.875rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.tm-chatbot__bubble-text {
    white-space: pre-wrap;
}

.tm-chatbot__bubble--user {
    background: linear-gradient(135deg, var(--tm-chatbot-primary), var(--tm-chatbot-primary-end));
    color: var(--tm-chatbot-primary-foreground);
    border-top-right-radius: 0.3rem;
}

.tm-chatbot__bubble--bot,
.tm-chatbot__bubble--human {
    background: var(--tm-chatbot-card);
    color: #0f172a;
    border: 1px solid var(--tm-chatbot-border);
    border-top-left-radius: 0.3rem;
}

.tm-chatbot__bubble--human {
    border-color: #bfdbfe;
}

.tm-chatbot__bubble--loading {
    display: inline-flex;
    align-items: center;
    min-height: 2.25rem;
    background: var(--tm-chatbot-card);
    border: 1px solid var(--tm-chatbot-border);
}

.tm-chatbot__timestamp {
    font-size: 0.68rem;
    color: var(--tm-chatbot-muted-foreground);
    padding: 0 0.25rem;
}

.tm-chatbot__typing {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.tm-chatbot__typing-dot {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 999px;
    background: var(--tm-chatbot-muted-foreground);
    animation: tm-chatbot-typing 1.2s ease-in-out infinite;
}

.tm-chatbot__typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.tm-chatbot__typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes tm-chatbot-typing {
    0%,
    80%,
    100% {
        opacity: 0.35;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-1px);
    }
}

@keyframes tm-chatbot-launcher-pulse {
    0% {
        transform: scale(1);
        opacity: 0.45;
    }

    70% {
        transform: scale(1.35);
        opacity: 0;
    }

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

.tm-chatbot__product-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.tm-chatbot__product-card {
    display: grid;
    grid-template-columns: 44px 1fr;
    gap: 0.5rem;
    align-items: start;
    padding: 0.45rem;
    border: 1px solid var(--tm-chatbot-border);
    border-radius: 0.5rem;
    background: #fff;
    color: inherit;
    text-decoration: none;
}

.tm-chatbot__product-card:hover {
    border-color: #93c5fd;
    background: #f8fafc;
}

.tm-chatbot__product-card-image {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 0.35rem;
    background: var(--tm-chatbot-messages-bg);
}

.tm-chatbot__product-card-body {
    min-width: 0;
}

.tm-chatbot__product-card-title {
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tm-chatbot__product-card-price {
    margin-top: 0.2rem;
    font-size: 0.76rem;
    font-weight: 600;
}

.tm-chatbot__product-card-stock {
    margin-top: 0.15rem;
    font-size: 0.7rem;
    color: var(--tm-chatbot-muted-foreground);
}

.tm-chatbot__form {
    border-top: 1px solid var(--tm-chatbot-border);
    background: var(--tm-chatbot-card);
    padding: 0.85rem 1rem 1rem;
}

.tm-chatbot__form--busy {
    opacity: 0.92;
}

.tm-chatbot__composer {
    display: flex;
    align-items: flex-end;
    gap: 0.55rem;
}

.tm-chatbot__input {
    flex: 1;
    width: 100%;
    min-height: 2.75rem;
    max-height: 7.5rem;
    resize: none;
    border: 1px solid var(--tm-chatbot-border);
    border-radius: 999px;
    padding: 0.7rem 1rem;
    font: inherit;
    background: var(--tm-chatbot-input-bg);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.tm-chatbot__input:focus {
    outline: none;
    border-color: var(--tm-chatbot-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.tm-chatbot__input[readonly] {
    opacity: 0.85;
}

.tm-chatbot__send {
    width: 2.75rem;
    height: 2.75rem;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--tm-chatbot-primary), var(--tm-chatbot-primary-end));
    color: var(--tm-chatbot-primary-foreground);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.tm-chatbot__send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.tm-chatbot__send-icon {
    width: 1rem;
    height: 1rem;
    display: block;
    transform: translateX(1px);
    background:
        linear-gradient(currentColor, currentColor) center/0.12rem 0.55rem no-repeat,
        conic-gradient(from 135deg at 50% 50%, transparent 0 45deg, currentColor 45deg 360deg) center/100% 100% no-repeat;
    clip-path: polygon(18% 44%, 62% 44%, 62% 28%, 92% 50%, 62% 72%, 62% 56%, 18% 56%);
}

.tm-chatbot__help {
    margin: 0.55rem 0 0;
    font-size: 0.75rem;
    color: var(--tm-chatbot-muted-foreground);
}

.tm-chatbot__contact-capture {
    margin: 0.75rem 1rem 0;
    padding: 0.75rem;
    border: 1px solid var(--tm-chatbot-border);
    border-radius: calc(var(--tm-chatbot-radius) - 0.125rem);
    background: var(--tm-chatbot-input-bg);
}

.tm-chatbot__contact-capture-title {
    margin: 0 0 0.35rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.tm-chatbot__contact-capture-copy {
    margin: 0 0 0.65rem;
    font-size: 0.75rem;
    color: var(--tm-chatbot-muted-foreground);
}

.tm-chatbot__contact-label {
    display: block;
    margin: 0.45rem 0 0.2rem;
    font-size: 0.75rem;
}

.tm-chatbot__contact-input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--tm-chatbot-border);
    border-radius: 0.375rem;
    padding: 0.45rem 0.55rem;
    font: inherit;
    background: var(--tm-chatbot-card);
}

.tm-chatbot__contact-submit {
    margin-top: 0.65rem;
    width: 100%;
    border: 0;
    border-radius: 0.375rem;
    padding: 0.55rem 0.75rem;
    background: var(--tm-chatbot-primary);
    color: var(--tm-chatbot-primary-foreground);
    font: inherit;
    cursor: pointer;
}

.tm-chatbot__contact-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.tm-chatbot__contact-status {
    margin: 0.5rem 0 0;
    font-size: 0.75rem;
    color: var(--tm-chatbot-muted-foreground);
}

.tm-chatbot__sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 480px) {
    .tm-chatbot {
        right: 0.75rem;
        bottom: 0.75rem;
    }

    .tm-chatbot__panel {
        width: calc(100vw - 1.5rem);
        height: min(30rem, calc(100vh - 5rem));
    }
}
