/* TRAMA Web Local v0.3 — override Tailwind */

/* ── Markdown rendering nel pannello chat ──────────────────────── */
.markdown-body {
  line-height: 1.6;
  color: #1e293b;
  font-size: 0.925rem;
}
.markdown-body h1 { font-size: 1.4rem; font-weight: 700; margin: 1rem 0 0.6rem 0; color: #0f172a; }
.markdown-body h2 { font-size: 1.2rem; font-weight: 700; margin: 1rem 0 0.5rem 0; color: #0f172a; }
.markdown-body h3 { font-size: 1.05rem; font-weight: 600; margin: 0.8rem 0 0.4rem 0; color: #0f172a; }
.markdown-body p  { margin: 0.5rem 0; }
.markdown-body strong { font-weight: 600; color: #0f172a; }
.markdown-body ul, .markdown-body ol { margin: 0.4rem 0 0.4rem 1.4rem; }
.markdown-body li { margin: 0.2rem 0; }
.markdown-body code {
  background: #f1f5f9;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.markdown-body pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 0.8rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.6rem 0;
  font-size: 0.85rem;
}
.markdown-body pre code { background: transparent; padding: 0; color: inherit; }
.markdown-body blockquote {
  border-left: 3px solid #94a3b8;
  padding: 0.3rem 0.8rem;
  color: #475569;
  margin: 0.6rem 0;
  background: #f8fafc;
}
.markdown-body table {
  border-collapse: collapse;
  margin: 0.8rem 0;
  font-size: 0.85rem;
  width: 100%;
}
.markdown-body th, .markdown-body td {
  border: 1px solid #e2e8f0;
  padding: 0.4rem 0.6rem;
  text-align: left;
}
.markdown-body th { background: #f1f5f9; font-weight: 600; }
.markdown-body tr:nth-child(even) { background: #f8fafc; }
.markdown-body a { color: #0369a1; text-decoration: underline; }
.markdown-body hr { border: none; border-top: 1px solid #e2e8f0; margin: 1rem 0; }

/* ── Bubble user e assistant ───────────────────────────────────── */
.turn-user {
  display: flex;
  justify-content: flex-end;
}
.turn-user .bubble {
  background: #1e293b;
  color: #f1f5f9;
  padding: 0.6rem 0.9rem;
  border-radius: 12px 12px 2px 12px;
  max-width: 80%;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.turn-assistant {
  display: flex;
  justify-content: flex-start;
}
.turn-assistant .content-wrap {
  max-width: 95%;
  width: 100%;
}
.turn-assistant .label {
  font-weight: 600;
  color: #0f172a;
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}

/* ── Card copertura/confidenza (compact single-line) ─────────────── */
.coverage-card {
  margin: 0.8rem 0 0.4rem 0;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  border: 1px solid;
  font-size: 0.82rem;
  line-height: 1.45;
}
.coverage-card.cov-alta {
  background: #ecfdf5;
  border-color: #10b981;
  color: #064e3b;
}
.coverage-card.cov-media {
  background: #fefce8;
  border-color: #eab308;
  color: #713f12;
}
.coverage-card.cov-bassa {
  background: #fff7ed;
  border-color: #f97316;
  color: #7c2d12;
}
.coverage-card.cov-nulla,
.coverage-card.cov-na {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: #334155;
}
.coverage-card .cov-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.6rem;
}
.coverage-card .cov-line .seg {
  display: inline;
  white-space: normal;
  word-break: break-word;
}
.coverage-card .cov-line .seg + .seg::before {
  /* il separatore "·" tra i segmenti è già nell'HTML, non serve generato */
}
.coverage-card b {
  font-weight: 600;
}
.coverage-card .cov-note {
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px dashed currentColor;
  opacity: 0.85;
  font-size: 0.78rem;
}

/* ── Sezioni collassabili (details) ────────────────────────────── */
details.debug-section {
  margin: 0.4rem 0;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #f8fafc;
}
details.debug-section summary {
  cursor: pointer;
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  color: #475569;
  font-weight: 500;
  user-select: none;
}
details.debug-section[open] summary {
  border-bottom: 1px solid #e2e8f0;
}
details.debug-section .body {
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
}

.query-item {
  margin-bottom: 0.7rem;
  padding: 0.5rem;
  border-left: 3px solid #cbd5e1;
  background: white;
  border-radius: 4px;
}
.query-item .qlabel {
  font-weight: 600;
  font-size: 0.8rem;
  color: #334155;
  margin-bottom: 0.2rem;
}
.query-item .qmeta {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 0.2rem;
}
.query-item .qmeta.error { color: #b91c1c; }
.query-item pre {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  overflow-x: hidden;
  margin: 0;
  font-size: 0.8rem;
}
.query-item pre code {
  white-space: pre-wrap;
  word-break: break-word;
}

.tech-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}
.tech-grid .k { color: #64748b; }
.tech-grid .v { color: #0f172a; }

/* ── Banner risposta troncata (max_tokens) ─────────────────────── */
.truncation-warning {
  margin: 0.6rem 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid #f59e0b;
  background: #fffbeb;
  color: #78350f;
  border-radius: 6px;
  font-size: 0.82rem;
  line-height: 1.45;
}
.truncation-warning code {
  background: #fef3c7;
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  font-size: 0.85em;
}

/* ── Sidebar sessioni ──────────────────────────────────────────── */
.session-item {
  display: block;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}
.session-item:hover {
  background: #f8fafc;
}
.session-item.active {
  background: #e0f2fe;
  border-left: 3px solid #0369a1;
  padding-left: calc(0.8rem - 3px);
}
.session-item .titolo {
  font-weight: 500;
  color: #0f172a;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-item .when {
  font-size: 0.7rem;
  color: #94a3b8;
  margin-top: 0.1rem;
}
.session-item .delete {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  font-size: 0.75rem;
  color: #94a3b8;
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  cursor: pointer;
}
.session-item:hover .delete { display: inline-block; }
.session-item .delete:hover { background: #fee2e2; color: #b91c1c; }

.session-item .rename {
  position: absolute;
  right: 1.8rem;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  font-size: 0.75rem;
  color: #94a3b8;
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  cursor: pointer;
}
.session-item:hover .rename { display: inline-block; }
.session-item .rename:hover { background: #dbeafe; color: #1e40af; }

.session-item .titolo-edit {
  background: #fff;
  border: 1px solid #3b82f6;
  border-radius: 3px;
  padding: 0.1rem 0.3rem;
  width: calc(100% - 0.5rem);
  outline: none;
  box-sizing: border-box;
  font-family: inherit;
}
.session-item .titolo-edit:focus { border-color: #1e40af; }

/* ── Sidebar collapsable ───────────────────────────────────────── */
#sidebar.collapsed { display: none; }

/* ── ROI card (voce backlog #42) ───────────────────────────────── */
details.roi-card {
  margin: 0.6rem 0 0.4rem 0;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  border-radius: 6px;
}
details.roi-card summary {
  cursor: pointer;
  padding: 0.5rem 0.8rem;
  font-size: 0.82rem;
  color: #1e40af;
  font-weight: 600;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
details.roi-card summary::after {
  content: "▼";
  font-size: 0.7rem;
  color: #60a5fa;
  transition: transform 0.15s;
}
details.roi-card[open] summary::after { transform: rotate(180deg); }
details.roi-card[open] summary { border-bottom: 1px solid #bfdbfe; }
details.roi-card .body {
  padding: 0.7rem 0.9rem;
}
details.roi-card .roi-headline {
  font-size: 0.78rem;
  font-weight: 500;
  color: #475569;
}
details.roi-card .roi-headline b {
  color: #0c4a6e;
  font-weight: 700;
}
details.roi-card .roi-section {
  display: grid;
  grid-template-columns: 1.4em 1fr;
  gap: 0.2rem 0.5rem;
  margin: 0.4rem 0;
  font-size: 0.84rem;
  line-height: 1.45;
}
details.roi-card .roi-section .roi-icon { font-size: 0.95em; }
details.roi-card .roi-section .roi-label { color: #475569; font-weight: 600; }
details.roi-card .roi-section .roi-detail { color: #0f172a; }
details.roi-card .roi-section .roi-detail b { color: #0c4a6e; }
details.roi-card .roi-tooltip {
  display: inline-block;
  width: 14px;
  height: 14px;
  line-height: 14px;
  text-align: center;
  background: #cbd5e1;
  color: #475569;
  border-radius: 50%;
  font-size: 0.7rem;
  cursor: help;
  font-style: normal;
  font-weight: 600;
  margin-left: 0.25rem;
}

/* Espansione inline parametri di calcolo (sotto la riga dei valori) */
details.roi-info-inline {
  margin-top: 0.3rem;
}
details.roi-info-inline summary {
  cursor: pointer;
  font-size: 0.72rem;
  color: #64748b;
  font-weight: 500;
  user-select: none;
  list-style: none;
  display: inline-block;
}
details.roi-info-inline summary::-webkit-details-marker { display: none; }
details.roi-info-inline summary:hover { color: #0c4a6e; }
details.roi-info-inline[open] summary { color: #0c4a6e; font-weight: 600; }
details.roi-info-inline .roi-info-content {
  margin-top: 0.4rem;
  padding: 0.5rem 0.7rem;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  font-size: 0.76rem;
  color: #0f172a;
}
details.roi-info-inline .roi-calc-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin: 0.2rem 0;
  font-variant-numeric: tabular-nums;
}
details.roi-info-inline .roi-calc-row .k {
  color: #475569;
  flex: 1 1 auto;
  min-width: 0;
}
details.roi-info-inline .roi-calc-row .v {
  color: #0c4a6e;
  font-weight: 600;
  flex: 0 0 auto;
  text-align: right;
  white-space: nowrap;
}
/* Riga sotto-dettaglio (k vuoto, solo v) */
details.roi-info-inline .roi-calc-row:has(.k:empty) {
  margin-top: -0.05rem;
  font-size: 0.7rem;
  justify-content: flex-end;
}
details.roi-info-inline .roi-calc-row:has(.k:empty) .v {
  color: #64748b;
  font-weight: normal;
  font-style: italic;
}
details.roi-card .roi-compressione {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed #bfdbfe;
  font-weight: 600;
  color: #0c4a6e;
  font-size: 0.85rem;
}
details.roi-card .roi-compressione b { color: #1e3a8a; }
details.roi-card .roi-empty {
  color: #475569;
  font-style: italic;
  font-size: 0.82rem;
}

/* ── Portfolio modal ───────────────────────────────────────────── */
#portfolioModal:not(.hidden) { display: flex; }
#portfolioBody h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  color: #64748b;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin: 1rem 0 0.4rem 0;
}
#portfolioBody h3:first-child { margin-top: 0; }
#portfolioBody .pf-block {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.4rem;
}
#portfolioBody .pf-block .pf-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0.2rem 0;
  font-size: 0.86rem;
}
#portfolioBody .pf-block .pf-row .lbl { color: #475569; }
#portfolioBody .pf-block .pf-row .val { color: #0f172a; font-weight: 600; font-variant-numeric: tabular-nums; }
#portfolioBody .pf-headline {
  font-size: 0.95rem;
  color: #0c4a6e;
  font-weight: 700;
  text-align: center;
  padding: 0.5rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  margin-bottom: 0.6rem;
}
#portfolioBody .pf-foot {
  margin-top: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px dashed #cbd5e1;
  font-size: 0.75rem;
  color: #64748b;
  line-height: 1.5;
}

/* ── Welcome message in nuova sessione ─────────────────────────── */
.welcome {
  padding: 1.5rem;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  text-align: center;
  color: #475569;
  font-size: 0.9rem;
  max-width: 600px;
  margin: 2rem auto;
}
.welcome strong { color: #0f172a; }

/* ── Truncate to 2 lines (line-clamp) ───────────────────────────
   Custom utility per evitare problemi col JIT del Tailwind CDN
   che a volte non genera CSS per classi inserite via innerHTML.
   Usata da renderExpandableText in dashboard.js. */
.tx-clamp-2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
