/* =============================================
   TFAST HUB — AI Chatbot Widget Styles
   ============================================= */

/* CSS Custom Properties */
.tf-chat-widget {
    --tf-primary: #502C97;
    --tf-primary-hover: color-mix(in srgb, var(--tf-primary) 85%, #000);
    --tf-primary-light: color-mix(in srgb, var(--tf-primary) 10%, #fff);
    --tf-bg: #ffffff;
    --tf-bg-light: #f8f9fa;
    --tf-text: #1a1a2e;
    --tf-text-muted: #6c757d;
    --tf-border: #e9ecef;
    --tf-radius: 16px;
    --tf-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    --tf-shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.18);
    --tf-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --tf-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-family: var(--tf-font);
    z-index: 999999;
}

/* ===== Position ===== */
.tf-chat-widget {
    position: fixed;
    bottom: 20px;
    z-index: 999999;
}

.tf-chat-widget.tf-chat-right {
    right: 20px;
}

.tf-chat-widget.tf-chat-left {
    left: 20px;
}

/* ===== Toggle Button ===== */
.tf-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--tf-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--tf-shadow);
    transition: var(--tf-transition);
    position: relative;
    outline: none;
}

.tf-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: var(--tf-shadow-lg);
}

.tf-chat-toggle:active {
    transform: scale(0.95);
}

.tf-chat-toggle-icon {
    font-size: 24px;
}

.tf-chat-toggle-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.tf-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    background: #dc3545;
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* ===== Chat Window ===== */
.tf-chat-window {
    position: absolute;
    bottom: 75px;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--tf-bg);
    border-radius: var(--tf-radius);
    box-shadow: var(--tf-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: tfChatOpen 0.3s ease-out;
    border: 1px solid var(--tf-border);
}

.tf-chat-right .tf-chat-window {
    right: 0;
}

.tf-chat-left .tf-chat-window {
    left: 0;
}

@keyframes tfChatOpen {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.tf-chat-window.tf-chat-closing {
    animation: tfChatClose 0.2s ease-in forwards;
}

@keyframes tfChatClose {
    to {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
}

/* ===== Header ===== */
.tf-chat-header {
    background: var(--tf-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 60px;
    flex-shrink: 0;
}

.tf-chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.tf-chat-header-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.tf-chat-title {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tf-chat-subtitle {
    font-size: 11px;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tf-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.tf-chat-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    font-size: 14px;
}

.tf-chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ===== Pre-chat Form ===== */
.tf-chat-prechat {
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--tf-bg);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tf-chat-prechat-inner {
    padding: 30px;
    text-align: center;
    width: 100%;
}

.tf-chat-prechat-icon {
    margin-bottom: 16px;
}

.tf-chat-avatar-lg {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    margin: 0 auto;
    display: block;
}

.tf-chat-avatar-default {
    background: var(--tf-primary-light);
    color: var(--tf-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    margin: 0 auto;
}

.tf-chat-prechat-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--tf-text);
    margin-bottom: 8px;
}

.tf-chat-prechat-text {
    font-size: 13px;
    color: var(--tf-text-muted);
    margin-bottom: 20px;
    line-height: 1.5;
}

.tf-chat-form-group {
    margin-bottom: 12px;
}

.tf-chat-input-field {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--tf-border);
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: var(--tf-font);
}

.tf-chat-input-field:focus {
    border-color: var(--tf-primary);
}

.tf-chat-prechat-btn {
    width: 100%;
    padding: 11px 20px;
    background: var(--tf-primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--tf-transition);
    font-family: var(--tf-font);
    margin-top: 6px;
}

.tf-chat-prechat-btn:hover {
    background: var(--tf-primary-hover);
}

/* ===== Messages Area ===== */
.tf-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.tf-chat-messages::-webkit-scrollbar {
    width: 5px;
}

.tf-chat-messages::-webkit-scrollbar-thumb {
    background: var(--tf-border);
    border-radius: 10px;
}

/* ===== Message Bubbles ===== */
.tf-chat-msg {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: tfMsgIn 0.3s ease-out;
}

@keyframes tfMsgIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tf-chat-msg-bot {
    justify-content: flex-start;
}

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

.tf-chat-msg-avatar {
    flex-shrink: 0;
}

.tf-chat-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
}

.tf-chat-avatar-default-sm {
    background: var(--tf-primary-light);
    color: var(--tf-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
}

.tf-chat-msg-content {
    max-width: 78%;
    display: flex;
    flex-direction: column;
}

.tf-chat-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
}

.tf-chat-bubble-bot {
    background: var(--tf-bg-light);
    color: var(--tf-text);
    border-bottom-left-radius: 4px;
}

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

.tf-chat-msg-time {
    font-size: 10px;
    color: var(--tf-text-muted);
    margin-top: 3px;
    padding: 0 4px;
}

.tf-chat-msg-user .tf-chat-msg-time {
    text-align: right;
}

/* Message content formatting */
.tf-chat-bubble p {
    margin: 0 0 8px;
}

.tf-chat-bubble p:last-child {
    margin-bottom: 0;
}

.tf-chat-bubble ul,
.tf-chat-bubble ol {
    margin: 0 0 8px;
    padding-left: 20px;
}

.tf-chat-bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
}

