/**
 * ProteIndex Live Search - Styles Front-end
 * Mobile-first, responsive
 */

/* =============================================
   VARIABLES
   ============================================= */
:root {
    --pi-primary: #2563eb;
    --pi-primary-hover: #1d4ed8;
    --pi-secondary: #64748b;
    --pi-success: #10b981;
    --pi-warning: #f59e0b;
    --pi-danger: #ef4444;
    --pi-light: #f8fafc;
    --pi-dark: #1e293b;
    --pi-border: #e2e8f0;
    --pi-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --pi-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --pi-radius: 8px;
    --pi-radius-lg: 12px;
    --pi-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* =============================================
   BARRE DE RECHERCHE
   ============================================= */
.pi-search-wrapper {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    font-family: var(--pi-font);
}

.pi-search-form {
    width: 100%;
}

.pi-search-input-container {
    position: relative;
    display: flex;
    align-items: center;
    background: #fff;
    border: 2px solid var(--pi-border);
    border-radius: var(--pi-radius-lg);
    transition: all 0.2s ease;
    box-shadow: var(--pi-shadow);
}

.pi-search-input-container:focus-within {
    border-color: var(--pi-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.pi-search-icon {
    display: flex;
    align-items: center;
    padding-left: 16px;
    color: var(--pi-secondary);
}

.pi-search-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 14px 12px;
    font-size: 16px;
    outline: none;
    width: 100%;
}

.pi-search-input::placeholder {
    color: #94a3b8;
}

.pi-search-loader {
    padding: 0 12px;
}

.pi-spinner {
    width: 20px;
    height: 20px;
    animation: pi-spin 1s linear infinite;
    color: var(--pi-primary);
}

@keyframes pi-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.pi-search-clear {
    background: none;
    border: none;
    padding: 0 16px;
    font-size: 24px;
    color: var(--pi-secondary);
    cursor: pointer;
    line-height: 1;
}

.pi-search-clear:hover {
    color: var(--pi-dark);
}

/* Dropdown résultats rapides */
.pi-search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: #fff;
    border-radius: var(--pi-radius);
    box-shadow: var(--pi-shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
    border: 1px solid var(--pi-border);
}

/* =============================================
   PAGE DE RECHERCHE
   ============================================= */
.pi-search-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.pi-search-page .pi-search-wrapper {
    max-width: 100%;
}

.pi-search-page-bar .pi-search-input-container {
    padding: 4px;
}

.pi-search-page-bar .pi-search-input {
    font-size: 18px;
    padding: 16px 12px;
}

.pi-search-info {
    text-align: center;
    color: var(--pi-secondary);
    margin: 20px 0;
    font-size: 14px;
}

.pi-search-filters {
    margin: 20px 0;
    padding: 12px 16px;
    background: var(--pi-light);
    border-radius: var(--pi-radius);
}

.pi-search-filters label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
}

/* =============================================
   RÉSULTATS
   ============================================= */
.pi-results-section {
    margin: 30px 0;
}

.pi-results-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--pi-dark);
}

.pi-results-title .pi-count {
    font-weight: 400;
    color: var(--pi-secondary);
}

.pi-results-subtitle {
    font-size: 14px;
    color: var(--pi-secondary);
    margin-bottom: 16px;
}

.pi-results-off {
    padding-top: 20px;
    border-top: 1px solid var(--pi-border);
}

.pi-results-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

/* Responsive grid */
@media (min-width: 480px) {
    .pi-results-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .pi-results-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1024px) {
    .pi-results-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.pi-no-results {
    text-align: center;
    padding: 40px 20px;
    color: var(--pi-secondary);
}

/* =============================================
   CARTE PRODUIT
   ============================================= */
.pi-product-card {
    background: #fff;
    border-radius: var(--pi-radius-lg);
    overflow: hidden;
    box-shadow: var(--pi-shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    display: flex;
    flex-direction: column;
}

.pi-product-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--pi-shadow-lg);
}

.pi-product-local {
    border: 2px solid var(--pi-success);
}

.pi-product-off {
    border: 1px solid var(--pi-border);
    opacity: 0.9;
}

/* Badge */
.pi-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    z-index: 1;
}

.pi-badge-price {
    background: var(--pi-success);
    color: #fff;
}

/* Image */
.pi-card-image {
    height: 140px;
    background: var(--pi-light);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.pi-card-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.pi-no-image {
    font-size: 40px;
    color: #cbd5e1;
}

/* Body */
.pi-card-body {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.pi-card-title {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 4px 0;
    line-height: 1.3;
    color: var(--pi-dark);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.pi-card-brand {
    font-size: 12px;
    color: var(--pi-secondary);
    margin: 0 0 8px 0;
}

.pi-card-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: auto;
}

.pi-stat {
    font-size: 11px;
    padding: 3px 8px;
    background: var(--pi-light);
    border-radius: 4px;
    color: var(--pi-secondary);
}

.pi-stat-protein {
    background: #dcfce7;
    color: #166534;
}

.pi-stat-protein strong {
    font-size: 13px;
}

/* Prix par gramme */
.pi-card-price-per-gram {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--pi-border);
    text-align: center;
}

.pi-price-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--pi-primary);
}

