:root {
  --card: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #3b82f6;
  --ok: #16a34a;
  --err: #ef4444;
  --border: #1f2937;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial; }

header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display:flex; align-items:center; justify-content:space-between;
}
h1 { margin: 0; font-size: 20px; font-weight: 600; }
#auth-status { font-size: 14px; color: var(--muted); }

section { margin: 18px auto; width: min(1100px, 94%); background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
h2 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }
.row { display:flex; gap: 10px; align-items:center; margin: 10px 0; flex-wrap: wrap; }

label { font-size: 14px; color: var(--muted); }
input[type="text"], input[type="password"], input:not([type]) {
  background: #0b1220; border:1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 8px; min-width: 320px;
}
select {
  background: #0b1220; border:1px solid var(--border); color: var(--text);
  padding: 8px 10px; border-radius: 8px; min-width: 240px;
}
button {
  background: var(--accent); color: white; border: none; border-radius: 8px;
  padding: 10px 14px; cursor: pointer; font-weight: 600;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.ghost-btn {
  background: transparent;
  border: 1px solid rgba(148,163,184,.35);
  color: var(--text);
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(148,163,184,.4);
}

.sql {
  background: #0b1220; border:1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow:auto; max-height: 240px;
}
.sql-modal-processors {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(148,163,184,.35);
  border-radius: 12px;
  background: rgba(15,23,42,.7);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sql-modal-processors.hidden { display: none; }
.sql-modal-processors p {
  margin: 0 0 4px;
  font-size: 0.85rem;
  color: #cbd5f5;
}
.sql-modal-processor-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sql-modal-processors label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text);
}
.sql-modal-processors input[type="checkbox"] {
  transform: scale(1.05);
}

#current-note {
  width: 100%;
  min-height: 70px;
  resize: vertical;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
  font-size: 0.95rem;
}

.sql-snippet {
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  color: #00d9ff;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.narrative {
  margin-bottom: 12px;
  padding: 12px;
  border-left: 4px solid var(--accent);
  background: rgba(15,23,42,.85);
  border-radius: 8px;
  line-height: 1.4;
}
.narrative.hidden { display:none; }

.grid-collapsed { margin-top: 10px; }
.grid-collapsed summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
}
.grid-collapsed summary::marker { color: var(--accent); }

