/* TopVite AI Chat - frontend widget */
#tvac-widget {
    --tvac-primary: #1e3a8a;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    z-index: 999999;
}

#tvac-widget *,
#tvac-widget *::before,
#tvac-widget *::after {
    box-sizing: border-box;
}

#tvac-toggle {
    position: fixed;
    bottom: 24px;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: var(--tvac-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
    transition: transform .2s ease, box-shadow .2s ease;
}

#tvac-toggle:hover {
    transform: scale(1.06);
    box-shadow: 0 8px 26px rgba(0, 0, 0, .3);
}

.tvac-position-right #tvac-toggle { right: 24px; }
.tvac-position-left #tvac-toggle { left: 24px; }

.tvac-position-right #tvac-panel { right: 24px; }
.tvac-position-left #tvac-panel { left: 24px; }

#tvac-widget .tvac-icon-close { display: none; }
#tvac-widget.tvac-open .tvac-icon-open { display: none; }
#tvac-widget.tvac-open .tvac-icon-close { display: block; }

#tvac-panel {
    position: fixed;
    bottom: 96px;
    width: 370px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 130px);
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: tvac-pop .18s ease;
}

#tvac-panel[hidden] {
    display: none;
}

@keyframes tvac-pop {
    from { opacity: 0; transform: translateY(10px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

#tvac-header {
    background: var(--tvac-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
}

.tvac-header-actions button {
    background: rgba(255, 255, 255, .15);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    margin-left: 6px;
}

.tvac-header-actions button:hover {
    background: rgba(255, 255, 255, .3);
}

#tvac-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f6f7fb;
}

.tvac-msg {
    display: flex;
    margin-bottom: 12px;
}

.tvac-msg-user {
    justify-content: flex-end;
}

.tvac-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.tvac-msg-assistant .tvac-bubble {
    background: #fff;
    color: #1d2327;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

.tvac-msg-user .tvac-bubble {
    background: var(--tvac-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

#tvac-typing {
    padding: 0 16px 8px;
    background: #f6f7fb;
}

#tvac-typing span {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 4px;
    border-radius: 50%;
    background: #9aa0a6;
    animation: tvac-blink 1.2s infinite;
}

#tvac-typing span:nth-child(2) { animation-delay: .2s; }
#tvac-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes tvac-blink {
    0%, 80%, 100% { opacity: .3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

#tvac-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #e5e7eb;
}

#tvac-input {
    flex: 1;
    resize: none;
    border: 1px solid #d7dce2;
    border-radius: 20px;
    padding: 9px 14px;
    font-family: inherit;
    font-size: 15px;
    max-height: 110px;
    outline: none;
}

#tvac-input:focus {
    border-color: var(--tvac-primary);
}

#tvac-send {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: var(--tvac-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(45deg);
}

#tvac-send:hover {
    filter: brightness(1.1);
}

.tvac-privacy {
    margin: 0;
    padding: 0 14px 10px;
    font-size: 11px;
    color: #8a9097;
    background: #fff;
}

@media (max-width: 480px) {
    #tvac-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    .tvac-position-right #tvac-toggle,
    .tvac-position-left #tvac-toggle {
        right: 16px;
        left: auto;
        bottom: 16px;
    }
}

/* Track my order */
#tvac-track-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 8px 12px 0;
    padding: 8px 12px;
    width: calc(100% - 24px);
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: #1d2327;
    transition: border-color .15s ease, color .15s ease;
}

#tvac-track-toggle:hover {
    border-color: var(--tvac-primary);
    color: var(--tvac-primary);
}

#tvac-track-form {
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #eef0f2;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#tvac-track-form[hidden] {
    display: none;
}

#tvac-track-form input {
    border: 1px solid #d7dce2;
    border-radius: 10px;
    padding: 9px 12px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    width: 100%;
}

#tvac-track-form input:focus {
    border-color: var(--tvac-primary);
}

.tvac-track-actions {
    display: flex;
    gap: 8px;
}

