/**
 * Printer Expert Chatbot - Public Styles
 * Version: 2.1.1
 * 100% Mobile Responsive
 */

/* ==========================================================================
   CSS VARIABLES
   ========================================================================== */

:root {
    --pec-primary: #1abc9c;
    --pec-primary-dark: #16a085;
    --pec-secondary: #2c3e50;
    --pec-secondary-light: #34495e;
    --pec-white: #ffffff;
    --pec-light-gray: #f8f9fa;
    --pec-gray: #6c757d;
    --pec-dark-gray: #495057;
    --pec-border: #e9ecef;
    --pec-shadow: rgba(0, 0, 0, 0.1);
    --pec-shadow-strong: rgba(0, 0, 0, 0.15);
    --pec-error: #e74c3c;
    --pec-warning: #f39c12;
    --pec-success: #27ae60;
    --pec-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --pec-z-index: 999999;
}

/* ==========================================================================
   BASE STYLES
   ========================================================================== */

#pec-chatbot-wrapper {
    font-family: var(--pec-font-family);
    font-size: 16px;
    line-height: 1.6;
    color: #333;
    z-index: var(--pec-z-index);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#pec-chatbot-wrapper * {
    box-sizing: border-box;
}

#pec-chatbot-wrapper.pec-chatbot-fixed {
    position: fixed;
    bottom: 20px;
    right: 20px;
}

#pec-chatbot-wrapper.pec-chatbot-inline {
    position: relative;
    margin: 20px 0;
    width: 100%;
}

/* Inline mode - always visible, no toggle */
#pec-chatbot-wrapper.pec-chatbot-inline .pec-chat-button {
    display: none !important;
}

#pec-chatbot-wrapper.pec-chatbot-inline .pec-chat-window {
    display: flex !important;
    position: relative;
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: none;
    bottom: auto;
    right: auto;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

#pec-chatbot-wrapper.pec-chatbot-inline .pec-messages-container {
    max-height: none;
    overflow-y: visible;
}

#pec-chatbot-wrapper.pec-chatbot-inline .pec-messages {
    min-height: 150px;
}

/* Large inline mode - landing page hero style */
#pec-chatbot-wrapper.pec-chatbot-large {
    position: relative;
    margin: 20px auto;
    width: 100%;
    max-width: 900px;
}

#pec-chatbot-wrapper.pec-chatbot-large .pec-chat-button {
    display: none !important;
}

#pec-chatbot-wrapper.pec-chatbot-large .pec-chat-window {
    display: flex !important;
    position: relative;
    width: 100%;
    height: auto;
    min-height: 450px;
    max-height: none;
    bottom: auto;
    right: auto;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

#pec-chatbot-wrapper.pec-chatbot-large .pec-chat-header {
    padding: 20px 24px;
    border-radius: 16px 16px 0 0;
}

#pec-chatbot-wrapper.pec-chatbot-large .pec-header-title {
    font-size: 20px;
}

#pec-chatbot-wrapper.pec-chatbot-large .pec-header-subtitle {
    font-size: 14px;
}

#pec-chatbot-wrapper.pec-chatbot-large .pec-messages-container {
    min-height: 150px;
    max-height: 400px;
    padding: 20px 24px;
}

#pec-chatbot-wrapper.pec-chatbot-large .pec-message-content {
    font-size: 15px;
    padding: 14px 18px;
    max-width: 85%;
}

#pec-chatbot-wrapper.pec-chatbot-large .pec-quick-actions {
    padding: 12px 24px;
    gap: 10px;
}

#pec-chatbot-wrapper.pec-chatbot-large .pec-quick-action {
    padding: 10px 18px;
    font-size: 14px;
}

#pec-chatbot-wrapper.pec-chatbot-large .pec-input-area {
    padding: 16px 24px 20px;
    border-radius: 0 0 16px 16px;
}

#pec-chatbot-wrapper.pec-chatbot-large .pec-message-input {
    font-size: 15px;
    padding: 14px 16px;
}

#pec-chatbot-wrapper.pec-chatbot-large .pec-send-button {
    width: 48px;
    height: 48px;
}

/* Inline mode mobile responsive */
@media (max-width: 768px) {
    #pec-chatbot-wrapper.pec-chatbot-inline {
        margin: 10px 0;
    }

    #pec-chatbot-wrapper.pec-chatbot-inline .pec-chat-window {
        min-height: 300px;
        border-radius: 10px;
    }

    #pec-chatbot-wrapper.pec-chatbot-inline .pec-messages-container {
        min-height: 100px;
        max-height: none;
        overflow-y: visible;
    }

    #pec-chatbot-wrapper.pec-chatbot-inline .pec-chat-header {
        padding: 14px 16px;
    }

    #pec-chatbot-wrapper.pec-chatbot-inline .pec-input-area {
        padding: 12px;
    }

    #pec-chatbot-wrapper.pec-chatbot-inline .pec-input-wrapper {
        gap: 6px;
        padding: 6px 8px;
    }
}

