/* Sales AI Sales-Companion — stile thin (BravoRic: JS vanilla, CSS essenziale, zero build chain). */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1220;
  --panel: #1a1f33;
  --fg: #e6e9f2;
  --muted: #8b90a8;
  --accent: #4f7cff;
  --danger: #ff5a5a;
  --success: #4ade80;
  --warning: #fbbf24;
  --radius: 10px;
  /* Token superficie riusabili (default = scuro). Il tema chiaro li override. */
  --surface: #131729;      /* input, statusbar, badge, select, textarea, suggestion-box */
  --surface-2: #1e2740;    /* conn-ind, toast, chip */
  --border: #2c3350;
  --log-bg: #f5f6f8;       /* riga cronologia suggerimenti (mantiene l'attuale look) */
}
[data-theme="light"] {
  --bg: #eef2f8;
  --panel: #ffffff;
  --fg: #1c2230;
  --muted: #5b6478;
  --accent: #2f6fed;
  --danger: #d63031;
  --success: #15803d;
  --warning: #b45309;
  --surface: #ffffff;
  --surface-2: #f1f5fb;
  --border: #d5dbe7;
  --log-bg: #eef2f8;
}
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin-top: 10px; }
.view { width: 100%; max-width: 420px; padding: 16px; }
.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
}
h1 { font-size: 18px; margin-bottom: 4px; }
label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font-size: 15px;
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; }
button {
  margin-top: 16px;
  width: 100%;
  padding: 11px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  font-weight: 600;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; color: var(--muted); box-shadow: none; font-weight: 400; padding: 6px 0; }
button.danger { background: var(--danger); }
button.danger:hover { filter: brightness(1.08); }
header { display: flex; justify-content: space-between; align-items: center; }
.statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 14px 0;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: 8px;
  font-size: 13px;
}

