:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #dcdfe4;
  --text: #151515;
  --muted: #5f6670;
  --ink: #111827;
}

* { box-sizing: border-box; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}
.shell {
  width: min(100vw, 1440px);
  margin: 0 auto;
  padding: 10px 12px;
}
header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
h1 { margin: 0; font-size: 20px; line-height: 1.1; }
header p { margin: 0; color: var(--muted); font-size: 12px; }
.controls {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.usage-badge {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 5px 10px;
  border-radius: 8px;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  font-size: 12px;
  color: #374151;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  margin-left: 4px;
}
.usage-badge[hidden] { display: none; }
.usage-badge-label {
  color: #6b7280;
  font-weight: 600;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.usage-badge-sep { color: #9ca3af; }
#usageTokens, #usageCost { font-weight: 700; color: #111827; }
button {
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid #9ca3af;
  background: white;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}
button:disabled { opacity: .45; cursor: not-allowed; }

.cards,
.module3-status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: stretch;
}
.operator-workspace {
  display: grid;
  grid-template-columns: minmax(560px, 1.08fr) minmax(520px, 1fr);
  gap: 12px;
  align-items: start;
}
.operator-workspace .module3-status {
  grid-template-columns: 1fr;
}
.right-column {
  display: grid;
  gap: 8px;
  min-width: 0;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.035);
  min-width: 0;
}
.card h2 {
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: .02em;
}

.cards .card:first-child { grid-column: span 3; }
.cards .card:nth-child(2) { grid-column: span 1; }
.module3-section[data-section-id] { grid-column: span 1; }
.module3-section[data-section-id="stato_raccolta"] { grid-column: span 1; }
.module3-section[data-section-id="richiesta"] { grid-column: span 1; }
.module3-section[data-section-id="identificazione_chiamante"] { grid-column: span 1; }
.module3-section[data-section-id="condominio"] { grid-column: span 1; }
.module3-section[data-section-id="preferenze_escalation"] { grid-column: span 1; }

.module3-section[data-section-id="stato_raccolta"] dl,
#statusPanel {
  display: grid;
  grid-template-columns: repeat(5, auto minmax(0, 1fr));
  gap: 4px 8px;
  align-items: baseline;
}

#realtimeStatusPanel.realtime-status-panel {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr);
  gap: 6px 10px;
  align-items: start;
}

#realtimeStatusPanel.realtime-status-panel dt {
  white-space: nowrap;
}

#realtimeStatusPanel.realtime-status-panel dd {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.3;
}

#realtimeStatusPanel.realtime-status-panel .m2-timeline-label,
#realtimeStatusPanel.realtime-status-panel .m2-timeline-value {
  grid-column: 1 / -1;
}

#realtimeStatusPanel.realtime-status-panel .m2-timeline-label {
  color: var(--text);
}

#realtimeStatusPanel.realtime-status-panel .m2-state-timeline {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 0;
  list-style: none;
}

#realtimeStatusPanel.realtime-status-panel .m2-state-timeline li {
  display: grid;
  gap: 3px;
  padding: 7px 8px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fff;
}

#realtimeStatusPanel.realtime-status-panel .m2-state-name {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  font-weight: 700;
}

.m2-phase-badge,
.transcript-phase {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid #d1d5db;
  color: #374151;
  background: #f9fafb;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

#realtimeStatusPanel.realtime-status-panel .m2-state-detail {
  color: var(--muted);
}

#realtimeStatusPanel.realtime-status-panel .m2-turn-text {
  color: var(--text);
  white-space: normal;
}

#realtimeStatusPanel.realtime-status-panel .m2-turn-row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 8px;
  color: var(--muted);
}

#realtimeStatusPanel.realtime-status-panel .m2-turn-row b {
  color: var(--text);
}

#realtimeStatusPanel.realtime-status-panel .m2-turn-next span {
  color: var(--text);
}