/* Large mode mobile responsive */
@media (max-width: 768px) {
    #pec-chatbot-wrapper.pec-chatbot-large {
        margin: 10px;
        max-width: calc(100% - 20px);
    }

    #pec-chatbot-wrapper.pec-chatbot-large .pec-chat-window {
        border-radius: 12px;
        min-height: 350px;
    }

    #pec-chatbot-wrapper.pec-chatbot-large .pec-messages-container {
        min-height: 100px;
        max-height: 400px;
        padding: 16px;
    }

    #pec-chatbot-wrapper.pec-chatbot-large .pec-chat-header {
        padding: 16px;
    }

    #pec-chatbot-wrapper.pec-chatbot-large .pec-input-area {
        padding: 12px 16px 16px;
    }
}

/* ==========================================================================
   CHAT BUTTON
   ========================================================================== */

.pec-chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--pec-primary) 0%, var(--pec-primary-dark) 100%);
    border: none;
    border-radius: 50%;
    color: var(--pec-white);
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(26, 188, 156, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: var(--pec-z-index);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.pec-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(26, 188, 156, 0.5);
}

.pec-chat-button:active {
    transform: scale(0.95);
}

.pec-chat-button svg {
    width: 28px;
    height: 28px;
}

.pec-chat-button-text {
    display: none;
    margin-left: 10px;
    font-size: 16px;
    font-weight: 500;
}

.pec-chat-button.expanded {
    width: auto;
    padding: 0 24px;
    border-radius: 32px;
}

.pec-chat-button.expanded .pec-chat-button-text {
    display: inline;
}

.pec-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--pec-error);
    color: var(--pec-white);
    font-size: 12px;
    font-weight: 600;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    animation: pec-pulse 2s infinite;
}

@keyframes pec-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

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

.pec-chat-window {
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 140px);
    background: var(--pec-white);
    border-radius: 16px;
    box-shadow: 0 8px 32px var(--pec-shadow-strong);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: var(--pec-z-index);
    animation: pec-slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* ==========================================================================
   CHAT HEADER - Improved Design
   ========================================================================== */

.pec-chat-header {
    background: linear-gradient(135deg, #1abc9c 0%, #16a085 100%);
    color: var(--pec-white);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.pec-header-content {
    display: flex;
    flex-direction: column;
}

.pec-header-content h3 {
    margin: 0 0 2px 0;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.3px;
}

.pec-header-content p {
    margin: 0;
    font-size: 13px;
    opacity: 0.9;
    font-weight: 400;
}

/* ==========================================================================
   THEME OPTIONS
   Add class "pec-theme-light" or "pec-theme-dark" to wrapper
   ========================================================================== */

/* LIGHT THEME (default) */
#pec-chatbot-wrapper.pec-theme-light .pec-chat-window,
#pec-chatbot-wrapper:not(.pec-theme-dark) .pec-chat-window {
    background: #ffffff;
}

#pec-chatbot-wrapper.pec-theme-light .pec-messages-container,
#pec-chatbot-wrapper:not(.pec-theme-dark) .pec-messages-container {
    background: #ffffff;
}

#pec-chatbot-wrapper.pec-theme-light .pec-assistant-message .pec-message-content,
#pec-chatbot-wrapper:not(.pec-theme-dark) .pec-assistant-message .pec-message-content {
    background: #f0f0f0;
    color: #333333;
}

#pec-chatbot-wrapper.pec-theme-light .pec-input-area,
#pec-chatbot-wrapper:not(.pec-theme-dark) .pec-input-area {
    background: #ffffff;
    border-top: 1px solid #e9ecef;
}

#pec-chatbot-wrapper.pec-theme-light .pec-message-input,
#pec-chatbot-wrapper:not(.pec-theme-dark) .pec-message-input {
    background: #f8f9fa;
    color: #333333;
    border: 1px solid #e9ecef;
}

#pec-chatbot-wrapper.pec-theme-light .pec-quick-actions,
#pec-chatbot-wrapper:not(.pec-theme-dark) .pec-quick-actions {
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
}

#pec-chatbot-wrapper.pec-theme-light .pec-quick-action,
#pec-chatbot-wrapper:not(.pec-theme-dark) .pec-quick-action {
    background: #ffffff;
    color: #333333;
    border: 1px solid #e9ecef;
}

#pec-chatbot-wrapper.pec-theme-light .pec-chat-footer,
#pec-chatbot-wrapper:not(.pec-theme-dark) .pec-chat-footer {
    background: #f8f9fa;
    color: #666666;
}