.pi-price-unit {
    display: block;
    font-size: 11px;
    color: var(--pi-secondary);
}

/* Footer */
.pi-card-footer {
    padding: 12px;
    background: var(--pi-light);
    border-top: 1px solid var(--pi-border);
}

/* =============================================
   BOUTONS
   ============================================= */
.pi-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--pi-radius);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    font-family: var(--pi-font);
}

.pi-btn-sm {
    padding: 8px 14px;
    font-size: 13px;
    width: 100%;
}

.pi-btn-primary {
    background: var(--pi-primary);
    color: #fff;
}

.pi-btn-primary:hover {
    background: var(--pi-primary-hover);
}

.pi-btn-secondary {
    background: #fff;
    color: var(--pi-dark);
    border: 1px solid var(--pi-border);
}

.pi-btn-secondary:hover {
    background: var(--pi-light);
    border-color: var(--pi-secondary);
}

/* =============================================
   MODAL
   ============================================= */
.pi-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pi-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.pi-modal-content {
    position: relative;
    background: #fff;
    border-radius: var(--pi-radius-lg);
    padding: 24px;
    max-width: 450px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--pi-shadow-lg);
}

.pi-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--pi-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}

.pi-modal-close:hover {
    color: var(--pi-dark);
}

.pi-modal-content h3 {
    margin: 0 0 16px 0;
    font-size: 20px;
    color: var(--pi-dark);
}

/* Preview produit dans modal */
.pi-suggest-product-preview {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--pi-light);
    border-radius: var(--pi-radius);
    margin-bottom: 20px;
}

.pi-suggest-product-preview img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    border-radius: 4px;
    background: #fff;
}

.pi-suggest-product-preview .pi-preview-info {
    flex: 1;
}

.pi-suggest-product-preview .pi-preview-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.pi-suggest-product-preview .pi-preview-brand {
    font-size: 12px;
    color: var(--pi-secondary);
}

.pi-suggest-product-preview .pi-preview-stats {
    font-size: 12px;
    color: var(--pi-secondary);
    margin-top: 4px;
}

/* Formulaire */
.pi-form-group {
    margin-bottom: 16px;
}

.pi-form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--pi-dark);
}

.pi-form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--pi-border);
    border-radius: var(--pi-radius);
    font-size: 14px;
    transition: border-color 0.2s;
}

.pi-form-group input:focus {
    outline: none;
    border-color: var(--pi-primary);
}

.pi-input-addon {
    display: flex;
    align-items: stretch;
}

.pi-input-addon input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.pi-input-addon span {
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: var(--pi-light);
    border: 1px solid var(--pi-border);
    border-left: none;
    border-radius: 0 var(--pi-radius) var(--pi-radius) 0;
    font-size: 14px;
    color: var(--pi-secondary);
}

.pi-form-actions {
    margin-top: 20px;
}

.pi-form-actions .pi-btn {
    width: 100%;
}

/* Success state */
.pi-suggest-success {
    text-align: center;
    padding: 20px 0;
}

.pi-success-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 16px;
    background: var(--pi-success);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.pi-text-muted {
    color: var(--pi-secondary);
    font-size: 14px;
}

/* =============================================
   LOAD MORE
   ============================================= */
.pi-search-load-more {
    text-align: center;
    padding: 20px;
}

/* =============================================
   RESPONSIVE MOBILE
   ============================================= */
@media (max-width: 480px) {
    .pi-search-page {
        padding: 12px;
    }
    
    .pi-search-input {
        font-size: 16px; /* Évite le zoom iOS */
    }
    
    .pi-modal-content {
        padding: 16px;
        margin: 10px;
    }
    
    .pi-card-image {
        height: 120px;
    }
    
    .pi-price-value {
        font-size: 20px;
    }
}

/* =============================================
   DARK MODE SUPPORT
   ============================================= */
@media (prefers-color-scheme: dark) {
    .pi-search-wrapper,
    .pi-search-page {
        /* On garde le light mode pour la cohérence avec le thème WP */
    }
}

/* =============================================
   ANIMATIONS
   ============================================= */
.pi-product-card {
    animation: pi-fade-in 0.3s ease;
}

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

.pi-modal-content {
    animation: pi-modal-in 0.2s ease;
}

@keyframes pi-modal-in {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}
