/**
 * Trill Chat Lite — Chat Widget Styles
 *
 * @package TrillChatLite
 * @since 1.0.0
 * @version 1.1.0 — Mobile responsive improvements
 * @license GPL-2.0-or-later
 */

/* ========================================
   Chat Widget Container
   ======================================== */

.trcl-chat-widget {
    position: fixed;
    bottom: 20px;
    /* right/left set dynamically via wp_add_inline_style based on widget_position setting */
    right: 20px;
    left: auto;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.trcl-chat-widget * {
    box-sizing: border-box;
}

/* ========================================
   Chat Toggle Button
   ======================================== */

/*
 * Launcher button — no outer circle.
 * The logo (bubble + tail + graph) floats directly on the page, with a
 * shape-aware drop-shadow applied to the SVG for depth on light backgrounds.
 */
.trcl-chat-toggle {
    width: 52px;
    height: 52px;
    border-radius: 0;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    transition: transform 0.2s ease, filter 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.trcl-chat-toggle:hover {
    transform: scale(1.05);
}

.trcl-chat-toggle:hover .trcl-launcher-svg {
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.28));
}

.trcl-chat-toggle:focus-visible {
    outline: 2px solid var(--trcl-primary, #10B981);
    outline-offset: 4px;
    border-radius: 8px;
}

.trcl-launcher-svg {
    width: 100%;
    height: 100%;
    display: block;
    /* Drop-shadow follows the bubble silhouette (not a rectangular box) */
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.22));
}

/*
 * The bubble fill inherits the configured widget colour.
 * Nodes (white) and amber accent are hardcoded in the SVG and stay fixed.
 */