dl { margin: 0; }
dt { font-weight: 700; color: var(--muted); white-space: nowrap; }
dd { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.meter { height: 12px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin: 4px 0 6px; }
#audioLevelBar { height: 100%; width: 0%; background: var(--ink); transition: width .08s linear; }
#audioStatus { margin: 0; color: var(--muted); font-size: 12px; }

.field-table { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
.field-table th,
.field-table td {
  border-bottom: 1px solid #eef0f3;
  padding: 6px 5px;
  text-align: left;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field-table th { font-weight: 700; background: #fafafa; color: var(--muted); }
.field-table th:nth-child(1), .field-table td:nth-child(1) { width: 30%; }
.field-table th:nth-child(2), .field-table td:nth-child(2) {
  width: 38%;
  white-space: normal;
  line-height: 1.25;
}
.field-table th:nth-child(3), .field-table td:nth-child(3) { width: 17%; }
.field-table th:nth-child(4), .field-table td:nth-child(4) { width: 15%; }

.diagnostics-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 0;
}
.diagnostics-grid .card { min-height: 0; }
pre {
  background: #111827;
  color: #f9fafb;
  padding: 8px;
  border-radius: 8px;
  overflow: auto;
  max-height: 180px;
  margin: 0;
  font-size: 11px;
  line-height: 1.25;
}

@media (max-width: 1100px) {
  .cards,
  .module3-status,
  .diagnostics-grid,
  .operator-workspace { grid-template-columns: 1fr; }
  .cards .card:first-child,
  .cards .card:nth-child(2),
  .module3-section[data-section-id] { grid-column: span 1; }
  .module3-section[data-section-id="stato_raccolta"] dl,
  #statusPanel { grid-template-columns: 160px 1fr; }
  #realtimeStatusPanel.realtime-status-panel { grid-template-columns: 160px 1fr; }
  header { display: block; }
}

.transcript-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 0;
}
.transcript-card { min-height: 0; }
.transcript-view {
  background: #ffffff;
  border: 1px solid #eef0f3;
  border-radius: 8px;
  padding: 8px;
  min-height: 260px;
  max-height: 42vh;
  overflow: auto;
  font-size: 12px;
  line-height: 1.35;
}
.transcript-placeholder { margin: 0; color: var(--muted); }
.transcript-entry {
  padding: 3px 0;
  border-bottom: 1px solid #f2f3f5;
}
.transcript-entry:last-child { border-bottom: 0; }
.transcript-time {
  color: var(--muted);
  font-size: 11px;
  margin-right: 6px;
}

.card-header-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-header-inline h2 {
  margin: 0;
}

.build-marker {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  white-space: nowrap;
}

.secondary-button {
  border: 1px solid #d6dae1;
  background: #fff;
  color: #1f2937;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.2;
  cursor: pointer;
}

.secondary-button:hover {
  background: #f8fafc;
}

.secondary-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.m2-strategy-panel {
  display: grid;
  gap: 7px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #eef0f3;
}

.m2-strategy-panel h3 {
  margin: 0;
  font-size: 12px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: .02em;
}

.m2-strategy-panel label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.m2-strategy-panel select {
  width: 100%;
  min-height: 32px;
  border: 1px solid #9ca3af;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 6px 8px;
  font-size: 12px;
}

.m2-strategy-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.m2-cost-grid {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 8px;
  font-size: 11px;
}

.m2-cost-grid dt,
.m2-cost-grid dd {
  white-space: normal;
}

.call-feedback-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 24, 39, .46);
}

.call-feedback-dialog {
  width: min(520px, 100%);
  display: grid;
  gap: 12px;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 18px 44px rgba(0,0,0,.22);
}

.call-feedback-dialog h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
}

.call-feedback-copy,
.call-feedback-hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.call-feedback-stars {
  display: grid;
  gap: 7px;
}

.call-feedback-star {
  width: 100%;
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  text-align: left;
  border-radius: 8px;
  border-color: #d1d5db;
  background: #fff;
}

.call-feedback-star:hover,
.call-feedback-star:focus {
  border-color: #6b7280;
  background: #f9fafb;
}

.call-feedback-star.is-selected {
  border-color: #111827;
  background: #f3f4f6;
}

.call-feedback-star-count {
  color: #111827;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  letter-spacing: 0;
}

.call-feedback-star-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.call-feedback-comment-label {
  font-weight: 700;
  color: var(--muted);
}

.call-feedback-comment {
  width: 100%;
  resize: vertical;
  min-height: 78px;
  border: 1px solid #9ca3af;
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}

.call-feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Sezione "Cosa e' stato raccolto" — sotto rating/comment, sopra actions.
   Mostra motivo + caso (codice + label matrice) + tipo/urgenza + durata/turni
   + costo + campi raccolti. Stile asciutto, leggermente staccato dal resto
   tramite border-top, non un box completo. */
.call-feedback-summary {
  display: grid;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid #e5e7eb;
  margin-top: 4px;
}

.call-feedback-summary-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.call-feedback-summary-list {
  margin: 0;
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  gap: 4px 12px;
  font-size: 13px;
  line-height: 1.4;
}

.call-feedback-summary-list dt {
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.call-feedback-summary-list dd {
  margin: 0;
  color: #111827;
  overflow-wrap: anywhere;
}

/* M3 preview (priorita'/tema dashboard): testo secondario per il code in parentesi. */
.call-feedback-summary-muted {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

#audioStatus[data-state="active"] { font-weight: 650; }
#audioStatus[data-state="suppressed"] { font-weight: 650; }
#audioStatus[data-state="inactive"] { opacity: .75; }

/* ─── v0.9.45 simple_intake default ─────────────────────────────────── */

/* Pannello Campi raccolti — sostituisce la vecchia matrice di triage. */
.collected-fields-card {
  padding: 14px 18px;
}
.collected-fields-card .collected-fields-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
  gap: 12px;
}
.collected-fields-card h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #111827;
}
.collected-fields-phase {
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
}
.collected-fields-list {
  display: grid;
  gap: 6px;
}
.collected-fields-list .field-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dashed #e5e7eb;
  font-size: 13.5px;
  line-height: 1.4;
}
.collected-fields-list .field-row:last-child {
  border-bottom: none;
}
.collected-fields-list .field-label {
  color: #6b7280;
  font-weight: 600;
}
.collected-fields-list .field-row.filled .field-value {
  color: #111827;
  font-weight: 500;
}
.collected-fields-list .field-row.empty .field-value {
  color: #9ca3af;
}
.field-confirmed-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  background: #d1fae5;
  color: #065f46;
  font-size: 11px;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Card "Mostra log diagnostico" — un singolo bottone per espandere il log. */
.debug-toggle-card {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}
.debug-toggle-card button {
  background: transparent;
  border: 1px dashed #d1d5db;
  color: #6b7280;
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 6px;
}
.debug-toggle-card button:hover {
  background: #f3f4f6;
  color: #111827;
}

/* ─── v0.9.46 player "Riascolta chiamata" ───────────────────────────── */
.call-playback {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-wrap: wrap;
}
.call-playback-label {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
}
.call-playback audio {
  height: 34px;
  vertical-align: middle;
}
