/* BACKdigit — elementi BD (ex BD Header Elements): pulsante modalità scura, Content Block, ricerca live. */

/* ====== PULSANTE DARK MODE ====== */
.bdhe-dark-toggle.bdhe-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bdhe-color-btn-bg, transparent);
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--bdhe-color-icon, inherit);
    line-height: 1;
    transition: opacity 0.2s ease;
}
.bdhe-dark-toggle.bdhe-button:hover { opacity: 0.75; }
.bdhe-dark-toggle.bdhe-button:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
    border-radius: 3px;
}
.bdhe-toggle-icon { display: inline-block; line-height: 1; }

/* ====== INTERRUTTORE ON/OFF ====== */
.bdhe-switch-wrap {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.bdhe-switch-label {
    font-size: 0.85em;
    color: var(--bdhe-color-label, inherit);
    opacity: 0.7;
    transition: opacity 0.25s;
    user-select: none;
}

.bdhe-switch-label-light { opacity: 1; }
.bdhe-switch-label-dark  { opacity: 0.5; }

.custom-dark .bdhe-switch-label-light { opacity: 0.5; }
.custom-dark .bdhe-switch-label-dark  { opacity: 1; }

/* Il pulsante switch */
.bdhe-dark-toggle.bdhe-switch {
    position: relative;
    display: inline-block;
    width: var(--bdhe-sw-w, 40px);
    height: var(--bdhe-sw-h, 22px);
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
}
.bdhe-dark-toggle.bdhe-switch:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
    border-radius: 999px;
}

/* Traccia */
.bdhe-switch-track {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--bdhe-color-track-off, rgba(128,128,128,0.6));
    border: 1px solid rgba(0,0,0,0.2);
    border-radius: 999px;
    transition: background 0.25s ease;
    position: relative;
}

.custom-dark .bdhe-switch-track,
.bdhe-dark-toggle.bdhe-switch[aria-checked="true"] .bdhe-switch-track {
    background: var(--bdhe-color-track-on, var(--theme-palette-color-1, #2872fa));
    border-color: transparent;
}

/* Knob */
.bdhe-switch-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: var(--bdhe-sw-k, 18px);
    height: var(--bdhe-sw-k, 18px);
    background: var(--bdhe-color-knob, #fff);
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
    transition: transform 0.25s ease;
}

.custom-dark .bdhe-switch-knob,
.bdhe-dark-toggle.bdhe-switch[aria-checked="true"] .bdhe-switch-knob {
    transform: translateX(calc(var(--bdhe-sw-w, 40px) - var(--bdhe-sw-k, 18px) - 4px));
}

/* Knob con icone ☾ / ☼ */
.bdhe-switch-knob.bdhe-knob-icons {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--bdhe-sw-icon-size, calc(var(--bdhe-sw-k, 18px) * 0.6));
    line-height: 1;
    user-select: none;
    color: var(--bdhe-color-knob-icon-light, #888);
    transition: transform 0.25s ease, color 0.25s ease;
}
/* Icona chiara visibile di default */
.bdhe-switch-knob.bdhe-knob-icons::before {
    content: var(--bdhe-sw-icon-light, '☾');
    display: block;
}
/* Icona scura quando attivo */
.custom-dark .bdhe-switch-knob.bdhe-knob-icons::before,
.bdhe-dark-toggle.bdhe-switch[aria-checked="true"] .bdhe-switch-knob.bdhe-knob-icons::before {
    content: var(--bdhe-sw-icon-dark, '☼');
    color: var(--bdhe-color-knob-icon-dark, #f5c542);
}

/* ====== CONTENT BLOCK (e Blocchi HTML BD rimasti) ====== */
.bdhe-content-block,
.bdhe-html-block { display: flex; align-items: center; }
.bdhe-content-block > *,
.bdhe-html-block > * { margin: 0; }
.bdhe-content-block p:last-child { margin-bottom: 0; }

/* Contenitori degli elementi: flex come gli altri elementi dell'header. */
[data-id="dark-mode-toggle"],
[data-id="bd-search"] {
    display: flex !important;
    align-items: center;
}

/* ====== BD SEARCH ====== */

/* Bottone icona nell'header */
.bdhe-search-wrap {
    display: inline-flex;
    align-items: center;
}

.bdhe-search-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--bdhe-search-icon-color, inherit);
    line-height: 1;
    transition: color 0.2s ease, opacity 0.2s ease;
}
.bdhe-search-btn:hover {
    color: var(--bdhe-search-icon-hover-color, var(--bdhe-search-icon-color, inherit));
    opacity: 0.75;
}
.bdhe-search-btn:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
    border-radius: 3px;
}
.bdhe-search-btn svg {
    display: block;
    width: 1em;
    height: 1em;
    flex-shrink: 0;
}