/* DARK THEME */
#pec-chatbot-wrapper.pec-theme-dark .pec-chat-window {
    background: #2c3e50;
}

#pec-chatbot-wrapper.pec-theme-dark .pec-messages-container {
    background: #2c3e50;
}

#pec-chatbot-wrapper.pec-theme-dark .pec-assistant-message .pec-message-content {
    background: #34495e;
    color: #ffffff;
}

#pec-chatbot-wrapper.pec-theme-dark .pec-user-message .pec-message-content {
    background: linear-gradient(135deg, #1abc9c 0%, #16a085 100%);
    color: #ffffff;
}

#pec-chatbot-wrapper.pec-theme-dark .pec-input-area {
    background: #1a252f;
    border-top: 1px solid #34495e;
}

#pec-chatbot-wrapper.pec-theme-dark .pec-message-input {
    background: #2c3e50;
    color: #ffffff;
    border: 1px solid #34495e;
}

#pec-chatbot-wrapper.pec-theme-dark .pec-message-input::placeholder {
    color: #95a5a6;
}

#pec-chatbot-wrapper.pec-theme-dark .pec-quick-actions {
    background: #1a252f;
    border-top: 1px solid #34495e;
}

#pec-chatbot-wrapper.pec-theme-dark .pec-quick-action {
    background: #34495e;
    color: #ffffff;
    border: 1px solid #4a6278;
}

#pec-chatbot-wrapper.pec-theme-dark .pec-quick-action:hover {
    background: #4a6278;
}

#pec-chatbot-wrapper.pec-theme-dark .pec-chat-footer {
    background: #1a252f;
    color: #95a5a6;
}

#pec-chatbot-wrapper.pec-theme-dark .pec-chat-footer a {
    color: #1abc9c;
}

.pec-close-button {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    color: var(--pec-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.pec-close-button:hover {
    background: rgba(255, 255, 255, 0.25);
}

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

.pec-messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.pec-messages {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.pec-message {
    display: flex;
    flex-direction: column;
    animation: pec-fade-in 0.3s ease;
}

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

.pec-user-message {
    align-items: flex-end;
}

.pec-assistant-message {
    align-items: flex-start;
}

.pec-message-content {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 18px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.pec-user-message .pec-message-content {
    background: linear-gradient(135deg, var(--pec-primary) 0%, var(--pec-primary-dark) 100%);
    color: var(--pec-white);
    border-bottom-right-radius: 4px;
}

.pec-assistant-message .pec-message-content {
    background: var(--pec-light-gray);
    color: var(--pec-dark-gray);
    border-bottom-left-radius: 4px;
}

.pec-message-content p {
    margin: 0 0 10px 0;
}

.pec-message-content p:last-child {
    margin-bottom: 0;
}

/* ==========================================================================
   MESSAGE LINKS
   ========================================================================== */
.pec-message-content a {
    color: #0070ff;
    text-decoration: underline;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.pec-message-content a:hover {
    opacity: 0.9;
}

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

.pec-typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 16px 20px;
    background: var(--pec-light-gray);
    border-radius: 18px;
    margin: 0 20px 10px 20px;
    width: fit-content;
}

.pec-typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--pec-gray);
    border-radius: 50%;
    animation: pec-typing 1.4s infinite;
}

.pec-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.pec-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pec-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ==========================================================================
   QUICK ACTIONS
   ========================================================================== */

.pec-quick-actions {
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    flex-shrink: 0;
    border-top: 1px solid var(--pec-border);
}

.pec-quick-actions::-webkit-scrollbar {
    display: none;
}

.pec-quick-action {
    flex-shrink: 0;
    padding: 12px 18px;
    background: var(--pec-white);
    border: 1px solid var(--pec-border);
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    color: var(--pec-dark-gray);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    min-height: 48px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.pec-quick-action:hover {
    background: var(--pec-primary);
    color: var(--pec-white);
    border-color: var(--pec-primary);
    transform: translateY(-2px);
}

.pec-quick-action:active {
    transform: scale(0.95);
}

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

.pec-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--pec-border);
    background: var(--pec-white);
    flex-shrink: 0;
}

.pec-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--pec-light-gray);
    border-radius: 24px;
    padding: 8px 12px;
}

.pec-message-input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    padding: 8px 4px;
    resize: none;
    max-height: 120px;
    min-height: 44px;
    outline: none;
    -webkit-appearance: none;
}

.pec-message-input::placeholder {
    color: var(--pec-gray);
}

/* Prevent iOS zoom on input focus */
@supports (-webkit-touch-callout: none) {
    .pec-message-input {
        font-size: 16px !important;
    }
}