.tf-chat-bubble-user code {
    background: rgba(255, 255, 255, 0.2);
}

.tf-chat-bubble pre {
    background: rgba(0, 0, 0, 0.06);
    padding: 8px 10px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 4px 0;
    font-size: 12px;
}

.tf-chat-bubble-user pre {
    background: rgba(255, 255, 255, 0.15);
}

/* TTS button on bot messages */
.tf-chat-tts-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--tf-border);
    color: var(--tf-text-muted);
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s;
    margin-top: 4px;
}

.tf-chat-tts-btn:hover {
    background: var(--tf-primary-light);
    color: var(--tf-primary);
    border-color: var(--tf-primary);
}

.tf-chat-tts-btn.playing {
    background: var(--tf-primary);
    color: #fff;
    border-color: var(--tf-primary);
    animation: tfPulse 1.5s infinite;
}

@keyframes tfPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

/* Audio message */
.tf-chat-audio-player {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.tf-chat-audio-player audio {
    height: 32px;
    max-width: 200px;
}

/* Image message */
.tf-chat-msg-image {
    max-width: 200px;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s;
}

.tf-chat-msg-image:hover {
    transform: scale(1.03);
}

/* File message */
.tf-chat-file-msg {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 12px;
}

.tf-chat-file-msg i {
    font-size: 18px;
}

.tf-chat-file-msg a {
    color: inherit;
    text-decoration: underline;
}

/* ===== Quick Replies ===== */
.tf-chat-quick-replies {
    padding: 8px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border-top: 1px solid var(--tf-border);
    flex-shrink: 0;
}

.tf-chat-quick-btn {
    padding: 6px 14px;
    border: 1.5px solid var(--tf-primary);
    background: transparent;
    color: var(--tf-primary);
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--tf-font);
    white-space: nowrap;
}

.tf-chat-quick-btn:hover {
    background: var(--tf-primary);
    color: #fff;
}

/* ===== Typing Indicator ===== */
.tf-chat-typing {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.tf-chat-typing-dots {
    display: flex;
    gap: 4px;
    padding: 8px 14px;
    background: var(--tf-bg-light);
    border-radius: 14px;
}

.tf-chat-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--tf-text-muted);
    animation: tfTypingDot 1.4s infinite ease-in-out both;
}

.tf-chat-typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.tf-chat-typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes tfTypingDot {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ===== Input Area ===== */
.tf-chat-input {
    border-top: 1px solid var(--tf-border);
    padding: 10px 12px;
    flex-shrink: 0;
    background: var(--tf-bg);
}

.tf-chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.tf-chat-textarea {
    flex: 1;
    border: 1.5px solid var(--tf-border);
    border-radius: 12px;
    padding: 9px 14px;
    font-size: 13.5px;
    resize: none;
    outline: none;
    max-height: 100px;
    transition: border-color 0.2s;
    font-family: var(--tf-font);
    line-height: 1.45;
}

.tf-chat-textarea:focus {
    border-color: var(--tf-primary);
}

.tf-chat-textarea::placeholder {
    color: var(--tf-text-muted);
}

.tf-chat-input-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    border: 1.5px solid var(--tf-border);
    color: var(--tf-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    font-size: 15px;
}

.tf-chat-input-btn:hover {
    background: var(--tf-primary-light);
    color: var(--tf-primary);
    border-color: var(--tf-primary);
}

.tf-chat-stt-btn.recording {
    background: #dc3545;
    color: #fff;
    border-color: #dc3545;
    animation: tfPulse 1s infinite;
}

.tf-chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--tf-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--tf-transition);
    flex-shrink: 0;
    font-size: 14px;
}

.tf-chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.tf-chat-send-btn:not(:disabled):hover {
    background: var(--tf-primary-hover);
    transform: scale(1.05);
}

/* ===== Voice Recording UI ===== */
.tf-chat-voice-recording {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 6px 0;
}

.tf-chat-voice-cancel,
.tf-chat-voice-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s;
}

.tf-chat-voice-cancel {
    background: var(--tf-bg-light);
    color: #dc3545;
}

.tf-chat-voice-cancel:hover {
    background: #dc3545;
    color: #fff;
}

.tf-chat-voice-send {
    background: var(--tf-primary);
    color: #fff;
}

.tf-chat-voice-send:hover {
    background: var(--tf-primary-hover);
}