.tvac-track-submit {
    flex: 1;
    background: var(--tvac-primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 9px;
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
    font-size: 14px;
}

.tvac-track-submit:hover {
    filter: brightness(1.1);
}

.tvac-track-cancel {
    background: #f0f1f3;
    color: #1d2327;
    border: none;
    border-radius: 10px;
    padding: 9px 14px;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
}

/* --- Sizing fixes: prevent theme styles from inflating the composer ------- */

/* The message list must always keep its flex space and scroll internally. */
#tvac-messages {
    min-height: 0;
}

/* The composer must never grow beyond its content. */
#tvac-form {
    flex-shrink: 0;
}

/* Explicit composer dimensions (ID specificity beats theme element rules). */
#tvac-input {
    height: 42px;
    min-height: 42px;
    max-height: 110px;
    overflow-y: auto;
}

/* Keep theme min-heights away from every field inside the widget. */
#tvac-widget textarea,
#tvac-widget input[type="text"],
#tvac-widget input[type="email"] {
    min-height: 0;
}

/* Track-order fields get an explicit comfortable height. */
#tvac-track-form input {
    height: 42px;
    min-height: 42px;
}

/* --- Floating contact menu (bot + messenger + email) ----------------------- */

#tvac-fab-stack {
    position: fixed;
    bottom: 96px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 1;
}

.tvac-position-right #tvac-fab-stack { right: 30px; }
.tvac-position-left #tvac-fab-stack { left: 30px; }

.tvac-fab-item {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--tvac-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .22);
    text-decoration: none;
    opacity: 0;
    transform: translateY(14px) scale(.5);
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease, box-shadow .15s ease;
    padding: 0;
}

.tvac-fab-item img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.tvac-fab-item:hover {
    box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
    transform: translateY(-2px) scale(1.05);
}

#tvac-widget.tvac-menu-open .tvac-fab-item {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

#tvac-widget.tvac-menu-open .tvac-fab-item:nth-child(1) { transition-delay: .1s; }
#tvac-widget.tvac-menu-open .tvac-fab-item:nth-child(2) { transition-delay: .05s; }
#tvac-widget.tvac-menu-open .tvac-fab-item:nth-child(3) { transition-delay: 0s; }

/* Chat panel must sit above the stack. */
#tvac-panel {
    z-index: 2;
}

@media (max-width: 480px) {
    .tvac-position-right #tvac-fab-stack,
    .tvac-position-left #tvac-fab-stack {
        right: 22px;
        left: auto;
        bottom: 80px;
    }
}

/* Human agent (Telegram takeover) messages */
.tvac-msg-human .tvac-bubble {
    background: #065f46;
    color: #fff;
    border-bottom-left-radius: 4px;
}

.tvac-agent-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    opacity: .8;
    margin-bottom: 4px;
}

/* Clickable product cards shown under AI replies */
.tvac-products {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tvac-product {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 8px;
    text-decoration: none;
    color: #1d2327;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.tvac-product:hover {
    border-color: var(--tvac-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

.tvac-product img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
}

.tvac-product-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.tvac-product-name {
    font-weight: 600;
    font-size: 13px;
    line-height: 1.3;
}

.tvac-product-price {
    color: var(--tvac-primary);
    font-weight: 700;
    font-size: 13px;
}

.tvac-product-cta {
    font-size: 11px;
    color: #8a9097;
}

/* Links inside bubbles */
.tvac-bubble a {
    color: var(--tvac-primary);
    text-decoration: underline;
    word-break: break-all;
}

.tvac-msg-user .tvac-bubble a {
    color: #fff;
}

/* --- Hover tooltips on the floating buttons ------------------------------- */

.tvac-fab-item,
#tvac-toggle {
    position: relative;
}

.tvac-fab-item::after,
#tvac-toggle::after {
    content: attr(data-label);
    position: absolute;
    top: 50%;
    right: calc(100% + 12px);
    transform: translateY(-50%) translateX(4px);
    background: #1d2327;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    padding: 6px 11px;
    border-radius: 8px;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease, transform .15s ease;
    z-index: 3;
}

.tvac-position-left .tvac-fab-item::after,
.tvac-position-left #tvac-toggle::after {
    right: auto;
    left: calc(100% + 12px);
    transform: translateY(-50%) translateX(-4px);
}

.tvac-fab-item:hover::after,
#tvac-toggle:hover::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

@media (max-width: 480px) {
    .tvac-fab-item::after,
    #tvac-toggle::after {
        display: none;
    }
}