table.grid {
  width: 100%; border-collapse: collapse; border:1px solid var(--border); border-radius: 8px; overflow:hidden;
}
table.grid thead th {
  background: #0b1220; color: var(--text); padding: 8px; border-bottom:1px solid var(--border);
  position: sticky; top: 0;
}
table.grid tbody td { padding: 8px; border-bottom:1px solid var(--border); color: var(--text); }
table.grid tbody tr:nth-child(odd) { background: #0d1424; }

.error { color: var(--err); font-size: 13px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display:flex; align-items:center; justify-content:center; z-index: 50;
}
.modal-backdrop.hidden { display:none; }
.modal {
  width: min(480px, 92%); background: var(--card); border:1px solid var(--border);
  border-radius: 12px; padding: 18px;
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid #ffffff40; border-top-color: #fff; animation: spin 1s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }
 
.suggestions { background: #0b1220; border:1px solid var(--border); border-radius:8px; max-height:220px; overflow:auto; margin-top:-6px; padding:6px 0; display:none; }
.suggestions.visible { display:block; }
.suggestions p { margin:0; padding:6px 12px; color: var(--muted); font-size:13px; }
.suggestions ul { list-style:none; margin:0; padding:0; }
.suggestions li { padding:6px 12px; cursor:pointer; color: var(--text); }
.suggestions li:hover { background:#111b2e; }

.muted-label {
  font-weight: 600;
  color: var(--muted);
  margin-left: 8px;
}

.action-row { gap: 16px; }
.normalize-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.normalize-controls .normalize-label { font-weight: 600; color: var(--muted); }
.normalize-controls button { background: #6366f1; white-space: nowrap; }

.choice-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
}
.choice-options button {
  width: 100%;
  background: #1d4ed8;
}

.test-conversation-feed {
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.test-conversation-entry {
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 12px;
  padding: 12px;
  background: rgba(15, 23, 42, 0.35);
}

.test-conversation-entry h4 {
  margin: 0 0 8px;
  font-size: 1rem;
  color: var(--text);
}

.test-conversation-narrative {
  margin: 0 0 8px;
  font-style: italic;
  color: var(--muted);
}

.test-conversation-table {
  margin-top: 8px;
  overflow-x: auto;
}

.test-conversation-meta {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.templates-panel,
.followups-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.template-row,
.followup-row {
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 12px;
  padding: 12px;
  background: rgba(15, 23, 42, 0.35);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.template-row.validated-entry {
  border-color: #39ff14;
  box-shadow: 0 0 14px rgba(57, 255, 20, 0.35);
}

.template-row.validated-entry textarea,
.template-row.validated-entry input[type="text"] {
  border-color: rgba(57, 255, 20, 0.45);
}

.template-row textarea,
.followup-row textarea,
.template-row input[type="text"],
.followup-row input[type="text"] {
  width: 100%;
  min-height: 60px;
  background: #0b1220;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px;
  font-family: "Fira Code", "SFMono-Regular", Consolas, monospace;
  resize: vertical;
}

.template-row .meta,
.followup-row .meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.template-actions,
.followup-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.processors-input {
  width: 100%;
  min-height: auto;
  font-family: inherit;
}

.hints-panel {
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 12px;
  padding: 12px;
  background: rgba(11, 18, 32, 0.4);
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.hint-entry {
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 10px;
  padding: 10px;
  background: rgba(30, 41, 72, 0.4);
}
.hint-entry h4 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--text);
}
.hint-entry p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.hint-entry .hint-text {
  margin-top: 6px;
  color: #d5f5ff;
  font-weight: 500;
}

.train-controls {
  flex-wrap: wrap;
  gap: 12px;
}
.training-status {
  margin-bottom: 12px;
  color: var(--muted);
}
.training-modal textarea {
  width: 100%;
  min-height: 80px;
  background: #0b1220;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-family: inherit;
}
.training-modal input[type="text"] {
  width: 100%;
  background: #0b1220;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px;
}
.training-question {
  font-weight: 600;
  margin-bottom: 12px;
}
.training-duration {
  margin: 0 0 12px;
  font-size: 0.8rem;
  color: var(--muted);
}
.training-actions {
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

/* --- Revisione conversazioni --- */
.review-body {
  background: #030712;
  min-height: 100vh;
}
.review-app {
  min-height: 100vh;
  display: flex;
  background: #030712;
}
.review-sidebar {
  width: 300px;
  background: #0b1220;
  border-right: 1px solid rgba(148, 163, 184, 0.2);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.review-sidebar h1 {
  margin: 0;
  font-size: 1.35rem;
}
.review-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.nav-btn {
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  color: var(--text);
  transition: background 0.2s, border 0.2s;
}
.nav-btn.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.6);
  color: #dbeafe;
}
.sidebar-note {
  font-size: 0.9rem;
  color: var(--muted);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 10px;
  padding: 12px;
  background: rgba(8, 16, 32, 0.7);
}
.sidebar-note ul {
  padding-left: 18px;
  margin: 6px 0 0;
}
.review-main {
  flex: 1;
  padding: 28px;
  overflow-y: auto;
}
.review-header {
  background: transparent;
  border: none;
  padding: 0 0 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}
.review-header h2 {
  margin: 0;
  font-size: 1.35rem;
}
.review-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.counter-badge {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-weight: 600;
}
.review-actions .ghost-btn {
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: var(--text);
}
.conversation-container {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.conversation-card {
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 14px;
  padding: 20px;
  background: rgba(11, 18, 32, 0.55);
}
.conversation-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  padding-bottom: 12px;
  margin-bottom: 18px;
}
.conversation-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 10px;
}
.meta-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge.pending {
  background: rgba(251, 146, 60, 0.15);
  color: #fb923c;
}
.badge.validated {
  background: rgba(34, 197, 94, 0.15);
  color: #34d399;
}
.badge.warning {
  background: rgba(248, 113, 113, 0.18);
  color: #f87171;
}
.steps-wrapper {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.danger-btn {
  border: 1px solid rgba(239, 68, 68, 0.7);
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
}
.step-card {
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 12px;
  padding: 16px;
  background: rgba(15, 23, 42, 0.65);
}
.step-card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.step-card label {
  display: block;
  margin: 10px 0 4px;
  font-size: 0.85rem;
  color: var(--muted);
}
.step-card textarea,
.step-card input,
.step-card select {
  width: 100%;
  background: #020617;
  color: var(--text);
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  padding: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
}
.step-card textarea.sql-input {
  font-family: "Fira Code", "SFMono-Regular", Consolas, monospace;
  min-height: 140px;
}
.processors-input {
  font-family: "Fira Code", "SFMono-Regular", Consolas, monospace;
}
.step-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}
.step-message {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}
.replay-block {
  margin-top: 12px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(59, 130, 246, 0.35);
  background: rgba(11, 18, 32, 0.6);
}
.replay-status {
  margin: 0 0 6px;
  font-weight: 700;
  color: #a5b4fc;
}
.replay-status.success { color: #34d399; }
.replay-status.error { color: #f87171; }
.replay-meta {
  margin: 0 0 6px;
  font-size: 0.9rem;
  color: var(--muted);
}
.replay-preview {
  margin: 6px 0 0;
  color: #e5e7eb;
}
.hint-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: rgba(59, 130, 246, 0.15);
  color: #bfdbfe;
  border-radius: 999px;
  margin: 0 6px 6px 0;
  font-size: 0.8rem;
}
.chip-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.chip {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  background: rgba(15, 118, 110, 0.2);
  color: #5eead4;
}
.chain-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.85rem;
}
.meta-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
}
.meta-grid span {
  font-size: 0.8rem;
  color: var(--muted);
}
.empty-state {
  border: 1px dashed rgba(148, 163, 184, 0.4);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  background: rgba(11, 18, 32, 0.4);
}
.read-only .step-card textarea,
.read-only .step-card input,
.read-only .step-card select,
.read-only .step-actions button {
  pointer-events: none;
  opacity: 0.6;
}

/* Notice banner in chat bubbles (desktop/mobile shared) */
.chat-notice {
  margin: 8px 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,196,107,.12);
  border: 1px solid rgba(255,196,107,.35);
  color: #d97706;
  font-weight: 700;
  line-height: 1.4;
}
