/**
 * Enhanced AI Search Interface Styles
 * Responsive, accessible filter UI with Pro/Enterprise tier support
 */

:root {
    --wp-ai-primary: #ffffff;
    --wp-ai-primary-hover: #f5f5f5;
    --wp-ai-border: #e0e0e0;
    --wp-ai-border-light: #f0f0f0;
    --wp-ai-bg-light: #ffffff;
    --wp-ai-bg-lighter: #fafafa;
    --wp-ai-text-primary: #1a1a1a;
    --wp-ai-text-secondary: #555;
    --wp-ai-text-muted: #888;
    --wp-ai-success: #28a745;
    --wp-ai-error: #dc3545;
    --wp-ai-info-bg: #f0f8ff;
    --wp-ai-info-border: #cce5ff;
}

/* Container */
.wp-ai-search-container {
    margin: 20px 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--wp-ai-text-primary);
}

/* ============================================
   FILTER SECTION
   ============================================ */

.wp-ai-search-filters {
    margin-bottom: 20px;
}

.filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--wp-ai-bg-light);
    border: 1px solid var(--wp-ai-border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--wp-ai-text-primary);
    transition: all 0.2s ease;
    position: relative;
}

.filter-toggle:hover {
    background: #efefef;
    border-color: #ccc;
}

.filter-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.25);
}

.filter-toggle[aria-expanded="true"] {
    background: var(--wp-ai-primary);
    color: white;
    border-color: var(--wp-ai-primary);
}

.filter-toggle svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.filter-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    background: var(--wp-ai-error);
    color: white;
    padding: 0 6px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 4px;
}

.filter-toggle[aria-expanded="true"] .filter-count {
    background: rgba(255, 255, 255, 0.3);
}

/* Filter Panel */
.filter-panel {
    background: white;
    border: 1px solid var(--wp-ai-border);
    border-radius: 6px;
    margin-top: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    animation: slideDown 0.2s ease;
    z-index: 100;
}

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

.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px;
    border-bottom: 1px solid var(--wp-ai-border-light);
}

.filter-header h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--wp-ai-text-primary);
}

.filter-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.filter-clear {
    background: none;
    border: none;
    color: #0073aa;
    cursor: pointer;
    font-size: 12px;
    text-decoration: underline;
    padding: 0;
    transition: color 0.2s ease;
}

.filter-clear:hover {
    color: #005a87;
    text-decoration: none;
}

.filter-clear:focus {
    outline: 2px solid var(--wp-ai-primary);
    outline-offset: 2px;
}

.filter-close {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--wp-ai-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 0.2s ease, background 0.2s ease;
}

.filter-close:hover {
    color: var(--wp-ai-text-primary);
    background: var(--wp-ai-border-light);
}

.filter-close:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}
    outline-offset: 2px;
}

/* Filter Content */
.filter-content {
    padding: 14px;
    max-height: 400px;
    overflow-y: auto;
}

.filter-content::-webkit-scrollbar {
    width: 8px;
}

.filter-content::-webkit-scrollbar-track {
    background: var(--wp-ai-bg-light);
}

.filter-content::-webkit-scrollbar-thumb {
    background: var(--wp-ai-border);
    border-radius: 4px;
}

.filter-content::-webkit-scrollbar-thumb:hover {
    background: var(--wp-ai-text-muted);
}

.filter-group {
    margin-bottom: 18px;
}

.filter-group:last-child {
    margin-bottom: 0;
}

.filter-group-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    cursor: default;
    color: var(--wp-ai-text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-group-label svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    opacity: 0.7;
}

.filter-limit {
    color: var(--wp-ai-text-secondary);
    font-weight: 400;
    font-size: 12px;
    margin-left: auto;
    text-transform: none;
    letter-spacing: normal;
}

.filter-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-tags {
    gap: 8px;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    cursor: pointer;
    user-select: none;
    border-radius: 4px;
    transition: background 0.15s ease;
}

.filter-checkbox:hover {
    background: var(--wp-ai-bg-light);
}

.filter-checkbox-input {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--wp-ai-primary);
    flex-shrink: 0;
}

.checkbox-label {
    font-size: 13px;
    color: var(--wp-ai-text-primary);
    flex: 1;
}

.filter-item-count {
    color: var(--wp-ai-text-muted);
    font-size: 12px;
    flex-shrink: 0;
}

.filter-more-tags {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--wp-ai-border-light);
    animation: fadeIn 0.2s ease;
}

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

.filter-show-more {
    align-self: flex-start;
    background: none;
    border: none;
    color: var(--wp-ai-primary);
    cursor: pointer;
    font-size: 12px;
    text-decoration: underline;
    padding: 4px 6px;
    margin-top: 4px;
    border-radius: 3px;
    transition: color 0.2s ease;
}

.filter-show-more:hover {
    color: var(--wp-ai-primary-hover);
    text-decoration: none;
}