.pec-voice-button,
.pec-send-button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.pec-voice-button {
    background: var(--pec-white);
    color: var(--pec-gray);
}

.pec-voice-button:hover {
    background: var(--pec-border);
    color: var(--pec-dark-gray);
}

.pec-voice-button.connecting {
    background: #f39c12;
    color: var(--pec-white);
    animation: pec-pulse-connecting 0.6s infinite;
}

@keyframes pec-pulse-connecting {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.pec-voice-button.recording {
    background: var(--pec-error);
    color: var(--pec-white);
    animation: pec-pulse-recording 1s infinite;
}

@keyframes pec-pulse-recording {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    50% { box-shadow: 0 0 0 10px rgba(231, 76, 60, 0); }
}

.pec-send-button {
    background: var(--pec-primary);
    color: var(--pec-white);
}

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

.pec-send-button:disabled {
    background: var(--pec-gray);
    cursor: not-allowed;
    transform: none;
}

/* ==========================================================================
   RECORDING INDICATOR
   ========================================================================== */

.pec-recording-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #fee;
    border-radius: 12px;
    margin-top: 12px;
    font-size: 14px;
    color: var(--pec-error);
}

.pec-recording-dot {
    width: 12px;
    height: 12px;
    background: var(--pec-error);
    border-radius: 50%;
    animation: pec-blink 1s infinite;
}

@keyframes pec-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ==========================================================================
   VOICE CTA LINK
   ========================================================================== */

.pec-voice-cta .pec-message-content {
    text-align: center;
    padding: 8px 16px;
}

.pec-quote-link {
    display: inline-block;
    background: var(--pec-primary);
    color: var(--pec-white) !important;
    text-decoration: none !important;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 15px;
    transition: background 0.2s;
}

.pec-quote-link:hover {
    background: var(--pec-primary-dark);
}

/* ==========================================================================
   CHAT FOOTER
   ========================================================================== */

.pec-chat-footer {
    padding: 12px 20px;
    background: var(--pec-light-gray);
    text-align: center;
    font-size: 13px;
    color: var(--pec-gray);
    flex-shrink: 0;
}

.pec-chat-footer p {
    margin: 0 0 4px 0;
}

.pec-chat-footer p:last-child {
    margin-bottom: 0;
}

.pec-privacy-notice {
    font-size: 11px;
}

.pec-privacy-notice a {
    color: var(--pec-primary);
    text-decoration: none;
}

.pec-privacy-notice a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   QUOTE HIGHLIGHT OVERLAY
   ========================================================================== */

.pec-quote-highlight {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: calc(var(--pec-z-index) + 1);
    animation: pec-fade-in 0.3s ease;
    padding: 20px;
}

.pec-highlight-content {
    background: var(--pec-white);
    padding: 32px;
    border-radius: 16px;
    text-align: center;
    max-width: 400px;
    width: 100%;
    animation: pec-scale-in 0.3s ease;
}

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

.pec-highlight-content h4 {
    margin: 0 0 12px 0;
    font-size: 22px;
    color: var(--pec-secondary);
}

.pec-highlight-content p {
    margin: 0 0 24px 0;
    color: var(--pec-gray);
    font-size: 16px;
}

.pec-highlight-close {
    padding: 14px 32px;
    background: var(--pec-primary);
    color: var(--pec-white);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: background 0.2s ease;
    min-height: 48px;
    -webkit-tap-highlight-color: transparent;
}

.pec-highlight-close:hover {
    background: var(--pec-primary-dark);
}

/* ==========================================================================
   TABLET BREAKPOINT - 800px (Avada theme compatible)
   ========================================================================== */

@media only screen and (max-width: 800px) {
    .pec-chat-window {
        width: calc(100% - 40px);
        max-width: 420px;
        height: calc(100vh - 140px);
        max-height: 650px;
        bottom: 100px;
        right: 20px;
    }
    
    .pec-chat-header {
        padding: 18px;
    }
    
    .pec-header-content h3 {
        font-size: 17px;
    }
    
    .pec-messages {
        padding: 18px;
    }
    
    .pec-message-content {
        max-width: 88%;
    }
}

/* ==========================================================================
   MOBILE BREAKPOINT - 768px
   ========================================================================== */

@media only screen and (max-width: 768px) {
    .pec-chat-window {
        width: calc(100% - 30px);
        max-width: 400px;
        height: calc(100vh - 120px);
        max-height: 600px;
        bottom: 90px;
        right: 15px;
    }
    
    .pec-chat-header {
        padding: 16px;
    }
    
    .pec-header-content h3 {
        font-size: 17px;
    }
    
    .pec-messages {
        padding: 16px;
    }
    
    .pec-message-content {
        max-width: 88%;
        padding: 14px 16px;
    }
    
    .pec-quick-actions {
        padding: 14px 16px;
        gap: 8px;
    }
    
    .pec-input-area {
        padding: 14px 16px;
    }
    
    .pec-message-input {
        min-height: 44px;
        padding: 10px 4px;
    }
}