/* Indicatore stato connessione live (toni semaforo) */
.conn-ind {
  margin-left: auto;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 12px;
  white-space: nowrap;
  background: var(--surface-2);
  color: #cbd5e1;
}
.conn-ind.conn-ok { background: #16301f; color: #4ade80; }
.conn-ind.conn-warn { background: #33290f; color: #facc15; }
.conn-ind.conn-err { background: #3a1414; color: #f87171; }
.conn-ind.conn-neutral { background: var(--surface-2); color: #cbd5e1; }

/* --- HUD Live Call --- */
.hud-section { margin-bottom: 18px; }
.hud-section label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }

.status-row { display: flex; align-items: center; gap: 10px; }
.badge {
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--surface);
  color: var(--muted);
}
.badge.state-connected { background: rgba(74, 222, 128, 0.15); color: var(--success); }
.badge.state-streaming { background: rgba(251, 191, 36, 0.15); color: var(--warning); }
.badge.state-suggesting { background: rgba(79, 124, 255, 0.15); color: var(--accent); }
.badge.state-disconnected { background: rgba(255, 90, 90, 0.15); color: var(--danger); }
.badge.badge-info { background: rgba(79, 124, 255, 0.15); color: var(--accent); font-weight: 500; text-transform: none; }
.badge.state-error { background: rgba(255, 90, 90, 0.25); color: var(--danger); }

.suggestion-box {
  margin-top: 8px;
  padding: 12px;
  background: var(--surface);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  min-height: 48px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.capture-indicators { margin-top: 8px; }
.indicator-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.2s, box-shadow 0.2s;
}
.indicator.active { background: var(--success); box-shadow: 0 0 8px var(--success); }
.indicator.degraded { background: var(--warning); box-shadow: 0 0 8px var(--warning); }

.capture-controls { display: flex; gap: 8px; margin-top: 10px; }
.capture-controls button { margin-top: 0; flex: 1; }
.capture-controls button.danger { background: var(--danger); }

.connect-controls { display: flex; gap: 8px; margin-top: 10px; }
.connect-controls button { margin-top: 0; flex: 1; }
.connect-controls button.danger { background: var(--danger); }
/* Feedback F-002: riga voti 1-10 */
.vote-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.vote-btn { width: 36px; height: 36px; margin: 0; padding: 0; border-radius: 6px; text-align: center; }
.vote-btn.selected { background: var(--primary, #2f6fed); color: #fff; font-weight: 700; }

/* Cronologia suggerimenti di sessione (thin) */
.suggestion-log-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; max-height: 180px; overflow-y: auto; }
.suggestion-log-row { display: flex; align-items: center; gap: 8px; background: var(--log-bg); border-radius: 6px; padding: 6px 8px; }
.suggestion-log-row .suggestion-log-text { flex: 1; font-size: 13px; line-height: 1.35; }
.suggestion-log-row button { flex: 0 0 auto; margin: 0; padding: 4px 10px; font-size: 12px; }

/* Ruolo attivo + feedback testuale + esito vendita (F-002, steering per ruolo) */
.small { font-size: 12px; margin-top: 6px; }
select#hud-role-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font-size: 15px;
}
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font-size: 14px;
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.outcome-controls button { flex: 1; margin-top: 0; }
.outcome-controls button.neutral { background: var(--border); }
.outcome-controls button[aria-pressed="true"] {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.outcome-legend { margin-top: 6px; opacity: 0.85; line-height: 1.4; }
/* --- Toast non bloccante (thin) --- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
}
.toast {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface-2);
  color: #e2e8f0;
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  opacity: 1;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
[data-theme="light"] .toast { color: var(--fg); box-shadow: 0 4px 14px rgba(20, 30, 60, 0.16); }
.toast.toast-success { border-left: 3px solid #4ade80; }
.toast.toast-error { border-left: 3px solid #f87171; }
.toast.toast-warn { border-left: 3px solid #facc15; }
.toast.toast-info { border-left: 3px solid #60a5fa; }
.toast.toast-hide { opacity: 0; transform: translateY(-8px); }

/* --- Header actions (conn-ind + logout) --- */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* --- Responsive: overlay HUD su schermi piccoli --- */
@media (max-width: 640px) {
  .panel { margin: 8px; padding: 12px; }
  h1 { font-size: 18px; }
  .statusbar, .connect-controls, .capture-controls { flex-direction: column; align-items: stretch; }
  input, select, button { width: 100%; }
  .toast-container { left: 16px; right: 16px; max-width: none; }
}

/* --- Preferenze UI (settings.js) — pannello thin --- */
details.hud-section summary {
  cursor: pointer;
  list-style: none;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  user-select: none;
}
details.hud-section summary::-webkit-details-marker { display: none; }
details.hud-section[open] summary { margin-bottom: 6px; }
.settings-grid { display: grid; gap: 8px; }
.settings-grid label {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--fg);
}
.settings-grid label select,
.settings-grid label input[type="number"] {
  flex: 1;
  width: auto;
  padding: 6px 8px;
  font-size: 13px;
}
.settings-grid label input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}

/* --- Accessibilità: riduzione movimento (settings.reducedMotion) --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after {
  animation: none !important;
  transition: none !important;
}

/* --- Cronologia call (thin, call-history.js) — filtro + lista + scheda --- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.filter-btn {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border, #334);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.call-history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.call-history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--log-bg);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
}
.call-history-row:hover, .call-history-row:focus-visible { border-color: var(--accent); outline: none; }
.call-row-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.call-row-title { font-size: 13px; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-row-date { font-size: 11px; }
.call-row-chips { display: flex; flex-wrap: wrap; gap: 4px; flex: 0 0 auto; }
.chip {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border, #334);
  white-space: nowrap;
}
.chip-setting { border-left: 3px solid #60a5fa; }
.chip-sale   { border-left: 3px solid #4ade80; }
.call-detail { margin-top: 8px; background: var(--surface-2); border-radius: 6px; padding: 8px 10px; }
.call-detail-title { font-size: 13px; font-weight: 600; color: var(--fg); }
.call-detail-meta { font-size: 11px; margin-top: 3px; }
.call-detail-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.call-detail-note { font-size: 12px; margin-top: 6px; line-height: 1.4; }
/* --- Esiti cronologia (thin, outcome-stats.js) — riepilogo win-rate per-asse --- */
.outcome-stats { display: flex; align-items: baseline; gap: 8px; margin: 4px 0 8px; }
.outcome-stats label { font-weight: 600; font-size: 12px; color: var(--fg, #eef); }
.outcome-stats p { margin: 0; }
/* --- Export dettaglio call (thin, export-call.js) — txt/SRT/note --- */
.call-detail-export { margin-top: 8px; gap: 6px; }

/* --- Cronologia call estesa (paging + ricerca + dettaglio approfondito) --- */
.history-query-wrap { margin: 4px 0 6px; }
.history-query-wrap input {
  width: 100%; box-sizing: border-box; padding: 6px 8px; font-size: 12px;
  border: 1px solid var(--border, #444); border-radius: 5px; background: var(--surface-2, #1c1f24);
  color: var(--fg, #eef); }
.history-query-wrap input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.more-btn { margin: 8px auto 0; display: block; }
.call-detail-kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin-top: 6px; font-size: 11px; }
.call-detail-kv .meta-k { color: var(--muted, #9aa); text-transform: uppercase; letter-spacing: .03em; }

/* --- Cronologia call: raggruppamento per data, empty-state, a11y, esporta --- */
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.history-head .ghost.small { font-size: 11px; padding: 3px 8px; }
.call-row-group { list-style: none; display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.call-row-group-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.call-row-group .call-history-row { margin-top: 2px; }
.call-list-extra { margin-top: 2px; font-size: 11px; }
/* sr-only: testo solo per screen reader (letti via aria-live, invisibili). */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.more-spinner { color: var(--accent, #4f8); }
.call-detail-kv .meta-v { color: var(--fg, #eef); word-break: break-word; }
.call-detail-segments { margin-top: 8px; font-size: 12px; }
.call-detail-segments summary { cursor: pointer; color: var(--accent, #6ab0f3); font-weight: 600; }
.seg-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; max-height: 200px; overflow-y: auto; border-top: 1px solid var(--border, #333); padding-top: 6px; }
.seg-row { display: flex; gap: 8px; align-items: baseline; }
.seg-time { flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.seg-speaker { flex: 0 0 auto; font-weight: 600; color: var(--accent, #6ab0f3); min-width: 24px; }
.seg-text { flex: 1 1 auto; line-height: 1.4; word-break: break-word; }

/* --- Pannello Playbook + Validazione (thin, Fase 6 sez 5.12 #2) --- */
.playbook-panel { list-style: none; margin: 4px 0 8px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.pb-card {
  background: var(--surface-2, #171a28);
  border: 1px solid var(--border, #2c3245);
  border-radius: 6px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.pb-card-title { font-size: 13px; font-weight: 600; color: var(--fg, #eef); word-break: break-word; }
.pb-card-summary { font-size: 11px; line-height: 1.35; word-break: break-word; margin-top: 1px; }
.pb-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.pb-chip {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2, #1a1d2b);
  border: 1px solid var(--border, #334);
  white-space: nowrap;
  color: var(--muted, #9aa);
}
.pb-chip-ok   { border-left: 3px solid #4ade80; }
.pb-chip-ko   { border-left: 3px solid #f87171; }
.pb-chip-conf { border-left: 3px solid #60a5fa; color: var(--fg, #eef); }
.pb-topic     { border-style: dashed; }
.validation-line { font-size: 11px; margin: 2px 0 0; }
.pb-status { margin: 2px 0 4px; }
