/**
 * TP Chat Testimonials - Frontend Styles
 * WhatsApp-style chat widget with scale-based sizing
 */

/* ==========================================================================
   CSS Custom Properties - Theme Colors Only
   ========================================================================== */
:root {
    /* WhatsApp Dark Theme (default) */
    --tpct-bg-primary: #0b141a;
    --tpct-bg-header: #1f2c34;
    --tpct-bg-footer: #1f2c34;
    --tpct-bg-input: #2a3942;
    --tpct-bg-customer: #005c4b;
    --tpct-bg-business: #1f2c34;
    --tpct-text-primary: #ffffff;
    --tpct-text-secondary: #8696a0;
    --tpct-text-meta: rgba(255, 255, 255, 0.6);
    --tpct-accent: #00a884;
    --tpct-checkmarks: #53bdeb;
    --tpct-frame-bg: #000000;
}

/* Theme: WhatsApp Light */
.tpct-theme-whatsapp-light {
    --tpct-bg-primary: #efeae2;
    --tpct-bg-header: #008069;
    --tpct-bg-footer: #f0f2f5;
    --tpct-bg-input: #ffffff;
    --tpct-bg-customer: #d9fdd3;
    --tpct-bg-business: #ffffff;
    --tpct-text-primary: #111b21;
    --tpct-text-secondary: #667781;
    --tpct-text-meta: rgba(0, 0, 0, 0.45);
    --tpct-accent: #008069;
    --tpct-checkmarks: #53bdeb;
    --tpct-frame-bg: #1f2c34;
}

.tpct-theme-whatsapp-light .tpct-chat-header {
    color: #fff;
}

.tpct-theme-whatsapp-light .tpct-chat-name {
    color: #fff;
}

.tpct-theme-whatsapp-light .tpct-chat-status {
    color: rgba(255, 255, 255, 0.8);
}

.tpct-theme-whatsapp-light .tpct-msg-customer .tpct-message-bubble,
.tpct-theme-whatsapp-light .tpct-msg-business .tpct-message-bubble {
    color: var(--tpct-text-primary);
}

.tpct-theme-whatsapp-light .tpct-message-meta {
    color: var(--tpct-text-meta);
}

/* ==========================================================================
   Phone Widget - Base with scale variable
   ========================================================================== */
.tpct-phone-widget {
    --tpct-scale: 1;
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.4;
    direction: ltr;
    text-align: left;
}

/* Size Variants */
.tpct-phone-widget.tpct-size-small {
    --tpct-scale: 0.55;
}

.tpct-phone-widget.tpct-size-medium {
    --tpct-scale: 0.75;
}

.tpct-phone-widget.tpct-size-large {
    --tpct-scale: 1;
}

.tpct-phone-widget.tpct-size-xl {
    --tpct-scale: 1.35;
}

/* Position variants */
.tpct-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.tpct-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Mobile override */
.tpct-mobile {
    --tpct-scale: 0.7;
    bottom: 10px;
}

.tpct-mobile.tpct-position-bottom-right {
    right: 10px;
}

.tpct-mobile.tpct-position-bottom-left {
    left: 10px;
}

/* Shortcode inline widget */
.tpct-shortcode-wrapper {
    display: flex;
    justify-content: center;
    padding: 20px;
}

.tpct-shortcode {
    position: relative;
}

/* ==========================================================================
   Close Button
   ========================================================================== */
.tpct-close-btn {
    position: absolute;
    top: calc(0 * var(--tpct-scale));
    right: calc(0 * var(--tpct-scale));
    width: calc(28px * var(--tpct-scale));
    height: calc(28px * var(--tpct-scale));
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    border: 2px solid var(--tpct-frame-bg);
    color: #fff;
    font-size: calc(18px * var(--tpct-scale));
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.2s;
    z-index: 10;
    padding: 0;
}

.tpct-close-btn:hover {
    background: #4a5c66;
    transform: scale(1.1);
}

/* ==========================================================================
   Phone Frame
   ========================================================================== */
.tpct-phone-frame {
    width: calc(280px * var(--tpct-scale));
    background: var(--tpct-frame-bg);
    border-radius: calc(35px * var(--tpct-scale));
    overflow: hidden;
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.1);
    position: relative;
}

