/* ========================================
   ChatLink Frontend - Modern WhatsApp UI
   ======================================== */

/* --- CSS Variables for Easy Customization --- */
:root {
    --chatlink-primary: #25D366;
    --chatlink-hover: #20BA5A;
    --chatlink-wa-green: #00a884;
    --chatlink-wa-bg: #efe7dd;
    --chatlink-bubble-received: #ffffff;
    --chatlink-bubble-sent: #d9fdd3;
    --chatlink-text-dark: #111b21;
    --chatlink-text-light: #667781;
    --chatlink-border: #e9edef;
    --chatlink-shadow: rgba(0, 0, 0, 0.15);
}

/* --- Floating Widget Container --- */
.chatlink-widget {
    position: fixed;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
}

/* --- Position Classes --- */
.chatlink-position-bottom-right { bottom: 20px; right: 20px; }
.chatlink-position-bottom-left { bottom: 20px; left: 20px; }
.chatlink-position-top-right { top: 20px; right: 20px; }
.chatlink-position-top-left { top: 20px; left: 20px; }

/* --- Floating Button --- */
.chatlink-button {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50% !important;
    width: 60px;
    height: 60px;
    border: none !important;
    outline: none !important;
    box-shadow: 0 4px 12px var(--chatlink-shadow);
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s ease;
    text-decoration: none !important;
    padding: 0;
    background-color: var(--chatlink-primary);
    position: relative;
}

.chatlink-button:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.chatlink-button:active {
    transform: scale(1.05) translateY(0);
}

/* Icon Size */
.chatlink-button .chatlink-icon {
    width: 32px;
    height: 32px;
    fill: #ffffff;
    transition: transform 0.2s ease;
}

/* Hide close icon, keep WhatsApp icon always visible */
.chatlink-icon-close {
    display: none !important;
}

.chatlink-widget.chatlink-open .chatlink-icon-wa {
    display: block !important;
}

/* --- Animations --- */
@keyframes chatlink-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes chatlink-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 4px 12px var(--chatlink-shadow); }
    50% { transform: scale(1.05); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2); }
}

.chatlink-animation-bounce .chatlink-button {
    animation: chatlink-bounce 2s infinite;
}

.chatlink-animation-pulse .chatlink-button {
    animation: chatlink-pulse 2s infinite;
}

/* --- Tooltip --- */
.chatlink-tooltip {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    padding: 8px 14px;
    background: rgba(20, 20, 20, 0.92);
    color: #fff;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 1;
}

.chatlink-tooltip::after {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-style: solid;
}

/* Tooltip Positions */
.chatlink-position-bottom-right .chatlink-tooltip,
.chatlink-position-top-right .chatlink-tooltip {
    right: 110%;
    margin-right: 10px;
}

.chatlink-position-bottom-right .chatlink-tooltip::after,
.chatlink-position-top-right .chatlink-tooltip::after {
    left: 100%;
    border-width: 6px 0 6px 8px;
    border-color: transparent transparent transparent rgba(20, 20, 20, 0.92);
}

.chatlink-position-bottom-left .chatlink-tooltip,
.chatlink-position-top-left .chatlink-tooltip {
    left: 110%;
    margin-left: 10px;
}

.chatlink-position-bottom-left .chatlink-tooltip::after,
.chatlink-position-top-left .chatlink-tooltip::after {
    right: 100%;
    border-width: 6px 8px 6px 0;
    border-color: transparent rgba(20, 20, 20, 0.92) transparent transparent;
}

.chatlink-button:hover .chatlink-tooltip {
    opacity: 1;
    visibility: visible;
}

/* --- Chat Popup --- */
.chatlink-chat {
    position: absolute;
    width: 360px;
    max-width: calc(100vw - 40px);
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    display: none;
    flex-direction: column;
    animation: chatlink-fadeScale 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

/* Position Popup Correctly */
.chatlink-position-bottom-right .chatlink-chat {
    bottom: 80px;
    right: 0;
    transform-origin: bottom right;
}

.chatlink-position-bottom-left .chatlink-chat {
    bottom: 80px;
    left: 0;
    transform-origin: bottom left;
}

.chatlink-position-top-right .chatlink-chat {
    top: 80px;
    right: 0;
    transform-origin: top right;
}

.chatlink-position-top-left .chatlink-chat {
    top: 80px;
    left: 0;
    transform-origin: top left;
}

@keyframes chatlink-fadeScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* --- Chat Header --- */
.chatlink-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    color: #fff;
    background: #075E54; /* Default, overridden by inline style */
}

