/* ==========================================
   WP Live Chat - Tawk.to Style Frontend
   ========================================== */

/* CSS Variables */
:root {
    --wplc-primary: #03a84e;
    --wplc-primary-dark: #028a3f;
    --wplc-primary-light: #e8f8ef;
    --wplc-received-bg: #f1f1f4;
    --wplc-received-text: #1a1a2e;
    --wplc-sent-bg: #03a84e;
    --wplc-sent-text: #ffffff;
    --wplc-bg: #ffffff;
    --wplc-surface: #f5f5f7;
    --wplc-text: #1a1a2e;
    --wplc-text-secondary: #6e6e80;
    --wplc-border: #e8e8ec;
    --wplc-shadow: 0 8px 40px rgba(0, 0, 0, 0.16);
    --wplc-shadow-btn: 0 4px 20px rgba(3, 168, 78, 0.4);
    --wplc-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --wplc-transition: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset */
.wplc-chat-container,
.wplc-chat-container *,
.wplc-chat-container *::before,
.wplc-chat-container *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ---- Chat Container ---- */
.wplc-chat-container {
    position: fixed;
    z-index: 999999;
    font-family: var(--wplc-font);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

.wplc-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(3, 168, 78, 0.55);
    background: var(--wplc-primary-dark);
}

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

.wplc-chat-toggle svg {
    width: 28px;
    height: 28px;
    transition: all 0.3s var(--wplc-transition);
}

.wplc-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.wplc-chat-toggle.active .wplc-icon-chat {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.wplc-chat-toggle.active .wplc-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Pulse animation */
.wplc-chat-toggle::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--wplc-primary);
    opacity: 0;
    animation: wplcPulse 2.5s ease-out infinite;
}

.wplc-chat-toggle.active::before {
    animation: none;
    opacity: 0;
}

@keyframes wplcPulse {
    0% { transform: scale(1); opacity: 0.4; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* Unread Badge */
.wplc-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: #e53935;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(229, 57, 53, 0.4);
    animation: wplcBadgeBounce 0.4s var(--wplc-transition);
}

@keyframes wplcBadgeBounce {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* ---- Chat Window ---- */
.wplc-chat-window {
    position: absolute;
    width: 376px;
    height: 550px;
    max-height: calc(100vh - 100px);
    max-width: calc(100vw - 32px);
    border-radius: 16px;
    background: var(--wplc-bg);
    box-shadow: var(--wplc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: scale(0.8) translateY(16px);
    transform-origin: bottom right;
    pointer-events: none;
    transition: all 0.3s var(--wplc-transition);
}

.wplc-chat-window.wplc-open {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: all;
}

/* Window position variants */
.wplc-chat-window.wplc-pos-bottom-right,
.wplc-chat-window.wplc-pos-middle-right,
.wplc-chat-window.wplc-pos-top-right {
    right: 0;
    bottom: 72px;
    transform-origin: bottom right;
}

.wplc-chat-window.wplc-pos-bottom-left,
.wplc-chat-window.wplc-pos-middle-left,
.wplc-chat-window.wplc-pos-top-left {
    left: 0;
    bottom: 72px;
    transform-origin: bottom left;
}

.wplc-chat-window.wplc-pos-bottom-center,
.wplc-chat-window.wplc-pos-middle-center,
.wplc-chat-window.wplc-pos-top-center {
    left: 50%;
    bottom: 72px;
    margin-left: -188px;
    transform-origin: bottom center;
}

.wplc-chat-window.wplc-pos-top-right,
.wplc-chat-window.wplc-pos-top-left,
.wplc-chat-window.wplc-pos-top-center {
    bottom: auto;
    top: 72px;
    transform-origin: top center;
}

.wplc-chat-window.wplc-pos-top-right { transform-origin: top right; }
.wplc-chat-window.wplc-pos-top-left { transform-origin: top left; }

/* ---- Chat Header (Tawk-style green bar) ---- */
.wplc-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--wplc-primary) 0%, #04c45a 100%);
    flex-shrink: 0;
    min-height: 60px;
}

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

.wplc-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.wplc-avatar svg {
    width: 22px;
    height: 22px;
}

.wplc-header-text h3 {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    letter-spacing: 0;
}

.wplc-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
}

.wplc-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #a0f5c4;
    display: inline-block;
    box-shadow: 0 0 6px rgba(160, 245, 196, 0.6);
}

.wplc-status-dot.offline {
    background: #ffc107;
    box-shadow: 0 0 6px rgba(255, 193, 7, 0.5);
}

