/* ============================================
   ELVEXA CMS — Stili globali (dark)
   Allineato con elvexa-crm/console: DM Sans, gradient viola→magenta,
   palette warm gray-violet.
   ============================================ */

:root {
  /* Brand neon */
  --viola:   #9D4EDD;
  --magenta: #FF006E;
  --coral:   #FF6B6B;
  --yellow:  #FFD93D;
  --cyan:    #00FFFF;

  /* Dark surfaces */
  --bg-base:    #1A1720;
  --bg-gradient: linear-gradient(135deg, #1A1720 0%, #221E2E 50%, #1A1720 100%);
  --bg-card:    #242030;
  --bg-section: #1E1B28;
  --bg-warm:    #1F1C26;

  /* Text */
  --text-primary:   #EDECF0;
  --text-secondary: #A8A4B4;
  --text-muted:     #6E6A7C;

  /* Borders */
  --border-color: #2E2A3A;
  --border-light: #262238;

  /* Semantic */
  --success:    #10B981;
  --success-bg: rgba(16,185,129,.12);
  --danger:     #EF4444;
  --danger-bg:  rgba(239,68,68,.12);
  --warning:    #F59E0B;
  --warning-bg: rgba(245,158,11,.12);
  --info:       #3B82F6;
  --info-bg:    rgba(59,130,246,.12);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.2), 0 1px 2px rgba(0,0,0,.12);
  --shadow-md: 0 4px 12px rgba(0,0,0,.25), 0 2px 4px rgba(0,0,0,.15);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.3), 0 4px 8px rgba(0,0,0,.2);
  --shadow-xl: 0 16px 40px rgba(0,0,0,.35), 0 8px 16px rgba(0,0,0,.25);

  /* Type / spacing */
  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --transition: 150ms ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

/* Scrollbar dark globale (in linea col tema). Firefox: scrollbar-color. */
* { scrollbar-color: #3a3548 transparent; scrollbar-width: thin; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: #3a3548; border-radius: 6px;
  border: 2px solid transparent; background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: #4a4458; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-primary);
  background-color: var(--bg-base);
  background-image: var(--bg-gradient);
  line-height: 1.5;
  min-height: 100vh;
}

/* ============================================
   Login / auth (centered card, gradient brand)
   ============================================ */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  box-shadow: var(--shadow-xl);
}
.login-brand { text-align: center; margin-bottom: 32px; }
.login-title {
  font-size: 24px; font-weight: 700; letter-spacing: -0.01em;
}
.login-title .brand-grad {
  background: linear-gradient(135deg, var(--viola), var(--magenta));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.login-sub { color: var(--text-muted); font-size: 13px; margin-top: 6px; }

.login-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 13px; color: var(--text-secondary); font-weight: 500;
}
.field input {
  padding: 12px 14px;
  background: var(--bg-section);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit; font-size: 14px;
  transition: border var(--transition), background var(--transition);
}
.field input::placeholder { color: var(--text-muted); }
.field input:focus {
  outline: none; border-color: var(--viola);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(157,78,221,.18);
}

.btn-primary {
  padding: 13px 18px; border: 0; border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--viola), var(--magenta));
  color: #fff; font-weight: 600; font-size: 14px; font-family: inherit;
  cursor: pointer;
  transition: filter var(--transition), box-shadow var(--transition), transform var(--transition);
}
.btn-primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 8px 24px rgba(157,78,221,.35);
}
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled {
  opacity: .55; cursor: not-allowed; filter: none; box-shadow: none;
}