.chatlink-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chatlink-chat-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatlink-chat-avatar svg {
    width: 22px;
    height: 22px;
    fill: #fff;
}

.chatlink-chat-header-text {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chatlink-chat-title {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chatlink-chat-subtitle {
    font-size: 12px;
    opacity: 0.9;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Close Button */
.chatlink-chat-close {
    background: transparent !important;
    border: none !important;
    cursor: pointer;
    padding: 8px;
    opacity: 0.8;
    transition: opacity 0.2s ease, background 0.2s ease;
    outline: none !important;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
}

.chatlink-chat-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15) !important;
}

.chatlink-chat-close svg {
    width: 24px;
    height: 24px;
    fill: #ffffff !important;
    stroke: #ffffff !important;
}

/* --- Chat Body --- */
.chatlink-chat-body {
    padding: 20px;
    background: var(--chatlink-wa-bg);
    background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAAIklEQVQIW2NkQAKrVq36zwjjgzhhYWGMYAEYB8RmROaABADeOQ8CXl/xfgAAAABJRU5ErkJggg==');
    min-height: 250px;
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

/* Custom Scrollbar for Webkit */
.chatlink-chat-body::-webkit-scrollbar {
    width: 6px;
}

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

.chatlink-chat-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.chatlink-chat-body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* --- Chat Bubbles --- */
.chatlink-chat-bubble {
    background: var(--chatlink-bubble-received);
    padding: 10px 14px;
    border-radius: 0 12px 12px 12px;
    max-width: 85%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    font-size: 14px;
    color: var(--chatlink-text-dark);
    line-height: 1.5;
    align-self: flex-start;
    word-wrap: break-word;
    animation: chatlink-bubbleIn 0.3s ease-out;
}

.chatlink-bubble-sent {
    background: var(--chatlink-bubble-sent);
    align-self: flex-end;
    border-radius: 12px 0 12px 12px;
}

.chatlink-bubble-received {
    background: var(--chatlink-bubble-received);
}

@keyframes chatlink-bubbleIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.chatlink-bubble-text {
    margin-bottom: 4px;
}

.chatlink-chat-time {
    display: block;
    font-size: 10px;
    color: var(--chatlink-text-light);
    text-align: right;
    margin-top: 4px;
    opacity: 0.8;
}

/* --- FAQ Section --- */
.chatlink-faq-section {
    margin-top: 15px !important;
    width: 100% !important;
    padding-top: 15px !important;
    border-top: 1px solid rgba(0, 0, 0, 0.08) !important;
    clear: both !important;
}

.chatlink-faq-title {
    font-size: 11px !important;
    font-weight: 700 !important;
    color: var(--chatlink-text-light) !important;
    margin-bottom: 10px !important;
    text-align: center !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
}

.chatlink-faq-buttons {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    justify-content: center !important;
    padding-bottom: 5px !important;
}

.chatlink-faq-btn {
    background-color: #ffffff !important;
    color: var(--chatlink-text-dark) !important;
    border: 1px solid var(--chatlink-border) !important;
    padding: 8px 16px !important;
    border-radius: 20px !important;
    font-size: 13px !important;
    font-family: inherit !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08) !important;
    outline: none !important;
    line-height: 1.4 !important;
    text-align: center !important;
    text-decoration: none !important;
    margin: 0 !important;
}

.chatlink-faq-btn:hover {
    background-color: #f0f2f5 !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.12) !important;
    color: var(--chatlink-wa-green) !important;
    border-color: #d1d7db !important;
}

.chatlink-faq-btn:active {
    transform: translateY(0) !important;
    background-color: var(--chatlink-border) !important;
}

/* --- Chat Footer --- */
.chatlink-chat-footer {
    padding: 14px 16px;
    background: #f0f2f5;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.chatlink-chat-start,
.chatlink-start-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 20px;
    background: var(--chatlink-wa-green);
    color: #fff;
    text-decoration: none !important;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 600;
    transition: background 0.2s ease, transform 0.1s ease;
    border: none;
    cursor: pointer;
    outline: none;
}

.chatlink-chat-start:hover,
.chatlink-start-chat:hover {
    background: #008f6f;
    color: #fff !important;
    transform: translateY(-1px);
}

.chatlink-chat-start:active,
.chatlink-start-chat:active {
    transform: translateY(0);
}

.chatlink-chat-start svg,
.chatlink-start-chat svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* --- WooCommerce Inquiry Button --- */
.chatlink-inquiry-wrap {
    margin: 15px 0;
}

.chatlink-quantity-selector {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chatlink-quantity-selector label {
    font-weight: 500;
    margin: 0;
}

.chatlink-qty-input {
    width: 60px !important;
    padding: 6px 10px !important;
    border: 1px solid #ddd !important;
    border-radius: 4px !important;
    font-size: 14px !important;
    text-align: center !important;
}

.chatlink-inquiry-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    text-decoration: none !important;
    transition: all 0.2s ease !important;
    cursor: pointer !important;
}

.chatlink-inquiry-btn:hover {
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

.chatlink-inquiry-btn svg {
    flex-shrink: 0;
}

/* --- Shortcode Styles --- */
a.chatlink-sc {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none !important;
    line-height: 1;
    transition: opacity 0.3s ease, transform 0.2s ease;
    cursor: pointer;
    gap: 8px;
    font-family: inherit;
}

a.chatlink-sc:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Style: Button */
a.chatlink-sc-button {
    padding: 10px 20px;
    font-weight: 600;
    border-radius: 5px;
}

/* Style: Link */
a.chatlink-sc-link {
    background: transparent !important;
    padding: 0;
    font-weight: inherit;
}

a.chatlink-sc-link:hover {
    text-decoration: underline !important;
}

/* Style: Icon Only */
a.chatlink-sc-icon {
    background: transparent !important;
    padding: 8px;
    border-radius: 50%;
}

/* Sizes */
.chatlink-sc-small {
    font-size: 12px;
}

.chatlink-sc-small svg {
    width: 16px;
    height: 16px;
}

.chatlink-sc-medium {
    font-size: 16px;
}

.chatlink-sc-medium svg {
    width: 20px;
    height: 20px;
}

.chatlink-sc-large {
    font-size: 20px;
}

.chatlink-sc-large svg {
    width: 26px;
    height: 26px;
}

/* Alignments */
.chatlink-sc-align-left {
    display: flex;
    margin-right: auto;
}

.chatlink-sc-align-center {
    display: flex;
    margin-left: auto;
    margin-right: auto;
}

.chatlink-sc-align-right {
    display: flex;
    margin-left: auto;
}

.chatlink-sc-align-inline {
    display: inline-flex;
}

/* Label */
.chatlink-sc-label {
    display: inline-block;
}

.chatlink-sc-icon svg {
    display: block;
}

/* --- Mobile Responsive --- */
@media (max-width: 480px) {
    .chatlink-chat {
        width: calc(100vw - 20px);
        max-height: calc(100vh - 100px);
    }
    
    .chatlink-chat-body {
        max-height: calc(100vh - 300px);
    }
    
    .chatlink-position-bottom-right,
    .chatlink-position-bottom-left {
        bottom: 10px;
        left: 10px;
        right: 10px;
    }
    
    .chatlink-position-bottom-right .chatlink-chat,
    .chatlink-position-bottom-left .chatlink-chat {
        left: 0;
        right: 0;
        bottom: 70px;
    }
}

/* --- Device Visibility --- */
@media (max-width: 768px) {
    .chatlink-device-desktop {
        display: none !important;
    }
}

@media (min-width: 769px) {
    .chatlink-device-mobile {
        display: none !important;
    }
}

/* --- Print Styles --- */
@media print {
    .chatlink-widget {
        display: none !important;
    }
}