.trcl-launcher-bubble {
    fill: var(--trcl-primary, #10B981);
}

/* ========================================
   Classic bubble launcher (v2.1)
   — kept in sync with chat-launcher.css
   ======================================== */

.trcl-chat-toggle--bubble {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--trcl-primary, #10B981);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.trcl-chat-toggle--bubble:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.trcl-chat-toggle--bubble .trcl-bubble-icon {
    width: 26px;
    height: 26px;
    display: block;
}

/* ========================================
   Chat Window
   ======================================== */

.trcl-chat-window {
    display: none;
    width: var(--trcl-widget-width, 370px);
    height: var(--trcl-widget-height, 520px);
    background: var(--trcl-window-bg, #fff);
    border-radius: var(--trcl-radius, 12px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    flex-direction: column;
    position: absolute;
    bottom: 0;
    /* right/left set dynamically via wp_add_inline_style based on widget_position setting */
    right: 0;
    left: auto;
}

.trcl-chat-window--open {
    display: flex;
}

/* ========================================
   Chat Header
   ======================================== */

.trcl-chat-header {
    background: var(--trcl-primary, #10B981);
    color: var(--trcl-header-text, #fff);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

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

.trcl-chat-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

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

.trcl-chat-header-name {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
}

.trcl-chat-header-role {
    font-size: 11px;
    opacity: 0.75;
    margin-top: 1px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.trcl-chat-header-status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.trcl-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #86efac;
    display: inline-block;
}

.trcl-chat-close {
    background: none;
    border: none;
    color: var(--trcl-header-text, #fff);
    cursor: pointer;
    padding: 8px;
    opacity: 0.8;
    transition: opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.trcl-chat-close:hover {
    opacity: 1;
}

.trcl-chat-close svg {
    width: 20px;
    height: 20px;
}

/* Expand / collapse toggle (v2.1) — desktop only. */
.trcl-chat-expand {
    background: none;
    border: none;
    color: var(--trcl-header-text, #fff);
    cursor: pointer;
    padding: 8px;
    opacity: 0.8;
    transition: opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.trcl-chat-expand:hover,
.trcl-chat-expand--active {
    opacity: 1;
}

.trcl-chat-expand svg {
    width: 18px;
    height: 18px;
}

/* Expanded window state (v2.1) — desktop only; the mobile and
   landscape full-screen overrides further down still win because
   they appear later in this stylesheet. */
.trcl-chat-window--expanded {
    width: min(720px, calc(100vw - 80px));
    height: min(85vh, 860px);
}

/* ========================================
   Chat Messages
   ======================================== */

.trcl-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.trcl-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    animation: tcl-fade-in 0.3s ease;
}

.trcl-message--user {
    background: var(--trcl-user-bubble, var(--trcl-primary, #10B981));
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.trcl-message--assistant {
    background: var(--trcl-ai-bubble, #f3f4f6);
    color: var(--trcl-body-text, #1f2937);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.trcl-message--assistant a {
    color: var(--trcl-primary-hover, #059669);
    text-decoration: underline;
}

/* Typing Indicator */
.trcl-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--trcl-ai-bubble, #f3f4f6);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    max-width: 80px;
}

.trcl-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: tcl-bounce 1.4s ease-in-out infinite;
}

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

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

/* ========================================
   Quick Replies
   ======================================== */

.trcl-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 16px;
    flex-shrink: 0;
}

.trcl-quick-reply {
    background: #fff;
    border: 1px solid var(--trcl-primary, #10B981);
    color: var(--trcl-primary-hover, #059669);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.trcl-quick-reply:hover {
    background: var(--trcl-primary, #10B981);
    color: #fff;
}

/* ========================================
   Product Cards
   ======================================== */

.trcl-product-cards {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 16px;
    scrollbar-width: thin;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
}

.trcl-product-card {
    min-width: 150px;
    max-width: 150px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.trcl-product-card-image {
    width: 100%;
    height: 100px;
    object-fit: cover;
}

.trcl-product-card-body {
    padding: 8px;
}

.trcl-product-card-name {
    font-size: 12px;
    font-weight: 600;
    color: #1f2937;
    margin: 0 0 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.trcl-product-card-price {
    font-size: 13px;
    font-weight: 700;
    color: var(--trcl-primary-hover, #059669);
}

.trcl-product-card-action {
    display: block;
    width: 100%;
    padding: 6px;
    background: var(--trcl-primary, #10B981);
    color: #fff;
    border: none;
    font-size: 11px;
    cursor: pointer;
    text-align: center;
    transition: opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.trcl-product-card-action:hover {
    opacity: 0.9;
}

/* ========================================
   Chat Input
   ======================================== */

.trcl-chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.trcl-chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    resize: none;
    min-height: 36px;
    max-height: 100px;
    -webkit-appearance: none;
    appearance: none;
}

.trcl-chat-input:focus {
    border-color: var(--trcl-primary, #10B981);
}

.trcl-chat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--trcl-primary, #10B981);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.trcl-chat-send:hover {
    background: var(--trcl-primary-hover, var(--trcl-primary, #059669));
}

.trcl-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.trcl-chat-send svg {
    width: 16px;
    height: 16px;
}

/* ========================================
   Privacy Notice (v2.0)
   ======================================== */

.trcl-privacy-notice {
    display: block;
    text-align: center;
    padding: 6px 12px;
    font-size: 11px;
    line-height: 1.4;
    color: #6b7280;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.trcl-privacy-notice a {
    color: inherit;
    text-decoration: underline;
}

.trcl-privacy-notice a:hover {
    color: #374151;
}

/* ========================================
   Powered By Badge
   ======================================== */

.trcl-powered-by {
    display: block;
    text-align: center;
    padding: 6px;
    font-size: 10px;
    color: #9ca3af;
    text-decoration: none;
    border-top: 1px solid #f3f4f6;
    flex-shrink: 0;
}

.trcl-powered-by:hover {
    color: #6b7280;
}

/* ========================================
   Limit Reached
   ======================================== */

.trcl-limit-banner {
    background: #fef3c7;
    border-top: 1px solid #f59e0b;
    padding: 12px 16px;
    text-align: center;
    flex-shrink: 0;
}

.trcl-limit-banner p {
    margin: 0 0 8px;
    font-size: 13px;
    color: #92400e;
}

.trcl-limit-banner a {
    display: inline-block;
    background: #f59e0b;
    color: #fff;
    padding: 6px 16px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}

.trcl-limit-banner a:hover {
    background: #d97706;
}

/* ========================================
   Noscript Message
   ======================================== */

.trcl-noscript-message {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--trcl-primary, #10B981);
    color: #fff;
    padding: 15px 20px;
    border-radius: 8px;
    font-family: sans-serif;
    font-size: 14px;
    z-index: 9999;
}

/* ========================================
   Shortcode Styles
   ======================================== */

.trcl-shortcode-inline {
    background: #f3f4f6;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.trcl-shortcode-trigger {
    cursor: pointer;
}

/* ========================================
   Animations
   ======================================== */

@keyframes tcl-fade-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

@media (max-width: 480px) {

    /* Widget container: flush to edges when open */
    .trcl-chat-widget {
        bottom: 16px;
        right: 16px;
    }

    /* Full-screen chat window on mobile */
    .trcl-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        z-index: 100000;
    }

    /* Use dynamic viewport height for browsers with address bar */
    @supports (height: 100dvh) {
        .trcl-chat-window {
            height: 100dvh;
        }
    }

    /* Header: slightly smaller padding on mobile */
    .trcl-chat-header {
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top));
    }

    /* Close button: larger tap target on mobile */
    .trcl-chat-close {
        padding: 12px;
        margin: -8px -8px -8px 0;
    }

    /* Expand toggle: pointless when already full-screen */
    .trcl-chat-expand {
        display: none;
    }

    /* Messages area: fill available space */
    .trcl-chat-messages {
        padding: 12px;
        gap: 10px;
    }

    /* Messages: slightly wider on mobile */
    .trcl-message {
        max-width: 90%;
    }

    /* Input area: safe area padding for notch devices */
    .trcl-chat-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    /* Input: 16px font prevents iOS zoom on focus */
    .trcl-chat-input {
        font-size: 16px;
        padding: 10px 14px;
        min-height: 40px;
    }

    /* Send button: slightly larger tap target */
    .trcl-chat-send {
        width: 40px;
        height: 40px;
    }

    /* Quick replies: horizontal scroll on mobile */
    .trcl-quick-replies {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 8px 12px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .trcl-quick-replies::-webkit-scrollbar {
        display: none;
    }

    /* Product cards: smaller cards on mobile */
    .trcl-product-card {
        min-width: 130px;
        max-width: 130px;
    }

    .trcl-product-cards {
        padding: 8px 12px;
    }

    /* Powered by: safe area bottom */
    .trcl-powered-by {
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }

    /* Privacy notice: safe area bottom + slightly tighter on mobile */
    .trcl-privacy-notice {
        padding-bottom: max(6px, env(safe-area-inset-bottom));
        font-size: 10px;
    }

    /* Limit banner */
    .trcl-limit-banner {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* ========================================
   SMALL HEIGHT DEVICES (landscape mobile)
   ======================================== */

@media (max-height: 500px) and (max-width: 900px) {
    .trcl-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        z-index: 100000;
    }

    /* Expand toggle: pointless when already full-screen */
    .trcl-chat-expand {
        display: none;
    }

    .trcl-chat-header {
        padding: 8px 16px;
    }

    .trcl-chat-avatar {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .trcl-chat-messages {
        padding: 8px 12px;
        gap: 6px;
    }

    .trcl-message {
        padding: 8px 12px;
        font-size: 13px;
    }
}