.login-error {
  background: var(--danger-bg); color: #FCA5A5;
  border: 1px solid rgba(239,68,68,.3);
  padding: 11px 13px; border-radius: var(--radius-md);
  font-size: 13px; line-height: 1.5;
}
.login-success {
  background: var(--success-bg); color: #6EE7B7;
  border: 1px solid rgba(16,185,129,.3);
  padding: 14px 16px; border-radius: var(--radius-md);
  margin-top: 8px;
}
.login-success p { margin: 0 0 6px; font-size: 14px; }
.login-success p:last-child { margin: 0; }
.login-success-sub { color: #A7F3D0; font-size: 13px; }

.powered-by {
  text-align: center; margin-top: 24px;
  font-size: 12px; color: var(--text-muted);
}
.powered-by strong {
  background: linear-gradient(135deg, var(--viola), var(--magenta));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ============================================
   App split (chat + iframe anteprima)
   ============================================ */
.app-body {
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;   /* la SPA è alta esattamente la viewport;
                                        lo scroll vive solo dentro chat-history */
}
.app-header {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
}
.brand {
  font-weight: 700; font-size: 16px; letter-spacing: -.01em;
}
.brand .brand-grad {
  background: linear-gradient(135deg, var(--viola), var(--magenta));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tenant-selector { flex: 1; }
.tenant-selector select {
  padding: 8px 12px;
  background: var(--bg-section);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit; font-size: 14px;
  min-width: 220px;
}
.tenant-selector select:focus {
  outline: none; border-color: var(--viola);
}

.user-area {
  display: flex; align-items: center; gap: 12px;
  font-size: 13px; color: var(--text-secondary);
}
.btn-link {
  background: none; border: none; cursor: pointer;
  color: var(--viola); font-family: inherit; font-size: 13px;
}
.btn-link:hover { color: var(--magenta); }

/* Badge stato ambiente nell'header: verde se attivo, giallo se spento
   (GC idle 30min), grigio se preparazione in corso. */
.env-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 500;
  padding: 3px 9px; border-radius: 10px;
  background: rgba(255,255,255,.04);
  color: var(--text-muted);
  border: 1px solid rgba(255,255,255,.08);
}
.env-badge::before {
  content: ''; display: inline-block;
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
}
.env-badge.is-active   { color: #2ecc71; background: rgba(46,204,113,.06); border-color: rgba(46,204,113,.2); }
.env-badge.is-starting { color: #f1c40f; background: rgba(241,196,15,.08); border-color: rgba(241,196,15,.25); }
.env-badge.is-idle     { color: #8a8a8a; }

/* Bubble risultati SEO (tool seo-keywords / seo-serp → DataForSEO) */
.msg-seo {
  margin: 8px 0 16px;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(46,204,113,.04), rgba(46,204,113,.02));
  border: 1px solid rgba(46,204,113,.22);
  border-radius: var(--radius-md);
  max-width: 95%;
}
.msg-seo__head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.msg-seo__title { font-weight: 600; font-size: 13px; color: var(--text-primary); }
.msg-seo__title i { color: #2ecc71; margin-right: 6px; }
.msg-seo__where {
  font-size: 11px; color: var(--text-muted);
  background: rgba(255,255,255,.04);
  padding: 2px 8px; border-radius: 10px;
}
.msg-seo__counter {
  display: inline-block; margin-top: 10px;
  font-size: 11px; color: var(--text-muted);
  padding: 2px 8px; background: rgba(255,255,255,.04); border-radius: 10px;
}
.msg-seo__unit { font-size: 10px; color: var(--text-muted); margin-left: 3px; }

/* Tabella keywords */
.msg-seo__table {
  width: 100%; border-collapse: collapse;
  font-size: 12px;
}
.msg-seo__table th {
  text-align: left; padding: 6px 8px;
  font-weight: 500; font-size: 11px; text-transform: uppercase;
  color: var(--text-muted); letter-spacing: .03em;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.msg-seo__table td {
  padding: 8px;
  border-bottom: 1px solid rgba(255,255,255,.03);
}
.msg-seo__table td.kw  { font-weight: 500; color: var(--text-primary); }
.msg-seo__table td.vol { font-variant-numeric: tabular-nums; color: var(--text-primary); }
.msg-seo__table td.cpc { font-variant-numeric: tabular-nums; color: var(--text-muted); }
.msg-seo__empty { text-align: center; color: var(--text-muted); padding: 16px; }

.comp-badge {
  display: inline-block; padding: 1px 8px; border-radius: 10px;
  font-size: 10px; font-weight: 500;
}
.comp-low  { background: rgba(46,204,113,.15);  color: #2ecc71; }
.comp-med  { background: rgba(241,196,15,.15);  color: #f1c40f; }
.comp-high { background: rgba(231,76,60,.15);   color: #e74c3c; }
.comp-na   { background: rgba(255,255,255,.04); color: var(--text-muted); }

/* SERP lista */
.msg-seo__our-banner {
  padding: 8px 12px; margin: 0 0 12px;
  border-radius: var(--radius-sm); font-size: 12px;
}
.msg-seo__our-banner.is-found   { background: rgba(46,204,113,.10); color: #2ecc71; border: 1px solid rgba(46,204,113,.25); }
.msg-seo__our-banner.is-missing { background: rgba(231,76,60,.08);  color: #e74c3c; border: 1px solid rgba(231,76,60,.20); }
.msg-seo__serp { list-style: none; padding: 0; margin: 0; }
.msg-seo__serp li {
  display: flex; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.msg-seo__serp li.is-ours {
  background: rgba(46,204,113,.05);
  border-left: 3px solid #2ecc71;
  padding-left: 10px; margin-left: -10px;
}
.msg-seo__serp .pos {
  flex: 0 0 28px;
  font-weight: 600; font-size: 14px; color: var(--viola);
  font-variant-numeric: tabular-nums;
}
.msg-seo__serp-title {
  display: block;
  font-size: 13px; font-weight: 500;
  color: var(--text-primary); text-decoration: none;
  margin-bottom: 2px;
}
.msg-seo__serp-title:hover { text-decoration: underline; color: var(--magenta); }
.msg-seo__serp-domain { font-size: 11px; color: #2ecc71; margin-bottom: 4px; }
.msg-seo__serp-desc {
  font-size: 12px; color: var(--text-secondary); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* Bubble immagine generata (tool generate-image → fal.ai) */
.msg-media {
  display: flex; gap: 12px;
  margin: 8px 0 16px;
  padding: 10px 12px;
  background: linear-gradient(135deg, rgba(157,78,221,.06), rgba(255,77,168,.04));
  border: 1px solid rgba(157,78,221,.18);
  border-radius: var(--radius-md);
  max-width: 95%;
}
.msg-media__thumb-wrap {
  flex: 0 0 120px;
}
.msg-media__thumb {
  width: 120px; height: 120px; object-fit: cover;
  border-radius: var(--radius-sm);
  cursor: zoom-in;
  background: var(--bg-section);
}
.msg-media__thumb:hover {
  outline: 2px solid var(--viola);
  outline-offset: 1px;
}
.msg-media__meta { flex: 1; min-width: 0; }
.msg-media__title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  color: var(--viola); letter-spacing: .03em;
  margin-bottom: 6px;
}
.msg-media__prompt {
  font-size: 13px; color: var(--text-primary);
  line-height: 1.4; margin-bottom: 8px;
}
.msg-media__counter {
  display: inline-block;
  font-size: 11px; color: var(--text-muted);
  background: rgba(255,255,255,.04);
  padding: 2px 8px; border-radius: 10px;
}

/* Modal fullscreen per immagine (clic su thumbnail) */
.cms-img-modal {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.92);
  display: none; align-items: center; justify-content: center;
  padding: 32px;
}
.cms-img-modal.is-open { display: flex; }
.cms-img-modal__img {
  max-width: 100%; max-height: 100%;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 60px rgba(0,0,0,.6);
}
.cms-img-modal__close {
  position: absolute; top: 16px; right: 20px;
  background: rgba(255,255,255,.1); border: none;
  color: white; font-size: 28px; width: 40px; height: 40px;
  border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.cms-img-modal__close:hover { background: rgba(255,255,255,.2); }

/* Quick "Nuova conversazione" nell'header: piu' visibile dei btn-link
   normali, per chiarire all'utente che ogni "unita' di lavoro" inizia
   da qui (problema UX segnalato dai clienti). */
.btn-new-quick {
  padding: 5px 12px;
  border: 1px solid rgba(157,78,221,.4);
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(157,78,221,.12), rgba(255,77,168,.10));
  font-weight: 500;
}
.btn-new-quick:hover {
  background: linear-gradient(135deg, rgba(157,78,221,.22), rgba(255,77,168,.20));
  border-color: rgba(255,77,168,.6);
}

.app-split {
  display: grid; grid-template-columns: 440px 1fr;
  height: calc(100vh - 57px);
}

.chat-pane {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border-color);
  background: var(--bg-section);
  min-height: 0; min-width: 0;       /* essenziale: senza, il flex grow non
                                        rispetta il container e la chat
                                        spinge sotto gli elementi vicini */
}
.chat-empty { padding: 32px; color: var(--text-muted); font-size: 14px; }

/* Esempi cliccabili al primo turno (sessione vuota). */
.chat-suggestions {
  padding: 22px 18px; display: flex; flex-direction: column; gap: 10px;
}
.chat-suggestions__title {
  font-size: 13px; color: var(--text-muted); margin-bottom: 4px;
  letter-spacing: .02em;
}
.chat-suggestion {
  text-align: left; padding: 11px 14px; font-size: 13px;
  background: var(--bg-card); color: var(--text-primary);
  border: 1px solid var(--border-color); border-radius: var(--radius-md);
  cursor: pointer; font-family: inherit; line-height: 1.4;
  transition: border var(--transition), background var(--transition);
}
.chat-suggestion:hover {
  border-color: var(--viola);
  background: rgba(157,78,221,.08);
}

.chat-history {
  flex: 1 1 auto; overflow-y: auto;
  padding: 20px; display: flex; flex-direction: column; gap: 10px;
  min-height: 0;                     /* fondamentale per scroll interno in flex */
}
.msg {
  padding: 11px 14px; border-radius: var(--radius-md);
  font-size: 14px; max-width: 88%; line-height: 1.5;
}
.msg__body { white-space: pre-wrap; word-wrap: break-word; }
.msg-user {
  background: rgba(157,78,221,.18);
  border: 1px solid rgba(157,78,221,.3);
  color: var(--text-primary);
  align-self: flex-end;
}
.msg-assistant {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  align-self: flex-start;
}
.msg__attachments { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.msg__attachment {
  font-size: 12px; padding: 3px 8px; border-radius: 999px;
  background: rgba(0,0,0,.18); color: var(--text-secondary);
}

/* Tool group: <details> collapsibile che raggruppa tool_use consecutivi */
.tool-group {
  align-self: flex-start; max-width: 88%;
  background: rgba(157,78,221,.08);
  border: 1px solid rgba(157,78,221,.25);
  border-radius: var(--radius-md);
  padding: 0; font-size: 12px;
  color: var(--text-secondary);
}
.tool-group__summary {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  cursor: pointer; list-style: none; user-select: none;
}
.tool-group__summary::-webkit-details-marker { display: none; }
.tool-group__icon { color: var(--viola); flex: 0 0 auto; }
.tool-group__summary::after {
  font-family: 'Font Awesome 6 Free'; font-weight: 900;
  content: '\f078'; /* fa-chevron-down */
  margin-left: auto; opacity: .5; font-size: 10px;
  transition: transform var(--transition);
}
.tool-group:not([open]) .tool-group__summary::after { transform: rotate(-90deg); }
.tool-group__title {
  flex: 1; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.tool-group__count {
  font-variant-numeric: tabular-nums;
  background: rgba(157,78,221,.18); color: var(--viola);
  padding: 1px 7px; border-radius: 999px; font-size: 11px;
  font-weight: 600;
}
.tool-group__list {
  list-style: none; margin: 0; padding: 4px 12px 10px 30px;
  border-top: 1px solid rgba(157,78,221,.15);
}
.tool-group__item {
  padding: 3px 0; font-size: 12px; color: var(--text-secondary);
  position: relative;
}
.tool-group__item::before {
  content: '·'; color: var(--viola); position: absolute; left: -12px;
}

.msg-tool__dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--viola);
  animation: tool-pulse 1.2s ease-in-out infinite;
  flex: 0 0 6px;
}
.msg-tool__dot.tool-group__dot--done {
  background: var(--success);
  animation: none;
}
@keyframes tool-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .35; transform: scale(.7); }
}

/* Compatibilità: chip standalone (storico messaggi pre-refactor) */
.msg-tool {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: rgba(157,78,221,.08);
  border: 1px solid rgba(157,78,221,.25);
  color: var(--text-secondary);
  font-size: 12px;
}

/* Riga discreta per messaggi di sistema */
.msg-system {
  align-self: center; max-width: 80%;
  font-size: 12px; color: var(--text-muted);
  text-align: center; padding: 4px 12px;
}

/* Typing dots finché non arriva il primo testo */
.msg-typing { padding: 16px 18px; }
.typing-dots { display: inline-flex; gap: 5px; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.30s; }
@keyframes typing-bounce {
  0%, 80%, 100% { opacity: .3; transform: translateY(0); }
  40%           { opacity: 1;  transform: translateY(-3px); }
}

.chat-input {
  display: flex; flex-direction: column; gap: 10px; padding: 14px 16px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
  position: relative;
}
/* Linea orizzontale animata sopra la chat-input: si attiva quando Claude
   sta elaborando (.is-thinking). Gradient che scorre da sinistra a destra. */
.chat-input::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--viola) 30%, var(--magenta) 70%, transparent 100%);
  background-size: 30% 100%; background-repeat: no-repeat;
  animation: thinking-bar 1.8s linear infinite;
  opacity: 0; transition: opacity .25s; pointer-events: none;
}
.chat-input.is-thinking::before { opacity: 1; }
@keyframes thinking-bar {
  0%   { background-position: -30% 0; }
  100% { background-position: 130% 0; }
}

.chat-input.is-dragover {
  background: rgba(157,78,221,.08);
  border-top-color: var(--viola);
}
.chat-input textarea {
  resize: none;
  background: var(--bg-section);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: inherit; font-size: 14px;
  min-height: 44px; max-height: 220px;
  overflow-y: auto; line-height: 1.45;
}
.chat-input textarea::placeholder { color: var(--text-muted); }
.chat-input textarea:focus { outline: none; border-color: var(--viola); }

.chat-input__bar { display: flex; align-items: center; gap: 8px; }
.chat-input__icon {
  background: var(--bg-section);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; cursor: pointer; color: var(--text-secondary);
  font-family: inherit; transition: all var(--transition);
}
.chat-input__icon:hover {
  background: rgba(157,78,221,.12);
  border-color: var(--viola); color: var(--viola);
}
.chat-input__send,
.chat-input__stop {
  margin-left: auto;
  padding: 9px 18px; border: 0; border-radius: var(--radius-md);
  color: #fff; font-weight: 600; font-family: inherit; cursor: pointer;
  font-size: 13px;
  transition: filter var(--transition);
}
.chat-input__send {
  background: linear-gradient(135deg, var(--viola), var(--magenta));
}
.chat-input__send:hover { filter: brightness(1.08); }

.chat-input__stop {
  background: var(--danger);
  width: 38px; height: 38px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px;
  position: relative;
  animation: stop-pulse 1.4s ease-in-out infinite;
}
.chat-input__stop:hover { filter: brightness(1.1); animation: none; }
@keyframes stop-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.55); }
  50%      { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

/* Mic states */
.mic-btn.mic-recording {
  background: #DC2626; color: #fff; border-color: #DC2626;
  animation: mic-pulse 1.2s ease-in-out infinite;
}
.mic-btn.mic-loading { opacity: .7; cursor: not-allowed; }
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,.5); }
  50%      { box-shadow: 0 0 0 6px rgba(220,38,38,0); }
}
.mic-timer {
  font-family: 'SF Mono', 'Monaco', monospace;
  font-size: 13px; color: #FCA5A5;
  font-variant-numeric: tabular-nums; min-width: 44px;
}

/* Waveform live durante la registrazione (canvas) */
.mic-waveform {
  display: block; height: 28px; max-width: 220px;
  background: rgba(157,78,221,.06);
  border: 1px solid rgba(157,78,221,.25);
  border-radius: var(--radius-sm);
}

/* Attachment chips (sopra la chat-input) */
.chat-attachments {
  padding: 10px 16px 0;
  display: flex; flex-wrap: wrap; gap: 6px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
}
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px 4px 10px;
  background: rgba(157,78,221,.12);
  border: 1px solid rgba(157,78,221,.3);
  border-radius: 999px; font-size: 12px; color: var(--text-primary);
  max-width: 220px;
}
.attach-chip__name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 160px;
}
.attach-chip__x {
  background: none; border: 0; color: var(--text-muted);
  cursor: pointer; padding: 0 0 0 2px; font-size: 14px; line-height: 1;
}
.attach-chip__x:hover { color: var(--magenta); }