/* iPhone notch */
.tpct-phone-notch {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: calc(120px * var(--tpct-scale));
    height: calc(28px * var(--tpct-scale));
    background: #000;
    border-radius: 0 0 calc(15px * var(--tpct-scale)) calc(15px * var(--tpct-scale));
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: calc(8px * var(--tpct-scale));
}

.tpct-notch-speaker {
    width: calc(40px * var(--tpct-scale));
    height: calc(4px * var(--tpct-scale));
    background: #333;
    border-radius: calc(2px * var(--tpct-scale));
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}

.tpct-notch-camera {
    width: calc(10px * var(--tpct-scale));
    height: calc(10px * var(--tpct-scale));
    background: #0c2436;
    border-radius: 50%;
    border: 2px solid #1a1a1a;
    box-shadow: 0 0 3px rgba(0, 150, 200, 0.3);
}

/* Android style - no notch */
.tpct-style-android .tpct-phone-notch {
    display: none;
}

.tpct-style-android .tpct-phone-frame {
    border-radius: calc(20px * var(--tpct-scale));
}

.tpct-style-android .tpct-chat-header {
    padding-top: calc(12px * var(--tpct-scale));
}

/* Generic style */
.tpct-style-generic .tpct-phone-notch {
    display: none;
}

.tpct-style-generic .tpct-phone-frame {
    border-radius: calc(15px * var(--tpct-scale));
}

.tpct-style-generic .tpct-chat-header {
    padding-top: calc(12px * var(--tpct-scale));
}

/* ==========================================================================
   Phone Screen
   ========================================================================== */
.tpct-phone-screen {
    background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAKElEQVQoU2NkYGD4z4AHMOKSxKbg////DIyMjIxwhYgCokphCvApBgAFqgT/p99sFgAAAABJRU5ErkJggg==');
    background-color: var(--tpct-bg-primary);
    display: flex;
    flex-direction: column;
    height: calc(480px * var(--tpct-scale));
}

/* ==========================================================================
   Chat Header
   ========================================================================== */
.tpct-chat-header {
    background: var(--tpct-bg-header);
    padding: calc(36px * var(--tpct-scale)) calc(12px * var(--tpct-scale)) calc(12px * var(--tpct-scale));
    display: flex;
    align-items: center;
    gap: calc(8px * var(--tpct-scale));
    flex-shrink: 0;
}

.tpct-style-android .tpct-chat-header,
.tpct-style-generic .tpct-chat-header {
    padding-top: calc(12px * var(--tpct-scale));
}

.tpct-back-arrow {
    color: var(--tpct-accent);
    font-size: calc(24px * var(--tpct-scale));
    font-weight: 300;
    opacity: 0.8;
}

