/**
 * MantiLoad AJAX Search Styles
 * Beautiful, fast, and accessible search interface
 *
 * @package MantiLoad
 * @version 1.0.0
 */

/* ========================================
   Theme Compatibility & Font Inheritance
   ======================================== */

/* Inherit font from WoodMart or any active theme */
.mantiload-modal,
.mantiload-modal *,
.mantiload-search-box-inline,
.mantiload-search-box-inline * {
    font-family: inherit !important;
    box-sizing: border-box !important;
}

/* Reset WoodMart/theme input overrides */
.mantiload-search-input,
.mantiload-inline-search-input {
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    margin: 0 !important;
    line-height: normal !important;
}

/* Protect input focus styles from theme overrides */
.mantiload-search-input:focus,
.mantiload-inline-search-input:focus {
    outline: none !important;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1) !important;
}

.mantiload-inline-input-group:focus-within {
    border-color: #e5e7eb !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05) !important;
}

/* Protect button styles */
.mantiload-modal-close,
.mantiload-search-clear,
.mantiload-inline-clear,
.mantiload-inline-submit-btn {
    all: unset;
    box-sizing: border-box !important;
    font-family: inherit !important;
    cursor: pointer !important;
    display: flex !important;
}

/* Restore MantiLoad button styles */
.mantiload-modal-close {
    position: absolute !important;
    top: 16px !important;
    right: 16px !important;
    width: 32px !important;
    height: 32px !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 6px !important;
    color: #6b7280 !important;
    transition: all 0.2s ease !important;
}

.mantiload-inline-submit-btn {
    padding: 10px 24px !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    border-radius: 50px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    color: #fff !important;
    white-space: nowrap !important;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3) !important;
}

/* ========================================
   Search Modal
   ======================================== */

.mantiload-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999999;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 80px 20px 20px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.mantiload-modal.is-active {
    display: flex;
    opacity: 1;
}

.mantiload-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    cursor: pointer;
    animation: fadeIn 0.2s ease;
}

.mantiload-modal-content {
    position: relative;
    width: 100%;
    max-width: 680px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 160px);
    animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Modal Header */
.mantiload-modal-header {
    position: relative;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
}

.mantiload-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mantiload-modal-close:hover {
    background: #f3f4f6;
    color: #111827;
}

/* Search Form */
.mantiload-search-form-wrapper {
    padding: 24px 24px 16px;
    border-bottom: 1px solid #e5e7eb;
}

.mantiload-search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.mantiload-search-icon {
    position: absolute;
    left: 16px;
    color: #9ca3af;
    pointer-events: none;
    z-index: 1;
}

.mantiload-search-input {
    width: 100%;
    padding: 14px 48px 14px 48px;
    font-size: 16px;
    line-height: 1.5;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
    transition: all 0.2s ease;
    outline: none;
}

.mantiload-search-input:focus {
    background: #fff;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.mantiload-search-clear {
    position: absolute;
    right: 12px;
    width: 28px;
    height: 28px;
    display: none;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: #9ca3af;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mantiload-search-clear:hover {
    background: #f3f4f6;
    color: #111827;
}

.mantiload-search-input:not(:placeholder-shown) ~ .mantiload-search-clear {
    display: flex;
}

.mantiload-search-loader {
    position: absolute;
    right: 12px;
    display: none;
}

.mantiload-search-loader.is-loading {
    display: block;
}

.mantiload-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Search Stats */
.mantiload-search-stats {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 8px;
    font-size: 13px;
    color: #6b7280;
}

.mantiload-results-count {
    font-weight: 500;
}

.mantiload-query-time {
    opacity: 0.8;
}

/* Search Results */
.mantiload-search-results {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.mantiload-search-results::-webkit-scrollbar {
    width: 8px;
}

.mantiload-search-results::-webkit-scrollbar-track {
    background: transparent;
}

.mantiload-search-results::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

.mantiload-search-results::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Result Item */
.mantiload-result-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: all 0.15s ease;
    cursor: pointer;
}