/* Bottone con etichetta */
.bdhe-search-btn--with-label {
    gap: 6px;
}
.bdhe-search-btn-label {
    font-size: inherit;
    color: var(--bdhe-search-btn-label-color, var(--bdhe-search-icon-color, currentColor));
    line-height: 1;
    white-space: nowrap;
    transition: color 0.2s ease;
}
.bdhe-search-btn:hover .bdhe-search-btn-label {
    color: var(--bdhe-search-icon-hover-color, var(--bdhe-search-btn-label-color, currentColor));
}

/* ── Overlay fullscreen ────────────────────────────────────── */
#bdhe-search-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: var(--bdhe-search-overlay-bg, rgba(10, 10, 15, 0.92));
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    align-items: flex-start;
    justify-content: center;
    padding: 0;
    overflow-y: auto;
}
#bdhe-search-overlay.bdhe-search-open {
    display: flex;
    animation: bdheOverlayIn 0.22s ease both;
}

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

/* Blocca scroll body quando overlay aperto */
body.bdhe-search-body-open {
    overflow: hidden;
}

.bdhe-search-overlay-inner {
    width: 100%;
    max-width: 780px;
    margin: 0 auto;
    padding: 60px 24px 40px;
    position: relative;
    color: #fff;
}

/* Bottone chiudi (X) */
.bdhe-search-close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,0.7);
    padding: 6px;
    line-height: 1;
    transition: color 0.2s;
    border-radius: 50%;
}
.bdhe-search-close:hover { color: #fff; }
.bdhe-search-close:focus-visible {
    outline: 2px solid rgba(255,255,255,0.5);
    outline-offset: 2px;
}

/* Campo ricerca */
.bdhe-search-field-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 2px solid var(--bdhe-search-border-color, rgba(255,255,255,0.25));
    padding-bottom: 12px;
    margin-bottom: 28px;
    transition: border-color 0.2s;
}
.bdhe-search-field-wrap:focus-within {
    border-color: var(--bdhe-search-border-color, rgba(255,255,255,0.7));
    filter: brightness(1.3);
}

.bdhe-search-field-icon {
    flex-shrink: 0;
    opacity: 0.6;
    width: 28px;
    height: 28px;
}

/* Alta specificità per battere Blocksy (che usa selettore lungo su input[type=search]) */
#bdhe-search-overlay .bdhe-search-input {
    flex: 1;
    background: transparent !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    /* font-size e color vengono iniettati dal JS come <style> scoped con !important */
    font-size: var(--bdhe-search-field-fs, 2rem) !important;
    color: var(--bdhe-search-text-color, #fff) !important;
    font-weight: 400 !important;
    line-height: 1.2 !important;
    height: auto !important;
    padding: 0 !important;
    width: 100% !important;
    caret-color: var(--bdhe-search-text-color, #fff) !important;
    border-radius: 0 !important;
}
#bdhe-search-overlay .bdhe-search-input::placeholder {
    color: var(--bdhe-search-placeholder-color, rgba(255,255,255,0.35)) !important;
    opacity: 1 !important;
}
/* Rimuove la X nativa del browser */
#bdhe-search-overlay .bdhe-search-input::-webkit-search-cancel-button { display: none; }
#bdhe-search-overlay .bdhe-search-input::-webkit-search-decoration { display: none; }

/* ── Risultati live ────────────────────────────────────────── */
.bdhe-search-results { margin-bottom: 16px; }

