﻿/**
 * Public CSS for Mad Search
 *
 * @since      1.0.0
 */

/* Root variables for theming - these get overridden with inline styles */
:root {
    --maddy-primary-color: #6366f1;
    --maddy-secondary-color: #8b5cf6;
    --maddy-primary-color-light: rgba(99, 102, 241, 0.1);
    --maddy-secondary-color-light: rgba(139, 92, 246, 0.1);
    --maddy-success-color: #10b981;
    --maddy-error-color: #ef4444;
    --maddy-text-primary: #1f2937;
    --maddy-text-secondary: #6b7280;
    --maddy-bg-light: #f9fafb;
    --maddy-border-color: #e5e7eb;
    --maddy-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --maddy-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --maddy-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --maddy-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Main container styles */
.mad-search-container {
    position: fixed;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    line-height: 1.5;
    color: #333;
    /* Hide by default until JavaScript initializes */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    /* Ensure proper mobile rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Show when JavaScript has initialized */
.mad-search-container.maddy-initialized {
    opacity: 1;
    visibility: visible;
}

/* Mobile responsive styles - consolidated */
@media (max-width: 770px) {
    .mad-search-container {
        animation: mobile-fallback-show 0.5s ease 3s forwards;
        /* Force proper mobile positioning */
        position: fixed !important;
        z-index: 99999 !important;
        /* Ensure container stays within viewport */
        max-width: 100vw !important;
        max-height: 100vh !important;
        box-sizing: border-box !important;
        /* Override any inherited positioning */
        right: 10px !important;
        bottom: 10px !important;
        left: auto !important;
        top: auto !important;
    }
    
    /* Ensure proper initialization visibility on mobile */
    .mad-search-container.maddy-initialized {
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Force all position variants to use safe mobile positioning */
    .mad-search-position-bottom-right,
    .mad-search-position-bottom-left {
        right: 10px !important;
        bottom: 10px !important;
        left: auto !important;
        top: auto !important;
    }
    
    /* Chat window mobile styles */
    .mad-search-window {
        width: calc(100vw - 20px) !important;
        height: calc(100vh - 120px) !important;
        max-height: calc(100vh - 200px) !important;
        min-height: 220px !important;
        min-width: 280px !important;
        bottom: 70px !important;
        top: auto !important;
        position: absolute !important;
        z-index: 99998 !important;
        max-width: calc(100vw - 20px) !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
        transform: translateZ(0) !important;
        -webkit-transform: translateZ(0) !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Toggle button mobile styles */
    .mad-search-toggle {
        width: 56px !important;
        height: 56px !important;
        min-width: 56px !important;
        min-height: 56px !important;
        z-index: 99999 !important;
        position: absolute !important;
        right: 0 !important;
        left: auto !important;
        bottom: 0 !important;
        transform: translateZ(0) !important;
        -webkit-transform: translateZ(0) !important;
    }
    
    /* Ensure proper open state on mobile */
    .mad-search-container.open .mad-search-window {
        opacity: 1 !important;
        pointer-events: all !important;
        visibility: visible !important;
    }
    
    /* Message bubble adjustments */
    .mad-search-bubble {
        max-width: 85% !important;
        font-size: 14px !important;
    }
    
    /* Input field mobile optimization */
    #mad-search-input-field {
        font-size: 16px !important; /* Prevents zoom on iOS */
        min-height: 44px !important; /* iOS minimum touch target */
    }
    
    #mad-search-send {
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        min-height: 44px !important;
    }
}

@keyframes mobile-fallback-show {
    from {
        opacity: 0;
        visibility: hidden;
    }
    to {
        opacity: 1;
        visibility: visible;
    }
}

/* Chat position styles */
.mad-search-position-bottom-right {
    bottom: var(--maddy-chat-offset-y, 20px);
    right: var(--maddy-chat-offset-x, 20px);
}

.mad-search-position-bottom-left {
    bottom: var(--maddy-chat-offset-y, 20px);
    left: var(--maddy-chat-offset-x, 20px);
}


.mad-search-position-bottom-right .mad-search-toggle {
    right: 0;
    left: auto;
}

.mad-search-position-bottom-left .mad-search-toggle {
    left: 0;
    right: auto;
}

.mad-search-position-bottom-right .mad-search-window {
    right: 0;
    left: auto;
}

.mad-search-position-bottom-left .mad-search-window {
    left: 0;
    right: auto;
}

/* Toggle button styles */
.mad-search-toggle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--maddy-primary-color) !important;
    color: white;
    border: none !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 99999;
    /* Ensure button is touchable on mobile */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    overflow: hidden;
    padding: 0 !important;
    line-height: 0;
}