.mantiload-result-item:hover,
.mantiload-result-item.is-selected {
    background: #f3f4f6;
    transform: translateX(4px);
}

.mantiload-result-item.is-selected {
    outline: 2px solid #667eea;
    outline-offset: -2px;
}

.mantiload-result-thumbnail {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    border-radius: 6px;
    object-fit: cover;
    background: #f3f4f6;
}

.mantiload-result-content {
    flex: 1;
    min-width: 0;
}

.mantiload-result-title {
    font-size: 14px;
    font-weight: 500;
    color: #111827;
    margin: 0 0 4px;
    line-height: 1.4;
}

.mantiload-result-title mark {
    background: rgba(102, 126, 234, 0.15);
    color: #667eea;
    font-weight: 600;
    padding: 2px 0;
    border-radius: 2px;
}

.mantiload-result-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: #6b7280;
}

.mantiload-result-price {
    font-weight: 600;
    color: #059669;
}

.mantiload-result-sku {
    opacity: 0.8;
}

.mantiload-result-stock {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: #dcfce7;
    color: #166534;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.mantiload-result-stock.out-of-stock {
    background: #fee2e2;
    color: #991b1b;
}

/* Empty State */
.mantiload-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: #6b7280;
}

.mantiload-empty-icon {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.mantiload-empty-title {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    margin: 0 0 8px;
}

.mantiload-empty-description {
    font-size: 14px;
    margin: 0;
}

/* View All Button */
.mantiload-view-all {
    display: block;
    width: 100%;
    padding: 14px 20px;
    margin-top: 8px;
    background: #f3f4f6;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #667eea;
    text-align: center;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

.mantiload-view-all:hover {
    background: #e5e7eb;
    transform: translateY(-1px);
}

/* Modal Footer */
.mantiload-search-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
}

.mantiload-keyboard-shortcuts {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 12px;
    color: #6b7280;
}

.mantiload-keyboard-shortcuts kbd {
    display: inline-block;
    padding: 3px 8px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 11px;
    font-family: monospace;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.mantiload-powered-by {
    font-size: 12px;
    color: #9ca3af;
}

.mantiload-powered-by strong {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
}

/* Search Trigger Button */
.mantiload-search-trigger {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 999;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

.mantiload-search-trigger:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    border-color: #667eea;
    color: #667eea;
}

.mantiload-shortcut-hint {
    margin-left: 8px;
    padding: 3px 8px;
    background: #f3f4f6;
    border-radius: 4px;
    font-size: 11px;
    font-family: monospace;
}

/* Screen Reader Only */
.mantiload-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* RTL Support */
[dir="rtl"] .mantiload-search-icon {
    left: auto;
    right: 16px;
}

[dir="rtl"] .mantiload-search-input {
    padding: 14px 48px 14px 48px;
}

[dir="rtl"] .mantiload-search-clear {
    right: auto;
    left: 12px;
}

[dir="rtl"] .mantiload-modal-close {
    right: auto;
    left: 16px;
}

[dir="rtl"] .mantiload-result-item:hover,
[dir="rtl"] .mantiload-result-item.is-selected {
    transform: translateX(-4px);
}

/* Responsive */
@media (max-width: 640px) {
    .mantiload-modal {
        padding: 20px;
    }

    .mantiload-modal-content {
        max-height: calc(100vh - 40px);
    }

    .mantiload-search-form-wrapper {
        padding: 16px;
    }

    .mantiload-result-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .mantiload-result-thumbnail {
        width: 100%;
        height: 160px;
    }

    .mantiload-keyboard-shortcuts {
        display: none;
    }

    .mantiload-search-trigger {
        bottom: 20px;
        top: auto;
        right: 20px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .mantiload-modal-content {
        background: #1f2937;
        color: #f9fafb;
    }

    .mantiload-modal-header {
        border-bottom-color: #374151;
    }

    .mantiload-search-form-wrapper {
        border-bottom-color: #374151;
    }

    .mantiload-search-input {
        background: #111827;
        border-color: #374151;
        color: #f9fafb;
    }

    .mantiload-search-input:focus {
        background: #1f2937;
        border-color: #667eea;
    }

    .mantiload-result-item:hover,
    .mantiload-result-item.is-selected {
        background: #374151;
    }

    .mantiload-result-title {
        color: #f9fafb;
    }

    .mantiload-search-footer {
        background: #111827;
        border-top-color: #374151;
    }

    .mantiload-keyboard-shortcuts kbd {
        background: #374151;
        border-color: #4b5563;
    }

    .mantiload-search-trigger {
        background: #1f2937;
        border-color: #374151;
        color: #f9fafb;
    }
}

/* ========================================
   Inline Search Box (Shortcode/Widget)
   ======================================== */

.mantiload-search-box-inline {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.mantiload-inline-form {
    position: relative;
    width: 100%;
}

.mantiload-inline-input-group {
    position: relative;
    display: flex;
    align-items: center;
    background: #fff;
    border: 2px solid #e5e7eb;
    border-radius: 50px;
    padding: 4px 4px 4px 20px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    outline: none !important;
}

.mantiload-inline-input-group:focus-within {
    border-color: #e5e7eb;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    outline: none !important;
}

.mantiload-inline-search-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    color: #9ca3af;
    margin-right: 12px;
}

.mantiload-inline-search-input {
    flex: 1;
    min-width: 0;
    padding: 12px 8px;
    border: none;
    background: transparent !important;
    font-size: 15px;
    line-height: 1.5;
    color: #111827;
    outline: none;
    box-shadow: none !important;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.mantiload-inline-search-input:focus {
    background: transparent !important;
    box-shadow: none !important;
}

/* Remove browser autofill background */
.mantiload-inline-search-input:-webkit-autofill,
.mantiload-inline-search-input:-webkit-autofill:hover,
.mantiload-inline-search-input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px #fff inset !important;
    box-shadow: 0 0 0 1000px #fff inset !important;
    -webkit-text-fill-color: #111827 !important;
}

.mantiload-inline-search-input::placeholder {
    color: #9ca3af;
}

.mantiload-inline-clear {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: #9ca3af;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    margin: 0 4px;
    opacity: 0;
    pointer-events: none;
}

.mantiload-inline-clear.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.mantiload-inline-clear:hover {
    background: #f3f4f6;
    color: #111827;
}

.mantiload-inline-submit-btn {
    flex-shrink: 0;
    padding: 10px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.mantiload-inline-submit-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.mantiload-inline-loader {
    flex-shrink: 0;
    display: none;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
}

.mantiload-inline-loader.is-loading {
    display: flex;
}

.mantiload-inline-spinner {
    animation: spin 0.8s linear infinite;
}

.mantiload-inline-spinner circle {
    stroke: #667eea;
    animation: dash 1.5s ease-in-out infinite;
}

@keyframes dash {
    0% {
        stroke-dashoffset: 0;
    }
    50% {
        stroke-dashoffset: -25;
    }
    100% {
        stroke-dashoffset: -50;
    }
}

/* Results Dropdown */
.mantiload-inline-results-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    max-height: 500px;
    overflow: hidden;
    z-index: 1000;
    animation: fadeInDown 0.2s ease;
}

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

.mantiload-inline-results-container {
    max-height: 500px;
    overflow-y: auto;
    padding: 8px;
}

.mantiload-inline-results-container::-webkit-scrollbar {
    width: 6px;
}

.mantiload-inline-results-container::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

/* Result Item - Inline */
.mantiload-inline-result-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
    cursor: pointer;
}

.mantiload-inline-result-item:hover,
.mantiload-inline-result-item.is-selected {
    background: #f9fafb;
    transform: translateX(4px);
}

.mantiload-inline-result-thumb {
    flex-shrink: 0;
    width: 70px;
    height: 70px;
    border-radius: 8px;
    object-fit: cover;
    background: #f3f4f6;
}

.mantiload-inline-result-content {
    flex: 1;
    min-width: 0;
}

.mantiload-inline-result-title {
    font-size: 15px;
    font-weight: 500;
    color: #111827;
    margin: 0 0 6px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.mantiload-inline-result-title mark {
    background: rgba(102, 126, 234, 0.15);
    color: #667eea;
    font-weight: 600;
    padding: 1px 2px;
    border-radius: 2px;
}

.mantiload-inline-result-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}

.mantiload-inline-result-price {
    font-weight: 600;
    color: #059669;
}

.mantiload-inline-result-sku {
    color: #6b7280;
    font-size: 12px;
}

.mantiload-inline-result-stock {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: #dcfce7;
    color: #166534;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.mantiload-inline-result-stock.out-of-stock {
    background: #fee2e2;
    color: #991b1b;
}

/* Empty State - Inline */
.mantiload-inline-empty {
    padding: 40px 20px;
    text-align: center;
    color: #6b7280;
}

.mantiload-inline-empty-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    opacity: 0.4;
}

.mantiload-inline-empty-text {
    font-size: 14px;
    margin: 0;
}

/* Searching State - Inline */
.mantiload-inline-searching {
    padding: 40px 20px;
    text-align: center;
    color: #667eea;
}

.mantiload-inline-searching-spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 16px;
    border: 3px solid #e5e7eb;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: mantiload-spin 0.8s linear infinite;
}

