/* ============================================================
   chatbot.css — Transay Dijital Asistan UI
   Prefix: ts-chatbot
   Z-index: 9998 (below navbar 9999, below cookie banner 9999)
   ============================================================ */

/* ── Custom properties ──────────────────────────────────────── */
.ts-chatbot {
    --ts-cb-brand:        var(--tx-navy-500, #04415f);
    --ts-cb-brand-dark:   var(--tx-navy-700, #0a2940);
    --ts-cb-brand-light:  var(--tx-navy-100, #d3dee6);
    --ts-cb-surface:      var(--tx-white, #ffffff);
    --ts-cb-surface-alt:  var(--tx-cream, #f1f5f7);
    --ts-cb-text:         var(--tx-navy-900, #060e1a);
    --ts-cb-text-muted:   var(--tx-text-muted, #6a7a88);
    --ts-cb-user-bg:      var(--tx-navy-500, #04415f);
    --ts-cb-user-text:    var(--tx-white, #ffffff);
    --ts-cb-bot-bg:       var(--tx-cream, #f1f5f7);
    --ts-cb-bot-text:     var(--tx-navy-900, #060e1a);
    --ts-cb-border:       var(--tx-border, rgba(1, 30, 44, 0.10));
    --ts-cb-shadow:       var(--tx-shadow-lg, 0 28px 70px rgba(1, 30, 44, 0.14));
    --ts-cb-radius-lg:    16px;
    --ts-cb-radius-md:    12px;
    --ts-cb-radius-sm:    8px;
    --ts-cb-transition:   0.22s cubic-bezier(0.4, 0, 0.2, 1);
    --ts-cb-panel-w:      360px;
    --ts-cb-panel-h:      min(520px, 70vh);
    --ts-cb-launcher-sz:  56px;
    --ts-cb-offset:       1.5rem;
}

/* ── Container ──────────────────────────────────────────────── */
.ts-chatbot {
    position: fixed;
    bottom: var(--ts-cb-offset);
    right: var(--ts-cb-offset);
    z-index: 9998;
    font-family: inherit;
}

/* ── Launcher button ────────────────────────────────────────── */
.ts-chatbot-launcher {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--ts-cb-launcher-sz);
    height: var(--ts-cb-launcher-sz);
    border-radius: 50%;
    border: none;
    background: var(--ts-cb-brand);
    color: var(--ts-cb-surface);
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(4, 65, 95, 0.35);
    transition: background var(--ts-cb-transition),
                box-shadow var(--ts-cb-transition),
                transform var(--ts-cb-transition);
    position: relative;
    z-index: 1;
}
.ts-chatbot-launcher:hover {
    background: var(--ts-cb-brand-dark);
    box-shadow: 0 6px 24px rgba(4, 65, 95, 0.45);
    transform: translateY(-2px);
}
.ts-chatbot-launcher:focus-visible {
    outline: 3px solid var(--ts-cb-brand-light);
    outline-offset: 3px;
}

.ts-chatbot-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    transition: opacity var(--ts-cb-transition), transform var(--ts-cb-transition);
}
.ts-chatbot-icon--close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.7);
}
.ts-chatbot--open .ts-chatbot-icon--chat {
    opacity: 0;
    transform: rotate(90deg) scale(0.7);
}
.ts-chatbot--open .ts-chatbot-icon--close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* ── Panel ──────────────────────────────────────────────────── */
.ts-chatbot-panel {
    position: absolute;
    bottom: calc(var(--ts-cb-launcher-sz) + 0.75rem);
    right: 0;
    width: var(--ts-cb-panel-w);
    max-width: calc(100vw - 2rem);
    max-height: var(--ts-cb-panel-h);
    background: var(--ts-cb-surface);
    border-radius: var(--ts-cb-radius-lg);
    box-shadow: var(--ts-cb-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px) scale(0.97);
    transform-origin: bottom right;
    pointer-events: none;
    visibility: hidden;
    transition: opacity var(--ts-cb-transition),
                transform var(--ts-cb-transition),
                visibility var(--ts-cb-transition);
}
.ts-chatbot-panel--open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    visibility: visible;
}

/* ── Header ─────────────────────────────────────────────────── */
.ts-chatbot-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1rem 1rem 1.25rem;
    background: var(--ts-cb-brand);
    color: var(--ts-cb-surface);
    flex-shrink: 0;
}
.ts-chatbot-header-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.ts-chatbot-header-title {
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ts-chatbot-header-subtitle {
    font-size: 0.75rem;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ts-chatbot-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}
.ts-chatbot-header-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--ts-cb-surface);
    cursor: pointer;
    opacity: 0.7;
    transition: opacity var(--ts-cb-transition), background var(--ts-cb-transition);
    flex-shrink: 0;
}
.ts-chatbot-header-btn:hover { opacity: 1; background: rgba(255,255,255,0.12); }
.ts-chatbot-header-btn:focus-visible { outline: 2px solid rgba(255,255,255,0.6); outline-offset: 2px; }
.ts-chatbot-header-btn:disabled { opacity: 0.35; cursor: default; }
.ts-chatbot-header-btn:disabled:hover { background: transparent; }

/* ── Messages ───────────────────────────────────────────────── */
.ts-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scroll-behavior: smooth;
}
.ts-chatbot-messages::-webkit-scrollbar { width: 4px; }
.ts-chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.ts-chatbot-messages::-webkit-scrollbar-thumb { background: var(--ts-cb-border); border-radius: 2px; }

/* Message rows */
.ts-chatbot-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    gap: 0.375rem;
}
.ts-chatbot-message--user { align-self: flex-end; align-items: flex-end; }
.ts-chatbot-message--bot  { align-self: flex-start; align-items: flex-start; }

.ts-chatbot-message-bubble {
    padding: 0.625rem 0.875rem;
    border-radius: var(--ts-cb-radius-md);
    word-break: break-word;
    overflow-wrap: anywhere;
}
.ts-chatbot-message--user .ts-chatbot-message-bubble {
    background: var(--ts-cb-user-bg);
    color: var(--ts-cb-user-text);
    border-bottom-right-radius: 4px;
}
.ts-chatbot-message--bot .ts-chatbot-message-bubble {
    background: var(--ts-cb-bot-bg);
    color: var(--ts-cb-bot-text);
    border-bottom-left-radius: 4px;
}
.ts-chatbot-message-text {
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0;
    white-space: pre-wrap;
}

/* Actions within a message */
.ts-chatbot-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    padding: 0 0.25rem;
}
.ts-chatbot-action-btn {
    font-size: 0.8125rem;
    padding: 0.375rem 0.75rem;
    border-radius: 20px;
    border: 1.5px solid var(--ts-cb-brand);
    background: transparent;
    color: var(--ts-cb-brand);
    cursor: pointer;
    transition: background var(--ts-cb-transition), color var(--ts-cb-transition);
    line-height: 1.4;
}
.ts-chatbot-action-btn:hover {
    background: var(--ts-cb-brand);
    color: var(--ts-cb-surface);
}
.ts-chatbot-action-btn:focus-visible {
    outline: 2px solid var(--ts-cb-brand);
    outline-offset: 2px;
}

/* Typing indicator */
.ts-chatbot-typing {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 0.25rem 0.125rem;
}
.ts-chatbot-typing span {
    width: 7px;
    height: 7px;
    background: var(--ts-cb-text-muted);
    border-radius: 50%;
    animation: ts-chatbot-bounce 1.3s ease-in-out infinite;
}
.ts-chatbot-typing span:nth-child(2) { animation-delay: 0.18s; }
.ts-chatbot-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes ts-chatbot-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
    30%            { transform: translateY(-7px); opacity: 1; }
}