.mad-search-toggle:hover {
    background-color: var(--maddy-secondary-color);
    transform: scale(1.05);
}

.mad-search-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--maddy-primary-color-light);
}

/* Shape variants */
.mad-search-shape-circle .mad-search-toggle {
    border-radius: 50% !important;
}

.mad-search-shape-square .mad-search-toggle {
    border-radius: 0 !important;
}

.mad-search-shape-circle .mad-search-toggle img.mad-search-custom-icon {
    border-radius: 50% !important;
}

.mad-search-shape-square .mad-search-toggle img.mad-search-custom-icon {
    border-radius: 0 !important;
}

/* SVG icons default size */
.mad-search-toggle-icon:not(.mad-search-custom-icon),
.mad-search-close-icon:not(.mad-search-custom-icon) {
    width: 24px;
    height: 24px;
    transition: all 0.3s ease;
}

/* Custom icon images should fill the entire button */
img.mad-search-custom-icon {
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: cover !important;
    border-radius: 50% !important;
    transition: all 0.3s ease;
}

.mad-search-close-icon,
.mad-search-custom-icon.mad-search-close-icon {
    display: none !important;
}

/* Chat window styles */
.mad-search-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    max-height: 70vh;
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    z-index: 99998;
    min-height: 360px;
  min-width: 300px;
}

/* Chat header styles */
.mad-search-header {
    background: linear-gradient(135deg, var(--maddy-primary-color) 0%, var(--maddy-secondary-color) 100%);
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.mad-search-header-title {
    font-weight: bold;
    font-size: 16px;
}

.mad-search-minimize {
    background: transparent;
    color: white;
    border: none;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.mad-search-minimize:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.mad-search-minimize:focus {
    outline: none;
}

/* Chat messages container */
.mad-search-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    scrollbar-width: thin;
    scrollbar-color: var(--maddy-secondary-color-light) transparent;
}

.mad-search-messages::-webkit-scrollbar {
    width: 6px;
}

.mad-search-messages::-webkit-scrollbar-track {
    background: transparent;
}

.mad-search-messages::-webkit-scrollbar-thumb {
    background-color: var(--maddy-secondary-color-light);
    border-radius: 6px;
}

/* Chat message styles */
.mad-search-message {
    display: flex;
    margin-bottom: 15px;
}

.mad-search-message-user {
    flex-direction: row-reverse;
}

.mad-search-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: var(--maddy-primary-color-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--maddy-primary-color);
    margin-right: 10px;
}

.mad-search-message-user .mad-search-avatar {
    margin-right: 0;
    margin-left: 10px;
    background-color: var(--maddy-secondary-color-light);
    color: var(--maddy-secondary-color);
}

.mad-search-bubble {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 18px;
    background-color: #f0f2f5;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    word-wrap: break-word;
    position: relative;
}

.mad-search-message-ai .mad-search-bubble {
    border-top-left-radius: 2px;
}

.mad-search-message-user .mad-search-bubble {
    background-color: var(--maddy-primary-color);
    color: white;
    border-top-right-radius: 2px;
}

/* Chat typing indicator */
.mad-search-typing {
    display: none;
    padding: 0 15px 10px;
}

.mad-search-typing.active {
    display: block;
}

.mad-search-typing-indicator {
    display: flex;
    align-items: center;
}

.mad-search-typing-indicator span {
    width: 8px;
    height: 8px;
    margin: 0 2px;
    background-color: #bbb;
    border-radius: 50%;
    display: inline-block;
    opacity: 0.4;
}

.mad-search-typing-indicator span:nth-child(1) {
    animation: typing 1s infinite 0s;
}

.mad-search-typing-indicator span:nth-child(2) {
    animation: typing 1s infinite 0.2s;
}