@keyframes mantiload-spin {
    to {
        transform: rotate(360deg);
    }
}

.mantiload-inline-searching-text {
    font-size: 14px;
    margin: 0;
    font-weight: 500;
}

/* Stats - Inline */
.mantiload-inline-stats {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    font-size: 12px;
    color: #6b7280;
}

.mantiload-inline-count {
    font-weight: 500;
}

.mantiload-inline-time {
    opacity: 0.8;
}

/* View All Link - Inline */
.mantiload-inline-view-all {
    display: block;
    padding: 14px 20px;
    text-align: center;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    font-size: 14px;
    font-weight: 600;
    color: #667eea;
    text-decoration: none;
    transition: all 0.2s ease;
}

.mantiload-inline-view-all:hover {
    background: #f3f4f6;
    color: #5568d3;
}

/* RTL Support - Inline */
[dir="rtl"] .mantiload-inline-search-icon {
    margin-right: 0;
    margin-left: 12px;
}

[dir="rtl"] .mantiload-inline-result-item:hover,
[dir="rtl"] .mantiload-inline-result-item.is-selected {
    transform: translateX(-4px);
}

/* Responsive - Inline */
@media (max-width: 640px) {
    .mantiload-inline-input-group {
        padding: 3px 3px 3px 16px;
    }

    .mantiload-inline-search-input {
        font-size: 14px;
        padding: 10px 6px;
    }

    .mantiload-inline-submit-btn {
        padding: 8px 18px;
        font-size: 13px;
    }

    .mantiload-inline-result-thumb {
        width: 60px;
        height: 60px;
    }

    .mantiload-inline-result-title {
        font-size: 14px;
    }
}

/* Dark Mode Support - Inline */
@media (prefers-color-scheme: dark) {
    .mantiload-inline-input-group {
        background: #1f2937;
        border-color: #374151;
    }

    .mantiload-inline-input-group:focus-within {
        border-color: #374151;
    }

    .mantiload-inline-search-input {
        color: #f9fafb;
    }

    .mantiload-inline-results-dropdown {
        background: #1f2937;
    }

    .mantiload-inline-result-item:hover,
    .mantiload-inline-result-item.is-selected {
        background: #374151;
    }

    .mantiload-inline-result-title {
        color: #f9fafb;
    }

    .mantiload-inline-stats {
        background: #111827;
        border-bottom-color: #374151;
    }

    .mantiload-inline-view-all {
        background: #111827;
        border-top-color: #374151;
    }
}