.filter-show-more:focus {
    outline: 2px solid var(--wp-ai-primary);
    outline-offset: 2px;
}

.filter-footer {
    padding: 12px 14px;
    border-top: 1px solid var(--wp-ai-border-light);
    background: var(--wp-ai-bg-lighter);
    border-radius: 0 0 6px 6px;
}

.btn-apply-filters {
    width: 100%;
    padding: 10px;
    background: var(--wp-ai-primary);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.2s ease, box-shadow 0.2s ease;
}

.btn-apply-filters:hover {
    background: var(--wp-ai-primary-hover);
}

.btn-apply-filters:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.25);
}

.btn-apply-filters:active {
    transform: translateY(1px);
}

/* ============================================
   ACTIVE FILTERS PILLS
   ============================================ */

.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--wp-ai-info-bg);
    border: 1px solid var(--wp-ai-info-border);
    color: var(--wp-ai-primary);
    padding: 6px 10px;
    border-radius: 16px;
    font-size: 12px;
    animation: pillSlideIn 0.2s ease;
}

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

.filter-pill-remove {
    background: none;
    border: none;
    color: var(--wp-ai-primary);
    cursor: pointer;
    padding: 0;
    font-size: 16px;
    line-height: 1;
    transition: color 0.2s ease;
    flex-shrink: 0;
}

.filter-pill-remove:hover {
    color: var(--wp-ai-primary-hover);
}

/* ============================================
   SEARCH FORM
   ============================================ */

.wp-ai-search-form {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.search-input-wrapper {
    display: flex;
    gap: 8px;
    flex: 1;
    align-items: stretch;
}

.search-input-wrapper input {
    flex: 1;
    padding: 10px 12px;
    background: #ffffff;
    border: 1px solid var(--wp-ai-border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--wp-ai-text-primary);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    height: 44px;
    box-sizing: border-box;
}

.search-input-wrapper input::placeholder {
    color: var(--wp-ai-text-muted);
}

.search-input-wrapper input:focus {
    outline: none;
    border-color: var(--wp-ai-primary);
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.1);
}

.search-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 44px;
    padding: 0 16px;
    background: #333;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s ease, box-shadow 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
    box-sizing: border-box;
}

.search-button:hover {
    background: #555;
}

.search-button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.25);
}

.search-button:active {
    transform: translateY(1px);
}

.search-button svg {
    width: 20px;
    height: 20px;
}

.search-text {
    display: inline;
}

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

.wp-ai-search-loading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    background: var(--wp-ai-bg-light);
    border-radius: 6px;
    animation: fadeIn 0.2s ease;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--wp-ai-border);
    border-top-color: var(--wp-ai-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    flex-shrink: 0;
}

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

.loading-text {
    color: var(--wp-ai-text-secondary);
    font-size: 14px;
}

/* ============================================
   RESULTS SECTION
   ============================================ */

.wp-ai-search-results {
    background: white;
    border: 1px solid var(--wp-ai-border);
    border-radius: 6px;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--wp-ai-border-light);
}

.results-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--wp-ai-text-primary);
}

.results-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--wp-ai-text-muted);
}

.search-answer {
    line-height: 1.7;
    margin-bottom: 20px;
    color: var(--wp-ai-text-primary);
}

.search-answer p {
    margin: 0 0 10px;
}

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

.search-answer a {
    color: var(--wp-ai-primary);
    text-decoration: none;
    border-bottom: 1px solid rgba(0, 115, 170, 0.3);
    transition: border-color 0.2s ease;
}

.search-answer a:hover {
    border-bottom-color: var(--wp-ai-primary);
}

.search-sources {
    border-top: 1px solid var(--wp-ai-border-light);
    padding-top: 16px;
}

.search-sources h4 {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--wp-ai-text-secondary);
    letter-spacing: 0.5px;
}

.source-item {
    padding: 12px;
    background: var(--wp-ai-bg-lighter);
    border-left: 3px solid var(--wp-ai-primary);
    border-radius: 0 4px 4px 0;
    margin-bottom: 10px;
    transition: all 0.2s ease;
}

.source-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

.source-item:last-child {
    margin-bottom: 0;
}

.source-title {
    font-weight: 500;
    color: var(--wp-ai-primary);
    text-decoration: none;
    margin-bottom: 4px;
    display: block;
    transition: color 0.2s ease;
}

.source-title:hover {
    color: var(--wp-ai-primary-hover);
    text-decoration: underline;
}

.source-excerpt {
    font-size: 13px;
    color: var(--wp-ai-text-secondary);
    margin-bottom: 8px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.source-similarity {
    font-size: 12px;
    color: var(--wp-ai-success);
    font-weight: 500;
}

/* ============================================
   EMPTY STATE
   ============================================ */

.wp-ai-search-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--wp-ai-text-secondary);
    animation: fadeIn 0.3s ease;
}

.wp-ai-search-empty svg {
    width: 64px;
    height: 64px;
    opacity: 0.2;
    margin-bottom: 16px;
    color: var(--wp-ai-text-secondary);
}