/* ── Quick replies ───────────────────────────────────────────── */
.ts-chatbot-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border-top: 1px solid var(--ts-cb-border);
    flex-shrink: 0;
}
.ts-chatbot-quick-replies[hidden] { display: none; }

.ts-chatbot-quick-reply {
    font-size: 0.8125rem;
    padding: 0.375rem 0.75rem;
    border-radius: 20px;
    border: 1.5px solid var(--ts-cb-brand-light);
    background: var(--ts-cb-surface);
    color: var(--ts-cb-brand);
    cursor: pointer;
    transition: border-color var(--ts-cb-transition),
                background var(--ts-cb-transition),
                color var(--ts-cb-transition);
    line-height: 1.4;
}
.ts-chatbot-quick-reply:hover {
    border-color: var(--ts-cb-brand);
    background: var(--ts-cb-surface-alt);
}
.ts-chatbot-quick-reply:focus-visible {
    outline: 2px solid var(--ts-cb-brand);
    outline-offset: 2px;
}

/* ── Input area ──────────────────────────────────────────────── */
.ts-chatbot-input-area {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--ts-cb-border);
    background: var(--ts-cb-surface);
    flex-shrink: 0;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
}
.ts-chatbot-input {
    flex: 1;
    border: 1.5px solid var(--ts-cb-border);
    border-radius: var(--ts-cb-radius-sm);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    background: var(--ts-cb-surface-alt);
    color: var(--ts-cb-text);
    transition: border-color var(--ts-cb-transition);
    scrollbar-width: thin;
}
.ts-chatbot-input:focus {
    outline: none;
    border-color: var(--ts-cb-brand);
    background: var(--ts-cb-surface);
}
.ts-chatbot-input::placeholder { color: var(--ts-cb-text-muted); }

