/* Infocad docs — override minimi sul template "modern".
   Motivo: le etichette dei diagrammi Mermaid venivano rese troncate. Mermaid dimensiona i
   foreignObject delle label misurando il testo al momento del render; se il webfont arriva dopo,
   il testo diventa piu largo del box riservato e viene tagliato. Rendendo visibile l'overflow il
   testo esce dal box invece di essere troncato, e i diagrammi larghi scorrono in orizzontale. */

.mermaid,
pre.mermaid {
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
}

.mermaid svg,
pre.mermaid svg {
  max-width: 100%;
  height: auto;
  /* Mermaid calcola il viewBox dalle posizioni dei nodi: una label piu larga del nodo verrebbe
     tagliata dal bordo dell'SVG. */
  overflow: visible;
}

/* Niente clipping delle label (nodi, archi, cluster/subgraph, partecipanti sequence). */
.mermaid foreignObject,
.mermaid .label,
.mermaid .nodeLabel,
.mermaid .edgeLabel,
.mermaid .cluster-label,
.mermaid .actor,
.mermaid text {
  overflow: visible;
}

.mermaid .nodeLabel,
.mermaid .edgeLabel,
.mermaid .cluster-label {
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
}

/* Le tabelle larghe (reference DB) scorrono invece di sfondare la colonna di testo. */
article .table-responsive,
article table {
  max-width: 100%;
}

/* ==========================================================================
   Ricerca Typesense + "Chiedi all'AI" (RAG) e link di contribuzione.
   Vedi templates/infocad/public/main.js e docs-site/search/.
   ========================================================================== */

:root {
  --ifx-bg: #ffffff;
  --ifx-fg: #1b1f24;
  --ifx-muted: #5b6570;
  --ifx-border: #e3e6ea;
  --ifx-hover: #f2f6fb;
  --ifx-accent: #2f6fd6;
  --ifx-accent-soft: #e8f0fd;
  --ifx-shadow: 0 12px 40px rgba(20, 30, 50, 0.22);
  --ifx-kbd-bg: #eef1f5;
}
[data-bs-theme="dark"] {
  --ifx-bg: #1c2128;
  --ifx-fg: #e6edf3;
  --ifx-muted: #9aa5b1;
  --ifx-border: #2d333b;
  --ifx-hover: #262d36;
  --ifx-accent: #5b9bff;
  --ifx-accent-soft: #1e2a3d;
  --ifx-shadow: 0 12px 44px rgba(0, 0, 0, 0.55);
  --ifx-kbd-bg: #2d333b;
}

/* --- Pulsante trigger (stile DocSearch) --- */
.ifx-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 200px;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--ifx-border);
  border-radius: 8px;
  background: var(--ifx-bg);
  color: var(--ifx-muted);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ifx-trigger:hover { border-color: var(--ifx-accent); box-shadow: 0 1px 6px rgba(47, 111, 214, 0.18); }
.ifx-trigger-label { flex: 1; text-align: left; }
.ifx-trigger-kbd {
  font-size: 0.72rem;
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  background: var(--ifx-kbd-bg);
  color: var(--ifx-muted);
  white-space: nowrap;
}
@media (max-width: 767px) { .ifx-trigger { min-width: 0; } .ifx-trigger-label, .ifx-trigger-kbd { display: none; } }

/* --- Overlay + modale --- */
#ifx-search[hidden] { display: none; }
#ifx-search {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 9vh;
}
.ifx-backdrop { position: absolute; inset: 0; background: rgba(10, 16, 26, 0.5); backdrop-filter: blur(2px); }
.ifx-modal {
  position: relative;
  width: min(680px, 92vw);
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  background: var(--ifx-bg);
  color: var(--ifx-fg);
  border: 1px solid var(--ifx-border);
  border-radius: 14px;
  box-shadow: var(--ifx-shadow);
  overflow: hidden;
}
.ifx-tabs { display: flex; align-items: center; gap: 0.25rem; padding: 0.5rem 0.75rem 0; }
.ifx-tab {
  border: 0;
  background: transparent;
  color: var(--ifx-muted);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.4rem 0.7rem;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
}
.ifx-tab.is-active { color: var(--ifx-accent); background: var(--ifx-accent-soft); }
.ifx-spacer { flex: 1; }
.ifx-close {
  border: 1px solid var(--ifx-border);
  background: var(--ifx-kbd-bg);
  color: var(--ifx-muted);
  font-size: 0.72rem;
  border-radius: 5px;
  padding: 0.15rem 0.45rem;
  cursor: pointer;
}
.ifx-inputrow { padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--ifx-border); }
#ifx-input {
  width: 100%;
  border: 1px solid var(--ifx-border);
  border-radius: 9px;
  padding: 0.7rem 0.85rem;
  font-size: 1.05rem;
  background: var(--ifx-bg);
  color: var(--ifx-fg);
  outline: none;
}
#ifx-input:focus { border-color: var(--ifx-accent); box-shadow: 0 0 0 3px var(--ifx-accent-soft); }
.ifx-panel { overflow-y: auto; padding: 0.4rem; }
.ifx-empty { padding: 2rem 1rem; text-align: center; color: var(--ifx-muted); font-size: 0.92rem; }
.ifx-err { color: #c0392b; }
[data-bs-theme="dark"] .ifx-err { color: #ff7b72; }
.ifx-loading::after { content: " ⏳"; }

/* --- Risultati keyword (raggruppati per pagina) --- */
.ifx-group { margin-bottom: 0.4rem; }
.ifx-group-head {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ifx-muted);
  padding: 0.5rem 0.6rem 0.25rem;
}
.ifx-hit {
  display: block;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--ifx-fg);
}
.ifx-hit:hover, .ifx-hit.is-sel { background: var(--ifx-hover); }
.ifx-hit.is-sel { box-shadow: inset 3px 0 0 var(--ifx-accent); }
.ifx-hit-title { display: block; font-size: 0.95rem; }
.ifx-hit-title mark { background: var(--ifx-accent-soft); color: inherit; padding: 0 0.1em; border-radius: 3px; }
.ifx-hit-sub { display: block; font-size: 0.78rem; color: var(--ifx-muted); margin-top: 0.1rem; }

/* --- Risposta AI (RAG) --- */
.ifx-answer { padding: 0.9rem 1rem; font-size: 0.96rem; line-height: 1.55; white-space: normal; }
.ifx-sources { padding: 0 1rem 0.6rem; }
.ifx-sources-head { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ifx-muted); margin-bottom: 0.25rem; }
.ifx-src { display: block; font-size: 0.85rem; padding: 0.25rem 0; color: var(--ifx-accent); text-decoration: none; }
.ifx-src:hover { text-decoration: underline; }
.ifx-ai-note { padding: 0.5rem 1rem 0.9rem; font-size: 0.75rem; color: var(--ifx-muted); border-top: 1px solid var(--ifx-border); }

/* --- Barra di contribuzione per pagina --- */
.ifx-contrib {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--ifx-border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.1rem;
  align-items: center;
  font-size: 0.85rem;
}
.ifx-contrib-q { color: var(--ifx-muted); }
.ifx-contrib a { text-decoration: none; color: var(--ifx-accent); }
.ifx-contrib a:hover { text-decoration: underline; }