.wp-ai-search-empty h4 {
    margin: 0 0 8px;
    font-size: 16px;
    color: var(--wp-ai-text-primary);
}

.wp-ai-search-empty p {
    margin: 0;
    font-size: 14px;
    color: var(--wp-ai-text-secondary);
}

/* ============================================
   ERROR STATE
   ============================================ */

.wp-ai-search-error {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: #fef5f5;
    border: 1px solid #fcc;
    border-radius: 6px;
    color: var(--wp-ai-error);
    animation: fadeIn 0.3s ease;
}

.wp-ai-search-error svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    margin-top: 2px;
}

.error-message {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
}

/* ============================================
   UPGRADE NOTICE
   ============================================ */

.wp-ai-search-upgrade-notice {
    padding: 16px;
    background: var(--wp-ai-info-bg);
    border: 1px solid var(--wp-ai-info-border);
    border-radius: 6px;
    margin-top: 20px;
    animation: slideDown 0.3s ease;
}

.upgrade-content {
    display: flex;
    align-items: center;
    gap: 16px;
}

.upgrade-content svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    color: var(--wp-ai-primary);
}

.upgrade-text {
    flex: 1;
}

.upgrade-text strong {
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
    color: var(--wp-ai-text-primary);
}

.upgrade-text p {
    margin: 0;
    font-size: 13px;
    color: var(--wp-ai-text-secondary);
}

.btn-upgrade {
    flex-shrink: 0;
    padding: 8px 14px;
    background: var(--wp-ai-primary);
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s ease, box-shadow 0.2s ease;
    display: inline-block;
}

.btn-upgrade:hover {
    background: var(--wp-ai-primary-hover);
}

.btn-upgrade:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.25);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
    .search-input-wrapper {
        flex-direction: column;
    }
    
    .search-button {
        width: 100%;
    }
    
    .search-text {
        display: none;
    }
    
    .search-button svg {
        width: 16px;
        height: 16px;
    }
    
    .results-header {
        flex-direction: column;
    }
    
    .results-meta {
        flex-direction: column;
        margin-top: 8px;
        gap: 4px;
    }
    
    .upgrade-content {
        flex-direction: column;
        text-align: center;
    }
    
    .upgrade-content svg {
        margin-top: 0;
    }
    
    .btn-upgrade {
        width: 100%;
        text-align: center;
    }
    
    .filter-panel {
        position: fixed;
        top: 50%;
        left: 50%;
        right: auto;
        width: 90vw;
        max-width: 500px;
        transform: translate(-50%, -50%);
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
        border-radius: 8px;
        max-height: 80vh;
        overflow-y: auto;
    }
    
    .filter-content {
        max-height: calc(80vh - 140px);
    }
}

@media (max-width: 480px) {
    .wp-ai-search-container {
        margin: 15px 0;
    }
    
    .filter-toggle {
        width: 100%;
        justify-content: center;
    }
    
    .active-filters {
        gap: 6px;
    }
    
    .filter-pill {
        font-size: 11px;
        padding: 5px 8px;
    }
    
    .wp-ai-search-results {
        padding: 15px;
    }
    
    .results-header {
        gap: 8px;
    }
    
    .results-header h3 {
        font-size: 14px;
    }
    
    .results-meta {
        font-size: 11px;
    }
    
    .search-sources h4 {
        font-size: 12px;
    }
    
    .source-item {
        padding: 10px;
    }
    
    .source-excerpt {
        font-size: 12px;
    }
    
    .upgrade-text strong {
        font-size: 13px;
    }
    
    .upgrade-text p {
        font-size: 12px;
    }
}

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

@media (prefers-color-scheme: dark) {
    :root {
        --wp-ai-text-primary: #1a1a1a;
        --wp-ai-text-secondary: #555;
        --wp-ai-text-muted: #888;
        --wp-ai-bg-light: #ffffff;
        --wp-ai-bg-lighter: #fafafa;
        --wp-ai-border: #e0e0e0;
        --wp-ai-border-light: #f0f0f0;
    }
    
    .wp-ai-search-container {
        color: var(--wp-ai-text-primary);
        background: #ffffff;
    }
    
    .filter-panel,
    .wp-ai-search-results {
        background: #ffffff;
    }
    
    .search-input-wrapper input {
        background: #ffffff;
        color: var(--wp-ai-text-primary);
        border-color: var(--wp-ai-border);
    }
    
    .filter-checkbox:hover {
        background: var(--wp-ai-bg-light);
    }
    
    .source-item {
        background: var(--wp-ai-bg-lighter);
    }
}

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

@media print {
    .filter-toggle,
    .filter-panel,
    .search-button,
    .wp-ai-search-loading {
        display: none;
    }
    
    .wp-ai-search-form input {
        border: none;
        background: transparent;
    }
    
    .wp-ai-search-results {
        border: none;
        box-shadow: none;
        padding: 0;
    }
}