.bdhe-search-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.bdhe-search-item-link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--bdhe-search-result-title-color, #fff) !important;
    transition: background 0.15s, color 0.15s;
}
.bdhe-search-item-link:hover {
    background: var(--bdhe-search-result-hover-bg, rgba(255,255,255,0.1)) !important;
    color: var(--bdhe-search-result-hover-color, #fff) !important;
}

/* Thumbnail */
.bdhe-search-thumb {
    flex-shrink: 0;
    width: 56px;
    height: 56px;
    border-radius: 6px;
    overflow: hidden;
    background: rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: center;
}
.bdhe-search-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.bdhe-search-no-thumb {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.35;
}
.bdhe-search-no-thumb svg { width: 28px; height: 28px; }

/* Testo risultato */
.bdhe-search-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.bdhe-search-title {
    font-size: 1rem; /* override da JS scoped style */
    font-weight: 500;
    line-height: 1.3;
    color: var(--bdhe-search-result-title-color, #fff) !important;
    /* Nessun troncamento CSS fisso: il numero di parole è già gestito lato JS
       tramite l'opzione "Numero parole titolo risultato". Se il titolo resta
       lungo va a capo su più righe invece di tagliarsi con ... */
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    word-break: break-word;
}
.bdhe-search-type {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.5;
    color: var(--bdhe-search-result-type-color, inherit) !important;
    opacity: 1 !important;
}

/* Messaggi */
.bdhe-search-noresults,
.bdhe-search-error {
    color: rgba(255,255,255,0.55);
    font-size: 0.95rem;
    padding: 8px 12px;
    margin: 0;
}

/* Link "Visualizza tutti" */
.bdhe-search-viewall {
    border-top: 1px solid rgba(255,255,255,0.12);
    padding-top: 16px;
    text-align: center;
}
.bdhe-search-viewall-link {
    display: inline-block;
    color: var(--bdhe-search-viewall-color, rgba(255,255,255,0.75)) !important;
    font-size: 0.9rem;
    text-decoration: none;
    padding: 8px 20px;
    border: 1px solid var(--bdhe-search-viewall-color, rgba(255,255,255,0.25));
    border-radius: 999px;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.bdhe-search-viewall-link:hover {
    background: rgba(255,255,255,0.12);
    color: var(--bdhe-search-viewall-hover-color, #fff) !important;
    border-color: var(--bdhe-search-viewall-hover-color, rgba(255,255,255,0.5));
}

/* Loading dots */
.bdhe-search-loading {
    display: flex;
    gap: 8px;
    justify-content: center;
    padding: 20px 0;
}
.bdhe-search-loading span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.5);
    animation: bdheLoadingDot 1.2s infinite ease-in-out both;
}
.bdhe-search-loading span:nth-child(1) { animation-delay: 0s; }
.bdhe-search-loading span:nth-child(2) { animation-delay: 0.2s; }
.bdhe-search-loading span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bdheLoadingDot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
    40%           { transform: scale(1);   opacity: 1; }
}

/* Responsive */
@media (max-width: 600px) {
    .bdhe-search-overlay-inner {
        padding: 50px 16px 30px;
    }
    .bdhe-search-thumb {
        width: 44px;
        height: 44px;
    }
}

/* ── Overlay: evidenziazione keyword ── */
#bdhe-search-overlay .bdhe-search-highlight,
.bdhe-search-highlight {
    background: transparent;
    color: inherit;
    font-weight: 700;
    font-style: normal;
    text-decoration: underline;
    text-decoration-color: var(--bdhe-search-result-title-color, rgba(255,255,255,0.7));
    text-underline-offset: 2px;
}

/* ── Overlay: storico ricerche ── */
.bdhe-search-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 12px 8px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255,255,255,0.4);
}
.bdhe-search-history-clear {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
    padding: 2px 6px;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}
.bdhe-search-history-clear:hover {
    color: rgba(255,100,100,0.9);
    background: rgba(255,255,255,0.07);
}
.bdhe-search-history-item {
    display: flex;
    align-items: center;
}
.bdhe-search-history-item .bdhe-search-item-link { flex: 1; }
.bdhe-search-history-icon {
    background: rgba(255,255,255,0.07) !important;
    color: rgba(255,255,255,0.5);
}
.bdhe-search-history-remove {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px 10px;
    color: rgba(255,255,255,0.25);
    line-height: 1;
    transition: color 0.15s;
}
.bdhe-search-history-remove:hover { color: rgba(255,100,100,0.9); }

