/* =========================================================
   Product Search — searchbar, autocomplete e pagina risultati
   Coerente col tema (#214ecd) e con gli angoli quadrati del sito.
   ========================================================= */

/* ---- Header pagina: titolo a sinistra, searchbar a destra ---- */
.ps-page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
    margin: 8px 0 28px;
}
.ps-page-head-text { min-width: 0; }
.ps-results-summary {
    margin: 6px 0 0;
    color: var(--muted, #666);
    font-size: 15px;
}

/* ---- Searchbar ---- */
.ps-searchbar,
.ps-search {
    position: relative;
}
.ps-search {
    display: flex;
    align-items: stretch;
    width: min(380px, 100%);
    border: 1px solid var(--input-border, #ddd);
    background: #fff;
    transition: border-color .2s ease, box-shadow .2s ease;
}
.ps-search:focus-within {
    border-color: var(--primary-color, #214ecd);
    box-shadow: 0 0 0 1px var(--primary-color, #214ecd);
}
.ps-search-input {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    outline: 0;
    padding: 0 14px;
    height: 44px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text-primary, #333);
    background: transparent;
}
.ps-search-btn {
    flex: 0 0 auto;
    width: 46px;
    border: 0;
    background: var(--primary-color, #214ecd);
    color: #fff;
    cursor: pointer;
    font-size: 15px;
    transition: background .2s ease;
}
.ps-search-btn:hover { background: #1a3fa8; }

/* On the products listing pages: align the bar to the right */
.ps-searchbar-right {
    display: flex;
    justify-content: flex-end;
    margin: 0 0 18px;
}

/* ---- Autocomplete dropdown ---- */
.ps-suggest {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 60;
    background: #fff;
    border: 1px solid var(--input-border, #ddd);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
    max-height: 60vh;
    overflow-y: auto;
}
.ps-suggest[hidden] { display: none; }
.ps-suggest-group {
    padding: 8px 14px 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted, #666);
}
.ps-suggest-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary, #333);
    font-family: inherit;
}
.ps-suggest-item:hover,
.ps-suggest-item.is-active { background: #eef2fd; }
.ps-suggest-ico { color: var(--primary-color, #214ecd); font-size: 13px; width: 16px; text-align: center; }
.ps-suggest-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-suggest-meta {
    flex: 0 0 auto;
    color: var(--muted, #666);
    font-size: 12px;
    max-width: 45%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ps-suggest-hint {
    flex: 0 0 auto;
    font-size: 11px;
    color: #fff;
    background: #aab2c5;
    padding: 1px 6px;
    text-transform: lowercase;
    letter-spacing: .02em;
}
.ps-suggest-empty {
    padding: 12px 14px;
    color: var(--muted, #666);
    font-size: 14px;
}
.ps-suggest-all {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 0;
    border-top: 1px solid #eee;
    background: #fafbff;
    text-align: left;
    padding: 11px 14px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-color, #214ecd);
    font-family: inherit;
}
.ps-suggest-all:hover,
.ps-suggest-all.is-active { background: #eef2fd; }

/* ---- Lista risultati ---- */
.ps-results-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 8px;
}
.ps-result-card {
    display: flex;
    align-items: stretch;
    gap: 18px;
    padding: 16px;
    background: var(--card-bg, #fff);
    border: 1px solid #ececec;
    box-shadow: var(--card-shadow, 0 4px 6px rgba(0, 0, 0, .05));
    text-decoration: none;
    color: inherit;
    transition: box-shadow .2s ease, border-color .2s ease;
}
.ps-result-card:hover {
    border-color: var(--card-border, #214ecd);
    box-shadow: var(--card-shadow, 0 4px 6px rgba(0, 0, 0, .05)), 0 0 0 1px var(--card-border, #214ecd);
}
.ps-result-media {
    flex: 0 0 110px;
    width: 110px;
    height: 110px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f6f7f9;
    overflow: hidden;
}
.ps-result-media img { max-width: 100%; max-height: 100%; object-fit: contain; }
.ps-result-media .ps-noimg { color: #ccc; font-size: 28px; }
.ps-result-body { flex: 1 1 auto; min-width: 0; }
.ps-result-title {
    margin: 2px 0 10px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary, #222);
}
.ps-result-chevron {
    align-self: center;
    color: #c4c8d4;
    font-size: 14px;
    flex: 0 0 auto;
}

/* ---- Righe match (dove è stata trovata la parola) ---- */
.ps-result-matches { display: flex; flex-direction: column; gap: 6px; }
.ps-match {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 14px;
    line-height: 1.45;
}
.ps-match-badge {
    flex: 0 0 auto;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: 2px 7px;
    color: #fff;
    white-space: nowrap;
}
.ps-match-snippet { color: var(--text-secondary, #555); min-width: 0; }

/* Colore badge per tipo di campo */
.ps-badge-nome { background: #214ecd; }
.ps-badge-codice { background: #0e9f6e; }
.ps-badge-tag { background: #7c3aed; }
.ps-badge-sezione { background: #e8730c; }
.ps-badge-categoria { background: #2563a8; }
.ps-badge-descrizione { background: #6b7280; }

/* Evidenziazione del termine */
.ps-result-title mark,
.ps-match-snippet mark,
.ps-suggest-label mark {
    background: #fff3b0;
    color: inherit;
    padding: 0 1px;
    border-radius: 0;
    font-weight: 700;
}

/* ---- Stato vuoto ---- */
.ps-empty {
    padding: 40px 0;
    text-align: center;
    color: var(--muted, #666);
    font-size: 16px;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
    .ps-page-head { flex-direction: column; align-items: stretch; }
    .ps-search { width: 100%; }
    .ps-result-card { gap: 12px; padding: 12px; }
    .ps-result-media { flex-basis: 84px; width: 84px; height: 84px; }
    .ps-result-title { font-size: 16px; }
    .ps-result-chevron { display: none; }
}