.tf-chat-voice-timer {
    font-size: 16px;
    font-weight: 600;
    color: #dc3545;
    min-width: 50px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.tf-chat-voice-wave {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 24px;
}

.tf-chat-voice-wave span {
    width: 3px;
    height: 100%;
    background: #dc3545;
    border-radius: 2px;
    animation: tfVoiceWave 0.8s ease-in-out infinite alternate;
}

.tf-chat-voice-wave span:nth-child(1) {
    animation-delay: 0s;
    height: 40%;
}

.tf-chat-voice-wave span:nth-child(2) {
    animation-delay: 0.1s;
    height: 70%;
}

.tf-chat-voice-wave span:nth-child(3) {
    animation-delay: 0.2s;
    height: 100%;
}

.tf-chat-voice-wave span:nth-child(4) {
    animation-delay: 0.3s;
    height: 60%;
}

.tf-chat-voice-wave span:nth-child(5) {
    animation-delay: 0.4s;
    height: 30%;
}

@keyframes tfVoiceWave {
    from {
        transform: scaleY(0.4);
    }

    to {
        transform: scaleY(1);
    }
}

/* ===== Feedback Modal ===== */
.tf-chat-feedback {
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--tf-bg);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tf-chat-feedback-inner {
    padding: 30px;
    text-align: center;
    width: 100%;
}

.tf-chat-feedback-inner h5 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--tf-text);
}

.tf-chat-stars {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}

.tf-chat-star {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: transparent;
    border: 2px solid var(--tf-border);
    color: var(--tf-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.2s;
}

.tf-chat-star:hover,
.tf-chat-star.active {
    background: #fff3cd;
    border-color: #ffc107;
    color: #ffc107;
}

.tf-chat-star.active i {
    font-weight: 900;
}

.tf-chat-feedback-text {
    width: 100%;
    border: 1.5px solid var(--tf-border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    outline: none;
    resize: none;
    margin-bottom: 14px;
    font-family: var(--tf-font);
    transition: border-color 0.2s;
}

.tf-chat-feedback-text:focus {
    border-color: var(--tf-primary);
}

.tf-chat-feedback-skip {
    display: block;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--tf-text-muted);
    padding: 10px;
    cursor: pointer;
    font-size: 13px;
    font-family: var(--tf-font);
    margin-top: 6px;
}

.tf-chat-feedback-skip:hover {
    color: var(--tf-text);
}

/* ===== Mobile Responsive ===== */
@media (max-width: 480px) {
    .tf-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        animation: tfChatMobileOpen 0.3s ease-out;
    }

    .tf-chat-right .tf-chat-window,
    .tf-chat-left .tf-chat-window {
        right: auto;
        left: auto;
    }

    @keyframes tfChatMobileOpen {
        from {
            opacity: 0;
            transform: translateY(100%);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .tf-chat-window.tf-chat-closing {
        animation: tfChatMobileClose 0.25s ease-in forwards;
    }

    @keyframes tfChatMobileClose {
        to {
            opacity: 0;
            transform: translateY(100%);
        }
    }

    .tf-chat-toggle {
        width: 54px;
        height: 54px;
    }

    .tf-chat-widget {
        bottom: 16px;
    }

    .tf-chat-widget.tf-chat-right {
        right: 16px;
    }

    .tf-chat-widget.tf-chat-left {
        left: 16px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .tf-chat-window {
        width: 340px;
        height: 500px;
    }
}

/* ===== Utilities ===== */
.tf-chat-hidden {
    display: none !important;
}

.tf-chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.tf-chat-loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--tf-border);
    border-top: 3px solid var(--tf-primary);
    border-radius: 50%;
    animation: tfSpin 0.8s linear infinite;
}

@keyframes tfSpin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Scrollbar for widget on desktop ===== */
@media (pointer: fine) {
    .tf-chat-messages::-webkit-scrollbar {
        width: 5px;
    }

    .tf-chat-messages::-webkit-scrollbar-track {
        background: transparent;
    }

    .tf-chat-messages::-webkit-scrollbar-thumb {
        background: var(--tf-border);
        border-radius: 10px;
    }

    .tf-chat-messages::-webkit-scrollbar-thumb:hover {
        background: var(--tf-text-muted);
    }
}

/* ===== Business Hours Status Banner ===== */
.tf-chat-biz-status {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    border-radius: var(--tf-radius) var(--tf-radius) 0 0;
    color: #fff;
    margin-bottom: 0;
}

.tf-chat-biz-status.tf-biz-open {
    background: linear-gradient(135deg, #10b981, #059669);
}

.tf-chat-biz-status.tf-biz-closed {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.tf-biz-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fff;
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

/* ===== AI Suggestions ===== */
.tf-chat-suggestions {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid var(--tf-border);
    background: var(--tf-bg-light);
    max-height: 80px;
    overflow-y: auto;
}

.tf-chat-suggest-btn {
    padding: 4px 10px;
    font-size: 12px;
    background: var(--tf-primary-light);
    color: var(--tf-primary);
    border: 1px solid var(--tf-primary);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--tf-transition);
}

.tf-chat-suggest-btn:hover {
    background: var(--tf-primary);
    color: #fff;
}

/* ===== Translate Button ===== */
.tf-chat-translate-btn {
    transition: var(--tf-transition);
}

.tf-chat-translate-btn.active {
    background: var(--tf-primary);
    color: #fff;
}

/* ===== Translated Text ===== */
.tf-chat-translated {
    display: block;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--tf-border);
    font-size: 12px;
    color: var(--tf-text-muted);
}