/* ==========================================================================
   SMALL MOBILE - 480px (Full screen mode)
   ========================================================================== */

@media only screen and (max-width: 480px) {
    /* Full screen chat on mobile */
    .pec-chat-window {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        border-radius: 0;
        position: fixed;
    }
    
    /* Adjust chat button position for iPhone home bar */
    .pec-chat-button {
        bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        right: 20px;
        width: 60px;
        height: 60px;
    }
    
    .pec-chat-button svg {
        width: 26px;
        height: 26px;
    }
    
    /* Header with safe area for notch */
    .pec-chat-header {
        padding: 16px;
        padding-top: calc(16px + env(safe-area-inset-top, 0px));
    }
    
    .pec-header-content h3 {
        font-size: 18px;
    }
    
    .pec-header-content p {
        font-size: 14px;
    }
    
    /* Close button larger for mobile */
    .pec-close-button {
        width: 48px;
        height: 48px;
    }
    
    /* Messages */
    .pec-messages {
        padding: 16px;
    }
    
    .pec-message-content {
        max-width: 90%;
        padding: 14px 16px;
        font-size: 15px;
    }
    
    /* Quick actions */
    .pec-quick-actions {
        padding: 12px 16px;
        gap: 8px;
    }
    
    .pec-quick-action {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 44px;
    }
    
    /* Input area with safe area for home indicator */
    .pec-input-area {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
    
    .pec-input-wrapper {
        padding: 6px 8px;
        gap: 6px;
    }

    .pec-message-input {
        font-size: 16px;
        padding: 10px 4px;
        min-width: 0;
    }

    .pec-voice-button,
    .pec-send-button {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Footer */
    .pec-chat-footer {
        padding: 10px 16px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
}

/* ==========================================================================
   EXTRA SMALL MOBILE - 360px
   ========================================================================== */

@media only screen and (max-width: 360px) {
    .pec-chat-header {
        padding: 14px;
        padding-top: calc(14px + env(safe-area-inset-top, 0px));
    }
    
    .pec-header-content h3 {
        font-size: 16px;
        margin-bottom: 2px;
    }
    
    .pec-header-content p {
        font-size: 12px;
    }
    
    .pec-messages {
        padding: 12px;
    }
    
    .pec-message-content {
        padding: 12px 14px;
        font-size: 14px;
    }
    
    .pec-quick-actions {
        padding: 10px 12px;
    }
    
    .pec-quick-action {
        padding: 8px 14px;
        font-size: 13px;
    }
    
    .pec-input-area {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
}

/* ==========================================================================
   TOUCH DEVICE OPTIMISATIONS
   ========================================================================== */

@media (pointer: coarse) {
    .pec-voice-button,
    .pec-send-button {
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
    }
    
    .pec-quick-action {
        min-height: 48px;
        padding: 12px 18px;
    }
    
    .pec-close-button {
        min-width: 48px;
        min-height: 48px;
    }
    
    .pec-highlight-close {
        min-height: 52px;
        padding: 16px 36px;
    }
}

/* ==========================================================================
   iOS SPECIFIC FIXES
   ========================================================================== */

@supports (-webkit-touch-callout: none) {
    /* Prevent zoom on input focus */
    .pec-message-input {
        font-size: 16px !important;
    }
    
    .pec-message-input:focus {
        font-size: 16px !important;
    }
    
    /* Fix iOS momentum scrolling */
    .pec-messages-container {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Fix iOS input styling */
    .pec-message-input {
        -webkit-appearance: none;
        appearance: none;
    }
}

/* ==========================================================================
   HIGH CONTRAST MODE
   ========================================================================== */

@media (prefers-contrast: high) {
    .pec-chat-button {
        border: 2px solid var(--pec-white);
    }
    
    .pec-message-content {
        border: 1px solid currentColor;
    }
    
    .pec-quick-action {
        border-width: 2px;
    }
    
    .pec-input-wrapper {
        border: 2px solid var(--pec-dark-gray);
    }
}

@media (max-width: 800px) and (prefers-contrast: high) {
    .pec-message-content {
        border: 2px solid currentColor;
    }
    
    .pec-quick-action {
        border: 2px solid #333;
    }
    
    .pec-message-input {
        border: 2px solid #333;
    }
}

/* ==========================================================================
   REDUCED MOTION
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .pec-chat-window,
    .pec-message,
    .pec-chat-button,
    .pec-quick-action,
    .pec-send-button,
    .pec-voice-button,
    .pec-notification-badge,
    .pec-typing-indicator span {
        animation: none;
        transition: none;
    }
}

/* ==========================================================================
   DARK MODE SUPPORT
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .pec-chat-window {
        background: #1a1a1a;
    }
    
    .pec-messages-container {
        background: #1a1a1a;
    }
    
    .pec-assistant-message .pec-message-content {
        background: #2d2d2d;
        color: #e0e0e0;
    }
    
    .pec-quick-actions {
        background: #1a1a1a;
        border-color: #333;
    }
    
    .pec-quick-action {
        background: #2d2d2d;
        border-color: #444;
        color: #e0e0e0;
    }
    
    .pec-quick-action:hover {
        background: var(--pec-primary);
        color: var(--pec-white);
    }
    
    .pec-input-area {
        background: #1a1a1a;
        border-color: #333;
    }
    
    .pec-input-wrapper {
        background: #2d2d2d;
    }
    
    .pec-message-input {
        color: #e0e0e0;
    }
    
    .pec-message-input::placeholder {
        color: #888;
    }
    
    .pec-voice-button {
        background: #444;
        color: #ccc;
    }
    
    .pec-chat-footer {
        background: #2d2d2d;
        color: #999;
    }
}

/* ==========================================================================
   RTL SUPPORT
   ========================================================================== */

[dir="rtl"] .pec-chat-window {
    right: auto;
    left: 20px;
}

[dir="rtl"] .pec-chat-button {
    right: auto;
    left: 20px;
}

[dir="rtl"] .pec-user-message {
    align-items: flex-start;
}

[dir="rtl"] .pec-assistant-message {
    align-items: flex-end;
}

[dir="rtl"] .pec-user-message .pec-message-content {
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .pec-assistant-message .pec-message-content {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 4px;
}

[dir="rtl"] .pec-message-content {
    direction: rtl;
}

/* ==========================================================================
   AVADA THEME INTEGRATION
   ========================================================================== */

.fusion-chatbot .pec-chat-window {
    z-index: 99999;
}

.fusion-chatbot .pec-chat-button {
    z-index: 99999;
}

/* Avada mobile menu compatibility */
@media only screen and (max-width: 800px) {
    .fusion-mobile-menu-design-modern .pec-chat-button {
        z-index: 999999;
    }
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */

@media print {
    #pec-chatbot-wrapper {
        display: none !important;
    }
}

/* ==========================================================================
   LOADING STATE
   ========================================================================== */

.pec-loading {
    pointer-events: none;
    opacity: 0.6;
}

.pec-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid var(--pec-border);
    border-top: 3px solid var(--pec-primary);
    border-radius: 50%;
    animation: pec-spin 1s linear infinite;
}

@keyframes pec-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==========================================================================
   OFFLINE INDICATOR
   ========================================================================== */

.pec-offline-indicator {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff3cd;
    color: #856404;
    padding: 10px 20px;
    border-radius: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    box-shadow: 0 4px 12px var(--pec-shadow);
    z-index: 10;
}

/* ==========================================================================
   VOICE STATE PANEL (4-state visual feedback system)
   ========================================================================== */

.pec-voice-panel {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    margin: 8px 12px 0;
    background: linear-gradient(135deg, #f8f9fa 0%, #eef4f7 100%);
    border: 1px solid var(--pec-border);
    border-left: 4px solid var(--pec-primary);
    border-radius: 10px;
    box-shadow: 0 2px 6px var(--pec-shadow);
    transition: border-left-color 0.3s ease, background 0.3s ease;
    font-family: var(--pec-font-family);
}

#pec-chatbot-wrapper[data-voice-state="connecting"] .pec-voice-panel,
#pec-chatbot-wrapper[data-voice-state="listening"] .pec-voice-panel,
#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-panel,
#pec-chatbot-wrapper[data-voice-state="speaking"] .pec-voice-panel {
    display: flex;
}

/* Per-state accent colors on the panel */
#pec-chatbot-wrapper[data-voice-state="connecting"] .pec-voice-panel {
    border-left-color: #95a5a6;
    background: linear-gradient(135deg, #f8f9fa 0%, #eef0f2 100%);
}

#pec-chatbot-wrapper[data-voice-state="listening"] .pec-voice-panel {
    border-left-color: #1abc9c;
    background: linear-gradient(135deg, #f1fbf8 0%, #e3f6f1 100%);
}

#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-panel {
    border-left-color: #f39c12;
    background: linear-gradient(135deg, #fff9ec 0%, #fef2d8 100%);
}

#pec-chatbot-wrapper[data-voice-state="speaking"] .pec-voice-panel {
    border-left-color: #3498db;
    background: linear-gradient(135deg, #f0f7ff 0%, #dceeff 100%);
}

/* Sound bars container */
.pec-voice-bars {
    display: inline-flex;
    align-items: flex-end;
    gap: 3px;
    height: 28px;
    width: 60px;
    flex-shrink: 0;
}

.pec-voice-bar {
    display: inline-block;
    width: 5px;
    min-height: 4px;
    height: 4px;
    background: var(--pec-primary);
    border-radius: 3px;
    transform-origin: bottom center;
    transition: height 80ms ease-out, background 0.25s ease;
    will-change: height;
}

/* Bar color per state */
#pec-chatbot-wrapper[data-voice-state="connecting"] .pec-voice-bar {
    background: #95a5a6;
}

#pec-chatbot-wrapper[data-voice-state="listening"] .pec-voice-bar {
    background: #1abc9c;
}

#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-bar {
    background: #f39c12;
}

#pec-chatbot-wrapper[data-voice-state="speaking"] .pec-voice-bar {
    background: #3498db;
}

/* Thinking state: bars pulse/shimmer in place since mic is quiet */
#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-bar {
    animation: pec-bar-pulse 1.1s ease-in-out infinite;
}