.preview-pane { display: flex; flex-direction: column; }
.preview-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
}
.device-btn {
  padding: 5px 12px;
  background: var(--bg-section);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer; font-size: 13px; font-family: inherit;
}
.device-btn.active {
  background: linear-gradient(135deg, var(--viola), var(--magenta));
  color: #fff; border-color: transparent;
}
.preview-status { margin-left: auto; color: var(--text-muted); font-size: 12px; }
.preview-frame-wrap { flex: 1; background: var(--bg-base); padding: 16px; }
#preview-frame {
  width: 100%; height: 100%; background: #fff;
  border: 1px solid var(--border-color); border-radius: var(--radius-sm);
}

/* ---- Modal di conferma ------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(10, 8, 16, 0.65);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: modal-fade-in 150ms ease-out;
}
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 28px;
  width: 100%; max-width: 440px;
  box-shadow: var(--shadow-xl);
  animation: modal-pop-in 200ms cubic-bezier(.2,.8,.2,1.05);
}
@keyframes modal-pop-in {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal__title {
  font-size: 17px; font-weight: 600; margin-bottom: 8px;
  color: var(--text-primary);
}
.modal__body {
  font-size: 14px; color: var(--text-secondary);
  line-height: 1.55; margin-bottom: 22px;
  white-space: pre-wrap;
}
.modal__actions {
  display: flex; justify-content: flex-end; gap: 10px;
}
.modal__btn {
  padding: 9px 18px; border: 1px solid var(--border-color);
  border-radius: var(--radius-md); cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 500;
  background: var(--bg-section); color: var(--text-primary);
  transition: all var(--transition);
}
.modal__btn:hover { background: var(--bg-card); border-color: var(--text-muted); }
.modal__btn--primary {
  background: linear-gradient(135deg, var(--viola), var(--magenta));
  color: #fff; border-color: transparent;
}
.modal__btn--primary:hover { filter: brightness(1.1); }
.modal__btn--danger {
  background: var(--danger); color: #fff; border-color: var(--danger);
}
.modal__btn--danger:hover { filter: brightness(1.1); }

/* ---- Global loader (operazioni sul sito: undo, rollback, ...) ---------- */
.global-loader {
  position: fixed; inset: 0; z-index: 250;
  background: rgba(10, 8, 16, 0.55);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.global-loader__card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 22px 30px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow-xl);
  font-size: 14px; color: var(--text-primary);
}
.global-loader__spinner {
  font-size: 22px;
  background: linear-gradient(135deg, var(--viola), var(--magenta));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ---- Versions panel (timeline punti di salvataggio) ---- */
.versions-panel {
  position: fixed; top: 50px; right: 12px; bottom: 12px;
  width: 360px; max-width: calc(100vw - 24px);
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-xl);
  display: flex; flex-direction: column; z-index: 50;
}
.versions-panel__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border-color);
}
.versions-panel__head strong { font-size: 14px; }
.versions-panel__list { flex: 1; overflow-y: auto; padding: 8px; }
.versions-empty { color: var(--text-muted); font-size: 13px; padding: 12px; text-align: center; }
.version-row {
  padding: 10px 12px; border-radius: var(--radius-md);
  border: 1px solid var(--border-color); background: var(--bg-section);
  margin-bottom: 8px;
}
/* Rollback/undo: visivamente piu' tenue (sono "spostamenti nel tempo", non
   modifiche di contenuto). Bordo dashed + opacita' ridotta. */