.mad-search-typing-indicator span:nth-child(3) {
    animation: typing 1s infinite 0.4s;
}

@keyframes typing {
    0% {
        transform: translateY(0);
        opacity: 0.4;
    }
    50% {
        transform: translateY(-5px);
        opacity: 0.8;
    }
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }
}

/* Chat input area */
.mad-search-input {
    padding: 10px 15px;
    border-top: 1px solid #eaeaea;
    display: flex;
    align-items: center;
}

#mad-search-input-field {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    min-height: 20px;
    height: 36px;
    max-height: 80px;
    overflow-y: auto;
    line-height: 1.4;
}

#mad-search-input-field:focus {
    outline: none;
    border-color: var(--maddy-primary-color);
    box-shadow: 0 0 0 2px var(--maddy-primary-color-light);
}

#mad-search-send {
    background-color: var(--maddy-primary-color);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    /* Mobile touch optimization */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    /* Ensure button maintains round shape */
    flex-shrink: 0;
    min-width: 36px;
    min-height: 36px;
}

#mad-search-send svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    display: block;
    pointer-events: none;
    /* Ensure SVG is centered and visible */
    flex-shrink: 0;
}

#mad-search-send:hover {
    background-color: var(--maddy-secondary-color);
    transform: scale(1.05);
}

#mad-search-send:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--maddy-primary-color-light);
}

/* Clear chat button */
#mad-search-clear {
    background-color: #dc3545;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 10px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

#mad-search-clear:hover {
    background-color: #c82333;
    transform: translateY(-1px);
}

#mad-search-clear:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.3);
}

#mad-search-clear svg {
    width: 14px;
    height: 14px;
}

/* Send button icon styling handled above */

/* Chat footer */
.mad-search-footer {
    padding: 8px;
    text-align: center;
    font-size: 12px;
    color: #999;
    border-top: 1px solid #eaeaea;
}

/* States */
.mad-search-container.open .mad-search-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.mad-search-container.open .mad-search-toggle-icon {
    display: none !important;
}

.mad-search-container.open .mad-search-close-icon {
    display: block !important;
}

/* Code block and syntax highlighting within messages */
.mad-search-bubble pre {
    background-color: #f8f8f8;
    border-radius: 4px;
    padding: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-family: monospace;
}

.mad-search-message-user .mad-search-bubble pre {
    background-color: rgba(255, 255, 255, 0.2);
}

.mad-search-bubble code {
    font-family: monospace;
    background-color: rgba(0, 0, 0, 0.05);
    padding: 2px 4px;
    border-radius: 3px;
}

.mad-search-message-user .mad-search-bubble code {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Markdown formatting within bubbles */
.mad-search-bubble p {
    margin: 0 0 10px;
}

.mad-search-bubble p:last-child {
    margin-bottom: 0;
}

.mad-search-bubble ul, 
.mad-search-bubble ol {
    margin: 8px 0;
    padding-left: 20px;
}

.mad-search-bubble a {
    color: var(--maddy-primary-color);
    text-decoration: underline;
}

.mad-search-message-user .mad-search-bubble a {
    color: white;
}

/* Feedback buttons removed from front-end - only available in admin area for training */

/* Modern improvements */
.mad-search-window {
    backdrop-filter: blur(10px);
    border: 1px solid var(--maddy-border-color);
}

.mad-search-header {
    background: linear-gradient(135deg, var(--maddy-primary-color) 0%, var(--maddy-secondary-color) 100%);
    box-shadow: var(--maddy-shadow-sm);
}

.mad-search-bubble {
    box-shadow: var(--maddy-shadow-sm);
    transition: all 0.2s ease;
}

.mad-search-bubble:hover {
    box-shadow: var(--maddy-shadow-md);
}

.mad-search-toggle {
    box-shadow: var(--maddy-shadow-lg);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mad-search-toggle:hover {
    box-shadow: var(--maddy-shadow-xl);
}

/* Public notice shown when a site has used its configured AI allowance. */
.mad-search-limit-notice {
    background: #111827;
    border-radius: 8px;
    bottom: 24px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
    color: #fff;
    font-size: 14px;
    line-height: 1.4;
    max-width: 320px;
    padding: 14px 16px;
    position: fixed;
    right: 24px;
    z-index: 99999;
}
