/* ============================================================
   PHONEMA PoC — Confronto RAG vs LLM
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent:      #3b82f6;
  --accent-dk:   #2563eb;
  --bg:          #f1f5f9;
  --surface:     #ffffff;
  --border:      #e2e8f0;
  --text:        #1e293b;
  --muted:       #64748b;
  --radius:      12px;
  --shadow:      0 2px 12px rgba(0,0,0,.08);
  --rag-accent:  #2563eb;
  --norag-accent:#7c3aed;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Header ---- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: .8rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.logo-area { display: flex; align-items: center; gap: .75rem; }
.logo-icon  { font-size: 2rem; }
.logo-area h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent-dk);
  line-height: 1.1;
}
.tagline { font-size: .75rem; color: var(--muted); margin-top: .1rem; }
.btn-voicebooks {
  font-size: .82rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  padding: .35rem .8rem;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.btn-voicebooks:hover { background: var(--accent); color: #fff; }
.btn-voicebooks:hover .logo-voicebooks { filter: brightness(0) invert(1); }
.logo-voicebooks {
  height: 36px;
  width: auto;
  display: block;
}

/* ---- Main layout ---- */
.main-container {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 1.2rem 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

/* ---- Query bar (input fisso in cima) ---- */
.query-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .7rem;
}
.query-bar-intro {
  font-size: .85rem;
  color: var(--muted);
  line-height: 1.5;
}
.query-bar-intro strong { color: var(--text); }

.chat-form {
  display: flex;
  gap: .6rem;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: .7rem 1rem;
  font-size: .93rem;
  resize: none;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
  background: var(--surface);
}
.chat-input:focus { border-color: var(--accent); }

.btn-send {
  padding: .7rem 1.4rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: .93rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.btn-send:hover:not(:disabled) { background: var(--accent-dk); }
.btn-send:disabled { opacity: .55; cursor: not-allowed; }

.spinner { animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.chat-hint { font-size: .75rem; color: var(--muted); }
.examples-bar {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  flex-wrap: wrap;
}
.examples-label {
  font-size: .75rem;
  color: var(--muted);
  white-space: nowrap;
  padding-top: .3rem;
  font-weight: 600;
}
.examples-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}
.chip {
  font-size: .75rem;
  color: var(--accent);
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 99px;
  padding: .25rem .75rem;
  cursor: pointer;
  transition: background .15s, color .15s;
  font-family: inherit;
  text-align: left;
  line-height: 1.4;
}
.chip:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chat-hint kbd {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .1rem .3rem;
  font-size: .72rem;
}

/* ---- Results area ---- */
.results-area {
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
}

/* ---- Comparison turn ---- */
.comparison-turn {
  display: flex;
  flex-direction: column;
  gap: .9rem;
  animation: fadeIn .25s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } }

/* Domanda */
.turn-question {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  flex-wrap: wrap;
}
.turn-q-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  white-space: nowrap;
}
.turn-q-text {
  font-size: .97rem;
  font-weight: 600;
  color: var(--text);
}
.badge-cached {
  font-size: .68rem;
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
  border-radius: 4px;
  padding: .1rem .4rem;
  font-weight: 600;
}

/* ---- Pannello principale (RAG) — full width ---- */
.comparison-panels {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

/* ---- Sezione secondaria no-RAG (accordion) ---- */
.norag-section {
  margin-top: .5rem;
}
.norag-section > summary {
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem 0;
}
.norag-section > summary::before { content: '▸ '; font-size: .75rem; }
.norag-section[open] > summary::before { content: '▾ '; }
.norag-section > summary:hover { color: var(--text); }
.norag-section .comp-panel {
  margin-top: .5rem;
  opacity: .85;
}

/* ---- Singolo pannello ---- */
.comp-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

/* Bordo colorato in alto */
.panel-rag    { border-top: 3px solid var(--rag-accent); }
.panel-no-rag { border-top: 3px solid var(--norag-accent); }

/* Header pannello */
.panel-header {
  padding: .75rem 1rem .5rem;
  border-bottom: 1px solid var(--border);
}
.panel-titles { display: flex; flex-direction: column; gap: .1rem; }
.panel-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
}
.panel-rag    .panel-title { color: var(--rag-accent);   }
.panel-no-rag .panel-title { color: var(--norag-accent); }
.panel-subtitle {
  font-size: .72rem;
  color: var(--muted);
}

/* ---- Rilevanza (solo pannello RAG) ---- */
.relevance-meter {
  padding: .65rem 1rem .5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.relevance-bar-wrap {
  height: 6px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
}
.relevance-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .4s ease;
}
.relevance-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  flex-wrap: wrap;
}
.relevance-label {
  font-size: .8rem;
  font-weight: 700;
}
.relevance-score {
  font-size: .72rem;
  color: var(--muted);
}
.relevance-note {
  font-size: .71rem;
  color: var(--muted);
  line-height: 1.4;
  font-style: italic;
  margin-top: .15rem;
}

/* ---- Corpo risposta ---- */
.panel-body {
  padding: .9rem 1rem;
  font-size: .88rem;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  flex: 1;
}
.panel-body strong { font-weight: 600; }
.panel-body ul  { padding-left: 1.2em; margin: .3em 0; }
.panel-body li  { margin-bottom: .2em; }

/* ---- Fonti ---- */
.sources-panel {
  border-top: 1px solid var(--border);
  padding: .5rem .9rem;
  font-size: .76rem;
  color: var(--muted);
}
.sources-panel summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  user-select: none;
  padding: .2rem 0;
}
.sources-panel summary::before          { content: '▸ '; }
details[open] .sources-panel summary::before { content: '▾ '; }
.sources-list  { margin-top: .4rem; display: flex; flex-direction: column; gap: .3rem; }
.source-item   { display: flex; align-items: center; gap: .5rem; }
.source-badge {
  font-size: .65rem;
  font-weight: 700;
  padding: .1rem .4rem;
  border-radius: 4px;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-profilo { background: #dbeafe; color: #1e40af; }
.badge-paper   { background: #d1fae5; color: #065f46; }
.source-name   { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-score  { font-weight: 600; white-space: nowrap; }

/* ---- Shimmer / loading ---- */
.loading-shimmer .panel-body { display: none; }
.shimmer-line {
  height: 12px;
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 6px;
  margin: .7rem 1rem;
}
.shimmer-line.short { width: 60%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- Errore ---- */
.error-block {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: var(--radius);
  padding: .9rem 1.1rem;
  font-size: .9rem;
}

/* ---- Footer ---- */
.site-footer {
  text-align: center;
  font-size: .75rem;
  color: var(--muted);
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ---- Responsive ---- */
@media (max-width: 800px) {
  .header-inner { padding: .7rem 1rem; }
  .main-container { padding: 1rem 1rem 2rem; }
  .tagline { display: none; }
}