.tpct-chat-avatar {
    width: calc(36px * var(--tpct-scale));
    height: calc(36px * var(--tpct-scale));
    border-radius: 50%;
    background: var(--tpct-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.tpct-chat-avatar img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
}

.tpct-chat-avatar .dashicons {
    color: #fff;
    font-size: calc(20px * var(--tpct-scale));
    width: calc(20px * var(--tpct-scale));
    height: calc(20px * var(--tpct-scale));
}

.tpct-chat-info {
    flex: 1;
    min-width: 0;
}

.tpct-chat-name {
    display: block;
    color: var(--tpct-text-primary);
    font-size: calc(14px * var(--tpct-scale));
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tpct-chat-status {
    display: block;
    color: var(--tpct-text-secondary);
    font-size: calc(10px * var(--tpct-scale));
}

.tpct-header-icons {
    display: flex;
    gap: calc(12px * var(--tpct-scale));
    font-size: calc(14px * var(--tpct-scale));
    opacity: 0.8;
}

/* ==========================================================================
   Chat Body
   ========================================================================== */
.tpct-chat-body {
    flex: 1;
    padding: calc(12px * var(--tpct-scale));
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: calc(4px * var(--tpct-scale));
}

/* Scrollbar styling */
.tpct-chat-body::-webkit-scrollbar {
    width: 4px;
}

.tpct-chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.tpct-chat-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

/* ==========================================================================
   Chat Messages
   ========================================================================== */
.tpct-chat-message {
    display: flex;
    max-width: 85%;
    animation: tpct-slide-in 0.3s ease-out;
}

@keyframes tpct-slide-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tpct-msg-customer {
    align-self: flex-end;
}

.tpct-msg-business {
    align-self: flex-start;
}

.tpct-message-bubble {
    padding: calc(8px * var(--tpct-scale)) calc(12px * var(--tpct-scale));
    border-radius: calc(10px * var(--tpct-scale));
    font-size: calc(14px * var(--tpct-scale));
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
}

/* Customer bubble (outgoing - right side) */
.tpct-msg-customer .tpct-message-bubble {
    background: var(--tpct-bg-customer);
    color: var(--tpct-text-primary);
    border-bottom-right-radius: calc(4px * var(--tpct-scale));
}

/* Business bubble (incoming - left side) */
.tpct-msg-business .tpct-message-bubble {
    background: var(--tpct-bg-business);
    color: var(--tpct-text-primary);
    border-bottom-left-radius: calc(4px * var(--tpct-scale));
}

/* Message meta (time + checkmarks) */
.tpct-message-meta {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: calc(10px * var(--tpct-scale));
    color: var(--tpct-text-meta);
    margin-left: calc(8px * var(--tpct-scale));
    white-space: nowrap;
    float: right;
    margin-top: calc(4px * var(--tpct-scale));
}

.tpct-checkmarks {
    color: var(--tpct-checkmarks);
    font-size: calc(12px * var(--tpct-scale));
    letter-spacing: -2px;
}

/* ==========================================================================
   Typing Indicator
   ========================================================================== */
.tpct-typing-indicator {
    padding: 0 calc(12px * var(--tpct-scale));
    padding-bottom: calc(8px * var(--tpct-scale));
}

.tpct-typing-bubble {
    display: inline-flex;
    align-items: center;
    gap: calc(3px * var(--tpct-scale));
    padding: calc(8px * var(--tpct-scale)) calc(12px * var(--tpct-scale));
    background: var(--tpct-bg-business);
    border-radius: calc(10px * var(--tpct-scale));
}

.tpct-typing-dot {
    width: calc(8px * var(--tpct-scale));
    height: calc(8px * var(--tpct-scale));
    background: var(--tpct-text-secondary);
    border-radius: 50%;
    animation: tpct-typing-bounce 1.4s infinite ease-in-out both;
}

.tpct-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.tpct-typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

.tpct-typing-dot:nth-child(3) {
    animation-delay: 0s;
}

@keyframes tpct-typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==========================================================================
   Chat Footer
   ========================================================================== */
.tpct-chat-footer {
    background: var(--tpct-bg-footer);
    padding: calc(8px * var(--tpct-scale)) calc(12px * var(--tpct-scale));
    display: flex;
    align-items: center;
    gap: calc(8px * var(--tpct-scale));
    flex-shrink: 0;
}

.tpct-emoji-btn,
.tpct-mic-btn {
    font-size: calc(16px * var(--tpct-scale));
    opacity: 0.8;
    flex-shrink: 0;
}

.tpct-input-field {
    flex: 1;
    background: var(--tpct-bg-input);
    padding: calc(8px * var(--tpct-scale)) calc(12px * var(--tpct-scale));
    border-radius: calc(20px * var(--tpct-scale));
    min-width: 0;
}

.tpct-input-placeholder {
    color: var(--tpct-text-secondary);
    font-size: calc(14px * var(--tpct-scale));
}

/* ==========================================================================
   Hidden State (when closed)
   ========================================================================== */
.tpct-phone-widget.tpct-hidden {
    display: none;
}

/* ==========================================================================
   Transition Animation (fade in)
   ========================================================================== */
.tpct-phone-widget {
    animation: tpct-widget-appear 0.4s ease-out;
}

@keyframes tpct-widget-appear {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==========================================================================
   RTL Support
   ========================================================================== */
[dir="rtl"] .tpct-phone-widget,
.rtl .tpct-phone-widget {
    direction: ltr; /* Keep internal LTR for WhatsApp authenticity */
}

.tpct-position-bottom-right[dir="rtl"],
.rtl .tpct-position-bottom-right {
    right: auto;
    left: 20px;
}

.tpct-position-bottom-left[dir="rtl"],
.rtl .tpct-position-bottom-left {
    left: auto;
    right: 20px;
}

/* ==========================================================================
   Accessibility
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .tpct-chat-message,
    .tpct-phone-widget,
    .tpct-typing-dot {
        animation: none;
    }
    
    .tpct-close-btn {
        transition: none;
    }
}

/* ==========================================================================
   Print - Hide widget
   ========================================================================== */
@media print {
    .tpct-phone-widget:not(.tpct-shortcode) {
        display: none !important;
    }
}
