/**
 * Tech Unlock Hub - Live Chat Widget Styles — Phase 2
 *
 * @package TUH_Theme
 * @version 2.0.0
 */

/* ==========================================================================
   CHAT BUBBLE
   ========================================================================== */

.tuh-chat-widget {
    position: fixed;
    bottom: 50px;
    right: 24px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

.tuh-chat-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--tuh-primary, #635bff);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    box-shadow: 0 4px 20px rgba(99, 91, 255, 0.4);
    transition: all 0.3s ease;
    position: relative;
}

.tuh-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(99, 91, 255, 0.5);
}

.tuh-chat-bubble__close {
    font-size: 1.5rem;
    line-height: 1;
}

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

/* ==========================================================================
   CHAT WINDOW
   ========================================================================== */

.tuh-chat-window {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: min(380px, calc(100vw - 24px));
    max-height: 560px;
    background: var(--tuh-bg, #ffffff);
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: tuh-chat-slide-up 0.3s ease;
}

[data-theme="dark"] .tuh-chat-window {
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
}

@keyframes tuh-chat-slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Header */
.tuh-chat-header {
    background: var(--tuh-primary, #635bff);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.tuh-chat-header__info strong {
    display: block;
    font-size: 1rem;
}

.tuh-chat-header__info small {
    opacity: 0.9;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tuh-chat-header__actions {
    display: flex;
    gap: 6px;
}

.tuh-chat-header__actions button {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    opacity: 0.7;
    padding: 4px;
    line-height: 1;
}

.tuh-chat-header__actions button:hover {
    opacity: 1;
}

/* Agent Status Dot */
.tuh-status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tuh-status-dot--online {
    background: #4ade80;
    box-shadow: 0 0 4px rgba(74, 222, 128, 0.6);
}

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

/* ==========================================================================
   PRE-CHAT FORM
   ========================================================================== */

.tuh-chat-prechat {
    padding: 32px 24px;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--tuh-bg, #ffffff);
}

.tuh-chat-prechat__icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.tuh-chat-prechat h3 {
    font-size: 1.25rem;
    margin-bottom: 4px;
    color: var(--tuh-text, #212529);
}

.tuh-chat-prechat p {
    color: var(--tuh-text-secondary, #868e96);
    font-size: 0.875rem;
    margin-bottom: 20px;
}

.tuh-chat-prechat form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tuh-chat-prechat input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--tuh-border, #e9ecef);
    border-radius: 8px;
    font-size: 0.9rem;
    background: var(--tuh-bg, #fff);
    color: var(--tuh-text, #212529);
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.tuh-chat-prechat input:focus {
    outline: none;
    border-color: var(--tuh-primary, #635bff);
}

.tuh-chat-start-btn {
    width: 100%;
    padding: 12px;
    background: var(--tuh-primary, #635bff);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.tuh-chat-start-btn:hover {
    background: var(--tuh-primary-hover, #524ae0);
}

.tuh-chat-start-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ==========================================================================
   OFFLINE — SOCIAL LINKS
   ========================================================================== */

.tuh-chat-offline {
    padding: 32px 24px;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.tuh-chat-offline__icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.tuh-chat-offline h3 {
    font-size: 1.25rem;
    margin-bottom: 4px;
    color: var(--tuh-text, #212529);
}

.tuh-chat-offline p {
    color: var(--tuh-text-secondary, #868e96);
    font-size: 0.875rem;
    margin-bottom: 20px;
}

.tuh-chat-social-links {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.tuh-social-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    transition: transform 0.15s, box-shadow 0.15s;
    color: #fff;
}

.tuh-social-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    color: #fff;
    text-decoration: none;
}

.tuh-social-link--whatsapp {
    background: #25d366;
}

.tuh-social-link--telegram {
    background: #0088cc;
}

.tuh-social-link--messenger {
    background: #0084ff;
}

.tuh-social-link svg {
    flex-shrink: 0;
}

/* ==========================================================================
   QUEUE POSITION
   ========================================================================== */

.tuh-chat-queue {
    padding: 8px 16px;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.8rem;
    text-align: center;
    flex-shrink: 0;
    border-bottom: 1px solid #fde68a;
}

[data-theme="dark"] .tuh-chat-queue {
    background: #422006;
    color: #fbbf24;
    border-bottom-color: #713f12;
}

/* ==========================================================================
   MESSAGES AREA
   ========================================================================== */

.tuh-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex !important;
    flex-direction: column;
    gap: 0 !important;
    min-height: 200px;
    max-height: 320px;
    background: var(--tuh-bg-alt, #f8f9fa);
}

.tuh-chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    margin-bottom: 12px !important;
}

.tuh-chat-msg:last-child {
    margin-bottom: 0 !important;
}

.tuh-chat-msg--visitor {
    align-self: flex-end;
    align-items: flex-end;
}

.tuh-chat-msg--agent,
.tuh-chat-msg--system {
    align-self: flex-start;
    align-items: flex-start;
}

.tuh-chat-msg__bubble {
    padding: 10px 14px;
    border-radius: 12px;
    word-break: break-word;
    line-height: 1.4;
}

.tuh-chat-msg--visitor .tuh-chat-msg__bubble {
    background: var(--tuh-primary, #635bff);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.tuh-chat-msg--agent .tuh-chat-msg__bubble {
    background: var(--tuh-gray-100, #f1f3f5);
    color: var(--tuh-text, #212529);
    border-bottom-left-radius: 4px;
}

[data-theme="dark"] .tuh-chat-msg--agent .tuh-chat-msg__bubble {
    background: var(--tuh-bg-card, #2a2a40);
    color: var(--tuh-text, #e8e8f0);
}

.tuh-chat-msg__system {
    text-align: center;
    width: 100%;
    font-size: 0.75rem;
    color: var(--tuh-text-muted, #adb5bd);
    padding: 4px 0;
    font-style: italic;
}

.tuh-chat-msg--system {
    max-width: 100%;
    align-self: center;
}

.tuh-chat-msg__time {
    font-size: 0.65rem;
    color: var(--tuh-text-muted, #adb5bd);
    margin-top: 2px;
    padding: 0 4px;
}

/* Message formatting */
.tuh-chat-msg__bubble strong {
    font-weight: 700;
}

.tuh-chat-msg__bubble em {
    font-style: italic;
}

.tuh-chat-msg__bubble a {
    color: inherit;
    text-decoration: underline;
}

.tuh-chat-msg--agent .tuh-chat-msg__bubble a {
    color: var(--tuh-primary, #635bff);
}

/* ==========================================================================
   FILE/IMAGE ATTACHMENTS
   ========================================================================== */

.tuh-chat-msg__bubble--image {
    padding: 4px;
    background: transparent !important;
    position: relative;
}

.tuh-chat-msg__bubble--image:hover .tuh-chat-download-link {
    opacity: 1;
}

.tuh-chat-attachment-img {
    max-width: 220px;
    max-height: 200px;
    border-radius: 10px;
    display: block;
    cursor: zoom-in;
}

.tuh-chat-download-link {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    text-decoration: none;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.tuh-chat-msg__bubble--image:hover .tuh-chat-download-link {
    pointer-events: auto;
}

.tuh-chat-download-link:hover {
    background: rgba(0,0,0,0.8);
    color: #fff;
    text-decoration: none;
}

.tuh-chat-msg__bubble--file {
    padding: 10px 14px;
}

.tuh-chat-file-link {
    color: inherit;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
}

.tuh-chat-file-link:hover {
    text-decoration: underline;
}

.tuh-chat-file-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1.2rem;
    opacity: 0.6;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.tuh-chat-file-btn:hover {
    opacity: 1;
}

/* ==========================================================================
   TYPING INDICATOR
   ========================================================================== */

.tuh-chat-typing {
    padding: 4px 16px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--tuh-text-muted, #adb5bd);
}

.tuh-typing-dots {
    display: flex;
    gap: 3px;
}

.tuh-typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--tuh-text-muted, #adb5bd);
    border-radius: 50%;
    animation: tuh-typing-bounce 1.2s infinite;
}

.tuh-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.tuh-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes tuh-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* ==========================================================================
   INPUT AREA
   ========================================================================== */

.tuh-chat-input {
    padding: 12px 16px;
    border-top: 1px solid var(--tuh-border, #e9ecef);
    background: var(--tuh-bg, #ffffff);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.tuh-chat-input textarea {
    flex: 1;
    border: 2px solid var(--tuh-border, #e9ecef);
    border-radius: 8px;
    padding: 8px 12px;
    resize: none;
    font-size: 0.9rem;
    max-height: 100px;
    background: var(--tuh-bg, #fff);
    color: var(--tuh-text, #212529);
    line-height: 1.4;
    font-family: inherit;
}

.tuh-chat-input textarea:focus {
    outline: none;
    border-color: var(--tuh-primary, #635bff);
}

.tuh-chat-input button#tuh-chat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--tuh-primary, #635bff);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    transition: background 0.2s;
}

.tuh-chat-input button#tuh-chat-send:hover {
    background: var(--tuh-primary-hover, #524ae0);
}

/* ==========================================================================
   CHAT RATING
   ========================================================================== */

.tuh-chat-rating {
    padding: 24px;
    text-align: center;
    flex-shrink: 0;
    background: var(--tuh-bg, #ffffff);
}

.tuh-chat-rating p {
    margin: 0 0 12px;
    color: var(--tuh-text, #212529);
    font-weight: 600;
}

.tuh-chat-rating__buttons {
    display: flex;
    justify-content: center;
    gap: 16px;
}

.tuh-rate-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid var(--tuh-border, #e9ecef);
    background: var(--tuh-bg, #fff);
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.tuh-rate-btn:hover {
    transform: scale(1.15);
    border-color: var(--tuh-primary, #635bff);
    box-shadow: 0 4px 12px rgba(99, 91, 255, 0.2);
}

.tuh-chat-rating__thanks {
    color: var(--tuh-primary, #635bff);
    font-weight: 600;
    font-size: 0.95rem;
}

/* ==========================================================================
   POWERED BY
   ========================================================================== */

.tuh-chat-powered {
    text-align: center;
    font-size: 0.65rem;
    color: var(--tuh-text-muted, #adb5bd);
    padding: 6px;
    border-top: 1px solid var(--tuh-border, #e9ecef);
    background: var(--tuh-bg, #ffffff);
    flex-shrink: 0;
}

/* ==========================================================================
   MOBILE RESPONSIVE
   ========================================================================== */

@media (max-width: 480px) {
    .tuh-chat-widget {
        bottom: 44px;
        right: 16px;
    }

    .tuh-chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 100vh;
        border-radius: 16px 16px 0 0;
    }

    .tuh-chat-bubble {
        width: 52px;
        height: 52px;
        font-size: 1.5rem;
    }

    .tuh-chat-messages {
        max-height: calc(100vh - 280px);
    }

    .tuh-chat-attachment-img {
        max-width: 180px;
    }
}

/* ==========================================================================
   QUICK REPLY BUTTONS
   ========================================================================== */

.tuh-chat-quick-replies {
    padding: 8px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
    border-top: 1px solid var(--tuh-border, #e9ecef);
}

.tuh-quick-reply-btn {
    padding: 6px 14px;
    border: 1.5px solid var(--tuh-primary, #635bff);
    background: transparent;
    color: var(--tuh-primary, #635bff);
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.tuh-quick-reply-btn:hover {
    background: var(--tuh-primary, #635bff);
    color: #fff;
}

[data-theme="dark"] .tuh-quick-reply-btn {
    border-color: #8b85ff;
    color: #8b85ff;
}

[data-theme="dark"] .tuh-quick-reply-btn:hover {
    background: #8b85ff;
    color: #1e1e32;
}

/* ==========================================================================
   LIGHTBOX (Image Zoom)
   ========================================================================== */

.tuh-lightbox {
    position: fixed;
    inset: 0;
    z-index: 100000; /* Above chat widget (99999) */
    display: flex;
    align-items: center;
    justify-content: center;
}

.tuh-lightbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
}

.tuh-lightbox__img {
    position: relative;
    max-width: 90vw;
    max-height: 85vh;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
    object-fit: contain;
}

.tuh-lightbox__close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.tuh-lightbox__close:hover {
    opacity: 1;
}

.tuh-lightbox__download {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.9rem;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    transition: background 0.2s;
}

.tuh-lightbox__download:hover {
    background: rgba(255, 255, 255, 0.3);
    color: #fff;
    text-decoration: none;
}

/* ==========================================================================
   FLOATING SOCIAL BUTTONS (small)
   ========================================================================== */

.tuh-float-btns {
    position: absolute;
    bottom: 0;
    right: 68px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.tuh-float-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
    text-decoration: none;
}

.tuh-float-btn:hover {
    transform: scale(1.1);
    color: #fff;
    text-decoration: none;
}

.tuh-float-btn--wa {
    background: #25d366;
}

.tuh-float-btn--tg {
    background: #0088cc;
}

/* ==========================================================================
   CHAT HEADER AVATAR
   ========================================================================== */

.tuh-chat-header__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-right: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.tuh-chat-header__info {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0;
}

/* ==========================================================================
   FAQ BOT BUTTONS
   ========================================================================== */

.tuh-chat-faq {
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    border-top: 1px solid var(--tuh-border, #e9ecef);
}

.tuh-chat-faq__label {
    font-size: 0.75rem;
    color: var(--tuh-text-muted, #adb5bd);
    margin: 0;
}

.tuh-faq-btn {
    padding: 7px 14px;
    border: 1.5px solid var(--tuh-border, #e9ecef);
    background: var(--tuh-bg, #fff);
    color: var(--tuh-text, #212529);
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    font-family: inherit;
}

.tuh-faq-btn:hover {
    border-color: var(--tuh-primary, #635bff);
    background: var(--tuh-primary, #635bff);
    color: #fff;
}

.tuh-faq-btn--agent {
    background: var(--tuh-primary, #635bff);
    color: #fff;
    border-color: var(--tuh-primary, #635bff);
    text-align: center;
    font-weight: 600;
}

[data-theme="dark"] .tuh-faq-btn {
    border-color: #3a3a50;
    background: #2a2a40;
    color: #e8e8f0;
}

/* ==========================================================================
   READ RECEIPTS
   ========================================================================== */

.tuh-chat-msg__meta {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 4px;
    margin-top: 2px;
}

.tuh-chat-receipt {
    font-size: 0.7rem;
    color: var(--tuh-text-muted, #adb5bd);
    letter-spacing: -2px;
}

.tuh-chat-receipt--delivered {
    color: var(--tuh-text-muted, #adb5bd);
}

.tuh-chat-receipt--seen {
    color: #4ade80;
}

@media (max-width: 480px) {
    .tuh-float-btns {
        right: 60px;
    }

    .tuh-float-btn {
        width: 34px;
        height: 34px;
    }
}

/* Focus-visible states */
.tuh-chat-bubble:focus-visible,
.tuh-chat-send:focus-visible,
.tuh-chat-input textarea:focus-visible,
.tuh-rate-btn:focus-visible,
.tuh-float-btn:focus-visible,
.tuh-chat-file-btn:focus-visible,
.tuh-quick-reply:focus-visible {
    outline: 2px solid var(--tuh-primary, #635bff);
    outline-offset: 2px;
}