.ts-chatbot-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--ts-cb-radius-sm);
    border: none;
    background: var(--ts-cb-brand);
    color: var(--ts-cb-surface);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--ts-cb-transition), opacity var(--ts-cb-transition);
}
.ts-chatbot-send:hover:not(:disabled) { background: var(--ts-cb-brand-dark); }
.ts-chatbot-send:disabled { opacity: 0.45; cursor: default; }
.ts-chatbot-send:focus-visible { outline: 2px solid var(--ts-cb-brand); outline-offset: 2px; }

/* ── Error area ──────────────────────────────────────────────── */
.ts-chatbot-error {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    color: var(--tx-error, #dc2626);
    background: #fef2f2;
    border-top: 1px solid #fecaca;
    flex-shrink: 0;
}
.ts-chatbot-error[hidden] { display: none; }

/* ── Noscript fallback ───────────────────────────────────────── */
.ts-chatbot-noscript {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    padding: 0.75rem 1rem;
    background: var(--ts-cb-surface-alt);
    border: 1px solid var(--ts-cb-border);
    border-radius: var(--ts-cb-radius-sm);
    font-size: 0.875rem;
    color: var(--ts-cb-text);
    z-index: 9997;
    max-width: 280px;
}
.ts-chatbot-noscript a { color: var(--ts-cb-brand); }

/* ── Screen-reader only ──────────────────────────────────────── */
.ts-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;
}

/* ── RTL ─────────────────────────────────────────────────────── */
html[dir="rtl"] .ts-chatbot {
    right: auto;
    left: var(--ts-cb-offset);
}
html[dir="rtl"] .ts-chatbot-panel {
    right: auto;
    left: 0;
    transform-origin: bottom left;
}
html[dir="rtl"] .ts-chatbot-message--user { align-self: flex-start; align-items: flex-start; }
html[dir="rtl"] .ts-chatbot-message--bot  { align-self: flex-end;   align-items: flex-end; }
html[dir="rtl"] .ts-chatbot-message--user .ts-chatbot-message-bubble {
    border-bottom-right-radius: var(--ts-cb-radius-md);
    border-bottom-left-radius: 4px;
}
html[dir="rtl"] .ts-chatbot-message--bot .ts-chatbot-message-bubble {
    border-bottom-left-radius: var(--ts-cb-radius-md);
    border-bottom-right-radius: 4px;
}
html[dir="rtl"] .ts-chatbot-noscript { right: auto; left: 1rem; }

/* ── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 639px) {
    .ts-chatbot {
        bottom: 0;
        right: 0;
        left: 0;
        --ts-cb-offset: 0px;
    }
    .ts-chatbot-launcher {
        position: fixed;
        bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
        right: 1.25rem;
        z-index: 9998;
    }
    .ts-chatbot-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 90dvh;
        max-height: 90vh;
        border-radius: var(--ts-cb-radius-lg) var(--ts-cb-radius-lg) 0 0;
        transform: translateY(100%);
        transform-origin: bottom center;
    }
    .ts-chatbot-panel--open {
        transform: translateY(0);
    }
    html[dir="rtl"] .ts-chatbot-launcher { right: auto; left: 1.25rem; }
}

/* ── Scroll-top offset (body class set by JS) ────────────────── */
body.ts-chatbot-present #scroll-top {
    bottom: calc(56px + 1.5rem + 0.75rem) !important;
}
body.ts-chatbot-open #scroll-top {
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}
@media (max-width: 639px) {
    body.ts-chatbot-present #scroll-top {
        bottom: calc(56px + 1.25rem + 0.5rem + env(safe-area-inset-bottom, 0px)) !important;
    }
    body.ts-chatbot-open #scroll-top {
        display: none !important;
    }
}

/* ── Reduced motion ──────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .ts-chatbot-panel,
    .ts-chatbot-launcher,
    .ts-chatbot-icon,
    .ts-chatbot-action-btn,
    .ts-chatbot-quick-reply,
    .ts-chatbot-send,
    .ts-chatbot-input {
        transition: none;
    }
    .ts-chatbot-typing span {
        animation: none;
        opacity: 0.6;
    }
    .ts-chatbot-typing span:nth-child(2) { opacity: 0.8; }
    .ts-chatbot-typing span:nth-child(3) { opacity: 1; }
}