.wplc-chat-close {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.wplc-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.wplc-chat-close svg {
    width: 15px;
    height: 15px;
}

/* ---- Messages Area ---- */
.wplc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--wplc-bg);
    scroll-behavior: smooth;
}

/* Visible Scrollbar */
.wplc-messages::-webkit-scrollbar {
    width: 5px;
}
.wplc-messages::-webkit-scrollbar-track {
    background: transparent;
}
.wplc-messages::-webkit-scrollbar-thumb {
    background: #c8c8cc;
    border-radius: 3px;
}
.wplc-messages::-webkit-scrollbar-thumb:hover {
    background: #a0a0a8;
}

/* ---- Message Bubbles (Tawk flat style) ---- */
.wplc-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: wplcMsgAppear 0.3s var(--wplc-transition);
}

@keyframes wplcMsgAppear {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

.wplc-message.sent {
    align-self: flex-end;
}

.wplc-message.received {
    align-self: flex-start;
}

.wplc-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 14px;
    line-height: 1.5;
}

.wplc-message.sent .wplc-bubble {
    background: var(--wplc-sent-bg);
    color: var(--wplc-sent-text);
    border-bottom-right-radius: 4px;
}

.wplc-message.received .wplc-bubble {
    background: var(--wplc-received-bg);
    color: var(--wplc-received-text);
    border-bottom-left-radius: 4px;
}

/* No bubble tails — Tawk uses clean rectangles */

.wplc-message-time {
    font-size: 11px;
    color: var(--wplc-text-secondary);
    margin-top: 3px;
    padding: 0 2px;
}

.wplc-message.sent .wplc-message-time {
    text-align: right;
}

/* ---- Typing Indicator ---- */
.wplc-typing {
    padding: 4px 16px 8px;
}

.wplc-typing-bubble {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 10px 16px;
    background: var(--wplc-received-bg);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.wplc-typing-bubble span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--wplc-text-secondary);
    animation: wplcTypingBounce 1.4s infinite ease-in-out;
}

.wplc-typing-bubble span:nth-child(1) { animation-delay: 0s; }
.wplc-typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.wplc-typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes wplcTypingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ---- Input Area ---- */
.wplc-input-area {
    padding: 12px 14px 14px;
    background: var(--wplc-bg);
    border-top: 1px solid var(--wplc-border);
    flex-shrink: 0;
}

.wplc-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--wplc-surface);
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    border: 1px solid var(--wplc-border);
    transition: border-color 0.2s ease;
}

.wplc-input-wrapper:focus-within {
    border-color: var(--wplc-primary);
    box-shadow: 0 0 0 2px rgba(3, 168, 78, 0.1);
}

.wplc-message-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    font-family: var(--wplc-font);
    color: var(--wplc-text);
    outline: none;
    min-width: 0;
    padding: 8px 0;
}

.wplc-message-input::placeholder {
    color: var(--wplc-text-secondary);
}

.wplc-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--wplc-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.wplc-send-btn:hover {
    background: var(--wplc-primary-dark);
    transform: scale(1.05);
}

.wplc-send-btn:active {
    transform: scale(0.92);
}

.wplc-send-btn svg {
    width: 18px;
    height: 18px;
}

/* ---- Media & Emoji Inputs ---- */
.wplc-hidden {
    display: none !important;
}

.wplc-input-action-btn {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--wplc-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin: 0 1px;
    padding: 0;
}

.wplc-input-action-btn:hover {
    color: var(--wplc-primary);
    background: rgba(3, 168, 78, 0.1);
}

.wplc-input-action-btn svg {
    width: 16px;
    height: 16px;
}

.wplc-emoji-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.wplc-emoji-picker {
    position: absolute;
    bottom: 45px;
    right: -10px;
    width: 220px;
    background: var(--wplc-surface);
    border: 1px solid var(--wplc-border);
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.1);
    padding: 10px;
    z-index: 100;
}

.wplc-emoji-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 140px;
    overflow-y: auto;
}

.wplc-emoji-list::-webkit-scrollbar {
    width: 4px;
}
.wplc-emoji-list::-webkit-scrollbar-thumb {
    background: #c7c7cc;
    border-radius: 4px;
}

.wplc-emoji-list span {
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.2s;
    user-select: none;
    line-height: 1;
}

.wplc-emoji-list span:hover {
    background: var(--wplc-border);
}

/* ---- Media Bubbles ---- */
.wplc-bubble-image,
.wplc-bubble-video {
    padding: 4px !important;
    background: transparent !important;
    box-shadow: none !important;
}