#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-bar:nth-child(1) { animation-delay: 0s; }
#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-bar:nth-child(2) { animation-delay: 0.08s; }
#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-bar:nth-child(3) { animation-delay: 0.16s; }
#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-bar:nth-child(4) { animation-delay: 0.24s; }
#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-bar:nth-child(5) { animation-delay: 0.32s; }
#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-bar:nth-child(6) { animation-delay: 0.40s; }
#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-bar:nth-child(7) { animation-delay: 0.48s; }

/* Connecting state: gentle synchronous pulse */
#pec-chatbot-wrapper[data-voice-state="connecting"] .pec-voice-bar {
    animation: pec-bar-connecting 1.4s ease-in-out infinite;
}

@keyframes pec-bar-pulse {
    0%, 100% { height: 6px; }
    50% { height: 22px; }
}

@keyframes pec-bar-connecting {
    0%, 100% { height: 4px; opacity: 0.4; }
    50% { height: 10px; opacity: 1; }
}

/* State label text */
.pec-voice-state-label {
    flex: 1 1 auto;
    font-size: 14px;
    font-weight: 500;
    color: var(--pec-secondary);
    transition: color 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#pec-chatbot-wrapper[data-voice-state="connecting"] .pec-voice-state-label { color: #7f8c8d; }
#pec-chatbot-wrapper[data-voice-state="listening"] .pec-voice-state-label { color: #16a085; }
#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-state-label { color: #b9770e; }
#pec-chatbot-wrapper[data-voice-state="speaking"] .pec-voice-state-label { color: #2471a3; }

/* Stop speaking button (barge-in) */
.pec-voice-stop {
    display: none;
    align-items: center;
    gap: 6px;
    background: var(--pec-error);
    color: #fff;
    border: none;
    border-radius: 18px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(231, 76, 60, 0.3);
    transition: background 0.2s ease, transform 0.1s ease;
    flex-shrink: 0;
    font-family: var(--pec-font-family);
}

.pec-voice-stop:hover {
    background: #c0392b;
}

.pec-voice-stop:active {
    transform: scale(0.96);
}

.pec-voice-stop:focus {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

.pec-voice-stop .pec-voice-stop-icon {
    display: inline-block;
    width: 10px;
    height: 10px;
    background: #fff;
    border-radius: 2px;
}

/* ==========================================================================
   STREAMING TRANSCRIPT BUBBLES
   ========================================================================== */

.pec-message.pec-streaming .pec-message-content {
    position: relative;
    opacity: 0.95;
}

.pec-message.pec-streaming .pec-message-content::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 14px;
    margin-left: 3px;
    background: currentColor;
    vertical-align: text-bottom;
    opacity: 0.6;
    animation: pec-caret-blink 0.9s steps(2, start) infinite;
    border-radius: 1px;
}

@keyframes pec-caret-blink {
    to { visibility: hidden; }
}

/* Mic button reflects active voice state */
#pec-chatbot-wrapper[data-voice-state="listening"] .pec-voice-button,
#pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-button,
#pec-chatbot-wrapper[data-voice-state="speaking"] .pec-voice-button {
    background: var(--pec-primary);
    color: var(--pec-white);
    box-shadow: 0 0 0 4px rgba(26, 188, 156, 0.25);
}