.version-row.is-rollback {
  border-style: dashed;
  background: transparent;
  opacity: 0.78;
}
.version-row__summary { font-size: 13px; line-height: 1.4; color: var(--text-primary); }
.version-row__time { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.version-row__rollback {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 500;
  padding: 2px 8px; margin-top: 6px;
  background: rgba(255,193,7,.12); color: var(--warning);
  border-radius: 10px;
}
/* Actions header sopra la lista versioni (es. "Riparti dalla versione online") */
.versions-panel__actions {
  padding: 0 12px 8px; display: flex; gap: 8px; flex-wrap: wrap;
}
.versions-panel__actions .btn-link {
  font-size: 12px; padding: 6px 10px;
  border: 1px solid rgba(255,255,255,.1); border-radius: var(--radius-sm);
  background: rgba(255,255,255,.03);
}
.versions-panel__actions .btn-link:hover {
  background: rgba(255,255,255,.08);
}
.version-row__actions { margin-top: 8px; display: flex; gap: 8px; }
.version-row__btn {
  font-size: 12px; padding: 4px 10px;
  background: transparent; color: var(--viola);
  border: 1px solid rgba(157,78,221,.4); border-radius: var(--radius-sm);
  cursor: pointer; font-family: inherit;
}
.version-row__btn:hover { background: rgba(157,78,221,.1); }

/* Pulsante "Nuova conversazione" in cima al pannello conversazioni */
.btn-new-conv {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 10px 14px; margin-bottom: 12px;
  background: linear-gradient(135deg, var(--viola), var(--magenta));
  color: #fff; border: 0; border-radius: var(--radius-md);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: filter var(--transition);
}
.btn-new-conv:hover { filter: brightness(1.08); }

.conversation-row {
  padding: 10px 12px; border-radius: var(--radius-md);
  border: 1px solid var(--border-color); background: var(--bg-section);
  margin-bottom: 8px; cursor: pointer;
  transition: border var(--transition), background var(--transition);
}
.conversation-row:hover {
  border-color: var(--viola); background: rgba(157,78,221,.08);
}
.conversation-row.is-current {
  border-color: var(--viola);
  background: rgba(157,78,221,.12);
}
.conversation-row__title {
  font-size: 13px; line-height: 1.35; color: var(--text-primary);
  font-weight: 500;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.conversation-row__meta {
  font-size: 11px; color: var(--text-muted); margin-top: 4px;
  display: flex; gap: 10px;
}
.conversation-row {
  display: flex; align-items: flex-start; gap: 8px;
}
.conversation-row__main { flex: 1; min-width: 0; }
.conversation-row__actions {
  display: flex; flex: 0 0 auto; gap: 4px;
  opacity: 0; transition: opacity var(--transition);
}
.conversation-row:hover .conversation-row__actions { opacity: 1; }
.conversation-row__btn {
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); width: 26px; height: 26px;
  color: var(--text-muted); cursor: pointer; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color var(--transition), background var(--transition), border var(--transition);
}
.conversation-row__btn.js-rename:hover {
  color: var(--viola); background: rgba(157,78,221,.1);
  border-color: rgba(157,78,221,.3);
}
.conversation-row__btn.js-delete:hover {
  color: var(--danger); background: rgba(239,68,68,.1);
  border-color: rgba(239,68,68,.3);
}

/* Input dentro al modal di prompt */
.modal__input {
  width: 100%; padding: 10px 12px; margin-bottom: 18px;
  background: var(--bg-section); color: var(--text-primary);
  border: 1px solid var(--border-color); border-radius: var(--radius-md);
  font-family: inherit; font-size: 14px;
}
.modal__input:focus { outline: none; border-color: var(--viola); }

/* Form credenziali hosting nel modal */
.hostpoint-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.hostpoint-form .field { gap: 4px; }
.hostpoint-form .field input {
  background: var(--bg-section); color: var(--text-primary);
  border: 1px solid var(--border-color); border-radius: var(--radius-md);
  padding: 10px 12px; font-family: inherit; font-size: 14px;
}
.hostpoint-form .field input:focus { outline: none; border-color: var(--viola); }
.hostpoint-form .field-row { display: flex; gap: 10px; }

/* Banner "carica messaggi precedenti" in cima alla chat */
.chat-load-more {
  align-self: center; margin: 6px 0 4px;
  padding: 6px 14px; font-size: 12px;
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: 999px; color: var(--text-secondary); cursor: pointer;
  font-family: inherit;
}
.chat-load-more:hover { border-color: var(--viola); color: var(--viola); }

/* Riga azioni sotto la chat: Annulla a sinistra, Pubblica a destra */
.chat-actions {
  padding: 8px 12px 10px;
  display: flex; align-items: center; gap: 12px;
  border-top: 1px solid var(--border-color); background: var(--bg-card);
}
.chat-actions .btn-link { font-size: 12px; }

.btn-publish {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--viola), var(--magenta));
  color: #fff; border: 0; border-radius: var(--radius-md);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: filter var(--transition);
}
.btn-publish:hover:not(:disabled) { filter: brightness(1.08); }
.btn-publish:disabled {
  opacity: .55; cursor: not-allowed; filter: grayscale(.2);
}
.btn-publish.is-configure {
  background: var(--bg-section);
  color: var(--viola);
  border: 1px solid rgba(157,78,221,.4);
}
.btn-publish.is-configure:hover {
  background: rgba(157,78,221,.1);
  border-color: var(--viola);
}