.wplc-msg-image {
    max-width: 100%;
    max-height: 200px;
    border-radius: 12px;
    display: block;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.wplc-msg-video {
    max-width: 100%;
    max-height: 200px;
    border-radius: 12px;
    display: block;
    outline: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ---- Offline Form ---- */
.wplc-offline-form {
    flex: 1;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    background: var(--wplc-bg);
}

.wplc-offline-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FF9500, #FF6B00);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
}

.wplc-offline-icon svg {
    width: 30px;
    height: 30px;
}

.wplc-offline-form h4 {
    font-size: 18px;
    font-weight: 700;
    color: var(--wplc-text);
    margin-bottom: 6px;
}

.wplc-offline-form p {
    font-size: 13px;
    color: var(--wplc-text-secondary);
    text-align: center;
    margin-bottom: 18px;
    line-height: 1.5;
}

.wplc-offline-form form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.wplc-offline-form input,
.wplc-offline-form textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--wplc-border);
    border-radius: 10px;
    font-size: 14px;
    font-family: var(--wplc-font);
    color: var(--wplc-text);
    background: var(--wplc-surface);
    outline: none;
    transition: all 0.2s ease;
    resize: none;
}

.wplc-offline-form input:focus,
.wplc-offline-form textarea:focus {
    border-color: var(--wplc-primary);
    box-shadow: 0 0 0 2px rgba(3, 168, 78, 0.1);
}

.wplc-offline-form input::placeholder,
.wplc-offline-form textarea::placeholder {
    color: var(--wplc-text-secondary);
}

.wplc-offline-submit {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: var(--wplc-primary);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--wplc-font);
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 4px;
}

.wplc-offline-submit:hover {
    background: var(--wplc-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(3, 168, 78, 0.3);
}

.wplc-offline-submit:active {
    transform: translateY(0);
}

/* Offline Success */
.wplc-offline-success {
    text-align: center;
    padding: 32px 20px;
    color: var(--wplc-primary);
}

.wplc-offline-success svg {
    width: 52px;
    height: 52px;
    margin-bottom: 14px;
}

.wplc-offline-success p {
    font-size: 15px;
    color: var(--wplc-text);
    font-weight: 500;
}

/* ---- Date Separator ---- */
.wplc-date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 0;
}

.wplc-date-separator span {
    font-size: 11px;
    color: var(--wplc-text-secondary);
    background: var(--wplc-surface);
    padding: 3px 10px;
    border-radius: 8px;
    font-weight: 500;
}

/* ---- Welcome Message ---- */
.wplc-welcome {
    text-align: center;
    padding: 18px 16px 8px;
}

.wplc-welcome-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--wplc-primary), #04c45a);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    margin: 0 auto 10px;
}

.wplc-welcome-avatar svg {
    width: 28px;
    height: 28px;
}

.wplc-welcome h4 {
    font-size: 16px;
    font-weight: 600;
    color: var(--wplc-text);
    margin-bottom: 3px;
}

.wplc-welcome p {
    font-size: 12px;
    color: var(--wplc-text-secondary);
}

/* ---- Powered by footer (Tawk style) ---- */
.wplc-chat-window::after {
    content: '⚡ Powered by WP Live Chat';
    display: block;
    text-align: center;
    font-size: 10px;
    color: #a0a0a8;
    padding: 4px 0 6px;
    background: var(--wplc-bg);
    border-top: 1px solid var(--wplc-border);
    flex-shrink: 0;
}

/* ---- Responsive: Mobile Full Screen ---- */
@media (max-width: 480px) {
    .wplc-chat-container {
        bottom: 16px !important;
        right: 16px !important;
        left: auto !important;
        top: auto !important;
    }

    .wplc-chat-toggle {
        width: 52px;
        height: 52px;
    }

    .wplc-chat-toggle svg {
        width: 24px;
        height: 24px;
    }

    .wplc-chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
        z-index: 999999;
    }

    .wplc-chat-window.wplc-open {
        transform: scale(1) translateY(0) !important;
    }

    .wplc-chat-header {
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .wplc-messages {
        padding: 12px;
    }

    .wplc-message {
        max-width: 85%;
    }

    .wplc-input-area {
        padding: 10px 12px 14px;
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }

    .wplc-message-input {
        font-size: 16px;
    }

    .wplc-offline-form {
        padding: 20px 16px;
    }

    .wplc-chat-window::after {
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }
}

@media (max-width: 380px) {
    .wplc-chat-header {
        padding: 10px 12px;
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .wplc-avatar {
        width: 32px;
        height: 32px;
    }

    .wplc-header-text h3 {
        font-size: 14px;
    }
}