#pec-chatbot-wrapper[data-voice-state="listening"] .pec-voice-button {
    animation: pec-mic-breathe 1.6s ease-in-out infinite;
}

@keyframes pec-mic-breathe {
    0%, 100% { box-shadow: 0 0 0 4px rgba(26, 188, 156, 0.25); }
    50% { box-shadow: 0 0 0 10px rgba(26, 188, 156, 0.12); }
}

/* Mobile adjustments for voice panel */
@media (max-width: 480px) {
    .pec-voice-panel {
        margin: 6px 8px 0;
        padding: 8px 10px;
        gap: 8px;
    }

    .pec-voice-bars {
        width: 48px;
        height: 24px;
    }

    .pec-voice-state-label {
        font-size: 13px;
    }

    .pec-voice-stop {
        padding: 5px 10px;
        font-size: 12px;
    }
}

/* Reduced motion users: disable bar animations */
@media (prefers-reduced-motion: reduce) {
    .pec-voice-bar,
    #pec-chatbot-wrapper[data-voice-state="thinking"] .pec-voice-bar,
    #pec-chatbot-wrapper[data-voice-state="connecting"] .pec-voice-bar,
    #pec-chatbot-wrapper[data-voice-state="listening"] .pec-voice-button,
    .pec-message.pec-streaming .pec-message-content::after {
        animation: none !important;
        transition: none !important;
    }
}