/* ── Overlay: excerpt risultati ── */
.bdhe-search-excerpt {
    display: block;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.5);
    line-height: 1.4;
    margin-top: 3px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ── Nasconde Google AdSense mentre l'overlay ricerca è aperto ── */
body.bdhe-search-body-open .adsbygoogle,
body.bdhe-search-body-open ins.adsbygoogle,
body.bdhe-search-body-open [id^="google_ads_iframe"],
body.bdhe-search-body-open [id^="aswift_"],
body.bdhe-search-body-open .google-auto-placed,
body.bdhe-search-body-open #google_ads_iframe_anchor,
body.bdhe-search-body-open .google-anchor-ad,
body.bdhe-search-body-open div[data-anchor-status],
body.bdhe-search-body-open iframe[id^="google_ads_iframe"],
body.bdhe-search-body-open .GoogleActiveViewElement {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ══ 2.3.0 — Pulsante modalità scura: 8 design (tema BACKdigit) ══════════
 * Chiaro/scuro dal CSS: classe custom-dark su <html>. Colore: --bdhe-dm-accent.
 */
.bdhe-dm {
	--bdhe-dm-accent: var(--bdt-accent, #fc8f00);
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: .45em;
	min-height: 0;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 17px;
	line-height: 1;
	text-transform: none;
	letter-spacing: 0;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}
.bdhe-dm:hover,
.bdhe-dm:focus { background: transparent; color: inherit; }
.bdhe-dm:focus-visible { outline: 2px solid var(--bdhe-dm-accent); outline-offset: 3px; border-radius: 6px; }
.bdhe-dm--s { font-size: 14px; }
.bdhe-dm--l { font-size: 21px; }
/* 2.4.0: dimensione per desktop, tablet e mobile */
.bdhe-dm[style*="--bdhe-dm-fs"] { font-size: var(--bdhe-dm-fs); }
@media (max-width: 999.98px) { .bdhe-dm[style*="--bdhe-dm-fs"] { font-size: var(--bdhe-dm-fs-t, var(--bdhe-dm-fs)); } }
@media (max-width: 689.98px) { .bdhe-dm[style*="--bdhe-dm-fs"] { font-size: var(--bdhe-dm-fs-m, var(--bdhe-dm-fs-t, var(--bdhe-dm-fs))); } }
.bdhe-dm .bdhe-dm-i { display: block; width: 1.15em; height: 1.15em; line-height: 1.15em; text-align: center; }
.bdhe-dm .bdhe-dm-moon,
.custom-dark .bdhe-dm .bdhe-dm-sun,
.bdhe-dm .bdhe-dm-d,
.custom-dark .bdhe-dm .bdhe-dm-l { display: none; }
.custom-dark .bdhe-dm .bdhe-dm-moon,
.custom-dark .bdhe-dm .bdhe-dm-d { display: block; }
.bdhe-dm-label { font-family: var(--bdt-font-menu, inherit); font-size: .82em; letter-spacing: .5px; white-space: nowrap; }
.bdhe-dm-label > span { display: inline; }
.custom-dark .bdhe-dm-label .bdhe-dm-d { display: inline; }
.bdhe-dm-ico { display: inline-flex; transition: transform .45s cubic-bezier(.4, 0, .2, 1); }
.custom-dark .bdhe-dm-ico { transform: rotate(-25deg); }

/* 1 Icona */
.bdhe-dm--icon:hover .bdhe-dm-ico { color: var(--bdhe-dm-accent); }

/* 2 Cerchio */
.bdhe-dm--circle .bdhe-dm-ico { width: 2.1em; height: 2.1em; align-items: center; justify-content: center; border-radius: 50%; background: var(--bdhe-dm-accent); color: #fff; }

/* 3 Pillola */
.bdhe-dm--pill { padding: .42em .9em; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); border-radius: 999px; }
.bdhe-dm--pill:hover { border-color: var(--bdhe-dm-accent); }
.bdhe-dm--pill .bdhe-dm-ico { color: var(--bdhe-dm-accent); }

/* 4 Interruttore */
.bdhe-dm-track { position: relative; display: inline-block; flex: none; width: 3.1em; height: 1.65em; border-radius: 999px; background: color-mix(in srgb, currentColor 30%, transparent); transition: background .25s; }
.custom-dark .bdhe-dm-track { background: var(--bdhe-dm-accent); }
.bdhe-dm-knob { position: absolute; top: .15em; left: .15em; display: flex; align-items: center; justify-content: center; width: 1.35em; height: 1.35em; border-radius: 50%; background: #fff; color: #f5a623; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .25s cubic-bezier(.4, 0, .2, 1); }
.custom-dark .bdhe-dm-knob { transform: translateX(1.45em); color: #3c4a7a; }
.bdhe-dm-knob .bdhe-dm-i { width: .85em; height: .85em; line-height: .85em; font-size: .9em; }

/* 5 Giorno e notte */
.bdhe-dm-sky { position: relative; display: inline-block; flex: none; width: 3.5em; height: 1.75em; overflow: hidden; border-radius: 999px; background: linear-gradient(180deg, #5ab4f5, #9bd6ff); box-shadow: inset 0 1px 3px rgba(0, 0, 0, .25); transition: background .4s; }
.custom-dark .bdhe-dm-sky { background: linear-gradient(180deg, #0d1330, #27306b); }
.bdhe-dm-orb { position: absolute; top: .2em; left: .2em; width: 1.35em; height: 1.35em; border-radius: 50%; background: #ffd23f; box-shadow: 0 0 .5em rgba(255, 210, 63, .8); transition: transform .4s cubic-bezier(.4, 0, .2, 1), background .4s, box-shadow .4s; }
.custom-dark .bdhe-dm-orb { transform: translateX(1.75em); background: #e9e9f2; box-shadow: inset -.35em -.15em 0 #c3c3d3; }
.bdhe-dm-sky i { position: absolute; width: 2px; height: 2px; border-radius: 50%; background: #fff; opacity: 0; transition: opacity .4s; }
.bdhe-dm-sky i:nth-child(1) { left: 22%; top: 30%; }
.bdhe-dm-sky i:nth-child(2) { left: 34%; top: 65%; }
.bdhe-dm-sky i:nth-child(3) { left: 14%; top: 60%; }
.custom-dark .bdhe-dm-sky i { opacity: 1; }

/* 6 Segmentato */
.bdhe-dm-seg { display: inline-flex; overflow: hidden; border: 1px solid color-mix(in srgb, currentColor 35%, transparent); border-radius: 8px; font-family: var(--bdt-font-menu, inherit); font-size: .8em; letter-spacing: .5px; }
.bdhe-dm-seg > span { display: inline-flex; align-items: center; padding: .4em .7em; opacity: .7; transition: background .2s, opacity .2s; }
.bdhe-dm-seg .bdhe-dm-i { width: 1.2em; height: 1.2em; }
html:not(.custom-dark) .bdhe-dm-seg-l,
.custom-dark .bdhe-dm-seg-d { background: var(--bdhe-dm-accent); color: #fff; opacity: 1; }

/* 7 Testo e interruttore */
.bdhe-dm--textswitch { gap: .6em; }
.bdhe-dm-text { font-family: var(--bdt-font-menu, inherit); font-size: .78em; letter-spacing: 1px; text-transform: uppercase; white-space: nowrap; }
.bdhe-dm-track--mini { width: 2.1em; height: 1.15em; }
.bdhe-dm-track--mini .bdhe-dm-knob { width: .85em; height: .85em; }
.custom-dark .bdhe-dm-track--mini .bdhe-dm-knob { transform: translateX(.95em); }

/* 8 Minimal */
.bdhe-dm--minimal .bdhe-dm-ico { width: 2em; height: 2em; align-items: center; justify-content: center; border-radius: 10px; opacity: .8; transition: background .2s, opacity .2s, transform .45s; }
.bdhe-dm--minimal:hover .bdhe-dm-ico { background: color-mix(in srgb, currentColor 12%, transparent); opacity: 1; }
.bdhe-dm--minimal .bdhe-dm-i { stroke-width: 1.5; }

@media (prefers-reduced-motion: reduce) {
	.bdhe-dm *, .bdhe-dm { transition: none !important; }
}