/* ==========================================================================
   MOBILE RESPONSIVENESS OVERRIDES
   ========================================================================== */

@media only screen and (max-width: 768px) {
    #pec-chatbot-wrapper {
        max-width: 100%;
    }

    #pec-chatbot-wrapper.pec-chatbot-inline,
    #pec-chatbot-wrapper.pec-chatbot-large {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0;
        margin-left: 0;
        margin-right: 0;
    }

    #pec-chatbot-wrapper.pec-chatbot-inline .pec-chat-window,
    #pec-chatbot-wrapper.pec-chatbot-large .pec-chat-window {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        height: auto;
        min-height: min(400px, calc(100dvh - 32px));
        max-height: none;
    }

    #pec-chatbot-wrapper.pec-chatbot-fixed .pec-chat-window {
        left: max(12px, env(safe-area-inset-left, 0px));
        right: max(12px, env(safe-area-inset-right, 0px));
        bottom: calc(88px + env(safe-area-inset-bottom, 0px));
        width: auto;
        max-width: none;
        height: min(620px, calc(100dvh - 112px - env(safe-area-inset-bottom, 0px)));
        max-height: calc(100dvh - 112px - env(safe-area-inset-bottom, 0px));
    }

    .pec-chat-header,
    .pec-input-wrapper,
    .pec-message-content {
        min-width: 0;
    }

    .pec-header-content {
        min-width: 0;
    }

    .pec-header-content h3,
    .pec-header-content p,
    .pec-message-content,
    .pec-quick-action {
        overflow-wrap: anywhere;
    }

    .pec-messages-container {
        min-height: 0;
    }
}

@media only screen and (max-width: 480px) {
    #pec-chatbot-wrapper.pec-chatbot-fixed .pec-chat-window {
        inset: 0;
        width: 100%;
        height: 100dvh;
        max-width: 100%;
        max-height: 100dvh;
        border-radius: 0;
    }

    #pec-chatbot-wrapper.pec-chatbot-fixed .pec-chat-header {
        border-radius: 0;
    }

    #pec-chatbot-wrapper.pec-chatbot-inline .pec-chat-window,
    #pec-chatbot-wrapper.pec-chatbot-large .pec-chat-window {
        border-radius: 12px;
        min-height: min(400px, calc(100dvh - 24px));
    }
}

/* ============================================================
   RICH TEXT FORMATTING INSIDE MESSAGE BUBBLES
   ============================================================ */
.pec-message-content ol.pec-list,
.pec-message-content ul.pec-list {
    margin: 8px 0 10px;
    padding-left: 1.35em;
    list-style-position: outside;
}

.pec-message-content ol.pec-list {
    list-style-type: decimal;
}

.pec-message-content ul.pec-list {
    list-style-type: disc;
}

.pec-message-content ol.pec-list li,
.pec-message-content ul.pec-list li {
    margin: 0 0 6px;
    padding-left: 2px;
    line-height: 1.5;
}

.pec-message-content ol.pec-list li:last-child,
.pec-message-content ul.pec-list li:last-child {
    margin-bottom: 0;
}

.pec-message-content strong {
    font-weight: 700;
}

.pec-message-content em {
    font-style: italic;
}

.pec-message-content p.pec-heading {
    margin: 12px 0 4px;
}

.pec-message-content p.pec-heading:first-child {
    margin-top: 0;
}

.pec-message-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.92em;
    word-break: break-word;
}

@media only screen and (max-width: 480px) {
    .pec-message-content ol.pec-list,
    .pec-message-content ul.pec-list {
        padding-left: 1.2em;
    }
}
